List of usage examples for javax.swing.tree TreePath getPathComponent
public Object getPathComponent(int index)
From source file:Main.java
public static String getNameNodoAtIndex(int ind, JTree jtree) { TreePath parentPath = jtree.getSelectionPath(); int level = 0; if (parentPath != null) { level = parentPath.getPathCount(); }/*from www .ja va 2 s.c o m*/ return "" + parentPath.getPathComponent(ind); }
From source file:org.schreibubi.JCombinations.ui.GridChartPanel.java
/** * Create PDF/*from w w w . j av a 2s.c o m*/ * * @param name * Filename * @param selection * Selected Nodes * @param dm * DataModel * @param pl * ProgressListener */ @SuppressWarnings("unchecked") public static void generatePDF(File name, DataModel dm, ArrayList<TreePath> selection, ProgressListener pl) { com.lowagie.text.Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50); try { ArrayList<ExtendedJFreeChart> charts = dm.getCharts(selection); if (charts.size() > 0) { PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(name)); writer.setViewerPreferences(PdfWriter.PageModeUseOutlines); document.addAuthor("Jrg Werner"); document.addSubject("Created by JCombinations"); document.addKeywords("JCombinations"); document.addCreator("JCombinations using iText"); // we define a header and a footer HeaderFooter header = new HeaderFooter(new Phrase("JCombinations by Jrg Werner"), false); HeaderFooter footer = new HeaderFooter(new Phrase("Page "), new Phrase(".")); footer.setAlignment(Element.ALIGN_CENTER); document.setHeader(header); document.setFooter(footer); document.open(); DefaultFontMapper mapper = new DefaultFontMapper(); FontFactory.registerDirectories(); mapper.insertDirectory("c:\\WINNT\\fonts"); PdfContentByte cb = writer.getDirectContent(); pl.progressStarted(new ProgressEvent(GridChartPanel.class, 0, charts.size())); for (int i = 0; i < charts.size(); i++) { ExtendedJFreeChart chart = charts.get(i); PdfTemplate tp = cb.createTemplate(document.right(EXTRA_MARGIN) - document.left(EXTRA_MARGIN), document.top(EXTRA_MARGIN) - document.bottom(EXTRA_MARGIN)); Graphics2D g2d = tp.createGraphics(document.right(EXTRA_MARGIN) - document.left(EXTRA_MARGIN), document.top(EXTRA_MARGIN) - document.bottom(EXTRA_MARGIN), mapper); Rectangle2D r2d = new Rectangle2D.Double(0, 0, document.right(EXTRA_MARGIN) - document.left(EXTRA_MARGIN), document.top(EXTRA_MARGIN) - document.bottom(EXTRA_MARGIN)); chart.draw(g2d, r2d); g2d.dispose(); cb.addTemplate(tp, document.left(EXTRA_MARGIN), document.bottom(EXTRA_MARGIN)); PdfDestination destination = new PdfDestination(PdfDestination.FIT); TreePath treePath = chart.getTreePath(); PdfOutline po = cb.getRootOutline(); for (int j = 0; j < treePath.getPathCount(); j++) { ArrayList<PdfOutline> lpo = po.getKids(); PdfOutline cpo = null; for (PdfOutline outline : lpo) if (outline.getTitle().compareTo(treePath.getPathComponent(j).toString()) == 0) cpo = outline; if (cpo == null) cpo = new PdfOutline(po, destination, treePath.getPathComponent(j).toString()); po = cpo; } document.newPage(); pl.progressIncremented(new ProgressEvent(GridChartPanel.class, i)); } document.close(); pl.progressEnded(new ProgressEvent(GridChartPanel.class)); } } catch (DocumentException de) { System.err.println(de.getMessage()); } catch (IOException ioe) { System.err.println(ioe.getMessage()); } }
From source file:net.pms.newgui.SelectRenderers.java
/** * Create the GUI and show it./*from w w w . ja v a2 s . co m*/ */ public void showDialog() { if (!init) { // Initial call build(); init = true; } SrvTree.validate(); // Refresh setting if modified selectedRenderers = configuration.getSelectedRenderers(); TreePath root = new TreePath(allRenderers); if (selectedRenderers.isEmpty() || (selectedRenderers.size() == 1 && selectedRenderers.get(0) == null)) { checkTreeManager.getSelectionModel().clearSelection(); } else if (selectedRenderers.size() == 1 && selectedRenderers.get(0).equals(allRenderersTreeName)) { checkTreeManager.getSelectionModel().setSelectionPath(root); } else { if (root.getLastPathComponent() instanceof SearchableMutableTreeNode) { SearchableMutableTreeNode rootNode = (SearchableMutableTreeNode) root.getLastPathComponent(); SearchableMutableTreeNode node = null; List<TreePath> selectedRenderersPath = new ArrayList<>(selectedRenderers.size()); for (String selectedRenderer : selectedRenderers) { try { node = rootNode.findInBranch(selectedRenderer, true); } catch (IllegalChildException e) { } if (node != null) { selectedRenderersPath.add(new TreePath(node.getPath())); } } checkTreeManager.getSelectionModel().setSelectionPaths( selectedRenderersPath.toArray(new TreePath[selectedRenderersPath.size()])); } else { LOGGER.error("Illegal node class in SelectRenderers.showDialog(): {}", root.getLastPathComponent().getClass().getSimpleName()); } } int selectRenderers = JOptionPane.showOptionDialog((Component) PMS.get().getFrame(), this, Messages.getString("GeneralTab.5"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (selectRenderers == JOptionPane.OK_OPTION) { TreePath[] selected = checkTreeManager.getSelectionModel().getSelectionPaths(); if (selected.length == 0) { if (configuration.setSelectedRenderers("")) { PMS.get().getFrame().setReloadable(true); // notify the user to restart the server } } else if (selected.length == 1 && selected[0].getLastPathComponent() instanceof SearchableMutableTreeNode && ((SearchableMutableTreeNode) selected[0].getLastPathComponent()).getNodeName() .equals(allRenderers.getNodeName())) { if (configuration.setSelectedRenderers(allRenderersTreeName)) { PMS.get().getFrame().setReloadable(true); // notify the user to restart the server } } else { List<String> selectedRenderers = new ArrayList<>(); for (TreePath path : selected) { String rendererName = ""; if (path.getPathComponent(0).equals(allRenderers)) { for (int i = 1; i < path.getPathCount(); i++) { if (path.getPathComponent(i) instanceof SearchableMutableTreeNode) { if (!rendererName.isEmpty()) { rendererName += " "; } rendererName += ((SearchableMutableTreeNode) path.getPathComponent(i)) .getNodeName(); } else { LOGGER.error("Invalid tree node component class {}", path.getPathComponent(i).getClass().getSimpleName()); } } if (!rendererName.isEmpty()) { selectedRenderers.add(rendererName); } } else { LOGGER.warn("Invalid renderer treepath encountered: {}", path.toString()); } } if (configuration.setSelectedRenderers(selectedRenderers)) { PMS.get().getFrame().setReloadable(true); // notify the user to restart the server } } } }
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 w w w. j a va 2 s.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:edu.purdue.cc.bionet.ui.DistributionAnalysisDisplayPanel.java
/** * Sets the SampleGroups for this panel. * //from w w w .ja v a 2 s . c o m * @param sampleGroups The new set of groups */ public void setSampleGroups(Collection<SampleGroup> sampleGroups) { super.setSampleGroups(sampleGroups); // clear the listeners CheckboxTree tree = this.selectorTree.getTree(); for (TreeSelectionListener t : tree.getTreeSelectionListeners()) { tree.removeTreeSelectionListener(t); // CheckboxTree doesn't have a method for getting TreeCheckingListeners, // so we'll try this and catch any exceptions. try { tree.removeTreeCheckingListener((TreeCheckingListener) t); } catch (ClassCastException e) { } } for (ItemListener i : this.noFitButton.getItemListeners()) { this.noFitButton.removeItemListener(i); } for (ItemListener i : this.robustFitButton.getItemListeners()) { this.robustFitButton.removeItemListener(i); } for (ItemListener i : this.chiSquareFitButton.getItemListeners()) { this.chiSquareFitButton.removeItemListener(i); } this.experimentGraphPanel.removeAll(); this.bottomPanel.removeAll(); int cols = (int) Math.ceil(Math.sqrt(sampleGroups.size())); int rows = (int) Math.ceil(sampleGroups.size() / cols); GridLayout layout = (GridLayout) this.experimentGraphPanel.getLayout(); layout.setRows(rows); layout.setColumns(cols); layout = (GridLayout) this.bottomPanel.getLayout(); layout.setRows(rows); layout.setColumns(cols); TreePath path = selectorTree.getTree().getSelectionPath(); int level = path.getPathCount(); DefaultMutableTreeNode selectedNode = null; if (level > MOLECULE) { selectedNode = (DefaultMutableTreeNode) path.getPathComponent(MOLECULE); } for (SampleGroup sampleGroup : sampleGroups) { SampleGraph sampleGraph = new SampleGraph(experiments, sampleGroup); ExperimentGraph experimentGraph = new ExperimentGraph(experiments, sampleGroup); this.bottomPanel.add(sampleGraph); this.selectorTree.getTree().addTreeSelectionListener(sampleGraph); this.experimentGraphPanel.add(experimentGraph, BorderLayout.CENTER); // add the listeners this.selectorTree.getTree().addTreeCheckingListener(sampleGraph); this.selectorTree.getTree().addTreeSelectionListener(experimentGraph); this.selectorTree.getTree().addTreeCheckingListener(experimentGraph); this.noFitButton.addItemListener(experimentGraph); this.robustFitButton.addItemListener(experimentGraph); this.chiSquareFitButton.addItemListener(experimentGraph); if (selectedNode != null) { sampleGraph.setGraph(selectedNode); experimentGraph.setGraph(selectedNode); } } this.removeSampleGroupsMenuItem.setEnabled(sampleGroups != null && sampleGroups.size() > 1); this.experimentGraphPanel.validate(); this.bottomPanel.validate(); }
From source file:edu.ku.brc.af.tasks.subpane.formeditor.ViewSetSelectorPanel.java
/** * @return// ww w . java 2s. c o m */ protected FormViewDef getViewDefFromSelection() { if (tree != null && tree.getSelectionModel() != null && tree.getSelectionModel().getSelectionPath() != null) { TreePath path = tree.getSelectionModel().getSelectionPath(); for (int i = 0; i < path.getPathCount(); i++) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getPathComponent(i); if (node.getUserObject() instanceof FormViewDef) { return (FormViewDef) node.getUserObject(); } } } return null; }
From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java
/** * /*from w w w . j a va 2 s .com*/ */ private DefaultMutableTreeNode getSelectedTreeNode() { boolean isNodeSelected = tree.getSelectionCount() > -1; if (isNodeSelected) { TreePath path = tree.getSelectionModel().getSelectionPath(); if (path != null) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path .getPathComponent(path.getPathCount() - 1); if (node != null) { return node; } } } return null; }
From source file:edu.ku.brc.specify.ui.containers.ContainerTreePanel.java
/** * // w ww.j ava 2s .com */ private void updateBtnUI() { containerAssocIcon.setEnabled(false); colObjAssocIcon.setEnabled(false); colObjIcon.setEnabled(false); containerIcon.setEnabled(false); if (tree != null) { boolean isNodeSelected = tree.getSelectionCount() > 0; if (isNodeSelected) { TreePath path = tree.getSelectionModel().getSelectionPath(); if (path != null && path.getPathCount() > 0) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) path .getPathComponent(path.getPathCount() - 1); if (node != null) { Object dataObj = node.getUserObject(); if (dataObj != null) { boolean isContainer = dataObj instanceof Container; if (isContainer) { int[] selInxs = tree.getSelectionRows(); Container cntr = (Container) dataObj; edaContnrPanel.getEditBtn().setEnabled(selInxs[0] > 0); if (!isViewMode) { edaContnrPanel.getAddBtn().setEnabled(true); edaContnrPanel.getDelBtn().setEnabled(selInxs[0] > 0); } else { edaContnrPanel.getEditBtn().setEnabled(selInxs[0] > -1); } if (!isViewMode) { colObjAssocIcon.setEnabled(true); containerAssocIcon.setEnabled(true); } else { containerAssocIcon.setEnabled(cntr.getCollectionObject() != null); colObjAssocIcon.setEnabled(cntr.getCollectionObject() != null); } colObjIcon.setEnabled(!isViewMode); containerIcon.setEnabled(true); if (!isViewMode) { edaColObjPanel.getAddBtn().setEnabled(true); edaColObjPanel.getDelBtn().setEnabled(false); } edaColObjPanel.getEditBtn().setEnabled(false); searchCOBtn.setEnabled(true); searchCNBtn.setEnabled(true); } else { edaContnrPanel.setEnabled(false); containerIcon.setEnabled(false); colObjIcon.setEnabled(true); edaColObjPanel.getEditBtn().setEnabled(true); if (!isViewMode) { edaColObjPanel.getDelBtn().setEnabled(true); edaColObjPanel.getAddBtn().setEnabled(false); searchCOBtn.setEnabled(false); searchCNBtn.setEnabled(false); } containerAssocIcon.setEnabled(false); colObjAssocIcon.setEnabled(false); } } } } } else { edaColObjPanel.setEnabled(false); edaContnrPanel.setEnabled(false); colObjIcon.setEnabled(false); containerIcon.setEnabled(false); searchCOBtn.setEnabled(false); searchCNBtn.setEnabled(false); containerAssocIcon.setEnabled(false); colObjAssocIcon.setEnabled(false); } } }
From source file:com.pironet.tda.TDA.java
private DefaultMutableTreeNode fetchTop(TreePath pathToRoot) { return ((DefaultMutableTreeNode) pathToRoot.getPathComponent(getRootNodeLevel())); }
From source file:net.jradius.client.gui.JRadiusSimulator.java
/** * This method initializes addButton /* www. j a v a 2s. c o m*/ * * @return javax.swing.JButton */ private JButton getAddButton() { if (addButton == null) { addButton = new JButton(); addButton.setText("Add"); addButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent e) { int rows[] = attributeTree.getSelectionRows(); if (rows != null) { for (int i = 0; i < rows.length; i++) { TreePath path = attributeTree.getPathForRow(rows[i]); DefaultMutableTreeNode node = (DefaultMutableTreeNode) path .getPathComponent(path.getPathCount() - 1); String attr = (String) node.getUserObject(); try { attributesTableModel.addAttribute(AttributeFactory.newAttribute(attr)); } catch (Exception ex) { ex.printStackTrace(); } } attributesTableModel.fireTableDataChanged(); } } }); } return addButton; }