// 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);
    }
  }
  // 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);
    }
  }
Beispiel #3
0
  @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;
    }
  }
Beispiel #4
0
  // IconFocusedMethods
  public static void merge(
      Node currentNode, JoeTree tree, OutlineLayoutManager layout, boolean withSpaces) {
    JoeNodeList nodeList = tree.getSelectedNodes();

    // Get merged text
    StringBuffer buf = new StringBuffer();
    boolean didMerge = false;

    if (withSpaces) {
      for (int i = 0, limit = nodeList.size(); i < limit; i++) {
        Node node = nodeList.get(i);

        // Skip if node is not editable
        if (!node.isEditable()) {
          continue;
        }

        didMerge = true;
        node.getMergedValueWithSpaces(buf, i);
      }
    } else {
      for (int i = 0, limit = nodeList.size(); i < limit; i++) {
        Node node = nodeList.get(i);

        // Skip if node is not editable
        if (!node.isEditable()) {
          continue;
        }

        didMerge = true;
        node.getMergedValue(buf);
      }
    }

    // It's possible all nodes were read-only. If so then abort.
    if (!didMerge) {
      return;
    }

    // Get youngest editable node
    Node youngestNode = null;
    for (int i = 0, limit = nodeList.size(); i < limit; i++) {
      Node node = nodeList.get(i);

      if (node.isEditable()) {
        youngestNode = node;
        break;
      }
    }

    // Abort if no editable nodes found.
    if (youngestNode == null) {
      return;
    }

    Node parent = youngestNode.getParent();
    CompoundUndoableReplace undoable = new CompoundUndoableReplace(parent);

    Node newNode = new NodeImpl(tree, buf.toString());
    newNode.setDepth(youngestNode.getDepth());
    newNode.setCommentState(youngestNode.getCommentState());

    undoable.addPrimitive(new PrimitiveUndoableReplace(parent, youngestNode, newNode));

    // Iterate over the remaining selected nodes deleting each one
    int mergeCount = 1;
    for (int i = 0, limit = nodeList.size(); i < limit; i++) {
      Node node = nodeList.get(i);

      // Abort if node is not editable
      if (!node.isEditable() || node == youngestNode) {
        continue;
      }

      undoable.addPrimitive(new PrimitiveUndoableReplace(parent, node, null));
      mergeCount++;
    }

    if (!undoable.isEmpty()) {
      if (withSpaces) {
        if (mergeCount == 1) {
          undoable.setName("Merge Node with Spaces");
        } else {
          undoable.setName(
              new StringBuffer()
                  .append("Merge ")
                  .append(mergeCount)
                  .append(" Nodes with Spaces")
                  .toString());
        }
      } else {
        if (mergeCount == 1) {
          undoable.setName("Merge Node");
        } else {
          undoable.setName(
              new StringBuffer().append("Merge ").append(mergeCount).append(" Nodes").toString());
        }
      }
      tree.getDocument().getUndoQueue().add(undoable);
      undoable.redo();
    }

    return;
  }