List of usage examples for javax.swing.tree DefaultMutableTreeNode getUserObject
public Object getUserObject()
From source file:com.mindcognition.mindraider.ui.swing.explorer.NotebooksTreeToolbar.java
public void actionPerformed(ActionEvent e) { logger.debug("Going to update Outline..."); DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) explorerJPanel.getNotebooksTree() .getLastSelectedPathComponent(); if (selectedNode.getDepth() == 0) { // it is leaf node - a notebook final String notebookUri = ((NotebookNodeUserObject) selectedNode.getUserObject()).getNotebookUri(); ResourceDescriptor resourceDescriptor = MindRaider.labelCustodian.getOutlineDescriptor(notebookUri); new UpdateOutlineJDialog(resourceDescriptor); explorerJPanel.refresh();/*from w ww . j a v a 2 s . co m*/ return; } else { JOptionPane.showMessageDialog(MindRaider.mainJFrame, "Please select Outline to be updated!"); } }
From source file:com.mindcognition.mindraider.ui.swing.explorer.NotebooksTreeToolbar.java
public void actionPerformed(ActionEvent e) { // find notebook through node's user object URI, discard notebook (move it to the archive), // tags are preserved until notebook is erased DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) explorerJPanel.getNotebooksTree() .getLastSelectedPathComponent(); if (selectedNode.getDepth() == 0) { // it is leaf node - a notebook final String notebookUri = ((NotebookNodeUserObject) selectedNode.getUserObject()).getNotebookUri(); ResourceDescriptor resourceDescriptor = MindRaider.labelCustodian.getOutlineDescriptor(notebookUri); if (JOptionPane.showConfirmDialog(MindRaider.mainJFrame, "Do you really want to discard Outline '" + (resourceDescriptor != null ? resourceDescriptor.getLabel() : notebookUri) + "'?", "Archive Outline", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) { // discard the notebook from ALL folders where it presents MindRaider.labelCustodian.discardOutline(notebookUri); explorerJPanel.refresh();//from w w w .jav a 2 s . c o m OutlineJPanel.getInstance().clear(); MindRaider.spidersGraph.clear(); MindRaider.profile.setActiveOutlineUri(null); return; } } else { JOptionPane.showMessageDialog(MindRaider.mainJFrame, "Please select Outline to be discarded!"); } }
From source file:org.eevolution.form.VCRPDetail.java
private void handleTreeEvent(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { model.getTree().setSelectionPath(model.getTree().getPathForLocation(e.getX(), e.getY())); DefaultMutableTreeNode node = (DefaultMutableTreeNode) model.getTree().getSelectionPath() .getLastPathComponent(); if (!(node.getUserObject() instanceof Date) && !(node.getUserObject() instanceof MPPOrderNode)) { popup.show(e.getComponent(), e.getX(), e.getY()); }//from w w w. j ava2 s. c o m } SwingTool.setCursorsFromChild(e.getComponent(), false); }
From source file:net.sf.mzmine.desktop.impl.projecttree.ProjectTreeMouseHandler.java
private void handlePopupTriggerEvent(MouseEvent e) { TreePath clickedPath = tree.getPathForLocation(e.getX(), e.getY()); if (clickedPath == null) return;/*from w w w. java2s. co m*/ DefaultMutableTreeNode node = (DefaultMutableTreeNode) clickedPath.getLastPathComponent(); Object clickedObject = node.getUserObject(); if (clickedObject instanceof RawDataFile) dataFilePopupMenu.show(e.getComponent(), e.getX(), e.getY()); if (clickedObject instanceof Scan) scanPopupMenu.show(e.getComponent(), e.getX(), e.getY()); if (clickedObject instanceof MassList) massListPopupMenu.show(e.getComponent(), e.getX(), e.getY()); if (clickedObject instanceof PeakList) peakListPopupMenu.show(e.getComponent(), e.getX(), e.getY()); if (clickedObject instanceof PeakListRow) peakListRowPopupMenu.show(e.getComponent(), e.getX(), e.getY()); }
From source file:com.mindcognition.mindraider.ui.swing.explorer.LabelsTree.java
public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) labelsTree.getLastSelectedPathComponent(); if (node != null) { logger.debug("Labels tree selection path: " + node.getPath()[node.getLevel()]); if (node.getUserObject() instanceof NotebookNodeUserObject) { NotebookNodeUserObject labelNode = (NotebookNodeUserObject) node.getUserObject(); // TODO bundle StatusBar.show("Label " + labelNode.getNotebookUri() + " selected..."); notebooksTree.reloadModel(labelNode.getNotebookUri()); }/*from w w w . j a va2 s .c o m*/ } }
From source file:com.mindcognition.mindraider.ui.swing.explorer.NotebooksTree.java
public void valueChanged(TreeSelectionEvent e) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) notebooksTree.getLastSelectedPathComponent(); if (node != null && !notebooksTree.isRoot(node)) { logger.debug("Outlines tree selection path: " + node.getPath()[node.getLevel()]); if (node.getUserObject() instanceof NotebookNodeUserObject) { NotebookNodeUserObject notebookNode = (NotebookNodeUserObject) node.getUserObject(); // TODO bundle StatusBar.show("Outline " + notebookNode.getNotebookUri() + " selected..."); try { OutlineJPanel.getInstance().conceptJPanel.clear(); MindRaider.profile.setActiveOutlineUri(null); MindRaider.outlineCustodian.loadOutline(new URI(notebookNode.getNotebookUri())); OutlineJPanel.getInstance().refresh(); } catch (URISyntaxException e1) { // TODO option with question whether to remove non-existent notebook logger.debug("Unable to load Outline: ", e1); }// ww w. jav a2 s.c o m } if (notebooksTree.getToolbar() != null) { notebooksTree.getToolbar().enableDisableToolbarButtons(NotebooksTree.LEVEL_NOTEBOOKS); } } else { if (notebooksTree.getToolbar() != null) { notebooksTree.getToolbar().enableDisableToolbarButtons(NotebooksTree.LEVEL_ROOT); } } }
From source file:net.sf.mzmine.desktop.impl.projecttree.ProjectTreeMouseHandler.java
private void handleDoubleClickEvent(MouseEvent e) { TreePath clickedPath = tree.getPathForLocation(e.getX(), e.getY()); if (clickedPath == null) return;/* w w w .ja va 2 s .c o m*/ DefaultMutableTreeNode node = (DefaultMutableTreeNode) clickedPath.getLastPathComponent(); Object clickedObject = node.getUserObject(); if (clickedObject instanceof RawDataFile) { RawDataFile clickedFile = (RawDataFile) clickedObject; TICVisualizerModule.setupNewTICVisualizer(clickedFile); } if (clickedObject instanceof PeakList) { PeakList clickedPeakList = (PeakList) clickedObject; PeakListTableModule.showNewPeakListVisualizerWindow(clickedPeakList); } if (clickedObject instanceof Scan) { Scan clickedScan = (Scan) clickedObject; SpectraVisualizerModule.showNewSpectrumWindow(clickedScan.getDataFile(), clickedScan.getScanNumber()); } if (clickedObject instanceof MassList) { MassList clickedMassList = (MassList) clickedObject; Scan clickedScan = clickedMassList.getScan(); SpectraVisualizerWindow window = SpectraVisualizerModule .showNewSpectrumWindow(clickedScan.getDataFile(), clickedScan.getScanNumber()); MassListDataSet dataset = new MassListDataSet(clickedMassList); window.addDataSet(dataset, Color.green); } if (clickedObject instanceof PeakListRow) { PeakListRow clickedPeak = (PeakListRow) clickedObject; PeakSummaryVisualizerModule.showNewPeakSummaryWindow(clickedPeak); } }
From source file:edu.ku.brc.specify.tasks.subpane.security.NavigationTreeContextMenuMgr.java
/** * @param node//from ww w . j a v a2 s . c o m */ private void addToAdminGroup(final DefaultMutableTreeNode node) { if (node != null) { Object userObject = node.getUserObject(); if (userObject != null) { FormDataObjIFace dmObject = ((DataModelObjBaseWrapper) userObject).getDataObj(); if (dmObject != null && dmObject instanceof SpecifyUser) { SpPrincipal adminPrin = null; DataProviderSessionIFace session = null; try { session = DataProviderFactory.getInstance().createSession(); adminPrin = (SpPrincipal) session.getData(SpPrincipal.class, "name", "Administrator", DataProviderSessionIFace.CompareType.Equals); if (adminPrin != null) { SpecifyUser spUser = session.get(SpecifyUser.class, ((SpecifyUser) dmObject).getId()); spUser.addUserToSpPrincipalGroup(adminPrin); session.beginTransaction(); session.saveOrUpdate(spUser); session.saveOrUpdate(adminPrin); session.commit(); DefaultMutableTreeNode adminNode = getAdminTreeNode( (DefaultMutableTreeNode) treeMgr.getTree().getModel().getRoot()); DefaultMutableTreeNode newNode = new DefaultMutableTreeNode( new DataModelObjBaseWrapper(spUser)); DefaultTreeModel model = (DefaultTreeModel) getTree().getModel(); model.insertNodeInto(newNode, adminNode, adminNode.getChildCount()); model.nodeChanged(adminNode); model.nodeChanged(newNode); getTree().repaint(); getTree().setSelectionPath(new TreePath(newNode.getPath())); lastClickComp = null; updateBtnUI(); } } catch (final Exception e1) { e1.printStackTrace(); edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount(); edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(NavigationTreeMgr.class, e1); session.rollback(); } finally { if (session != null) { session.close(); } } } } } }
From source file:FileTree2.java
public boolean expand(DefaultMutableTreeNode parent) { 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 File[] files = listFiles();// w w w. j a va 2s . c o m if (files == null) return true; Vector v = new Vector(); for (int k = 0; k < files.length; k++) { File f = files[k]; if (!(f.isDirectory())) continue; FileNode newNode = new FileNode(f); boolean isAdded = false; for (int i = 0; i < v.size(); i++) { FileNode nd = (FileNode) v.elementAt(i); if (newNode.compareTo(nd) < 0) { v.insertElementAt(newNode, i); isAdded = true; break; } } if (!isAdded) v.addElement(newNode); } for (int i = 0; i < v.size(); i++) { FileNode nd = (FileNode) v.elementAt(i); IconData idata = new IconData(FileTree2.ICON_FOLDER, FileTree2.ICON_EXPANDEDFOLDER, nd); DefaultMutableTreeNode node = new DefaultMutableTreeNode(idata); parent.add(node); if (nd.hasSubDirs()) node.add(new DefaultMutableTreeNode(new Boolean(true))); } return true; }
From source file:dotaSoundEditor.Controls.ItemPanel.java
@Override protected File promptUserForNewFile(String wavePath) { DefaultMutableTreeNode selectedTreeNode = (DefaultMutableTreeNode) getTreeNodeFromWavePath(wavePath); String waveString = selectedTreeNode.getUserObject().toString(); String allowedExtension = FilenameUtils.getExtension(waveString).replace("\"", ""); JFileChooser chooser = new JFileChooser(new File(UserPrefs.getInstance().getWorkingDirectory())); FileNameExtensionFilter filter = allowedExtension.equals("wav") ? new FileNameExtensionFilter("WAVs", "wav") : new FileNameExtensionFilter("MP3s", "mp3"); chooser.setAcceptAllFileFilterUsed((false)); chooser.setFileFilter(filter);// ww w . j ava 2s. co m chooser.setMultiSelectionEnabled(false); int chooserRetVal = chooser.showOpenDialog(chooser); if (chooserRetVal == JFileChooser.APPROVE_OPTION) { Path chosenFile = Paths.get(chooser.getSelectedFile().getAbsolutePath()); int startIndex = -1; int endIndex = -1; //Get the actual value for the wavestring key-value pair. if (waveString.contains("\"wave\"")) { startIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 2); endIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 3); } else //Some wavestrings don't have the "wave" at the beginning for some reason { startIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 0); endIndex = Utility.nthOccurrence(selectedTreeNode.getUserObject().toString(), '\"', 1); } String waveStringFilePath = waveString.substring(startIndex, endIndex + 1); String waveStringNormalizedFilePath = waveStringFilePath.substring(0, waveStringFilePath.lastIndexOf("\"")); waveStringNormalizedFilePath = waveStringNormalizedFilePath.replace(")", ""); waveStringNormalizedFilePath = waveStringNormalizedFilePath.replace("\"", ""); Path destPath = Paths.get(installDir, "/dota/sound/" + waveStringNormalizedFilePath); UserPrefs.getInstance().setWorkingDirectory(chosenFile.getParent().toString()); try { new File(destPath.toString()).mkdirs(); Files.copy(chosenFile, destPath, StandardCopyOption.REPLACE_EXISTING); if (waveString.contains("//")) { waveString = waveString .replace(waveString.substring(waveString.indexOf("//"), waveString.length()), ""); } waveString = waveString.replace(waveStringFilePath, "\"" + waveStringNormalizedFilePath + "\" //Replaced by: " + chosenFile.getFileName().toString()); selectedTreeNode.setUserObject(waveString); //Write out modified tree to scriptfile. ScriptParser parser = new ScriptParser(this.currentTreeModel); String scriptString = getCurrentScriptString(); Path scriptPath = Paths.get(scriptString); parser.writeModelToFile(scriptPath.toString()); //Update UI ((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()).setUserObject(waveString); ((DefaultTreeModel) currentTree.getModel()) .nodeChanged((DefaultMutableTreeNode) currentTree.getLastSelectedPathComponent()); JOptionPane.showMessageDialog(this, "Sound file successfully replaced."); } catch (IOException ex) { JOptionPane.showMessageDialog(null, "Unable to replace sound.\nDetails: " + ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); } } return null; }