Ejemplo n.º 1
0
  /**
   * Messages getTreeNodeForPage(path, onlyIfVisible, shouldCreate, path.length) as long as path is
   * non-null and the length is {@literal >} 0. Otherwise returns null.
   */
  private FHTreeStateNode getNodeForPath(
      TreePath path, boolean onlyIfVisible, boolean shouldCreate) {
    if (path != null) {
      FHTreeStateNode node;

      node = getMapping(path);
      if (node != null) {
        if (onlyIfVisible && !node.isVisible()) return null;
        return node;
      }
      if (onlyIfVisible) return null;

      // Check all the parent paths, until a match is found.
      Stack<TreePath> paths;

      if (tempStacks.size() == 0) {
        paths = new Stack<TreePath>();
      } else {
        paths = tempStacks.pop();
      }

      try {
        paths.push(path);
        path = path.getParentPath();
        node = null;
        while (path != null) {
          node = getMapping(path);
          if (node != null) {
            // Found a match, create entries for all paths in
            // paths.
            while (node != null && paths.size() > 0) {
              path = paths.pop();
              node = node.createChildFor(path.getLastPathComponent());
            }
            return node;
          }
          paths.push(path);
          path = path.getParentPath();
        }
      } finally {
        paths.removeAllElements();
        tempStacks.push(paths);
      }
      // If we get here it means they share a different root!
      return null;
    }
    return null;
  }
Ejemplo n.º 2
0
 public void makeVisible(TreePath path) {
   if (path != null) {
     TreePath parent = path.getParentPath();
     if (parent != null) {
       expandPath(parent);
     }
   }
 }
Ejemplo n.º 3
0
 public boolean isExpanded(TreePath path) {
   if (this.expandedPaths.contains(path)) {
     // Ensure all parents are expanded
     TreePath parent = path.getParentPath();
     return parent == null ? true : isExpanded(parent);
   } else {
     return false;
   }
 }
Ejemplo n.º 4
0
 public void removeSelectionPath(TreePath path) {
   if (this.selectedPaths.remove(path)) {
     // Need to redisplay the parent
     markForRefresh(path.getParentPath());
     if (this.selectionListener != null) {
       this.selectionListener.selectionChanged(new TreeSelectionEvent(this, path, false));
     }
   }
 }
Ejemplo n.º 5
0
  public Object getNode(TreePath path) {
    if (path == TreePath.ROOT_PATH) {
      return model.getRoot();
    }

    Object parent = getNode(path.getParentPath());
    if (parent == null) {
      return null;
    }

    return model.getChild(parent, path.getLastKey());
  }
Ejemplo n.º 6
0
  /** Marks the path <code>path</code> expanded state to <code>isExpanded</code>. */
  public void setExpandedState(TreePath path, boolean isExpanded) {
    if (isExpanded) ensurePathIsExpanded(path, true);
    else if (path != null) {
      TreePath parentPath = path.getParentPath();

      // YECK! Make the parent expanded.
      if (parentPath != null) {
        FHTreeStateNode parentNode = getNodeForPath(parentPath, false, true);
        if (parentNode != null) parentNode.makeVisible();
      }
      // And collapse the child.
      FHTreeStateNode childNode = getNodeForPath(path, true, false);

      if (childNode != null) childNode.collapse(true);
    }
  }
Ejemplo n.º 7
0
 /**
  * Returns true if the value identified by path is currently viewable, which means it is either
  * the root or all of its parents are expanded. Otherwise, this method returns false.
  *
  * @return true if the node is viewable, otherwise false
  */
 public boolean isVisible(TreePath path) {
   if (path == TreePath.ROOT_PATH) {
     return true;
   }
   if (path != null) {
     TreePath parent = path.getParentPath();
     if (parent != null) {
       return isExpanded(parent);
     } else {
       // root node
       return true;
     }
   } else {
     return false;
   }
 }
Ejemplo n.º 8
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;
  }
Ejemplo n.º 9
0
  /**
   * Ensures that all the path components in path are expanded, accept for the last component which
   * will only be expanded if expandLast is true. Returns true if succesful in finding the path.
   */
  private boolean ensurePathIsExpanded(TreePath aPath, boolean expandLast) {
    if (aPath != null) {
      // Make sure the last entry isn't a leaf.
      if (treeModel.isLeaf(aPath.getLastPathComponent())) {
        aPath = aPath.getParentPath();
        expandLast = true;
      }
      if (aPath != null) {
        FHTreeStateNode lastNode = getNodeForPath(aPath, false, true);

        if (lastNode != null) {
          lastNode.makeVisible();
          if (expandLast) lastNode.expand();
          return true;
        }
      }
    }
    return false;
  }
Ejemplo n.º 10
0
  /**
   * Returns an Enumerator that increments over the visible paths starting at the passed in
   * location. The ordering of the enumeration is based on how the paths are displayed.
   */
  public Enumeration<TreePath> getVisiblePathsFrom(TreePath path) {
    if (path == null) return null;

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

    if (node != null) {
      return new VisibleFHTreeStateNodeEnumeration(node);
    }
    TreePath parentPath = path.getParentPath();

    node = getNodeForPath(parentPath, true, false);
    if (node != null && node.isExpanded()) {
      return new VisibleFHTreeStateNodeEnumeration(
          node,
          treeModel.getIndexOfChild(
              parentPath.getLastPathComponent(), path.getLastPathComponent()));
    }
    return null;
  }
Ejemplo n.º 11
0
  /**
   * Returns a rectangle giving the bounds needed to draw path.
   *
   * @param path a TreePath specifying a node
   * @param placeIn a Rectangle object giving the available space
   * @return a Rectangle object specifying the space to be used
   */
  public Rectangle getBounds(TreePath path, Rectangle placeIn) {
    if (path == null) return null;

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

    if (node != null) return getBounds(node, -1, placeIn);

    // node hasn't been created yet.
    TreePath parentPath = path.getParentPath();

    node = getNodeForPath(parentPath, true, false);
    if (node != null && node.isExpanded()) {
      int childIndex =
          treeModel.getIndexOfChild(parentPath.getLastPathComponent(), path.getLastPathComponent());

      if (childIndex != -1) return getBounds(node, childIndex, placeIn);
    }
    return null;
  }