Example #1
0
  protected void collapsePaths(Set<TreePath> collapsedPaths) {
    for (TreePath path : collapsedPaths) {
      for (int i = 0; i < getRowCount(); ++i) {
        TreePath treePath = getPathForRow(i);

        if (treePath.toString().equals(path.toString())) {
          collapsePath(treePath);
          break;
        }
      }
    }
  }
 /**
  * Return the rocket component that a TreePath object is referring to.
  *
  * @param path the TreePath
  * @return the RocketComponent the path is referring to.
  * @throws NullPointerException if path is null
  * @throws BugException if the path does not refer to a RocketComponent
  */
 public static RocketComponent componentFromPath(TreePath path) {
   Object last = path.getLastPathComponent();
   if (!(last instanceof RocketComponent)) {
     throw new BugException("Tree path does not refer to a RocketComponent: " + path.toString());
   }
   return (RocketComponent) last;
 }
Example #3
0
 private void jTree1MousePressed(java.awt.event.MouseEvent evt) {
   if (evt.getButton() == MouseEvent.BUTTON3) {
     TreePath path = jTree1.getPathForLocation(evt.getX(), evt.getY());
     if (path != null) {
       System.out.println(path.toString());
       TreeNode node = (TreeNode) path.getLastPathComponent();
       menu = new SubMenu(node);
       menu.show(evt.getComponent(), evt.getX(), evt.getY());
     }
   }
 }
 private @Nonnull String[] selectionPaths(@Nonnull JTree tree) {
   TreePath[] paths = tree.getSelectionPaths();
   if (paths == null) {
     return EMPTY;
   }
   int count = paths.length;
   if (count == 0) {
     return EMPTY;
   }
   String[] pathArray = new String[count];
   for (int i = 0; i < count; i++) {
     TreePath path = paths[i];
     pathArray[i] = path != null ? path.toString() : null;
   }
   return pathArray;
 }
Example #5
0
  void doMouseClicked(MouseEvent me) {
    TreePath tp = tree.getPathForLocation(me.getX(), me.getY());

    if (tp != null) log.info(tp.toString()); // jtf.setText(tp.toString());
    else log.info(""); // jtf.setText("");
  }