Java Code Examples for javax.swing.tree.DefaultMutableTreeNode#getUserObject()
The following examples show how to use
javax.swing.tree.DefaultMutableTreeNode#getUserObject() .
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: ContentEntryEditingAction.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull protected final VirtualFile[] getSelectedFiles() { final TreePath[] selectionPaths = myTree.getSelectionPaths(); if (selectionPaths == null) { return VirtualFile.EMPTY_ARRAY; } final List<VirtualFile> selected = new ArrayList<VirtualFile>(); for (TreePath treePath : selectionPaths) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)treePath.getLastPathComponent(); final Object nodeDescriptor = node.getUserObject(); if (!(nodeDescriptor instanceof FileNodeDescriptor)) { return VirtualFile.EMPTY_ARRAY; } final FileElement fileElement = ((FileNodeDescriptor)nodeDescriptor).getElement(); final VirtualFile file = fileElement.getFile(); if (file != null) { selected.add(file); } } return selected.toArray(new VirtualFile[selected.size()]); }
Example 2
Source File: PToDoTree.java From PolyGlot with MIT License | 6 votes |
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { DefaultMutableTreeNode node = (DefaultMutableTreeNode)value; Object obj = node.getUserObject(); TreePath tp = new TreePath(node.getPath()); ToDoNode cn = nodesCheckingState.get(tp); if (cn == null) { return this; } checkBox.setSelected(cn.isDone() && cn.allChildrenDone()); checkBox.setText(obj.toString()); checkBox.setOpaque(cn.isDone() && cn.hasChildren() && !cn.allChildrenDone()); return this; }
Example 3
Source File: CustomTOCView.java From ghidra with Apache License 2.0 | 6 votes |
private boolean isAlreadySelected(TreePath path, ID id) { if (path == null) { return false; } Object pathComponent = path.getLastPathComponent(); if (!(pathComponent instanceof DefaultMutableTreeNode)) { return false; } DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) pathComponent; TOCItem item = (TOCItem) treeNode.getUserObject(); if (item == null) { return false; } ID selectedID = item.getID(); return selectedID != null && selectedID.equals(id); }
Example 4
Source File: AbstractTreeViewPanel.java From openAGV with Apache License 2.0 | 6 votes |
/** * Traversiert den gesamten Baum, um alle Knoten zu finden, die das übergebene * Datenobjekt in ihrem UserObject halten. * * @param dataObject * @return */ private List<DefaultMutableTreeNode> findAll(Object dataObject) { List<DefaultMutableTreeNode> searchNodes = new ArrayList<>(); @SuppressWarnings("unchecked") Enumeration<DefaultMutableTreeNode> e = fRootNode.preorderEnumeration(); while (e.hasMoreElements()) { DefaultMutableTreeNode node = e.nextElement(); UserObject userObject = (UserObject) node.getUserObject(); if (dataObject.equals(userObject.getModelComponent())) { searchNodes.add(node); } } return searchNodes; }
Example 5
Source File: Wizardry4BootDisk.java From DiskBrowser with GNU General Public License v3.0 | 5 votes |
private void linkBlock1 (DefaultMutableTreeNode scenarioNode, FileEntry fileEntry) // ---------------------------------------------------------------------------------// { byte[] buffer = fileEntry.getDataSource ().buffer; List<DiskAddress> blocks = fileEntry.getSectors (); StringBuilder text = new StringBuilder (); List<DiskAddress> allBlocks = new ArrayList<> (); for (int i = 0; i < 23; i++) { allBlocks.add (blocks.get (44 + i)); } int offset = 0x5800; int length = 66; for (int i = 0; i < 179; i++) { text.append (String.format ("%04X : %s%n", (offset + i * length), HexFormatter.getHexString (buffer, offset + i * length, length))); } DefaultMutableTreeNode oracleNode = linkNode ("Block1", text.toString (), scenarioNode); oracleNode.setAllowsChildren (false); DefaultAppleFileSource afs = (DefaultAppleFileSource) oracleNode.getUserObject (); afs.setSectors (allBlocks); }
Example 6
Source File: GuiForm.java From MavenHelper with Apache License 2.0 | 5 votes |
@Override public void valueChanged(TreeSelectionEvent e) { TreePath selectionPath = e.getPath(); if (selectionPath != null) { DefaultMutableTreeNode lastPathComponent = (DefaultMutableTreeNode) selectionPath.getLastPathComponent(); MyTreeUserObject userObject = (MyTreeUserObject) lastPathComponent.getUserObject(); final String key = getArtifactKey(userObject.getArtifact()); List<MavenArtifactNode> mavenArtifactNodes = allArtifactsMap.get(key); if (mavenArtifactNodes != null) {// can be null while refreshing fillRightTree(mavenArtifactNodes); } } }
Example 7
Source File: CheckBoxNodeEditor.java From sldeditor with GNU General Public License v3.0 | 5 votes |
public Component getTreeCellEditorComponent( JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; Object localUserObject = node.getUserObject(); Object parentUserObject = null; DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent(); if (parentNode != null) { parentUserObject = parentNode.getUserObject(); } if (ComponentCellRenderer.showCheckbox(parentUserObject, localUserObject)) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); Symbolizer localSymbolizer = (Symbolizer) parent.getUserObject(); boolean selectedItem = SLDTreeLeafFactory.getInstance() .isItemSelected(localUserObject, localSymbolizer); panel.setCheckboxSelected(selectedItem); panel.setLabelText(ComponentCellRenderer.getItemText(node, localUserObject)); panel.setSelected(true, true); return panel; } return renderer.getTreeCellRendererComponent(tree, value, true, expanded, leaf, row, true); }
Example 8
Source File: NoSqlExplorerPanel.java From nosql4idea with Apache License 2.0 | 5 votes |
public RedisDatabase getSelectedRedisDatabase() { DefaultMutableTreeNode databaseNode = getSelectedDatabaseNode(); if (databaseNode == null) { return null; } Object database = databaseNode.getUserObject(); if (!(database instanceof RedisDatabase)) { return null; } return (RedisDatabase) database; }
Example 9
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public void treeWillExpand(TreeExpansionEvent e) throws ExpandVetoException { TreePath path = e.getPath(); Object o = path.getLastPathComponent(); if (o instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) o; File file = (File) node.getUserObject(); if (file.isFile()) { throw new ExpandVetoException(e, "Tree expansion cancelled"); } } }
Example 10
Source File: TwoDBottomPanel.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
@Override public void treeStructureChanged(TreeModelEvent event) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) event.getTreePath().getLastPathComponent(); if (node.getUserObject() instanceof PeakList) rebuildPeakListSelector(); }
Example 11
Source File: XSheet.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
public synchronized void displayNode(DefaultMutableTreeNode node) { clear(); displayEmptyNode(); if (node == null) { return; } currentNode = node; Object userObject = node.getUserObject(); if (userObject instanceof XNodeInfo) { XNodeInfo uo = (XNodeInfo) userObject; switch (uo.getType()) { case MBEAN: displayMBeanNode(node); break; case NONMBEAN: displayEmptyNode(); break; case ATTRIBUTES: displayMBeanAttributesNode(node); break; case OPERATIONS: displayMBeanOperationsNode(node); break; case NOTIFICATIONS: displayMBeanNotificationsNode(node); break; case ATTRIBUTE: case OPERATION: case NOTIFICATION: displayMetadataNode(node); break; default: displayEmptyNode(); break; } } else { displayEmptyNode(); } }
Example 12
Source File: AbstractUpdatableAction.java From JPPF with Apache License 2.0 | 5 votes |
/** * Determine whether at least one of the selected elements is a job. * @param selected the selected elements. * @return {@code true} if at least one node is selected, {@code false} otherwise. */ protected boolean isJobSelected(final List<DefaultMutableTreeNode> selected) { for (final DefaultMutableTreeNode treeNode: selected) { final AbstractComponent<?> comp = (AbstractComponent<?>) treeNode.getUserObject(); if (comp instanceof Job) return true; } return false; }
Example 13
Source File: TopologyNodeRenderer.java From JPPF with Apache License 2.0 | 5 votes |
@Override public String getIconPath(final DefaultMutableTreeNode treeNode) { final AbstractTopologyComponent topologyComp = (AbstractTopologyComponent) treeNode.getUserObject(); String path = "driver.gif"; if (topologyComp.isNode()) { final TopologyNode topologyNode = (TopologyNode) topologyComp; path = topologyNode.getManagementInfo().isMasterNode() ? "node-master.png" : "node-slave.png"; } return "images/tree/" + path; }
Example 14
Source File: HintsPanel.java From netbeans with Apache License 2.0 | 5 votes |
@Override public boolean isPathEditable(TreePath path) { DefaultMutableTreeNode o = (DefaultMutableTreeNode) path.getLastPathComponent(); if (o.getUserObject() instanceof HintMetadata) { HintMetadata hint = (HintMetadata) o.getUserObject(); if (hint.category.equals(Utilities.CUSTOM_CATEGORY)) { return true; } } return false; }
Example 15
Source File: WizardryScenarioDisk.java From DiskBrowser with GNU General Public License v3.0 | 5 votes |
private void extractMonsters (DefaultMutableTreeNode node, List<DiskAddress> sectors) // ---------------------------------------------------------------------------------// { List<DiskAddress> nodeSectors = new ArrayList<> (); ScenarioData sd = scenarioHeader.data.get (Header.MONSTER_AREA); monsters = new ArrayList<> (sd.total); int max = sd.totalBlocks / 2; for (int i = 0; i < max; i++) { List<DiskAddress> blocks = getTwoBlocks (sd, i, sectors); nodeSectors.addAll (blocks); byte[] buffer = disk.readBlocks (blocks); addMonsters (buffer, blocks, node); } StringBuilder text = new StringBuilder (); for (int block = 0; block < 4; block++) { text.append (" ID Name\n"); text.append ("--- ---------------"); for (int i = 0; i < 24; i++) text.append (" --"); text.append ("\n"); for (Monster m : monsters) text.append (m.getDump (block) + "\n"); text.append ("\n"); } DefaultAppleFileSource afs = (DefaultAppleFileSource) node.getUserObject (); afs.setSectors (nodeSectors); DefaultDataSource dds = (DefaultDataSource) afs.getDataSource (); dds.text = text.toString (); }
Example 16
Source File: DataSourceInteractions.java From jetbrains-plugin-graph-database-support with Apache License 2.0 | 4 votes |
private boolean isDataSource(DefaultMutableTreeNode node) { return node.getUserObject() instanceof TreeNodeModelApi && ((TreeNodeModelApi) node.getUserObject()).getType() == Neo4jTreeNodeType.DATASOURCE; }
Example 17
Source File: XSheet.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private void displayMBeanNode(final DefaultMutableTreeNode node) { final XNodeInfo uo = (XNodeInfo) node.getUserObject(); if (!uo.getType().equals(Type.MBEAN)) { return; } mbean = (XMBean) uo.getData(); SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() { @Override public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { return mbean.getMBeanInfo(); } @Override protected void done() { try { MBeanInfo mbi = get(); if (mbi != null) { if (!isSelectedNode(node, currentNode)) { return; } mbeanInfo.addMBeanInfo(mbean, mbi); invalidate(); mainPanel.removeAll(); mainPanel.add(mbeanInfo, BorderLayout.CENTER); southPanel.setVisible(false); southPanel.removeAll(); validate(); repaint(); } } catch (Exception e) { Throwable t = Utils.getActualException(e); if (JConsole.isDebug()) { System.err.println("Couldn't get MBeanInfo for MBean [" + mbean.getObjectName() + "]"); t.printStackTrace(); } showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN); } } }; sw.execute(); }
Example 18
Source File: XSheet.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
private void displayMBeanOperationsNode(final DefaultMutableTreeNode node) { final XNodeInfo uo = (XNodeInfo) node.getUserObject(); if (!uo.getType().equals(Type.OPERATIONS)) { return; } mbean = (XMBean) uo.getData(); SwingWorker<MBeanInfo, Void> sw = new SwingWorker<MBeanInfo, Void>() { @Override public MBeanInfo doInBackground() throws InstanceNotFoundException, IntrospectionException, ReflectionException, IOException { return mbean.getMBeanInfo(); } @Override protected void done() { try { MBeanInfo mbi = get(); if (mbi != null) { if (!isSelectedNode(node, currentNode)) { return; } mbeanOperations.loadOperations(mbean, mbi); invalidate(); mainPanel.removeAll(); JPanel borderPanel = new JPanel(new BorderLayout()); borderPanel.setBorder(BorderFactory.createTitledBorder( Messages.OPERATION_INVOCATION)); borderPanel.add(new JScrollPane(mbeanOperations)); mainPanel.add(borderPanel, BorderLayout.CENTER); southPanel.setVisible(false); southPanel.removeAll(); validate(); repaint(); } } catch (Exception e) { Throwable t = Utils.getActualException(e); if (JConsole.isDebug()) { System.err.println("Problem displaying MBean " + "operations for MBean [" + mbean.getObjectName() + "]"); t.printStackTrace(); } showErrorDialog(t.toString(), Messages.PROBLEM_DISPLAYING_MBEAN); } } }; sw.execute(); }
Example 19
Source File: WizardryScenarioDisk.java From DiskBrowser with GNU General Public License v3.0 | 4 votes |
public WizardryScenarioDisk (Disk disk) // ---------------------------------------------------------------------------------// { super (disk); if (false) { sectorTypesList.add (mazeSector); sectorTypesList.add (monsterSector); sectorTypesList.add (itemSector); sectorTypesList.add (characterSector); sectorTypesList.add (spellSector); sectorTypesList.add (messageSector); sectorTypesList.add (imageSector); sectorTypesList.add (experienceSector); sectorTypesList.add (treasureSector); } CodedMessage.codeOffset = 185; Monster.counter = 0; Item.counter = 0; DefaultTreeModel model = (DefaultTreeModel) catalogTree.getModel (); DefaultMutableTreeNode currentRoot = (DefaultMutableTreeNode) model.getRoot (); DefaultMutableTreeNode dataNode = findNode (currentRoot, "SCENARIO.DATA"); DefaultMutableTreeNode msgNode = findNode (currentRoot, "SCENARIO.MESGS"); if (dataNode == null || msgNode == null) { System.out.println ("Wizardry data or msg node not found"); return; } dataNode.setAllowsChildren (true); msgNode.setAllowsChildren (true); scenarioHeader = new Header (dataNode, this); // Process SCENARIO.MESGS (requires scenario) AppleFileSource afs = (AppleFileSource) msgNode.getUserObject (); // DefaultMutableTreeNode node = linkNode ("Messages", "Messages string", msgNode); extractMessages (msgNode, afs.getSectors ()); // makeNodeVisible (node); // Process SCENARIO.DATA (requires scenario and messages) afs = (AppleFileSource) dataNode.getUserObject (); List<DiskAddress> sectors = afs.getSectors (); extractItems (linkNode ("Items", "Items string", dataNode), sectors); extractRewards (linkNode ("Rewards", "Treasure string", dataNode), sectors); extractMonsters (linkNode ("Monsters", "Monsters string", dataNode), sectors); extractCharacters (linkNode ("Characters", "Characters string", dataNode), sectors); extractImages (linkNode ("Images", "Images string", dataNode), sectors); extractExperienceLevels (linkNode ("Experience", "Experience string", dataNode), sectors); // node = linkNode ("Spells", "Spells string", dataNode); DefaultMutableTreeNode node = null; extractSpells (node, sectors); extractLevels (linkNode ("Maze", "Levels string", dataNode), sectors); // Make the Spells node (and its siblings) visible // makeNodeVisible (node); // add information about each characters' baggage, spells known etc. for (Character c : characters) { c.linkItems (items); c.linkSpells (spells); int type = c.getStatistics ().typeInt; c.linkExperience (experiences.get (type)); } }
Example 20
Source File: LeftTreePopupHandler.java From MavenHelper with Apache License 2.0 | 4 votes |
@SuppressWarnings("Duplicates") public void invokePopup(final Component comp, final int x, final int y) { final DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (selectedNode == null) { return; } final MyTreeUserObject myTreeUserObject = (MyTreeUserObject) selectedNode.getUserObject(); final MavenArtifactNode mavenArtifactNode = myTreeUserObject.getMavenArtifactNode(); DefaultActionGroup actionGroup = new DefaultActionGroup(); if (myTreeUserObject.getMavenArtifactNode().getParent() == null) { actionGroup.add(new JumpToSourceAction(project, mavenProject, mavenArtifactNode)); actionGroup.add(new RemoveDependencyAction(project, mavenProject, mavenArtifactNode) { @Override public void dependencyDeleted() { getModel().removeNodeFromParent(selectedNode); } }); } else { actionGroup.add(new JumpToSourceAction(project, mavenProject, mavenArtifactNode)); actionGroup.add(new ExcludeDependencyAction(project, mavenProject, mavenArtifactNode) { @Override public void dependencyExcluded() {// // root // | d1 // | L d2 // | | L d3 // | L d3 // L ... // After d3 is excluded; remove d3 in the whole subtree. // getModel().removeNodeFromParent(selectedNode); DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) selectedNode.getPath()[1]; Enumeration enumeration = treeNode.breadthFirstEnumeration(); MavenArtifact excludedArtifact = myArtifact.getArtifact(); java.util.List<DefaultMutableTreeNode> toRemove = new ArrayList<DefaultMutableTreeNode>(); while (enumeration.hasMoreElements()) { DefaultMutableTreeNode o = (DefaultMutableTreeNode) enumeration.nextElement(); MyTreeUserObject userObject = (MyTreeUserObject) o.getUserObject(); MavenArtifact artifact = userObject.getArtifact(); if (artifact.getArtifactId().equals(excludedArtifact.getArtifactId()) && artifact.getGroupId().equals(excludedArtifact.getGroupId())) { toRemove.add(o); } } for (DefaultMutableTreeNode node : toRemove) { getModel().removeNodeFromParent(node); } } }); } popup = ActionManager.getInstance().createActionPopupMenu("", actionGroup).getComponent(); popup.show(comp, x, y); }