Ejemplo n.º 1
0
 public static List<TreePath> collectExpandedPaths(final JTree tree, TreePath path) {
   final ArrayList<TreePath> result = new ArrayList<TreePath>();
   if (!tree.isExpanded(path)) return result;
   final Object lastPathComponent = path.getLastPathComponent();
   final TreeModel model = tree.getModel();
   if (model.isLeaf(lastPathComponent)) {
     result.add(path);
   } else {
     boolean pathWasAdded = false;
     for (int i = model.getChildCount(lastPathComponent) - 1; i >= 0; i--) {
       final TreePath childPath = path.pathByAddingChild(model.getChild(lastPathComponent, i));
       if (model.isLeaf(lastPathComponent)) {
         if (!pathWasAdded) {
           result.add(path);
           pathWasAdded = true;
         }
       } else if (tree.isExpanded(childPath)) {
         result.addAll(collectExpandedPaths(tree, childPath));
       } else {
         if (!pathWasAdded) {
           result.add(path);
           pathWasAdded = true;
         }
       }
     }
   }
   return result;
 }
Ejemplo n.º 2
0
  /**
   * @param tree JTree to collect expanded paths from.
   * @param paths output parameter.
   */
  public static void collectExpandedPaths(
      @NotNull final JTree tree, @NotNull final List<TreePath> paths) {
    final TreeModel model = tree.getModel();
    final Object root = model.getRoot();
    LOG.assertTrue(root != null);

    collectExpandedPathsImpl(tree, paths, new TreePath(root));
  }
Ejemplo n.º 3
0
 public static ActionCallback selectFirstNode(final JTree tree) {
   final TreeModel model = tree.getModel();
   final Object root = model.getRoot();
   TreePath selectionPath = new TreePath(root);
   if (!tree.isRootVisible() && model.getChildCount(root) > 0)
     selectionPath = selectionPath.pathByAddingChild(model.getChild(root, 0));
   return selectPath(tree, selectionPath);
 }
 @Override
 public boolean isModified(CodeStyleSettings settings) {
   TreeModel treeModel = myTreeTable.getTree().getModel();
   TreeNode root = (TreeNode) treeModel.getRoot();
   if (isModified(root, settings)) {
     return true;
   }
   return false;
 }
Ejemplo n.º 5
0
 @Nullable
 public static TreeNode findNodeWithObject(
     final Object object, final TreeModel model, final Object parent) {
   for (int i = 0; i < model.getChildCount(parent); i++) {
     final DefaultMutableTreeNode childNode = (DefaultMutableTreeNode) model.getChild(parent, i);
     if (childNode.getUserObject().equals(object)) return childNode;
   }
   return null;
 }
  @Nullable
  private static TreePath findNodePath(MavenArchetype object, TreeModel model, Object parent) {
    for (int i = 0; i < model.getChildCount(parent); i++) {
      DefaultMutableTreeNode each = (DefaultMutableTreeNode) model.getChild(parent, i);
      if (each.getUserObject().equals(object)) return new TreePath(each.getPath());

      TreePath result = findNodePath(object, model, each);
      if (result != null) return result;
    }
    return null;
  }
Ejemplo n.º 7
0
  private static boolean collectExpandedPathsImpl(
      final JTree tree, final Collection<TreePath> paths, final TreePath path) {
    final TreeModel model = tree.getModel();
    final Object lastPathComponent = path.getLastPathComponent();
    if (model.isLeaf(lastPathComponent)) {
      return false;
    }

    boolean hasExpandedChildren = false;

    for (int i = model.getChildCount(lastPathComponent) - 1; i >= 0; i--) {
      hasExpandedChildren |=
          collectExpandedPathsImpl(
              tree, paths, path.pathByAddingChild(model.getChild(lastPathComponent, i)));
    }

    if (!hasExpandedChildren) {
      paths.add(path);
      return true;
    } else {
      return false;
    }
  }
Ejemplo n.º 8
0
  @Nullable
  public static Range<Integer> getExpandControlRange(final JTree aTree, final TreePath path) {
    TreeModel treeModel = aTree.getModel();

    final BasicTreeUI basicTreeUI = (BasicTreeUI) aTree.getUI();
    Icon expandedIcon = basicTreeUI.getExpandedIcon();

    Range<Integer> box = null;
    if (path != null && !treeModel.isLeaf(path.getLastPathComponent())) {
      int boxWidth;
      Insets i = aTree.getInsets();

      if (expandedIcon != null) {
        boxWidth = expandedIcon.getIconWidth();
      } else {
        boxWidth = 8;
      }

      int boxLeftX = i != null ? i.left : 0;

      boolean leftToRight = aTree.getComponentOrientation().isLeftToRight();
      int depthOffset = getDepthOffset(aTree);
      int totalChildIndent = basicTreeUI.getLeftChildIndent() + basicTreeUI.getRightChildIndent();

      if (leftToRight) {
        boxLeftX +=
            ((path.getPathCount() + depthOffset - 2) * totalChildIndent
                    + basicTreeUI.getLeftChildIndent())
                - boxWidth / 2;
      }
      int boxRightX = boxLeftX + boxWidth;

      box = new Range<Integer>(boxLeftX, boxRightX);
    }
    return box;
  }
 @Override
 protected void resetImpl(final CodeStyleSettings settings) {
   TreeModel treeModel = myTreeTable.getTree().getModel();
   TreeNode root = (TreeNode) treeModel.getRoot();
   resetNode(root, settings);
 }
 @Override
 public void apply(CodeStyleSettings settings) {
   TreeModel treeModel = myTreeTable.getTree().getModel();
   TreeNode root = (TreeNode) treeModel.getRoot();
   applyNode(root, settings);
 }
 private String getFilterStatus(TreeModel displayModel, TreeModel originalModel) {
   int count = displayModel.getChildCount(displayModel.getRoot());
   String text =
       count + " out of " + originalModel.getChildCount(originalModel.getRoot()) + " files";
   return text;
 }