Java Code Examples for javax.swing.JTree#getSelectionPath()
The following examples show how to use
javax.swing.JTree#getSelectionPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FmtSpaces.java From netbeans with Apache License 2.0 | 7 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER) { if (e.getSource() instanceof JTree) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if (toggle(path)) { e.consume(); } } } }
Example 2
Source File: SortTreeHelper.java From ISO8583 with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("rawtypes") public static void sortTree(PnlGuiConfig pnlGuiConfig, DefaultMutableTreeNode root, JTree treeTypes) { if (root != null) { Enumeration e = root.depthFirstEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.nextElement(); if (!node.isLeaf()) { sort(node); //selection sort } } //Atualizando a arvore if (updateTree) { TreePath treePath = treeTypes.getSelectionPath(); DefaultTreeModel model = (DefaultTreeModel) treeTypes.getModel(); model.reload(); treeTypes.setSelectionPath(treePath); updateTree = false; } } }
Example 3
Source File: CheckListener.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyChar() == ' ') { // NOI18N JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if (path == null) { return; } Node node = Visualizer.findNode(path.getLastPathComponent()); if (node == null) { return; } boolean isSelected = model.isNodeSelected(node); model.setNodeSelected(node, !isSelected); tree.repaint(); e.consume(); } }
Example 4
Source File: NodeSelectionListener.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { if (e.getSource() instanceof JTree) { JTree t = (JTree) e.getSource(); TreePath path = t.getSelectionPath(); if (path != null) { CheckNode node = (CheckNode) path.getLastPathComponent(); boolean isSelected = !(node.isSelected()); node.setSelected(isSelected); ((DefaultTreeModel) tree.getModel()).nodeChanged(node); tree.revalidate(); tree.repaint(); } e.consume(); } } }
Example 5
Source File: CheckListener.java From netbeans with Apache License 2.0 | 6 votes |
public void keyPressed(KeyEvent e) { if (e.getKeyChar() == ' ') { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if( null == path ) return; Node node = Visualizer.findNode( path.getLastPathComponent() ); if( null == node ) return; boolean isSelected = settings.isNodeVisible( node ); settings.setNodeVisible( node, !isSelected ); tree.repaint(); e.consume(); } }
Example 6
Source File: CheckTreeView.java From netbeans with Apache License 2.0 | 5 votes |
public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE ) { if ( e.getSource() instanceof JTree ) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if ( toggle( path )) { e.consume(); repaint(); //XXX } } } }
Example 7
Source File: SpellBooksTab.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
/** * Identify the current spell book, being the spell book that spells should * be added to. If no books exist then return an empty string. * * @return The name of the 'current' spell book, or empty string if none * exist. */ String getCurrentSpellBookName() { String spellList = ""; Object selectedObject = selectedTable.getSelectedObject(); if (selectedObject != null) { if (selectedObject instanceof SpellNode) { spellList = ((SpellNode) selectedObject).getRootNode().getName(); } else if (selectedObject instanceof RootNode) { spellList = ((RootNode) selectedObject).getName(); } else { JTree tree = selectedTable.getTree(); TreePath path = tree.getSelectionPath(); while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) { path = path.getParentPath(); } spellList = path.getLastPathComponent().toString(); } } if (StringUtils.isEmpty(spellList)) { ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel(); if (!data.isEmpty()) { Object firstElem = data.getElementAt(0); if (firstElem instanceof SpellNode) { spellList = ((SpellNode) firstElem).getRootNode().getName(); } } } return spellList; }
Example 8
Source File: CTaggingFunctions.java From binnavi with Apache License 2.0 | 5 votes |
/** * Returns the currently selected tag of a tags tree. * * @param tagsTree The tags tree. * * @return The currently selected tag. * * @throws MaybeNullException Thrown if no tag is selected. */ public static CTag getSelectedTag(final JTree tagsTree) throws MaybeNullException { final TreePath selectionPath = tagsTree.getSelectionPath(); if (selectionPath != null && selectionPath.getLastPathComponent() instanceof CTagTreeNode && selectionPath.getLastPathComponent() instanceof CTagTreeNode) { final CTagTreeNode ttn = (CTagTreeNode) selectionPath.getLastPathComponent(); return ttn.getTag().getObject(); } throw new MaybeNullException(); }
Example 9
Source File: PlotConfigurationTreeTransferHandler.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
@Override public Transferable createTransferable(JComponent c) { JTree tree = (JTree) c; TreePath selectionPath = tree.getSelectionPath(); Object lastPathComponent = selectionPath.getLastPathComponent(); Transferable t = null; if (lastPathComponent instanceof ValueSourceTreeNode) { t = (ValueSourceTreeNode) lastPathComponent; } else if (lastPathComponent instanceof RangeAxisConfigTreeNode) { t = (RangeAxisConfigTreeNode) lastPathComponent; } return t; }
Example 10
Source File: GUIBrowser.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private TreePath getSelectionPath() { JTree tree = getSelectedTree(); if (tree != null) { return tree.getSelectionPath(); } else { return null; } }
Example 11
Source File: RevertDeletedAction.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { int keyCode = e.getKeyCode(); if (keyCode == KeyEvent.VK_SPACE) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if (path != null) { FileNode node = (FileNode) path.getLastPathComponent(); node.setSelected(!node.isSelected()); tree.repaint(); e.consume(); } } }
Example 12
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 5 votes |
public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { if ( e.getSource() instanceof JTree ) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if ( toggle( path )) { e.consume(); } } } }
Example 13
Source File: MenuEditor.java From jclic with GNU General Public License v2.0 | 5 votes |
public boolean createNewMenu(int index, boolean prompt, Component dlgParent) { boolean result = false; ProjectLibrary pl = getProjectLibrary(); if (pl != null) { JTree ct = getCurrentTree(); TreePath savePath = null; if (ct != null) savePath = ct.getSelectionPath(); Menu nm = new Menu(pl); nm.name = Long.toString(System.currentTimeMillis()); MenuEditor med = (MenuEditor) nm.getEditor(null); med.setDescription(getOptions().getMsg("menu_newMenuName")); if (prompt) { result = med.createEditorPanel(getOptions()).showDialog(med, "menu_newMenuElement_caption", dlgParent, true); } else { result = true; } if (result) { result = insertEditor(med, true, index, true); } else if (savePath != null && ct != null) { ct.clearSelection(); ct.setSelectionPath(savePath); } } return result; }
Example 14
Source File: FmtSpaces.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER ) { if ( e.getSource() instanceof JTree ) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if ( toggle( path )) { e.consume(); } } } }
Example 15
Source File: DnDTree.java From netbeans-mmd-plugin with Apache License 2.0 | 5 votes |
@Override public void dragGestureRecognized(@Nonnull final DragGestureEvent dragGestureEvent) { final JTree tree = (JTree) dragGestureEvent.getComponent(); final TreePath path = tree.getSelectionPath(); if (path != null) { final Object selection = path.getLastPathComponent(); if (selection instanceof NodeFileOrFolder) { FileTransferable node = new FileTransferable(Arrays.asList(((NodeFileOrFolder) selection).makeFileForNode())); dragGestureEvent.startDrag(DragSource.DefaultCopyDrop, node, this); } } }
Example 16
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER ) { if ( e.getSource() instanceof JTree ) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if ( toggle( path )) { e.consume(); } } } }
Example 17
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_SPACE) { if ( e.getSource() instanceof JTree ) { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if ( toggle( path )) { e.consume(); } } } }
Example 18
Source File: CheckNodeListener.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void keyPressed(KeyEvent e) { if (e.getKeyChar() == ' ') { JTree tree = (JTree) e.getSource(); TreePath path = tree.getSelectionPath(); if (path != null) { CheckNode node = (CheckNode) path.getLastPathComponent(); node.setSelected(!node.isSelected()); tree.repaint(); e.consume(); } } }
Example 19
Source File: SpellsPreparedTab.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
/** * Identify the current spell list, being the spell list that spell should * be added to. If no lists exist then a default one will be created. * * @param character The character qwe are checking for. * @return The name of the 'current' spell list. */ String getCurrentSpellListName(CharacterFacade character) { String spellList = ""; Object selectedObject = selectedTable.getSelectedObject(); if (selectedObject != null) { if (selectedObject instanceof SpellNode) { spellList = ((SpellNode) selectedObject).getRootNode().toString(); } else { JTree tree = selectedTable.getTree(); TreePath path = tree.getSelectionPath(); while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) { path = path.getParentPath(); } spellList = path.getLastPathComponent().toString(); } } if (StringUtils.isEmpty(spellList)) { spellList = spellListField.getText(); } if (StringUtils.isEmpty(spellList)) { ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel(); if (!data.isEmpty()) { Object firstElem = data.getElementAt(0); if (firstElem instanceof SpellNode) { spellList = ((SpellNode) firstElem).getRootNode().toString(); } } } if (StringUtils.isEmpty(spellList)) { // No lists exist, so create a default one! spellList = "Prepared Spells"; character.getSpellSupport().addSpellList(spellList); } return spellList; }
Example 20
Source File: SpellsPreparedTab.java From pcgen with GNU Lesser General Public License v2.1 | 4 votes |
/** * Identify the current spell list, being the spell list that spell should * be added to. If no lists exist then a default one will be created. * * @param character The character qwe are checking for. * @return The name of the 'current' spell list. */ String getCurrentSpellListName(CharacterFacade character) { String spellList = ""; Object selectedObject = selectedTable.getSelectedObject(); if (selectedObject != null) { if (selectedObject instanceof SpellNode) { spellList = ((SpellNode) selectedObject).getRootNode().toString(); } else { JTree tree = selectedTable.getTree(); TreePath path = tree.getSelectionPath(); while (path.getParentPath() != null && (path.getParentPath().getParentPath() != null)) { path = path.getParentPath(); } spellList = path.getLastPathComponent().toString(); } } if (StringUtils.isEmpty(spellList)) { spellList = spellListField.getText(); } if (StringUtils.isEmpty(spellList)) { ListFacade<?> data = selectedTable.getTreeViewModel().getDataModel(); if (!data.isEmpty()) { Object firstElem = data.getElementAt(0); if (firstElem instanceof SpellNode) { spellList = ((SpellNode) firstElem).getRootNode().toString(); } } } if (StringUtils.isEmpty(spellList)) { // No lists exist, so create a default one! spellList = "Prepared Spells"; character.getSpellSupport().addSpellList(spellList); } return spellList; }