javax.swing.tree.DefaultTreeModel Java Examples
The following examples show how to use
javax.swing.tree.DefaultTreeModel.
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: TreeUtil.java From Zettelkasten with GNU General Public License v3.0 | 6 votes |
/** * This method selects the first entry in a jTree that start with the text * that is entered in the filter-textfield. * * @param tree the jTree where the item should be selected * @param textfield the related filtertextfield that contains the user-input */ public static void selectByTyping(javax.swing.JTree tree, javax.swing.JTextField textfield) { DefaultTreeModel dtm = (DefaultTreeModel) tree.getModel(); MutableTreeNode root = (MutableTreeNode) dtm.getRoot(); String text = textfield.getText().toLowerCase(); if (root != null && !text.isEmpty()) { for (int cnt = 0; cnt < dtm.getChildCount(root); cnt++) { MutableTreeNode child = (MutableTreeNode) dtm.getChild(root, cnt); String childtext = child.toString().toLowerCase(); if (childtext.startsWith(text)) { TreePath tp = new TreePath(root); tp = tp.pathByAddingChild(child); tree.setSelectionPath(tp); tree.scrollPathToVisible(tp); return; } } } }
Example #2
Source File: MongoEditionPanel.java From nosql4idea with Apache License 2.0 | 6 votes |
public void addValue(Object value) { List<TreeNode> node = new LinkedList<TreeNode>(); NoSqlTreeNode parentNode = getParentNode(); NoSqlTreeNode treeNode = new NoSqlTreeNode(MongoValueDescriptor.createDescriptor(parentNode.getChildCount(), value)); if (value instanceof DBObject) { JsonTreeModel.processDbObject(treeNode, (DBObject) value); } node.add(treeNode); DefaultTreeModel treeModel = (DefaultTreeModel) editTableView.getTree().getModel(); TreeUtil.addChildrenTo(parentNode, node); treeModel.reload(parentNode); }
Example #3
Source File: XSheet.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Update the label of the supplied MBean tree node. */ // Call on EDT private void updateNotificationsNodeLabel( DefaultMutableTreeNode node, String label) { synchronized (mbeansTab.getTree()) { invalidate(); XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject(); XNodeInfo newUserObject = new XNodeInfo( oldUserObject.getType(), oldUserObject.getData(), label, oldUserObject.getToolTipText()); node.setUserObject(newUserObject); DefaultTreeModel model = (DefaultTreeModel) mbeansTab.getTree().getModel(); model.nodeChanged(node); validate(); repaint(); } }
Example #4
Source File: Test8015926.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example #5
Source File: ExcludeDependencyPanel.java From netbeans with Apache License 2.0 | 6 votes |
private void setReferenceTree(CheckNode mtb) { Artifact art = (Artifact) mtb.getUserObject(); if (modelCache.containsKey(art)) { trRef.setModel(modelCache.get(art)); } else { if (rootnode == null) { trRef.setModel(new DefaultTreeModel(new DefaultMutableTreeNode())); } else { DependencyExcludeNodeVisitor nv = new DependencyExcludeNodeVisitor(art.getGroupId(), art.getArtifactId(), art.getType()); rootnode.accept(nv); Set<DependencyNode> nds = nv.getDirectDependencies(); DefaultTreeModel dtm = new DefaultTreeModel(createReferenceModel(nds, mtb)); trRef.setModel(dtm); modelCache.put(art, dtm); } } }
Example #6
Source File: TemplateListPanel.java From consulo with Apache License 2.0 | 6 votes |
private void createTemplateEditor(final TemplateImpl template, String shortcut, Map<TemplateOptionalProcessor, Boolean> options, Map<TemplateContextType, Boolean> context) { myCurrentTemplateEditor = new LiveTemplateSettingsEditor(template, shortcut, options, context, new Runnable() { @Override public void run() { DefaultMutableTreeNode node = getNode(getSingleSelectedIndex()); if (node != null) { ((DefaultTreeModel)myTree.getModel()).nodeChanged(node); TemplateSettings.getInstance().setLastSelectedTemplate(template.getGroupName(), template.getKey()); } } }, TemplateSettings.getInstance().getTemplate(template.getKey(), template.getGroupName()) != null); for (Component component : myDetailsPanel.getComponents()) { if (component instanceof LiveTemplateSettingsEditor) { myDetailsPanel.remove(component); } } myDetailsPanel.add(myCurrentTemplateEditor, TEMPLATE_SETTINGS); }
Example #7
Source File: Model.java From Luyten with Apache License 2.0 | 6 votes |
public void closeFile() { for (OpenFile co : hmap) { int pos = house.indexOfTab(co.name); if (pos >= 0) house.remove(pos); co.close(); } final State oldState = state; Model.this.state = null; if (oldState != null) { Closer.tryClose(oldState); } hmap.clear(); tree.setModel(new DefaultTreeModel(null)); metadataSystem = new MetadataSystem(typeLoader); file = null; treeExpansionState = null; open = false; mainWindow.onFileLoadEnded(file, open); }
Example #8
Source File: XSheet.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
/** * Update the label of the supplied MBean tree node. */ // Call on EDT private void updateNotificationsNodeLabel( DefaultMutableTreeNode node, String label) { synchronized (mbeansTab.getTree()) { invalidate(); XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject(); XNodeInfo newUserObject = new XNodeInfo( oldUserObject.getType(), oldUserObject.getData(), label, oldUserObject.getToolTipText()); node.setUserObject(newUserObject); DefaultTreeModel model = (DefaultTreeModel) mbeansTab.getTree().getModel(); model.nodeChanged(node); validate(); repaint(); } }
Example #9
Source File: RTreeTest.java From marathonv5 with Apache License 2.0 | 6 votes |
public void singleNodeWithSpecialChars() throws Throwable, InvocationTargetException { final JTree tree = (JTree) ComponentUtils.findComponent(JTree.class, frame); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); siw(new Runnable() { @Override public void run() { DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); DefaultMutableTreeNode root = (DefaultMutableTreeNode) model.getRoot(); root.setUserObject("Root Node [] , / Special"); tree.expandRow(0); tree.setSelectionRow(0); } }); final LoggingRecorder lr = new LoggingRecorder(); siw(new Runnable() { @Override public void run() { Rectangle cb = tree.getPathBounds(tree.getPathForRow(0)); RTree rTree = new RTree(tree, null, new Point(cb.x + 2, cb.y + 2), lr); rTree.mouseButton1Pressed(null); } }); Call call = lr.getCall(); AssertJUnit.assertEquals("click", call.getFunction()); AssertJUnit.assertEquals("/Root Node [] , \\/ Special", call.getCellinfo()); }
Example #10
Source File: XSheet.java From hottub with GNU General Public License v2.0 | 6 votes |
/** * Update the label of the supplied MBean tree node. */ // Call on EDT private void updateNotificationsNodeLabel( DefaultMutableTreeNode node, String label) { synchronized (mbeansTab.getTree()) { invalidate(); XNodeInfo oldUserObject = (XNodeInfo) node.getUserObject(); XNodeInfo newUserObject = new XNodeInfo( oldUserObject.getType(), oldUserObject.getData(), label, oldUserObject.getToolTipText()); node.setUserObject(newUserObject); DefaultTreeModel model = (DefaultTreeModel) mbeansTab.getTree().getModel(); model.nodeChanged(node); validate(); repaint(); } }
Example #11
Source File: ClassTree.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
public ClassTree(JByteMod jam) { this.jbm = jam; this.setRootVisible(false); this.setShowsRootHandles(true); this.setCellRenderer(new TreeCellRenderer()); this.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { SortedTreeNode node = (SortedTreeNode) ClassTree.this.getLastSelectedPathComponent(); if (node == null) return; if (node.getCn() != null && node.getMn() != null) { jam.selectMethod(node.getCn(), node.getMn()); } else if (node.getCn() != null) { jam.selectClass(node.getCn()); } else { } } }); this.model = new DefaultTreeModel(new SortedTreeNode("")); this.setModel(model); this.setTransferHandler(new JarDropHandler(this, 0)); this.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); }
Example #12
Source File: Test8015926.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example #13
Source File: ProjectTree.java From TrakEM2 with GNU General Public License v3.0 | 6 votes |
/** Move up (-1) or down (1). */ private void move(final DefaultMutableTreeNode node, final int direction) { final ProjectThing pt = (ProjectThing)node.getUserObject(); if (null == pt) return; // Move: within the list of children of the parent ProjectThing: if (!pt.move(direction)) return; // If moved, reposition within the list of children final DefaultMutableTreeNode parent_node = (DefaultMutableTreeNode)node.getParent(); int index = parent_node.getChildCount() -1; ((DefaultTreeModel)this.getModel()).removeNodeFromParent(node); index = pt.getParent().getChildren().indexOf(pt); ((DefaultTreeModel)this.getModel()).insertNodeInto(node, parent_node, index); // restore selection path final TreePath trp = new TreePath(node.getPath()); this.scrollPathToVisible(trp); this.setSelectionPath(trp); this.updateUILater(); }
Example #14
Source File: KnowledgeViewPane.java From netbeans-mmd-plugin with Apache License 2.0 | 6 votes |
@Override public JComponent createComponent() { if (myComponent != null) { return myComponent; } DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(null); DefaultTreeModel treeModel = new DefaultTreeModel(rootNode); myTree = createTree(treeModel); enableDnD(); myComponent = ScrollPaneFactory.createScrollPane(myTree); myTreeStructure = createStructure(); setTreeBuilder(createBuilder(treeModel)); installComparator(); initTree(); return myComponent; }
Example #15
Source File: GeneratorLogPage.java From mobile-persistence with MIT License | 6 votes |
protected void logTree (final TreeNode node) { Runnable runner = new Runnable() { public void run() { setModel(new DefaultTreeModel(node)); getTree().expandPath(errorsPath); getTree().expandPath(runwarningsPath); getTree().expandPath(warningsPath); getTree().expandPath(informationPath); getTree().scrollRowToVisible(getTree().getRowCount()-1); } }; if (!SwingUtilities.isEventDispatchThread()) { SwingUtilities.invokeLater(runner); } else { runner.run(); } }
Example #16
Source File: JSONTree.java From rest-client with Apache License 2.0 | 6 votes |
/** * * @Title : JSONTree * @Description: Default constructor * @Param : */ public JSONTree() { super(new GridLayout(1, 0)); rootNode = new CheckBoxTreeNode(RESTConst.JSON); treeModel = new DefaultTreeModel(rootNode); tree = new JTree(treeModel); tree.setCellRenderer(new CheckBoxTreeCellRenderer()); tree.setEditable(false); tree.setToolTipText(RESTConst.EXCLUDE_NODE); tree.setShowsRootHandles(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.addMouseListener(ma); JScrollPane scrollPane = new JScrollPane(tree); this.add(scrollPane); this.initPopupMenu(); }
Example #17
Source File: NoSqlExplorerPanel.java From nosql4idea with Apache License 2.0 | 6 votes |
public void reloadAllServerConfigurations() { this.databaseVendorClientManager.cleanUpServers(); databaseTree.setRootVisible(false); List<ServerConfiguration> serverConfigurations = getServerConfigurations(); if (serverConfigurations.size() == 0) { databaseTree.setModel(null); return; } final DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(); databaseTree.setModel(new DefaultTreeModel(rootNode)); for (ServerConfiguration serverConfiguration : serverConfigurations) { DatabaseServer mongoServer = new DatabaseServer(serverConfiguration); this.databaseVendorClientManager.registerServer(mongoServer); DefaultMutableTreeNode serverNode = new DefaultMutableTreeNode(mongoServer); rootNode.add(serverNode); if (serverConfiguration.isConnectOnIdeStartup()) { this.reloadServerConfiguration(serverNode, false); } } TreeUtil.expand(databaseTree, 2); }
Example #18
Source File: LastNodeLowerHalfDrop.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
protected static TreeModel getTreeModel() { root = new DefaultMutableTreeNode("Root"); a = new DefaultMutableTreeNode("A"); root.add(a); a1 = new DefaultMutableTreeNode("a1"); a.add(a1); b = new DefaultMutableTreeNode("B"); root.add(b); b1 = new DefaultMutableTreeNode("b1"); b.add(b1); b2 = new DefaultMutableTreeNode("b2"); b.add(b2); c = new DefaultMutableTreeNode("C"); root.add(c); c1 = new DefaultMutableTreeNode("c1"); c.add(c1); return new DefaultTreeModel(root); }
Example #19
Source File: Test8015926.java From hottub with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example #20
Source File: AquaLocationSourceList.java From pumpernickel with MIT License | 6 votes |
public AquaLocationSourceList(LocationHistory directoryStack, GraphicCache graphicCache) { super(new DefaultTreeModel(new DefaultMutableTreeNode("root"))); treeModel = (DefaultTreeModel) getModel(); root = (DefaultMutableTreeNode) treeModel.getRoot(); this.directoryStack = directoryStack; this.graphicCache = graphicCache; treeModel.insertNodeInto(devices, root, 0); treeModel.insertNodeInto(places, root, 1); addTreeSelectionListener(treeSelectionListener); directoryStack.addChangeListener(directoryStackListener); setExpandsSelectedPaths(true); setCellRenderer(new SourceListLocationRenderer(graphicCache, this)); getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION); setUI(new SourceListTreeUI(this)); expandPath(new TreePath(devices.getPath())); expandPath(new TreePath(places.getPath())); }
Example #21
Source File: RecentFilesController.java From bigtable-sql with Apache License 2.0 | 6 votes |
private void onRemoveSelected() { HashSet<DefaultMutableTreeNode> changedParents = new HashSet<DefaultMutableTreeNode>(); TreePath[] paths = _dialog.treFiles.getSelectionPaths(); DefaultTreeModel model = (DefaultTreeModel) _dialog.treFiles.getModel(); for (TreePath path : paths) { DefaultMutableTreeNode dmtn = (DefaultMutableTreeNode) path.getLastPathComponent(); if( dmtn.getUserObject() instanceof File ) { model.removeNodeFromParent(dmtn); changedParents.add((DefaultMutableTreeNode) path.getParentPath().getLastPathComponent()); } } for (DefaultMutableTreeNode changedParent : changedParents) { model.nodeStructureChanged(changedParent); } writeUiTreeToModel(); }
Example #22
Source File: MainPanel.java From java-swing-tips with MIT License | 6 votes |
@Override public boolean importData(TransferHandler.TransferSupport support) { DefaultMutableTreeNode[] nodes; try { Transferable t = support.getTransferable(); nodes = (DefaultMutableTreeNode[]) t.getTransferData(FLAVOR); } catch (UnsupportedFlavorException | IOException ex) { return false; } TransferHandler.DropLocation tdl = support.getDropLocation(); if (tdl instanceof JTree.DropLocation) { JTree.DropLocation dl = (JTree.DropLocation) tdl; int childIndex = dl.getChildIndex(); TreePath dest = dl.getPath(); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) dest.getLastPathComponent(); JTree tree = (JTree) support.getComponent(); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); AtomicInteger idx = new AtomicInteger(childIndex < 0 ? parent.getChildCount() : childIndex); Stream.of(nodes).forEach(node -> { DefaultMutableTreeNode clone = new DefaultMutableTreeNode(node.getUserObject()); model.insertNodeInto(deepCopyTreeNode(node, clone), parent, idx.incrementAndGet()); }); return true; } return false; }
Example #23
Source File: StatefulView.java From Llunatic with GNU General Public License v3.0 | 6 votes |
public void scrollToNode(final Node n) { // has to be delayed to be sure that events for Visualizers // were processed and TreeNodes are already in hierarchy SwingUtilities.invokeLater(new Runnable() { @Override public void run() { TreeNode tn = Visualizer.findVisualizer(n); if (tn == null) { return; } TreeModel model = tree.getModel(); if (!(model instanceof DefaultTreeModel)) { return; } TreePath path = new TreePath(((DefaultTreeModel) model).getPathToRoot(tn)); Rectangle r = tree.getPathBounds(path); if (r != null) { tree.scrollRectToVisible(r); } } }); }
Example #24
Source File: FileTree.java From QLExpress with Apache License 2.0 | 6 votes |
public void initData(String rootPath){ File f=new File(rootPath); PathNode root=new PathNode(f.getName(), rootPath,f.isDirectory()); File[] files=f.listFiles(); for(int i=0;i<files.length;i++){ if(files[i].isDirectory() || files[i].getName().endsWith(".ql")){ PathNode node=new PathNode(files[i].getName(), files[i].getAbsolutePath(),files[i].isDirectory()); root.add(node); } } model=new DefaultTreeModel(root); this.setModel(model); FileTreeRenderer renderer=new FileTreeRenderer(); this.setCellRenderer(renderer); this.repaint(); }
Example #25
Source File: HintsPanelLogic.java From netbeans with Apache License 2.0 | 6 votes |
void connect( JTree errorTree, DefaultTreeModel errModel, JComboBox severityComboBox, JCheckBox tasklistCheckBox, JPanel customizerPanel, JEditorPane descriptionTextArea) { this.errorTree = errorTree; this.errModel = errModel; this.severityComboBox = severityComboBox; this.tasklistCheckBox = tasklistCheckBox; this.customizerPanel = customizerPanel; this.descriptionTextArea = descriptionTextArea; valueChanged( null ); errorTree.addKeyListener(this); errorTree.addMouseListener(this); errorTree.getSelectionModel().addTreeSelectionListener(this); severityComboBox.addActionListener(this); tasklistCheckBox.addChangeListener(this); }
Example #26
Source File: Test8015926.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
@Override public void run() { Thread.currentThread().setUncaughtExceptionHandler(this); DefaultMutableTreeNode root = new DefaultMutableTreeNode(); DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child"); DefaultTreeModel model = new DefaultTreeModel(root); this.tree = new JTree(); this.tree.setModel(model); JFrame frame = new JFrame(getClass().getSimpleName()); frame.add(this.tree); model.addTreeModelListener(this); // frame is not visible yet model.insertNodeInto(child, root, root.getChildCount()); model.removeNodeFromParent(child); frame.setSize(640, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(DISPOSE_ON_CLOSE); frame.setVisible(true); }
Example #27
Source File: SearchInConstantPoolsView.java From jd-gui with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unchecked") protected void populate(DefaultTreeModel model, T node) { // Populate node populate(node); // Populate children int i = node.getChildCount(); while (i-- > 0) { T child = (T)node.getChildAt(i); if ((child instanceof TreeNodeExpandable) && !expanded.contains(child.getUri())) { populate(child); } } // Refresh model.reload(node); }
Example #28
Source File: InspectionRVContentProvider.java From consulo with Apache License 2.0 | 5 votes |
protected static void add(@Nullable final DefaultTreeModel model, final InspectionTreeNode child, final InspectionTreeNode parent) { if (model == null) { insertByIndex(child, parent); } else { if (parent.getIndex(child) < 0) { model.insertNodeInto(child, parent, child.getParent() == parent ? parent.getChildCount() - 1 : parent.getChildCount()); } } }
Example #29
Source File: DynamicTree.java From marathonv5 with Apache License 2.0 | 5 votes |
public DynamicTree() { super(new GridLayout(1, 0)); rootNode = new DefaultMutableTreeNode("Root Node"); treeModel = new DefaultTreeModel(rootNode); treeModel.addTreeModelListener(new MyTreeModelListener()); tree = new JTree(treeModel); tree.setEditable(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setShowsRootHandles(true); JScrollPane scrollPane = new JScrollPane(tree); add(scrollPane); }
Example #30
Source File: ResourceExplorerTopComponent.java From syncope with Apache License 2.0 | 5 votes |
public ResourceExplorerTopComponent() { initComponents(); setName(PluginConstants.ROOT_NAME); setToolTipText(PluginConstants.TOOL_TIP_TEXT); treeModel = (DefaultTreeModel) resourceExplorerTree.getModel(); root = (DefaultMutableTreeNode) treeModel.getRoot(); visibleRoot = new DefaultMutableTreeNode(PluginConstants.ROOT_NAME); mailTemplates = new DefaultMutableTreeNode(PluginConstants.MAIL_TEMPLATES); reportXslts = new DefaultMutableTreeNode(PluginConstants.REPORT_XSLTS); groovyScripts = new DefaultMutableTreeNode(PluginConstants.GROOVY_SCRIPTS); root.add(visibleRoot); initTemplatesTree(); }