Search in sources :

Example 1 with NodeAnnotation

use of gov.sandia.n2a.ui.eq.tree.NodeAnnotation in project n2a by frothga.

the class PanelEquationTree method updateOrder.

/**
 *        Records the current order of nodes in "gui.order", provided that metadata field exists.
 *        Otherwise, we assume the user doesn't care.
 *        @param path To the node that changed (added, deleted, moved). In general, this node's
 *        parent will be the part that is tracking the order of its children.
 */
public void updateOrder(TreeNode[] path) {
    NodePart parent = null;
    for (int i = path.length - 2; i >= 0; i--) {
        if (path[i] instanceof NodePart) {
            parent = (NodePart) path[i];
            break;
        }
    }
    // This should never happen, because root of tree is a NodePart.
    if (parent == null)
        return;
    // Find $metadata/gui.order for the currently selected node. If it exists, update it.
    // Note that this is a modified version of moveSelected() which does not actually move
    // anything, and which only modifies an existing $metadata/gui.order, not create a new one.
    NodeAnnotations metadataNode = null;
    String order = null;
    Enumeration<?> i = parent.children();
    while (i.hasMoreElements()) {
        NodeBase c = (NodeBase) i.nextElement();
        String key = c.source.key();
        if (order == null)
            order = key;
        else
            order = order + "," + key;
        if (key.equals("$metadata"))
            metadataNode = (NodeAnnotations) c;
    }
    if (metadataNode == null)
        return;
    i = metadataNode.children();
    while (i.hasMoreElements()) {
        NodeAnnotation a = (NodeAnnotation) i.nextElement();
        if (a.source.key().equals("gui.order")) {
            a.source.set(order);
            FontMetrics fm = a.getFontMetrics(tree);
            metadataNode.updateTabStops(fm);
            model.nodeChanged(a);
            break;
        }
    }
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) NodeAnnotation(gov.sandia.n2a.ui.eq.tree.NodeAnnotation) FontMetrics(java.awt.FontMetrics) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) ExtensionPoint(gov.sandia.n2a.plugins.ExtensionPoint)

Example 2 with NodeAnnotation

use of gov.sandia.n2a.ui.eq.tree.NodeAnnotation in project n2a by frothga.

the class ChangeAnnotation method undo.

public void undo() {
    super.undo();
    apply(path, nameAfter, nameBefore, valueBefore, "$metadata", new NodeFactory() {

        public NodeBase create(MPart part) {
            return new NodeAnnotation(part);
        }
    });
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) MPart(gov.sandia.n2a.eqset.MPart) NodeAnnotation(gov.sandia.n2a.ui.eq.tree.NodeAnnotation)

Example 3 with NodeAnnotation

use of gov.sandia.n2a.ui.eq.tree.NodeAnnotation in project n2a by frothga.

the class Move method apply.

public static void apply(List<String> path, int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
    model.removeNodeFromParent(moveNode);
    NodeBase metadataNode = parent.child("$metadata");
    if (createOrder) {
        if (metadataNode == null) {
            metadataNode = new NodeAnnotations((MPart) parent.source.set("$metadata", ""));
            model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
        }
        NodeBase orderNode = new NodeAnnotation((MPart) metadataNode.source.set("gui.order", ""));
        model.insertNodeIntoUnfiltered(orderNode, metadataNode, metadataNode.getChildCount());
    }
    if (destroyOrder) {
        NodeBase orderNode = metadataNode.child("gui.order");
        FontMetrics fm = orderNode.getFontMetrics(tree);
        metadataNode.source.clear("gui.order");
        model.removeNodeFromParent(metadataNode.child("gui.order"));
        if (metadataNode.getChildCount() == 0) {
            parent.source.clear("$metadata");
            model.removeNodeFromParent(metadataNode);
        } else {
            metadataNode.updateTabStops(fm);
            metadataNode.allNodesChanged(model);
        }
    }
    model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
    TreeNode[] movePath = moveNode.getPath();
    if (!destroyOrder)
        mep.panelEquations.updateOrder(movePath);
    mep.panelEquations.updateVisibility(movePath);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) JTree(javax.swing.JTree) NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) MPart(gov.sandia.n2a.eqset.MPart) NodeAnnotation(gov.sandia.n2a.ui.eq.tree.NodeAnnotation) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 4 with NodeAnnotation

use of gov.sandia.n2a.ui.eq.tree.NodeAnnotation in project n2a by frothga.

the class ChangeAnnotation method redo.

public void redo() {
    super.redo();
    apply(path, nameBefore, nameAfter, valueAfter, "$metadata", new NodeFactory() {

        public NodeBase create(MPart part) {
            return new NodeAnnotation(part);
        }
    });
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) MPart(gov.sandia.n2a.eqset.MPart) NodeAnnotation(gov.sandia.n2a.ui.eq.tree.NodeAnnotation)

Aggregations

NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)4 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)4 MPart (gov.sandia.n2a.eqset.MPart)3 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)2 FontMetrics (java.awt.FontMetrics)2 ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)1 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)1 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)1 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)1 JTree (javax.swing.JTree)1 TreeNode (javax.swing.tree.TreeNode)1 CannotUndoException (javax.swing.undo.CannotUndoException)1