/** * 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); }
@Override @SuppressWarnings("unchecked") public boolean editCellAt(int row, int column, EventObject e) { Object o = getValueAt(row, column); if (o instanceof Node.Property) { // && (e == null || e instanceof KeyEvent)) { Node.Property p = (Node.Property)o; if (p.getValueType() == Boolean.class || p.getValueType() == Boolean.TYPE) { PropertiesRowModel.toggleBooleanProperty(p); Rectangle r = getCellRect(row, column, true); repaint (r.x, r.y, r.width, r.height); return false; boolean isTreeColumn = convertColumnIndexToModel(column) == 0; if (isTreeColumn && row != -1 && e instanceof MouseEvent && SwingUtilities.isLeftMouseButton ((MouseEvent) e)) { int clickCount = ((MouseEvent) e).getClickCount(); final Rectangle r = getCellRect(row, column, true); MouseEvent me = (MouseEvent) e; me.translatePoint(treePositionX, 0);
private void revalidateScrollBar() { if (!isDisplayable()) { return; } if (!isTreeHScrollBar) { return ; } if ( (outline.getColumnModel().getColumnCount() > 0) ) { int column = outline.convertColumnIndexToView(0); int extentWidth = outline.getColumnModel().getColumn(column).getWidth(); int maxWidth = outline.getTreePreferredWidth(); int positionX = outline.getTreePositionX(); int value = Math.max(0, Math.min(positionX, maxWidth - extentWidth)); hScrollBar.setValues(value, extentWidth, 0, maxWidth); hScrollBar.setBlockIncrement(extentWidth); } }
@Override public void layoutContainer(Container parent) { OutlineView ov = (OutlineView) parent; if (ov.isTreeHScrollBar && ov.outline.getColumnModel().getColumnCount() > 0) { int column = ov.outline.convertColumnIndexToView(0); int extentWidth = ov.outline.getColumnModel().getColumn(column).getWidth(); int maxWidth = ov.outline.getTreePreferredWidth(); boolean hsbvisible = thsb.isVisible(); boolean hideHsb = (maxWidth <= extentWidth) && ov.treeHorizontalScrollBarPolicy != JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS;
rowModel = new PropertiesRowModel(); model = createOutlineModel(treeModel, rowModel, nodesColumnLabel); outline = new OutlineViewOutline(model, rowModel); TableQuickSearchSupport tqss = outline.createDefaultTableQuickSearchSupport(); attachQuickSearch(tqss, false, tqss.createSearchPopupMenu()); outline.addKeyListener(qsKeyListener); rowModel.setOutline(outline); outline.setRenderDataProvider(new NodeRenderDataProvider(outline)); SheetCell tableCell = new SheetCell.OutlineSheetCell(outline); outline.setDefaultRenderer(Node.Property.class, tableCell); outline.setDefaultEditor(Node.Property.class, tableCell); outline.setRequestFocusEnabled(true); java.awt.Color c = javax.swing.UIManager.getColor("Table.background1"); if (c == null) { outline.registerKeyboardAction( defaultTreeActionListener, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0, false), JComponent.WHEN_FOCUSED ); final Color focusSelectionBackground = outline.getSelectionBackground(); final Color focusSelectionForeground = outline.getSelectionForeground(); outline.addFocusListener(new java.awt.event.FocusListener(){ @Override public void focusGained(java.awt.event.FocusEvent ev) { TableColumnSelector tcs = Lookup.getDefault ().lookup (TableColumnSelector.class); if (tcs != null) {
/** * Tries to expand nodes selected in the explorer manager. */ private void expandSelection() { Node[] arr = manager.getSelectedNodes (); for (int i = 0; i < arr.length; i++) { if ( (arr[i].getParentNode() == null) && (! outline.isRootVisible())) { // don't try to show root if it is invisible continue; } TreeNode tn = Visualizer.findVisualizer(arr[i]); if (tn != null) { ArrayList<TreeNode> al = new ArrayList<TreeNode> (); while (tn != null) { al.add(tn); tn = tn.getParent(); } Collections.reverse(al); TreePath tp = new TreePath(al.toArray()); while ((tp != null) && (tp.getPathCount() > 0)) { tp = tp.getParentPath(); if (tp != null) { outline.expandPath(tp); } } } } }
public OutlineViewOutline(final OutlineModel mdl, PropertiesRowModel rowModel) { super(mdl); this.rowModel = rowModel; setSelectVisibleColumnsLabel(NbBundle.getMessage(OutlineView.class, "CTL_ColumnsSelector")); //NOI18N // fix for #198694 // default action map for JTable defines these shortcuts // but we use our own mechanism for handling them // following lines disable default L&F handling (if it is // defined on Ctrl-c, Ctrl-v and Ctrl-x) removeDefaultCutCopyPaste(getInputMap(WHEN_FOCUSED)); removeDefaultCutCopyPaste(getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)); KeyStroke ctrlSpace; if (Utilities.isMac()) { ctrlSpace = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, KeyEvent.META_MASK, false); } else { ctrlSpace = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, KeyEvent.CTRL_DOWN_MASK, false); } Object ctrlSpaceActionBind = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).get(ctrlSpace); if (ctrlSpaceActionBind != null) { getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(ctrlSpace, "invokeCustomEditor"); //NOI18N Action invokeCustomEditorAction = new InvokeCustomEditorAction(ctrlSpaceActionBind); getActionMap().put("invokeCustomEditor", invokeCustomEditorAction); } }
/** Enable/disable displaying popup menus on tree view items. * Default is enabled. * @param value <code>true</code> to enable */ public void setPopupAllowed (boolean value) { if (popupListener == null && value) { // on popupListener = new PopupAdapter (); outline.addMouseListener (popupListener); addMouseListener(popupListener); return; } if (popupListener != null && !value) { // off outline.removeMouseListener (popupListener); removeMouseListener (popupListener); popupListener = null; return; } }
/** * Set whether the quick search feature is enabled or not. * @since 6.43 * @param allowedQuickSearch <code>true</code> if quick search shall be enabled */ public void setQuickSearchAllowed(boolean allowedQuickSearch) { if (allowedQuickSearch == isQuickSearchAllowed()) { return; } quickSearch.setEnabled(allowedQuickSearch); if (allowedQuickSearch) { outline.addKeyListener(qsKeyListener); } else { outline.removeKeyListener(qsKeyListener); } }
@Override public void actionPerformed(ActionEvent e) { if (!openCustomEditor(e)) { Action a = getActionMap().get(delegateActionBind); if (a != null && a.isEnabled()) { a.actionPerformed(e); } } }
private Action getCopyActionDelegate(InputMap map, KeyStroke ks) { ActionMap am = getActionMap(); if(map != null && am != null && isEnabled()) { Object binding = map.get(ks); final Action action = (binding == null) ? null : am.get(binding); if (action != null) { return new CopyToClipboardAction(action); } } return null; }
/** * */ Node getNodeFromRow(int rowIndex) { int row = outline.convertRowIndexToModel(rowIndex); TreePath tp = outline.getLayoutCache().getPathForRow(row); if (tp == null) { return null; } return Visualizer.findNode(tp.getLastPathComponent()); }
/** Translate the tree column renderer */ @Override public TableCellRenderer getCellRenderer(int row, int column) { TableCellRenderer result = super.getCellRenderer(row, column); if (isHScrollingEnabled) { int c = convertColumnIndexToModel(column); if (c == 0) { result = new TranslatedTableCellRenderer(this, result); } } return result; }
private void putActionDelegate(InputMap map, KeyStroke ks) { String binding = COPY_ACTION_DELEGATE+ks.toString(); Action action = getCopyActionDelegate(map, ks); if (action != null) { getActionMap().put(binding, action); map.put(ks, binding); } }