@Override protected void showPopup (MouseEvent e) { int selRow = outline.rowAtPoint(e.getPoint()); if (selRow != -1) { if (! outline.getSelectionModel().isSelectedIndex(selRow)) { outline.getSelectionModel().clearSelection(); outline.getSelectionModel().setSelectionInterval(selRow, selRow); } } else { outline.getSelectionModel().clearSelection(); } Point p = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), OutlineView.this); if (isPopupAllowed()) { JPopupMenu pop = createPopup(p); OutlineView.this.showPopup(p.x, p.y, pop); e.consume(); } }
/** * Find relevant actions and call the factory to create a popup. */ private JPopupMenu createPopup(Point p) { int[] selRows = outline.getSelectedRows(); ArrayList<Node> al = new ArrayList<Node> (selRows.length); for (int i = 0; i < selRows.length; i++) { Node n = getNodeFromRow(selRows[i]); if (n != null) { al.add(n); } } Node[] arr = al.toArray (new Node[al.size ()]); if (arr.length == 0) { if (manager.getRootContext() != null) { // display the context menu of the root node JPopupMenu popup = manager.getRootContext().getContextMenu(); if (popup != null && popup.getSubElements().length > 0) { popupFactory.addNoFilterItem(outline, popup); return popup; } } // we'll have an empty popup } p = SwingUtilities.convertPoint(this, p, outline); int column = outline.columnAtPoint(p); int row = outline.rowAtPoint(p); return popupFactory.createPopupMenu(row, column, arr, outline); }
int getTreePreferredWidth() { //int ci = convertColumnIndexToView(0); Rectangle visibleRect = getVisibleRect(); int r1 = rowAtPoint(new Point(0, visibleRect.y)); if (r1 < 0) { return 0; } if (hScrollBar.isVisible()) { // To prevent from "dancing" include the width of the row(s) under the horizontal scroll bar as well. visibleRect.height += hScrollBar.getSize().height; } int r2 = rowAtPoint(new Point(0, visibleRect.y + visibleRect.height)); if (r2 < 0) r2 = getRowCount() - 1; if (r2 >= rowWidths.length) { // some rows were added, but not rendered yet, thus their width is unknown. r2 = rowWidths.length - 1; } int width = 0; for (int r = r1; r <= r2; r++) { if (rowWidths[r] > width) { width = rowWidths[r]; } } width += 2*getIntercellSpacing().width; return width; }