mainPanel.add(splitPane); DefaultMutableTreeNode treeRootNode = new DefaultMutableTreeNode(NLS.str("msg.open_file")); treeModel = new DefaultTreeModel(treeRootNode); tree = new JTree(treeModel); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { leftPane.add(new JScrollPane(tree), BorderLayout.CENTER); leftPane.add(progressPane, BorderLayout.PAGE_END); splitPane.setLeftComponent(leftPane);
@Override public void valueChanged(TreeSelectionEvent e) { if (e.getNewLeadSelectionPath() != null) { ASTTreeNode astTreeNode = (ASTTreeNode) e.getNewLeadSelectionPath().getLastPathComponent(); DefaultMutableTreeNode symbolTableTreeNode = new DefaultMutableTreeNode(); DefaultMutableTreeNode selectedAstTreeNode = new DefaultMutableTreeNode( "AST Node: " + astTreeNode.label()); symbolTableTreeNode.add(selectedAstTreeNode); for (int i = 0; i < scopes.size(); i++) { scope = scopes.get(i); DefaultMutableTreeNode scopeTreeNode = new DefaultMutableTreeNode( "Scope: " + scope.getClass().getSimpleName()); selectedAstTreeNode.add(scopeTreeNode); for (Map.Entry<NameDeclaration, List<NameOccurrence>> entry : scope.getDeclarations().entrySet()) { DefaultMutableTreeNode nameDeclarationTreeNode = new DefaultMutableTreeNode( entry.getKey().getClass().getSimpleName() + ": " + entry.getKey()); scopeTreeNode.add(nameDeclarationTreeNode); for (NameOccurrence nameOccurrence : entry.getValue()) { DefaultMutableTreeNode nameOccurranceTreeNode = new DefaultMutableTreeNode( "Name occurrence: " + nameOccurrence); nameDeclarationTreeNode.add(nameOccurranceTreeNode); DefaultMutableTreeNode attributesNode = new DefaultMutableTreeNode( "Attributes (accessible via XPath):"); selectedAstTreeNode.add(attributesNode); for (String attribute : attributes) { attributesNode.add(new DefaultMutableTreeNode(attribute));
private boolean checkChildren(DefaultMutableTreeNode parent, MixedCheckBox.MixedCheckBoxStatus status) { boolean childrenCheck = true; Enumeration children = parent.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); MixedCheckBox checkBox = (MixedCheckBox) child.getUserObject(); if (checkBox.getStatus() != status) { childrenCheck = false; break; } } return childrenCheck; }
private void addNode(DefaultMutableTreeNode level, PathElement element) { DefaultMutableTreeNode node = new DefaultMutableTreeNode(); node.setUserObject(element); level.add(node); }
private DefaultMutableTreeNode getLastChildNode(DefaultMutableTreeNode node) { if (node.getChildCount() != 0) { return (DefaultMutableTreeNode) node.getLastChild(); } return node; }
public Service getSelectedService() { DefaultMutableTreeNode node = getSelectedNode(); if (node == null || node.getUserObject() == null) return null; if (node.getUserObject() instanceof Service) return (Service)node.getUserObject(); DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode)node.getParent(); if (parentNode == null || parentNode.getUserObject() == null) return null; if (parentNode.getUserObject() instanceof Service) return (Service)parentNode.getUserObject(); return null; }
Enumeration e = root.breadthFirstEnumeration(); while(e.hasMoreElements()) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)e.nextElement(); if(node.isLeaf()) continue; int row = tree.getRowForPath(new TreePath(node.getPath())); (DefaultMutableTreeNode)dest.getLastPathComponent(); (DefaultMutableTreeNode)path.getLastPathComponent(); if(firstNode.getChildCount() > 0 && target.getLevel() < firstNode.getLevel()) { return false; int childCount = first.getChildCount(); if(first.isNodeChild(next)) { if(next.getLevel() < node.getLevel()) { break; } else if(next.getLevel() > node.getLevel()) { // child node copy.add(copy(next)); return new DefaultMutableTreeNode(node); model.removeNodeFromParent(nodesToRemove[i]); index = parent.getChildCount();
/** * @deprecated */ public void setAllDescendantsSelected() { Enumeration children = children(); while (children.hasMoreElements()) { CategoryNode node = (CategoryNode) children.nextElement(); node.setSelected(true); node.setAllDescendantsSelected(); } }
private void expandSubtree(TreePath path, boolean expand) { if (path == null) { TreePath selectionPath = getSelectionPath(); path = selectionPath == null ? new TreePath(treeModel.getRoot()) : selectionPath; } DefaultMutableTreeNode currentNode = (DefaultMutableTreeNode) path.getLastPathComponent(); Enumeration children = currentNode.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); TreePath expandedPath = path.pathByAddingChild(child); expandSubtree(expandedPath, expand); } if (expand) { expandPath(path); } else if (path.getParentPath() != null) { collapsePath(path); } }
/** move to the next node matching the search criterion */ public DefaultMutableTreeNode next() { DefaultMutableTreeNode current; while ((enume != null) && enume.hasMoreElements()) { current = (DefaultMutableTreeNode) enume.nextElement(); if ((current.getUserObject() != null) && current.getUserObject().toString().contains(searchValue)) { setVisible(current); return current; } } return null; }
@Override public void run() { try { Queue<DefaultMutableTreeNode> q = new LinkedList<>(); q.add(node); while (!q.isEmpty()) { final DefaultMutableTreeNode n = q.poll(); expand(n); @SuppressWarnings("unchecked") Enumeration<TreeNode> children = n.children(); while (children.hasMoreElements()) { DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); if (!child.isLeaf() && child.getChildCount() > 0) { q.offer(child); } } } } finally { executor.shutdownNow(); } } });
/** * Removes any inactive nodes from the Category tree. */ protected int removeUnusedNodes() { int count = 0; CategoryNode root = _categoryModel.getRootCategoryNode(); Enumeration enumeration = root.depthFirstEnumeration(); while (enumeration.hasMoreElements()) { CategoryNode node = (CategoryNode) enumeration.nextElement(); if (node.isLeaf() && node.getNumberOfContainedRecords() == 0 && node.getParent() != null) { _categoryModel.removeNodeFromParent(node); count++; } } return count; }
/** * returns null if no CategoryNode exists. */ public CategoryNode getCategoryNode(CategoryPath path) { CategoryNode root = (CategoryNode) getRoot(); CategoryNode parent = root; // Start condition. for (int i = 0; i < path.size(); i++) { CategoryElement element = path.categoryElementAt(i); // If the two nodes have matching titles they are considered equal. Enumeration children = parent.children(); boolean categoryAlreadyExists = false; while (children.hasMoreElements()) { CategoryNode node = (CategoryNode) children.nextElement(); String title = node.getTitle().toLowerCase(); String pathLC = element.getTitle().toLowerCase(); if (title.equals(pathLC)) { categoryAlreadyExists = true; // This is now the new parent node. parent = node; break; // out of the while, and back to the for(). } } if (categoryAlreadyExists == false) { return null; // Didn't find the Node. } } return (parent); }
public XMLTreeView(String deviceName, File url) throws MalformedURLException { JFrame frame = new JFrame("Object Tree Browser: [ " + deviceName + " ]"); frame.setSize(400,400); // file = File; frame.getContentPane().setLayout(new BorderLayout()); DefaultMutableTreeNode top = new DefaultMutableTreeNode(file); // DefaultMutableTreeNode top1 = new DefaultMutableTreeNode(url); saxTree = new SAXTreeBuilder(top); try { SAXParser saxParser = new SAXParser(); saxParser.setContentHandler(saxTree); // saxParser.parse(new InputSource(new FileInputStream(file))); saxParser.parse(new InputSource(new FileInputStream(url))); }catch(Exception ex){ top.add(new DefaultMutableTreeNode(ex.getMessage())); } JTree tree = new JTree(saxTree.getTree()); JScrollPane scrollPane = new JScrollPane(tree); frame.getContentPane().add("Center",scrollPane); frame.setVisible(true); }
public static void main(String[] params) { JFrame f = new JFrame(); f.setSize(new Dimension(500,500)); f.getContentPane().add(p); JCheckBoxTree cbt = new JCheckBoxTree(); cbt.setShowsRootHandles(true); JScrollPane scroll = new JScrollPane(); scroll.setViewportView(cbt); p.add(scroll, BorderLayout.CENTER); DefaultMutableTreeNode root = new DefaultMutableTreeNode("Tech"); DefaultMutableTreeNode db = new DefaultMutableTreeNode("Db"); root.add(db); db.add(new DefaultMutableTreeNode("HypersonicSQL")); db.add(new DefaultMutableTreeNode("MsSQL")); db.add(new DefaultMutableTreeNode("MySQL")); db.add(new DefaultMutableTreeNode("Oracle")); db.add(new DefaultMutableTreeNode("PostgreSQL")); DefaultMutableTreeNode os = new DefaultMutableTreeNode("OS"); root.add(os); os.add(new DefaultMutableTreeNode("Linux")); DefaultMutableTreeNode ws = new DefaultMutableTreeNode("WS"); root.add(ws); DefaultTreeModel model = new DefaultTreeModel(root); cbt.setModel(model);
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Media"); DefaultTreeModel treeModel = new DefaultTreeModel(rootNode); DefaultMutableTreeNode imageNode = new DefaultMutableTreeNode("Image"); rootNode.add(imageNode); columnNames = new String[]{"Input/Output", "Image File Suffixes"}; MediaData md = new MediaData( "Suffixes", columnNames, data); imageNode.add(new DefaultMutableTreeNode(md)); columnNames = new String[]{"Input/Output", "Image MIME Types"}; md = new MediaData( "MIME", columnNames, data); imageNode.add(new DefaultMutableTreeNode(md)); DefaultMutableTreeNode soundNode = new DefaultMutableTreeNode("Sound"); rootNode.add(soundNode); DefaultMutableTreeNode soundSampledNode = new DefaultMutableTreeNode("Sampled"); soundNode.add(soundSampledNode); soundSampledNode.add(new DefaultMutableTreeNode(md)); DefaultMutableTreeNode soundSampledMixersNode = new DefaultMutableTreeNode(md); soundSampledNode.add(soundSampledMixersNode); columnNames = new String[]{ "Input/Output", "Line Info" }; md = new MediaData(mixerInfo[ii].getName(), columnNames, data); DefaultMutableTreeNode soundSampledMixerNode = new DefaultMutableTreeNode(md); soundSampledMixersNode.add( soundSampledMixerNode );
@Override public void run() { final DefaultMutableTreeNode root = new DefaultMutableTreeNode("root"); final DefaultTreeModel model = new DefaultTreeModel(root); JFrame frame = new JFrame("Test"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); frame.getContentPane().add(new JScrollPane(new JTree(model))); frame.getContentPane().add(new JButton( new AbstractAction("Add thousand children") { @Override public void actionPerformed(ActionEvent e) { int offset = root.getChildCount() + 1; for (int i = 0; i < 1000; i++) { DefaultMutableTreeNode child = new DefaultMutableTreeNode( "Person " + (i + offset)); root.add(child); model.nodeStructureChanged(root);
DefaultMutableTreeNode top = new DefaultMutableTreeNode( new IconData(ICON_COMPUTER, null, "Computer")); node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k]))); top.add(node); node.add(new DefaultMutableTreeNode( new Boolean(true) )); Object obj = node.getUserObject(); if (obj instanceof IconData) obj = ((IconData)obj).getObject(); Object obj = node.getUserObject(); setText(obj.toString()); DefaultMutableTreeNode flag = (DefaultMutableTreeNode)parent.getFirstChild(); if (flag==null) // No flag return false; Object obj = flag.getUserObject(); if (!(obj instanceof Boolean)) return false; // Already expanded parent.removeAllChildren(); // Remove Flag IconData idata = new IconData(FileTreeViewer.ICON_FOLDER, FileTreeViewer.ICON_EXPANDEDFOLDER, nd); DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata); parent.add(node); node.add(new DefaultMutableTreeNode(
public void openFrame(String label, DefaultMutableTreeNode node) { node(node, label); root = new DefaultMutableTreeNode("Root"); root.add(node); JTree tree = new JTree(root); tree.setRootVisible(false); tree.addTreeWillExpandListener(this); JScrollPane pane = new JScrollPane(tree); //pane.setMinimumSize(new Dimension(300, 100)); JFrame frame = new JFrame("Object Inspector"); frame.setContentPane(pane); frame.setMinimumSize(new Dimension(600, 500)); frame.pack(); frame.setDefaultCloseOperation(frame.DISPOSE_ON_CLOSE); frame.setVisible(true); }
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root"); DefaultMutableTreeNode leaf = new DefaultMutableTreeNode("Leaf: " + s); root.add(leaf); JTree tree1 = new JTree(root); tree1.setFont(new Font("Lucida Sans", 0, 16)); JTree tree2 = new JTree(root); tree2.setFont(new Font("DejaVu Sans", 0, 16)); p.add(new JScrollPane(tree1)); p.add(new JScrollPane(tree2)); return p; JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(new Demo2().makeUI()); f.setSize(320, 240); f.setLocationRelativeTo(null);