List of usage examples for javax.swing.tree TreePath getLastPathComponent
public Object getLastPathComponent()
From source file:edu.mbl.jif.datasetconvert.CheckboxTreeDimensions.java
/** * Initialize the tree.//from w w w .j av a 2 s . c o m * */ private JScrollPane getCheckboxTree() { if (this.checkboxTree == null) { this.checkboxTree = new CheckboxTree(getDimensionsTreeModel(sumMD)); //this.checkboxTree.addKeyListener(new RefreshListener()); System.out.println(this.checkboxTree.toString()); this.checkboxTree.getCheckingModel().setCheckingMode(TreeCheckingModel.CheckingMode.PROPAGATE); this.checkboxTree.setRootVisible(true); this.checkboxTree.setEnabled(true); this.checkboxTree.expandAll(); DefaultMutableTreeNode mn = (DefaultMutableTreeNode) this.checkboxTree.getModel().getRoot(); // mn = (DefaultMutableTreeNode) mn.getChildAt(2); // mn = (DefaultMutableTreeNode) mn.getChildAt(2); // System.out.println("row number: " + this.checkboxTree.getRowForPath(new TreePath(mn.getPath()))); this.checkboxTree.addCheckingPath(new TreePath(mn.getPath())); this.checkboxTree.addTreeCheckingListener(new TreeCheckingListener() { public void valueChanged(TreeCheckingEvent e) { System.out.println("checking set changed, leading path: " + ((TreeNode) e.getPath().getLastPathComponent()).toString()); System.out.println("checking roots: "); TreePath[] cr = CheckboxTreeDimensions.this.checkboxTree.getCheckingRoots(); for (TreePath path : cr) { System.out.println(path.getLastPathComponent()); } System.out.println("\nPaths: "); TreePath[] cp = CheckboxTreeDimensions.this.checkboxTree.getCheckingPaths(); for (TreePath path : cp) { System.out.println(path.toString()); } } }); } return new JScrollPane(this.checkboxTree); }
From source file:de.hsos.ecs.richwps.wpsmonitor.boundary.gui.controls.datasource.WpsDialog.java
private Map<URL, WpsDescription> assignSelectionsToMap(final TreePath[] selections) { Map<URL, WpsDescription> wpsDescriptions = new HashMap<>(); for (TreePath p : selections) { if (p.getLastPathComponent() instanceof WpsTreeNode) { WpsTreeNode node = (WpsTreeNode) p.getLastPathComponent(); WpsTreeNode wps;/*from w w w . ja v a 2s. c o m*/ if (node.getType() == WpsTreeNode.NodeType.PROCESS) { wps = (WpsTreeNode) node.getParent(); } else { wps = node; } WpsDescription wpsDesc; if (node.getType() == WpsTreeNode.NodeType.WPS) { wpsDesc = wps.getDescription(); } else { WpsDescription tmpDesc = wps.getDescription(); wpsDesc = new WpsDescription(tmpDesc.getEndpoint()); } if (!wpsDescriptions.containsKey(wpsDesc.getEndpoint())) { wpsDescriptions.put(wpsDesc.getEndpoint(), wpsDesc); } if (node.getType() == WpsTreeNode.NodeType.PROCESS) { WpsProcessDescription processDesc = node.getDescription(); wpsDescriptions.get(wpsDesc.getEndpoint()).add(processDesc); } } } return wpsDescriptions; }
From source file:de.hsos.ecs.richwps.wpsmonitor.boundary.gui.elements.datasource.WpsDialog.java
private Map<String, WpsDescription> assignSelectionsToMap(final TreePath[] selections) { Map<String, WpsDescription> wpsDescriptions = new HashMap<>(); for (TreePath p : selections) { if (p.getLastPathComponent() instanceof WpsTreeNode) { WpsTreeNode node = (WpsTreeNode) p.getLastPathComponent(); WpsTreeNode wps;// w w w.ja v a 2 s .c om if (node.getType() == WpsTreeNode.NodeType.PROCESS) { wps = (WpsTreeNode) node.getParent(); } else { wps = node; } WpsDescription wpsDesc; if (node.getType() == WpsTreeNode.NodeType.WPS) { wpsDesc = wps.getDescription(); } else { WpsDescription tmpDesc = wps.getDescription(); wpsDesc = new WpsDescription(tmpDesc.getIdentifier(), tmpDesc.getUri()); } String identifier = wpsDesc.getIdentifier(); if (!wpsDescriptions.containsKey(identifier)) { wpsDescriptions.put(identifier, wpsDesc); } if (node.getType() == WpsTreeNode.NodeType.PROCESS) { WpsProcessDescription processDesc = node.getDescription(); wpsDescriptions.get(identifier).add(processDesc); } } } return wpsDescriptions; }
From source file:TreeDragTest.java
public void drop(DropTargetDropEvent dtde) { Point pt = dtde.getLocation(); DropTargetContext dtc = dtde.getDropTargetContext(); JTree tree = (JTree) dtc.getComponent(); TreePath parentpath = tree.getClosestPathForLocation(pt.x, pt.y); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) parentpath.getLastPathComponent(); if (parent.isLeaf()) { dtde.rejectDrop();//w w w. j a v a2s .c o m return; } try { Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (int i = 0; i < flavors.length; i++) { if (tr.isDataFlavorSupported(flavors[i])) { dtde.acceptDrop(dtde.getDropAction()); TreePath p = (TreePath) tr.getTransferData(flavors[i]); DefaultMutableTreeNode node = (DefaultMutableTreeNode) p.getLastPathComponent(); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.insertNodeInto(node, parent, 0); dtde.dropComplete(true); return; } } dtde.rejectDrop(); } catch (Exception e) { e.printStackTrace(); dtde.rejectDrop(); } }
From source file:DynamicTreeDemo.java
/** Remove the currently selected node. */ public void removeCurrentNode() { TreePath currentSelection = tree.getSelectionPath(); if (currentSelection != null) { DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) (currentSelection.getLastPathComponent()); MutableTreeNode parent = (MutableTreeNode) (currentNode.getParent()); if (parent != null) { treeModel.removeNodeFromParent(currentNode); return; }//www . j a v a 2 s . co m } // Either there was no selection, or the root was selected. toolkit.beep(); }
From source file:cz.lidinsky.editor.Editor.java
/** * Add a link component -> tree to each new node. * And select last inserted node./*from www. j a v a 2 s . co m*/ */ public void treeNodesInserted(TreeModelEvent e) { // add a link component -> tree TreePath parentPath = e.getTreePath(); Node<GuiObject> parent = (Node<GuiObject>) parentPath.getLastPathComponent(); int[] indexes = e.getChildIndices(); for (int i : indexes) { Node<GuiObject> child = parent.getChild(i); setComponent2TreeLink(child); } // select last inserted node Node<GuiObject> child = parent.getChild(indexes[indexes.length - 1]); guiStructureTree.setSelectionPath(parentPath.pathByAddingChild(child)); }
From source file:DynamicTreeDemo.java
/** Add child to the currently selected node. */ public DefaultMutableTreeNode addObject(Object child) { DefaultMutableTreeNode parentNode = null; TreePath parentPath = tree.getSelectionPath(); if (parentPath == null) { parentNode = rootNode;// w w w. j a v a 2 s. c o m } else { parentNode = (DefaultMutableTreeNode) (parentPath.getLastPathComponent()); } return addObject(parentNode, child, true); }
From source file:ClassTree.java
public ClassTreeFrame() { setTitle("ClassTree"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // the root of the class tree is Object root = new DefaultMutableTreeNode(java.lang.Object.class); model = new DefaultTreeModel(root); tree = new JTree(model); // add this class to populate the tree with some data addClass(getClass());//from w ww . j a va 2 s. co m // set up node icons ClassNameTreeCellRenderer renderer = new ClassNameTreeCellRenderer(); renderer.setClosedIcon(new ImageIcon("red-ball.gif")); renderer.setOpenIcon(new ImageIcon("yellow-ball.gif")); renderer.setLeafIcon(new ImageIcon("blue-ball.gif")); tree.setCellRenderer(renderer); // set up selection mode tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent event) { // the user selected a different node--update description TreePath path = tree.getSelectionPath(); if (path == null) return; DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); Class<?> c = (Class<?>) selectedNode.getUserObject(); String description = getFieldDescription(c); textArea.setText(description); } }); int mode = TreeSelectionModel.SINGLE_TREE_SELECTION; tree.getSelectionModel().setSelectionMode(mode); // this text area holds the class description textArea = new JTextArea(); // add tree and text area JPanel panel = new JPanel(); panel.setLayout(new GridLayout(1, 2)); panel.add(new JScrollPane(tree)); panel.add(new JScrollPane(textArea)); add(panel, BorderLayout.CENTER); addTextField(); }
From source file:com.frostwire.gui.library.LibraryFilesTransferHandler.java
private LibraryNode getNodeFromLocation(DropLocation location) { TreePath path = tree.getUI().getClosestPathForLocation(tree, location.getDropPoint().x, location.getDropPoint().y);/*w w w . j a v a2s . com*/ return path != null ? (LibraryNode) path.getLastPathComponent() : null; }
From source file:de.codesourcery.eve.skills.ui.components.impl.BlueprintChooserComponent.java
protected void treeNodeSelected(TreePath path) { final ITreeNode node = (ITreeNode) path.getLastPathComponent(); final Blueprint bp = getSelectedBlueprint(node); if (bp != null) { listenerHelper.selectionChanged(bp); }//from w w w .ja va 2 s. com }