コード例 #1
0
ファイル: Forest.java プロジェクト: joval/jPE
  public ITree addTree(ITree tree) throws IllegalArgumentException {
    for (ITree t : this) {
      //
      // Make sure none of the existing trees have this tree as a path
      //
      try {
        Node node = (Node) t.lookup(tree.getName());
        switch (node.getType()) {
          case TREE:
            // ignore - the target is being replaced
            break;
          case LEAF:
            ((Tree) node.getTree()).remove(node);
            break;
          default:
            throw new IllegalArgumentException(
                "Cannot add tree "
                    + tree.getName()
                    + " because tree "
                    + t.getName()
                    + " has existing node of type "
                    + node.getType());
        }
      } catch (NoSuchElementException e) {
        // no problem
      }

      //
      // Make sure this tree has none of the existing trees as a path
      //
      try {
        Node node = (Node) tree.lookup(t.getName());
        switch (node.getType()) {
          case TREE:
            // ignore - the target is being replaced
            break;
          case LEAF:
            ((Tree) node.getTree()).remove(node);
            break;
          default:
            throw new IllegalArgumentException(
                "Cannot add tree "
                    + tree.getName()
                    + " because it contains the node "
                    + t.getName()
                    + " of type "
                    + node.getType());
        }
      } catch (NoSuchElementException e) {
        // no problem
      }
    }

    return trees.put(tree.getName(), tree);
  }
コード例 #2
0
  // The Constructor
  public HoistStackItem(Node hoistedNode) {
    this.hoistedNode = hoistedNode;
    this.hoistedNodeParent = hoistedNode.getParent();
    this.hoistedNodeIndex = hoistedNodeParent.getChildIndex(hoistedNode);
    this.hoistedNodeDepth = hoistedNode.getDepth();

    this.oldNodeSet = hoistedNode.getTree().getRootNode();
    this.lineCountOffset = hoistedNode.getLineNumber();

    this.oldTreeCommentState = hoistedNode.getTree().getRootNodeCommentState();
    this.newTreeCommentState = hoistedNode.isComment();
  }
  // ActionListener Interface
  public void actionPerformed(ActionEvent e) {
    OutlinerDocument doc = (OutlinerDocument) Outliner.documents.getMostRecentDocumentTouched();
    OutlinerCellRendererImpl textArea = doc.panel.layout.getUIComponent(doc.tree.getEditingNode());

    if (textArea == null) {
      return;
    }

    Node node = textArea.node;
    JoeTree tree = node.getTree();
    OutlineLayoutManager layout = tree.getDocument().panel.layout;

    if (doc.tree.getComponentFocus() == OutlineLayoutManager.TEXT) {
      ToggleEditableAction.toggleEditableInheritanceText(node, tree, layout);
    } else if (doc.tree.getComponentFocus() == OutlineLayoutManager.ICON) {
      ToggleEditableAction.toggleEditableInheritance(node, tree, layout);
    }
  }
コード例 #4
0
  public static void main(String[] args) {
    Node<String> prez = Node.getTree();

    List<Node> reachable = BFS(prez);
    System.out.println(reachable.size());
    for (Node node : reachable) {
      System.out.println("Node: " + node + " distance from root: " + node.getDistance());
    }

    // This is fragile, and might break if Node.getTree() changes.
    Node<String> pop = prez.getChildren().get(1).getChildren().get(0).getChildren().get(0);

    List<Node> path = BFS2(prez, pop);
    System.out.println(path.size());
    for (Node node : path) {
      System.out.println("Node: " + node + " distance from root: " + node.getDistance());
    }
  }
コード例 #5
0
  // Methods
  public void dehoist() {
    // Shorthand
    JoeTree tree = hoistedNode.getTree();
    tree.setRootNodeCommentState(oldTreeCommentState);

    hoistedNode.setHoisted(false);

    // Prune things
    tree.setRootNode(oldNodeSet);
    tree.getVisibleNodes().clear();
    hoistedNodeParent.insertChild(hoistedNode, hoistedNodeIndex);
    hoistedNode.setDepthRecursively(hoistedNodeDepth);
    for (int i = 0; i < oldNodeSet.numOfChildren(); i++) {
      Node node = oldNodeSet.getChild(i);
      tree.insertNode(node);
    }

    return;
  }
コード例 #6
0
  // Undoable Interface
  @Override
  public void redo() {
    JoeTree tree = parent.getTree();

    // Remove node from visible nodes cache
    tree.removeNode(oldNode);

    // Swap the nodes
    parent.removeChild(oldNode, index);

    if (newNode != null) {
      parent.insertChild(newNode, index);

      // Insert the node into the visible nodes cache
      tree.insertNode(newNode);

      // Handle Selection
      tree.addNodeToSelection(newNode);
    }
  }
コード例 #7
0
  public void hoist() {

    // Shorthand
    JoeTree tree = hoistedNode.getTree();
    tree.setRootNodeCommentState(newTreeCommentState);

    hoistedNode.setHoisted(true);

    // Prune things
    hoistedNode.getParent().removeChild(hoistedNode);
    hoistedNode.setDepthRecursively(-1);
    tree.setRootNode(hoistedNode);
    tree.getVisibleNodes().clear();
    for (int i = 0; i < hoistedNode.numOfChildren(); i++) {
      Node node = hoistedNode.getChild(i);
      tree.insertNode(node);
    }

    return;
  }
コード例 #8
0
ファイル: MergeAction.java プロジェクト: hashrock/JOutliner
  @Override
  public void actionPerformed(ActionEvent e) {
    // System.out.println("MergeAction");

    OutlinerCellRendererImpl textArea = null;
    boolean isIconFocused = true;
    Component c = (Component) e.getSource();
    if (c instanceof OutlineButton) {
      textArea = ((OutlineButton) c).renderer;
    } else if (c instanceof OutlineLineNumber) {
      textArea = ((OutlineLineNumber) c).renderer;
    } else if (c instanceof OutlineCommentIndicator) {
      textArea = ((OutlineCommentIndicator) c).renderer;
    } else if (c instanceof OutlinerCellRendererImpl) {
      textArea = (OutlinerCellRendererImpl) c;
      isIconFocused = false;
    }

    // Shorthand
    Node node = textArea.node;
    JoeTree tree = node.getTree();
    OutlineLayoutManager layout = tree.getDocument().panel.layout;

    // System.out.println(e.getModifiers());
    switch (e.getModifiers()) {
      case 2:
        if (isIconFocused) {
          merge(node, tree, layout, false);
        }
        break;

      case 3:
        if (isIconFocused) {
          merge(node, tree, layout, true);
        }
        break;
    }
  }