예제 #1
0
  /**
   * Returns the bounds for the given node. If <code>childIndex</code> is -1, the bounds of <code>
   * parent</code> are returned, otherwise the bounds of the node at <code>childIndex</code> are
   * returned.
   */
  private Rectangle getBounds(FHTreeStateNode parent, int childIndex, Rectangle placeIn) {
    boolean expanded;
    int level;
    int row;
    Object value;

    if (childIndex == -1) {
      // Getting bounds for parent
      row = parent.getRow();
      value = parent.getUserObject();
      expanded = parent.isExpanded();
      level = parent.getLevel();
    } else {
      row = parent.getRowToModelIndex(childIndex);
      value = treeModel.getChild(parent.getUserObject(), childIndex);
      expanded = false;
      level = parent.getLevel() + 1;
    }

    Rectangle bounds = getNodeDimensions(value, row, level, expanded, boundsBuffer);
    // No node dimensions, bail.
    if (bounds == null) return null;

    if (placeIn == null) placeIn = new Rectangle();

    placeIn.x = bounds.x;
    placeIn.height = getRowHeight();
    placeIn.y = row * placeIn.height;
    placeIn.width = bounds.width;
    return placeIn;
  }
예제 #2
0
  /**
   * Returns the row that the last item identified in path is visible at. Will return -1 if any of
   * the elements in path are not currently visible.
   */
  public int getRowForPath(TreePath path) {
    if (path == null || root == null) return -1;

    FHTreeStateNode node = getNodeForPath(path, true, false);

    if (node != null) return node.getRow();

    TreePath parentPath = path.getParentPath();

    node = getNodeForPath(parentPath, true, false);
    if (node != null && node.isExpanded()) {
      return node.getRowToModelIndex(
          treeModel.getIndexOfChild(
              parentPath.getLastPathComponent(), path.getLastPathComponent()));
    }
    return -1;
  }