List of usage examples for javax.swing.tree TreePath getLastPathComponent
public Object getLastPathComponent()
From source file:it.unibas.spicygui.controllo.tree.ActionSelectionCondition.java
private void updateSelectionCondition(boolean oldButtonState, String oldSelectionCondition, SelectionConditionInfo selectionConditionInfo) { try {//from w w w.j a v a 2 s . c om INode iNode = getNodeSelected(); TreePath treePath = jTree.getSelectionPath(); DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent(); review.removeSelectionCondition(selectionConditionInfo.getSelectionCondition(), dataSource); creator.createSelectionCondition(iNode, selectionConditionInfo.getExpressionString(), dataSource, selectionConditionInfo); analisiSelection.creaWidgetEsisteSelectionCondition(treeNode, selectionConditionInfo.getExpressionString(), selectionConditionInfo.getSelectionCondition()); VMDPinWidget vMDPinWidget = (VMDPinWidget) iNode.getAnnotation(Costanti.PIN_WIDGET_TREE); vMDPinWidget.setToolTipText(selectionConditionInfo.getSelectionCondition().toString()); aggiorna(); } catch (ExpressionSyntaxException e) { creator.undo(selectionConditionInfo.getSelectionCondition(), dataSource); DialogDisplayer.getDefault() .notify(new NotifyDescriptor.Message( NbBundle.getMessage(Costanti.class, Costanti.SYNTAX_WARNING) + " : " + e.getMessage(), DialogDescriptor.WARNING_MESSAGE)); StatusDisplayer.getDefault() .setStatusText(NbBundle.getMessage(Costanti.class, Costanti.SYNTAX_WARNING)); ripristina(oldButtonState, oldSelectionCondition, selectionConditionInfo); } }
From source file:CheckBoxNodeTreeSample.java
public boolean isCellEditable(EventObject event) { boolean returnValue = false; if (event instanceof MouseEvent) { MouseEvent mouseEvent = (MouseEvent) event; TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); if (path != null) { Object node = path.getLastPathComponent(); if ((node != null) && (node instanceof DefaultMutableTreeNode)) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) node; Object userObject = treeNode.getUserObject(); returnValue = ((treeNode.isLeaf()) && (userObject instanceof CheckBoxNode)); }//www . java 2 s .c o m } } return returnValue; }
From source file:Main.java
@Override public boolean isCellEditable(final EventObject event) { Object source = event.getSource(); if (!(source instanceof JTree) || !(event instanceof MouseEvent)) { return false; }//from w ww.j ava2 s . c om JTree tree = (JTree) source; MouseEvent mouseEvent = (MouseEvent) event; TreePath path = tree.getPathForLocation(mouseEvent.getX(), mouseEvent.getY()); if (path == null) { return false; } Object node = path.getLastPathComponent(); if (node == null || !(node instanceof DefaultMutableTreeNode)) { return false; } Rectangle r = tree.getPathBounds(path); if (r == null) { return false; } Dimension d = panel.getPreferredSize(); r.setSize(new Dimension(d.width, r.height)); if (r.contains(mouseEvent.getX(), mouseEvent.getY())) { Point pt = SwingUtilities.convertPoint(tree, mouseEvent.getPoint(), panel); Object o = SwingUtilities.getDeepestComponentAt(panel, pt.x, pt.y); if (o instanceof JComboBox) { comboBox.showPopup(); } else if (o instanceof Component) { Object oo = SwingUtilities.getAncestorOfClass(JComboBox.class, (Component) o); if (oo instanceof JComboBox) { comboBox.showPopup(); } } return true; } return delegate.isCellEditable(event); }
From source file:pl.piotrsukiennik.jbrain.gui.JBrainMainFrame.java
private void leftColumnMenuValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_leftColumnMenuValueChanged TreePath newPath = evt.getNewLeadSelectionPath(); String lastComponent = (String) ((DefaultMutableTreeNode) newPath.getLastPathComponent()).getUserObject(); switch (lastComponent) { case "model": appController.displayModelManagement(); break;/*from w w w . ja v a 2s. co m*/ case "new simulation": appController.displayNewSimulation(); break; case "history": appController.displaySimulationHistory(); break; } }
From source file:TreeDragTest.java
private TreeNode getNodeForEvent(DropTargetDragEvent dtde) { Point p = dtde.getLocation(); DropTargetContext dtc = dtde.getDropTargetContext(); JTree tree = (JTree) dtc.getComponent(); TreePath path = tree.getClosestPathForLocation(p.x, p.y); return (TreeNode) path.getLastPathComponent(); }
From source file:ec.nbdemetra.ui.demo.ComponentsDemo.java
public ComponentsDemo() { initStaticResources();//w w w .j ava 2 s . co m final Map<Id, Component> demoData = lookupComponents(); final JPanel main = new JPanel(new BorderLayout()); final JTree tree = new JTree(); tree.setRootVisible(false); tree.setCellRenderer(new IdRenderer(demoData)); IdsTree.fill(tree, Lists.newArrayList(demoData.keySet())); expandAll(tree); tree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { TreePath p = tree.getSelectionPath(); if (p != null) { main.removeAll(); DefaultMutableTreeNode node = (DefaultMutableTreeNode) p.getLastPathComponent(); Id id = IdsTree.translate(node); Component c = demoData.get(id); main.add(c != null ? c : new JPanel()); main.validate(); main.repaint(); } } }); JTsList dragDrop = new JTsList(); dragDrop.setShowHeader(false); dragDrop.setInformation(new ITsList.InfoType[] { ITsList.InfoType.TsIdentifier, ITsList.InfoType.Data }); dragDrop.setPreferredSize(new Dimension(200, 200)); dragDrop.setTsAction(DemoTsActions.DO_NOTHING); JSplitPane left = NbComponents.newJSplitPane(JSplitPane.VERTICAL_SPLIT, NbComponents.newJScrollPane(tree), dragDrop); JSplitPane splitPane = NbComponents.newJSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, main); splitPane.getLeftComponent().setPreferredSize(new Dimension(200, 400)); setLayout(new BorderLayout()); add(splitPane, BorderLayout.CENTER); }
From source file:cz.lidinsky.editor.TableCellEditor.java
public void valueChanged(TreeSelectionEvent e) { TreePath selectedPath = e.getNewLeadSelectionPath(); if (selectedPath != null) selected = selectedPath.getLastPathComponent(); else/*from ww w . ja v a 2 s. c o m*/ selected = null; }
From source file:com.mirth.connect.client.ui.codetemplate.CodeTemplateTreeTableCellEditor.java
@Override public boolean stopCellEditing() { String value = (String) getCellEditorValue(); boolean valid = StringUtils.isNotBlank(value) && value.length() <= 255; if (valid) {//from ww w. j a v a 2s.c om int selectedRow = parent.getTreeTable().getSelectedRow(); if (selectedRow >= 0) { TreePath selectedPath = parent.getTreeTable().getPathForRow(selectedRow); if (selectedPath != null) { TreeTableNode selectedNode = (TreeTableNode) selectedPath.getLastPathComponent(); if (selectedNode instanceof CodeTemplateLibraryTreeTableNode) { for (Enumeration<? extends MutableTreeTableNode> libraries = ((MutableTreeTableNode) parent .getFullModel().getRoot()).children(); libraries.hasMoreElements();) { if (((CodeTemplateLibraryTreeTableNode) libraries.nextElement()).getLibrary().getName() .equals(value)) { valid = false; break; } } } else { CodeTemplateLibraryTreeTableNode libraryNode = (CodeTemplateLibraryTreeTableNode) selectedNode .getParent(); for (Enumeration<? extends MutableTreeTableNode> codeTemplates = libraryNode .children(); codeTemplates.hasMoreElements();) { CodeTemplateTreeTableNode codeTemplateNode = (CodeTemplateTreeTableNode) codeTemplates .nextElement(); if (codeTemplateNode.getCodeTemplate().getName().equals(value)) { valid = false; break; } } } } } } if (valid) { parent.setSaveEnabled(true); TreePath selectedPath = parent.getTreeTable().getTreeSelectionModel().getSelectionPath(); if (selectedPath != null && selectedPath.getLastPathComponent() instanceof CodeTemplateLibraryTreeTableNode) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { parent.updateLibrariesComboBox(); } }); } } else { super.cancelCellEditing(); } return super.stopCellEditing(); }
From source file:net.landora.animeinfo.notifications.NotificationViewer.java
private void treeItemsValueChanged(javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_treeItemsValueChanged List<Object> items = new ArrayList<Object>(); for (TreePath path : treeItems.getSelectionPaths()) { DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) (path.getLastPathComponent()); addChildren(treeNode, items);//from ww w . j a v a2 s. c om } setCurrentContext(items); }
From source file:FileTree3.java
DefaultMutableTreeNode getTreeNode(TreePath path) { return (DefaultMutableTreeNode) (path.getLastPathComponent()); }