List of usage examples for javax.swing JTree getPathForRow
@BeanProperty(bound = false) public TreePath getPathForRow(int row)
From source file:Main.java
private static int getStopRow(JTree tree, int startRow) { int startDepth = tree.getPathForRow(startRow).getPathCount(); int last = tree.getRowCount(); int stopRow = last; for (int i = startRow + 1; i < last; ++i) { int depth = tree.getPathForRow(i).getPathCount(); if (depth <= startDepth) { stopRow = i;//from w w w. ja va2 s. c o m break; } } return stopRow; }
From source file:Main.java
/** * Saves the current expansion state of a JTree and returns it in an Enumeration for storing purposes. Example: A * JTree that has all its branches collapsed will return a TreeExpansionState of ",0". * //from w ww . j ava2 s . com * @param tree * Save the current expansion state of this tree * @return The current expansion state of the given tree as Enumeration<TreePath> */ public static String getTreeExpansionState(JTree tree, int row) { TreePath rowPath = tree.getPathForRow(row); StringBuilder sb = new StringBuilder(); int rowCount = tree.getRowCount(); for (int i = row; i < rowCount; i++) { TreePath path = tree.getPathForRow(i); if (i == row || isDescendant(path, rowPath)) { if (tree.isExpanded(path)) sb.append("," + String.valueOf(i - row)); } else { break; } } return sb.toString(); }
From source file:it.unibas.spicygui.controllo.datasource.operators.CreaWidgetAlberi.java
private void scansioneAlbero(JTree albero, Component source, Component target, boolean sourceFlag) { //VEcchio codice che mette widget solo per le foglie // for (int i = 0; i < listaFoglie.size(); i++) { // int tmp = (Integer) listaFoglie.get(i); for (int i = 0; i < albero.getRowCount(); i++) { TreePath treePath = albero.getPathForRow(i); if (treePath != null && albero.isVisible(treePath)) { if (logger.isTraceEnabled()) { logger.trace("punto trovato: " + albero.getPathBounds(treePath).getLocation()); }/*from w ww .j av a 2 s. c o m*/ Point convertedPoint = SwingUtilities.convertPoint(source, albero.getPathBounds(treePath).getLocation(), target); createWidget(convertedPoint, albero, treePath, sourceFlag); if (logger.isTraceEnabled()) { logger.trace("punto convertito: " + convertedPoint); } } } contatore = -1; listaFoglie = new ArrayList(); }
From source file:net.rptools.maptool.client.ui.MapToolFrame.java
private JComponent createDrawTreePanel() { final JTree tree = new JTree(); drawablesPanel = new DrawablesPanel(); drawPanelTreeModel = new DrawPanelTreeModel(tree); tree.setModel(drawPanelTreeModel);/* w ww . j a v a2s . c o m*/ tree.setCellRenderer(new DrawPanelTreeCellRenderer()); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); splitPane.setContinuousLayout(true); splitPane.setTopComponent(new JScrollPane(tree)); splitPane.setBottomComponent(drawablesPanel); splitPane.setDividerLocation(100); // Add mouse Event for right click menu tree.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { TreePath path = tree.getPathForLocation(e.getX(), e.getY()); if (path == null) { return; } Object row = path.getLastPathComponent(); int rowIndex = tree.getRowForLocation(e.getX(), e.getY()); if (SwingUtilities.isLeftMouseButton(e)) { if (!SwingUtil.isShiftDown(e) && !SwingUtil.isControlDown(e)) { tree.clearSelection(); } tree.addSelectionInterval(rowIndex, rowIndex); if (row instanceof DrawnElement) { if (e.getClickCount() == 2) { DrawnElement de = (DrawnElement) row; getCurrentZoneRenderer() .centerOn(new ZonePoint((int) de.getDrawable().getBounds().getCenterX(), (int) de.getDrawable().getBounds().getCenterY())); } } int[] treeRows = tree.getSelectionRows(); java.util.Arrays.sort(treeRows); drawablesPanel.clearSelectedIds(); for (int i = 0; i < treeRows.length; i++) { TreePath p = tree.getPathForRow(treeRows[i]); if (p.getLastPathComponent() instanceof DrawnElement) { DrawnElement de = (DrawnElement) p.getLastPathComponent(); drawablesPanel.addSelectedId(de.getDrawable().getId()); } } } if (SwingUtilities.isRightMouseButton(e)) { if (!isRowSelected(tree.getSelectionRows(), rowIndex) && !SwingUtil.isShiftDown(e)) { tree.clearSelection(); tree.addSelectionInterval(rowIndex, rowIndex); drawablesPanel.clearSelectedIds(); } final int x = e.getX(); final int y = e.getY(); EventQueue.invokeLater(new Runnable() { public void run() { DrawnElement firstElement = null; Set<GUID> selectedDrawSet = new HashSet<GUID>(); for (TreePath path : tree.getSelectionPaths()) { if (path.getLastPathComponent() instanceof DrawnElement) { DrawnElement de = (DrawnElement) path.getLastPathComponent(); if (firstElement == null) { firstElement = de; } selectedDrawSet.add(de.getDrawable().getId()); } } if (!selectedDrawSet.isEmpty()) { try { new DrawPanelPopupMenu(selectedDrawSet, x, y, getCurrentZoneRenderer(), firstElement).showPopup(tree); } catch (IllegalComponentStateException icse) { log.info(tree.toString(), icse); } } } }); } } }); // Add Zone Change event MapTool.getEventDispatcher().addListener(new AppEventListener() { public void handleAppEvent(AppEvent event) { drawPanelTreeModel.setZone((Zone) event.getNewValue()); } }, MapTool.ZoneEvent.Activated); return splitPane; }
From source file:org.apache.jmeter.JMeter.java
/** * Starts up JMeter in GUI mode/*from w w w .j a v a 2 s .c om*/ */ private void startGui(String testFile) { String jMeterLaf = LookAndFeelCommand.getJMeterLaf(); try { UIManager.setLookAndFeel(jMeterLaf); } catch (Exception ex) { log.warn("Could not set LAF to:" + jMeterLaf, ex); } PluginManager.install(this, true); JMeterTreeModel treeModel = new JMeterTreeModel(); JMeterTreeListener treeLis = new JMeterTreeListener(treeModel); final ActionRouter instance = ActionRouter.getInstance(); instance.populateCommandMap(); treeLis.setActionHandler(instance); // NOTUSED: GuiPackage guiPack = GuiPackage.getInstance(treeLis, treeModel); MainFrame main = new MainFrame(treeModel, treeLis); ComponentUtil.centerComponentInWindow(main, 80); main.setVisible(true); instance.actionPerformed(new ActionEvent(main, 1, ActionNames.ADD_ALL)); if (testFile != null) { try { File f = new File(testFile); log.info("Loading file: " + f); FileServer.getFileServer().setBaseForScript(f); HashTree tree = SaveService.loadTree(f); GuiPackage.getInstance().setTestPlanFile(f.getAbsolutePath()); Load.insertLoadedTree(1, tree); } catch (ConversionException e) { log.error("Failure loading test file", e); JMeterUtils.reportErrorToUser(SaveService.CEtoString(e)); } catch (Exception e) { log.error("Failure loading test file", e); JMeterUtils.reportErrorToUser(e.toString()); } } else { JTree jTree = GuiPackage.getInstance().getMainFrame().getTree(); TreePath path = jTree.getPathForRow(0); jTree.setSelectionPath(path); FocusRequester.requestFocus(jTree); } }
From source file:org.executequery.gui.browser.TreeFindAction.java
protected boolean changed(JComponent comp, String searchString, Position.Bias bias) { if (StringUtils.isBlank(searchString)) { return false; }//w ww .j a v a 2 s .c o m JTree tree = (JTree) comp; String prefix = searchString; if (ignoreCase()) { prefix = prefix.toUpperCase(); } boolean wildcardStart = prefix.startsWith("*"); if (wildcardStart) { prefix = prefix.substring(1); } else { prefix = "^" + prefix; } prefix = prefix.replaceAll("\\*", ".*"); Matcher matcher = Pattern.compile(prefix).matcher(""); List<TreePath> matchedPaths = new ArrayList<TreePath>(); for (int i = 1; i < tree.getRowCount(); i++) { TreePath path = tree.getPathForRow(i); String text = tree.convertValueToText(path.getLastPathComponent(), tree.isRowSelected(i), tree.isExpanded(i), true, i, false); if (ignoreCase()) { text = text.toUpperCase(); } // if ((wildcardStart && text.contains(prefix)) || text.startsWith(prefix, 0)) { // // matchedPaths.add(path); // } matcher.reset(text); if (matcher.find()) { matchedPaths.add(path); } } foundValues(matchedPaths); return !(matchedPaths.isEmpty()); }
From source file:org.executequery.gui.browser.TreeFindAction.java
public TreePath getNextMatch(JTree tree, String prefix, int startingRow, Position.Bias bias) { int max = tree.getRowCount(); if (prefix == null) { throw new IllegalArgumentException(); }//from www .j a v a2 s.c om if (startingRow < 0 || startingRow >= max) { throw new IllegalArgumentException(); } if (ignoreCase()) { prefix = prefix.toUpperCase(); } // start search from the next/previous element froom the // selected element int increment = (bias == null || bias == Position.Bias.Forward) ? 1 : -1; int row = startingRow; do { TreePath path = tree.getPathForRow(row); String text = tree.convertValueToText(path.getLastPathComponent(), tree.isRowSelected(row), tree.isExpanded(row), true, row, false); if (ignoreCase()) { text = text.toUpperCase(); } if (text.startsWith(prefix)) { return path; } row = (row + increment + max) % max; } while (row != startingRow); return null; }
From source file:pcgen.gui2.tabs.CompanionInfoTab.java
private void selectCompanion(CompanionFacade compFacade) { TreeTableModel treeTableModel = companionsTable.getTreeTableModel(); treeTableModel.getRoot();//from w w w . j a v a 2 s .co m TreePath path = null; JTree tree = companionsTable.getTree(); String companionType = compFacade.getCompanionType(); for (int i = 0; i < tree.getRowCount(); i++) { TreePath pathForRow = tree.getPathForRow(i); Object lastPathComponent = pathForRow.getLastPathComponent(); if (lastPathComponent.toString().startsWith(companionType)) { tree.expandRow(i); } else if (lastPathComponent instanceof pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) { CompanionFacade rowComp = (CompanionFacade) ((pcgen.gui2.tabs.CompanionInfoTab.CompanionsModel.CompanionNode) lastPathComponent) .getValueAt(0); if (rowComp != null && rowComp.getFileRef().get() == compFacade.getFileRef().get() && rowComp.getNameRef().get() == compFacade.getNameRef().get() && rowComp.getRaceRef().get() == compFacade.getRaceRef().get()) { path = pathForRow; } } } if (path != null) { companionsTable.getTree().setSelectionPath(path); companionsTable.getTree().scrollPathToVisible(path); } }