List of usage examples for javax.swing.tree TreePath getLastPathComponent
public Object getLastPathComponent()
From source file:de.codesourcery.eve.skills.ui.components.impl.BlueprintChooserComponent.java
protected void treeNodeDoubleClicked(TreePath path) { final ITreeNode node = (ITreeNode) path.getLastPathComponent(); final Blueprint bp = getSelectedBlueprint(node); if (bp == null) { return;/*w w w. j a va 2 s. c o m*/ } for (ISelectionListener<Blueprint> l : listenerHelper.getListeners()) { if (l instanceof IDoubleClickSelectionListener<?>) { ((IDoubleClickSelectionListener<Blueprint>) l).doubleClicked(bp); } } }
From source file:edu.mbl.jif.datasetconvert.CheckboxTreeDimensions.java
public void getSelectedIndices() { // channels = new int[]{0, 1, 2, 3, 4, 5, 6}; // slices = new int[]{0}; // frames = new int[]{0, 2}; // positions = new int[]{0}; List listChannels = new ArrayList(); List listSlices = new ArrayList(); List listFrames = new ArrayList(); List listPositions = new ArrayList(); // Check if root "All" selected, if so, not need to go further TreePath[] cr = CheckboxTreeDimensions.this.checkboxTree.getCheckingRoots(); for (TreePath path : cr) { System.out.println(path.getLastPathComponent()); }/*from www. jav a2s . c o m*/ System.out.println("\nPaths: "); TreePath[] cp = CheckboxTreeDimensions.this.checkboxTree.getCheckingPaths(); for (TreePath path : cp) { //Object[] pathObjs = path.getPath(); System.out.println(path.toString()); if (path.getPathCount() == 3) { DefaultMutableTreeNode nodeDim = (DefaultMutableTreeNode) path.getPathComponent(1); String dimension = (String) nodeDim.getUserObject(); DefaultMutableTreeNode nodeIndex = (DefaultMutableTreeNode) path.getPathComponent(2); Object uo = nodeIndex.getUserObject(); if (dimension.equalsIgnoreCase("Channel")) { String chan = (String) nodeIndex.getUserObject(); listChannels.add(chan); } if (dimension.equalsIgnoreCase("Z-Section")) { int index = (Integer) nodeIndex.getUserObject(); listSlices.add(index); } if (dimension.equalsIgnoreCase("TimePoint")) { int index = (Integer) nodeIndex.getUserObject(); listFrames.add(index); } if (dimension.equalsIgnoreCase("Position")) { int index = (Integer) nodeIndex.getUserObject(); listPositions.add(index); } } } // sort the list Collections.sort(listChannels); Collections.sort(listSlices); Collections.sort(listFrames); Collections.sort(listPositions); System.out.println("\nChannels: "); Iterator<Object> it = listChannels.iterator(); while (it.hasNext()) { Object obj = it.next(); System.out.print(" " + obj); } // Change list of channel names to an array of channel indices System.out.println("\nChannel Indices: "); Iterator<Object> itc = listChannels.iterator(); channels = new int[listChannels.size()]; int c = 0; while (itc.hasNext()) { Object obj = itc.next(); String channelName = (String) obj; int index = indexOfChannel(channelNamesOriginal, channelName, 0); channels[c] = index; c++; System.out.print(" " + channelName + " ::: " + index); } // String[] strArray = {"abcd", "abdc", "bcda"}; //for (String s : strArray) // if (s.startsWith(searchTerm)) // System.out.println(s); // Swap startsWith for contains you wish to simply look for containment. System.out.println("\nSlices: "); it = listSlices.iterator(); slices = new int[listSlices.size()]; c = 0; while (it.hasNext()) { Object obj = it.next(); int index = (Integer) obj; slices[c] = index; c++; System.out.print(" " + obj); } System.out.println("\nFrames: "); it = listFrames.iterator(); frames = new int[listFrames.size()]; c = 0; while (it.hasNext()) { Object obj = it.next(); int index = (Integer) obj; frames[c] = index; c++; System.out.print(" " + obj); } System.out.println("\nPositions: "); it = listPositions.iterator(); positions = new int[listPositions.size()]; c = 0; while (it.hasNext()) { Object obj = it.next(); int index = (Integer) obj; positions[c] = index; c++; System.out.print(" " + obj); } if (channels.length < 1) { promptForNoChoice("Channel"); } System.out.println(Arrays.toString(channels)); System.out.println(Arrays.toString(slices)); System.out.println(Arrays.toString(frames)); System.out.println(Arrays.toString(positions)); //CheckboxTreeExample_1.this.checkboxTree.; }
From source file:fi.elfcloud.client.tree.ClusterHierarchyModel.java
public void relocateDataItems(Cluster destination, TreePath[] paths) { try {//from ww w . ja va 2 s. com HashMap<String, Object[]> elements = destination.getElements(); DataItem[] dataitems = (DataItem[]) elements.get("dataitems"); //$NON-NLS-1$ Cluster[] clusters = (Cluster[]) elements.get("clusters"); //$NON-NLS-1$ for (TreePath path : paths) { ClusterTreeNode node = (ClusterTreeNode) path.getLastPathComponent(); if (!(node instanceof DataItemNode)) { continue; } DataItem di = (DataItem) node.getElement(); String name = di.getName(); for (DataItem dataitem : dataitems) { if (dataitem.getName().equals(di.getName())) { name = renameDataItem(name); break; } } for (Cluster cluster : clusters) { if (cluster.getName().equals(name)) { name = renameDataItem(name); break; } } if (name != null) { relocateDataItem(di, destination.getId(), name); } } } catch (ECException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } }
From source file:de.codesourcery.eve.skills.ui.model.FilteringTreeModel.java
@Override public void valueForPathChanged(TreePath path, Object newValue) { delegate.valueForPathChanged(path, newValue); final ITreeNode changedNode = (ITreeNode) path.getLastPathComponent(); if (isPathToRootVisible(changedNode)) { fireEvent(EventType.CHANGED, new TreeModelEvent(this, changedNode.getPathToRoot())); }//from w w w.j a v a 2 s. co m }
From source file:de.quadrillenschule.azocamsyncd.gui.ExploreWifiSDPanel.java
private void updateSingleView() { try {//from ww w . j a v a 2 s. c om if (remotejTree.getSelectionPaths().length > 0) { TreePath tp = remotejTree.getSelectionPaths()[0]; String mynode = tp.getLastPathComponent().toString(); AZoFTPFile myaffilea = null; for (AZoFTPFile af : afs) { if (new String(af.dir + af.ftpFile.getName()).equals(mynode)) { myaffilea = af; // GlobalProperties gp=new GlobalProperties(); // gp.setProperty(GlobalProperties.CamSyncProperties.LATESTIMAGEPATH, af.dir+af.ftpFile.getName()); break; } } final AZoFTPFile myaffile = myaffilea; Thread imageUpdater = new Thread(new Runnable() { @Override public void run() { try { File localFile; localFile = localStorage.getLocalFile(myaffile); localFileNamejTextField1.setText(localFile.getAbsolutePath()); ImageIcon ii = new ImageIcon(localFile.toURI().toURL()); int mywidth = imagejLabel.getWidth(); int width = ii.getIconWidth(); int height = ii.getIconHeight(); if (width <= 0) { imagejLabel.setText("No image to view."); } else { imagejLabel.setText(""); } double factor = (double) height / (double) width; Image image = ii.getImage().getScaledInstance(mywidth, (int) ((double) mywidth * factor), Image.SCALE_FAST); imagejLabel.setIcon(new ImageIcon(image)); } catch (Exception ex) { imagejLabel.setText("No image to view."); } } }); imageUpdater.start(); } } catch (Exception e) { } }
From source file:FileTreeDragSource.java
public String getPathName(TreePath path) { Object o = path.getLastPathComponent(); if (o instanceof FileTreeNode) { return ((FileTreeNode) o).fullName; }/*w w w . j a v a 2 s. com*/ return null; }
From source file:edu.ku.brc.specify.tasks.subpane.security.NavigationTreeContextMenuMgr.java
public void mousePressed(MouseEvent e) { TreePath clickedElement = getTree().getPathForLocation(e.getX(), e.getY()); // Update the selection if necessary updateSelection(clickedElement);//from w w w . j ava 2s. c om TreePath tp = clickedElement; if (tp != null) { lastClickComp = (DefaultMutableTreeNode) tp.getLastPathComponent(); updateBtnUI(); } }
From source file:TreeDragTest.java
public void dragGestureRecognized(DragGestureEvent dge) { TreePath path = sourceTree.getSelectionPath(); if ((path == null) || (path.getPathCount() <= 1)) { // We can't move the root node or an empty selection return;/*from w ww . j a v a 2 s . co m*/ } oldNode = (DefaultMutableTreeNode) path.getLastPathComponent(); transferable = new TransferableTreeNode(path); source.startDrag(dge, DragSource.DefaultMoveNoDrop, transferable, this); // If you support dropping the node anywhere, you should probably // start with a valid move cursor: //source.startDrag(dge, DragSource.DefaultMoveDrop, transferable, // this); }
From source file:com.compomics.cell_coord.gui.controller.load.LoadTracksController.java
/** * Import the files selected in the Data Tree. *//*ww w . j a v a 2 s.c o m*/ private void importFiles() { for (TreePath selectionPath : loadTracksPanel.getDirectoryTree().getSelectionPaths()) { String fileName = (String) selectionPath.getLastPathComponent().toString(); File trackFile = new File(directory.getAbsolutePath() + File.separator + fileName); try { // get the sample Sample sample = parseTrackFile(trackFile); // get the tracks from the sample List<Track> currentTracks = sample.getTracks(); // add all its spots to the binding list for (Track track : currentTracks) { trackSpotsBindingList.addAll(track.getTrackSpots()); } // add the sample to the list samples.add(sample); if (trackSpotsTableBinding == null) { trackSpotsTableBinding = SwingBindings.createJTableBinding(AutoBinding.UpdateStrategy.READ, trackSpotsBindingList, loadTracksPanel.getTracksTable()); showTracksInTable(); } } catch (FileParserException ex) { LOG.error("Could not parse the file: " + trackFile, ex); cellCoordController.showMessage( (String) loadTracksPanel.getFileFormatComboBox().getSelectedItem() + " expected!", "Error parsing file", JOptionPane.ERROR_MESSAGE); return; } } }
From source file:de.codesourcery.eve.skills.ui.components.impl.BlueprintChooserComponent.java
public Blueprint getCurrentlySelectedBlueprint() { final TreePath path = tree.getSelectionPath(); if (path != null && path.getPathCount() > 0) { return getSelectedBlueprint((ITreeNode) path.getLastPathComponent()); }/*from w w w . ja v a 2s .c o m*/ return null; }