List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:EditableTree.java
public DefaultMutableTreeNode searchNode(String nodeStr) { DefaultMutableTreeNode node = null; Enumeration e = m_rootNode.breadthFirstEnumeration(); while (e.hasMoreElements()) { node = (DefaultMutableTreeNode) e.nextElement(); if (nodeStr.equals(node.getUserObject().toString())) { return node; }//from ww w . j a va 2 s . co m } return null; }
From source file:MyTreeModelListener.java
public void treeNodesChanged(TreeModelEvent e) { DefaultMutableTreeNode node; node = (DefaultMutableTreeNode) (e.getTreePath().getLastPathComponent()); try {/*from w ww . ja va2 s. co m*/ int index = e.getChildIndices()[0]; node = (DefaultMutableTreeNode) (node.getChildAt(index)); } catch (NullPointerException exc) { } System.out.println("New value: " + node.getUserObject()); }
From source file:TreeUtil.java
/** Creates the menus by using recursion */ public JMenuItem getMenus(DefaultMutableTreeNode node, JMenu parentMenu) { String name = node.getUserObject().toString(); int numChild = node.getChildCount(); if (numChild < 1) { JMenuItem tempMenu = new JMenuItem(name); tempMenu.setActionCommand(parentMenu.getActionCommand() + "." + name); tempMenu.addActionListener(this); return tempMenu; }/*from w w w.j a v a 2 s. co m*/ JMenu tempMenu = new JMenu(name); tempMenu.setActionCommand(parentMenu.getActionCommand() + "." + name); tempMenu.addActionListener(this); for (int i = 0; i < numChild; i++) { tempMenu.add(getMenus((DefaultMutableTreeNode) node.getChildAt(i), tempMenu)); } return tempMenu; }
From source file:it.unibas.spicygui.vista.listener.ConstraintColoringTreeSelectionListener.java
public void valueChanged(TreeSelectionEvent e) { JTree albero = (JTree) e.getSource(); DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) albero.getLastSelectedPathComponent(); if (treeNode == null) { return;//from w w w. ja v a2 s . co m } TreeNodeAdapter adapter = (TreeNodeAdapter) treeNode.getUserObject(); INode node = adapter.getINode(); analyzeConnectionConstraints(node); analyzeJoinConditions(node); analyzeConnections(node); }
From source file:org.freeinternals.javaclassviewer.ui.JSplitPaneClassFile.java
private void jTreeClassFileSelectionChanged(final TreeSelectionEvent evt) { Object obj = evt.getPath().getLastPathComponent(); if (obj instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode objDmtn = (DefaultMutableTreeNode) obj; obj = objDmtn.getUserObject(); if (obj instanceof JTreeNodeClassComponent) { final JTreeNodeClassComponent objTncc = (JTreeNodeClassComponent) obj; // Select the bytes of this data this.binaryViewer.setSelection(objTncc.getStartPos(), objTncc.getLength()); // clear opcode values; this.opcode.setText(null); // Get the code bytes if (objTncc.getText().equals("code")) { // System.out.println("code"); final byte[] data = this.classFile.getClassByteArray(objTncc.getStartPos(), objTncc.getLength()); this.generateOpcodeParseResult(data); }/*from w ww . j a v a 2s. co m*/ } } }
From source file:net.sf.housekeeper.swing.CategoriesView.java
protected JComponent createControl() { tree = new JTree(); tree.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); final BeanTreeCellRenderer renderer = new BeanTreeCellRenderer(Category.class, "name"); renderer.setOpenIcon(null);/*from w w w . j a v a 2 s .c om*/ renderer.setClosedIcon(null); renderer.setLeafIcon(null); tree.setCellRenderer(renderer); tree.setRootVisible(true); tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) return; Object nodeInfo = node.getUserObject(); Category cat = (Category) nodeInfo; publishSelectionEvent(cat); } }); refresh(); return tree; }
From source file:Exporters.SaveFileExporter.java
public void save(File outfile, DefaultMutableTreeNode root) throws Exception { System.out.println("===SaveFileExporter==save:" + outfile.getAbsolutePath()); // Create new XML document DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); // Create the root element Document doc = docBuilder.newDocument(); Element rootElement = doc.createElement("reportCompiler"); rootElement.setAttribute("date", getNow()); // Debugging to say when saved // TODO - figure out a universal means to get the current version of the generating tool // Initial thoughts would be to create a convenience class in Utils package with some // final variables that can be updated when issuing a release. doc.appendChild(rootElement);// w ww. ja v a 2s .co m Element vulnerabilitiesElement = doc.createElement("vulnerabilities"); Enumeration enums = root.children(); while (enums.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) enums.nextElement(); Object obj = node.getUserObject(); if (obj instanceof Vulnerability) { Vulnerability vuln = (Vulnerability) obj; Element vulnElement = getVulnAsElement(vuln, doc); if (vulnElement != null) { vulnerabilitiesElement.appendChild(vulnElement); } } } rootElement.appendChild(vulnerabilitiesElement); // now write the XML file // write the content into xml file TransformerFactory transformerFactory = TransformerFactory.newInstance(); Transformer transformer = transformerFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); DOMSource source = new DOMSource(doc); StreamResult result = new StreamResult(outfile); // Output to console for testing //StreamResult result = new StreamResult(System.out); transformer.transform(source, result); System.out.println("File saved!"); }
From source file:AncestorTree.java
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object obj = node.getUserObject(); setText(obj.toString());//from w ww .j ava 2 s . c o m if (obj instanceof IconData) { IconData idata = (IconData) obj; if (expanded) setIcon(idata.getOpenIcon()); else setIcon(idata.getIcon()); } else setIcon(null); setFont(tree.getFont()); setForeground(sel ? m_textSelectionColor : m_textNonSelectionColor); setBackground(sel ? m_bkSelectionColor : m_bkNonSelectionColor); m_selected = sel; return this; }
From source file:AncestorTree.java
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) { if (value instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object obj = node.getUserObject(); if (obj instanceof IconData) { IconData idata = (IconData) obj; m_item = idata;//from ww w . j a va2 s.co m // Reserve some more space... setText(idata.toString() + " "); setIcon(idata.m_icon); setFont(tree.getFont()); return this; } } // We don't support other objects... return null; }
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());/* w ww .j a va2s . c om*/ // 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(); }