예제 #1
0
  /**
   * Compares this {@code TreePath} to the specified object. This returns {@code true} if {@code o}
   * is a {@code TreePath} with the exact same elements (as determined by using {@code equals} on
   * each element of the path).
   *
   * @param o the object to compare
   */
  public boolean equals(Object o) {
    if (o == this) return true;
    if (o instanceof TreePath) {
      TreePath oTreePath = (TreePath) o;

      if (getPathCount() != oTreePath.getPathCount()) return false;
      for (TreePath path = this; path != null; path = path.getParentPath()) {
        if (!(path.getLastPathComponent().equals(oTreePath.getLastPathComponent()))) {
          return false;
        }
        oTreePath = oTreePath.getParentPath();
      }
      return true;
    }
    return false;
  }
예제 #2
0
  /**
   * Returns an ordered array of the elements of this {@code TreePath}. The first element is the
   * root.
   *
   * @return an array of the elements in this {@code TreePath}
   */
  public Object[] getPath() {
    int i = getPathCount();
    Object[] result = new Object[i--];

    for (TreePath path = this; path != null; path = path.getParentPath()) {
      result[i--] = path.getLastPathComponent();
    }
    return result;
  }
예제 #3
0
 public void editSelected() {
   TreePath selected = tree.getSelectionPath();
   if (selected != null) {
     DefaultMutableTreeNode node = (DefaultMutableTreeNode) selected.getLastPathComponent();
     Object obj = node.getUserObject();
     if (obj instanceof CavityDBObject) {
       CavityDBObject dbObj = (CavityDBObject) obj;
       new ObjectEditingFrame(new ObjectEditingPanel(dbObj));
     }
   }
 }
예제 #4
0
  private String textGen(TreePath p) {

    MyNode selectedNode = (MyNode) p.getLastPathComponent();
    String text = "men allt som";
    int n = selectedNode.getPath().length;

    for (int i = n - 1; i >= 0; i--) {
      text = text + " är " + selectedNode.getPath()[i].toString();
    }
    return text;
  }
예제 #5
0
  /**
   * Returns the path element at the specified index.
   *
   * @param index the index of the element requested
   * @return the element at the specified index
   * @throws IllegalArgumentException if the index is outside the range of this path
   */
  public Object getPathComponent(int index) {
    int pathLength = getPathCount();

    if (index < 0 || index >= pathLength)
      throw new IllegalArgumentException("Index " + index + " is out of the specified range");

    TreePath path = this;

    for (int i = pathLength - 1; i != index; i--) {
      path = path.getParentPath();
    }
    return path.getLastPathComponent();
  }
예제 #6
0
  private void showDetails(TreePath p) {

    if (p == null) {
      return;
    }

    MyNode selectedNode = (MyNode) p.getLastPathComponent();
    String textPath = textGen(p);

    JOptionPane.showMessageDialog(
        this,
        selectedNode.getLevelName()
            + ": "
            + selectedNode.getUserObject()
            + "\n"
            + selectedNode.getText()
            + "\n"
            + textPath);
  }
    private void myDoubleClick(int row, TreePath path) {
      if (path != null) {
        JFrame infoFrame = new JFrame("Object Info for: " + path);
        JLabel objectLabel;
        JLabel parentPathLabel;

        // Display Selected Object Name;
        objectLabel = new JLabel("Object: " + path.getLastPathComponent().toString());
        objectLabel.setHorizontalAlignment(SwingConstants.CENTER);

        // Display specific object information
        parentPathLabel = new JLabel("Parent Path: " + path.getParentPath());
        parentPathLabel.setHorizontalAlignment(SwingConstants.CENTER);

        // Construct infoFrame
        infoFrame.getContentPane().add(objectLabel, BorderLayout.CENTER);
        infoFrame.getContentPane().add(parentPathLabel, BorderLayout.SOUTH);
        infoFrame.pack();
        infoFrame.setVisible(true);
      }
    }