Search in sources :

Example 1 with NodeAnnotations

use of gov.sandia.n2a.ui.eq.tree.NodeAnnotations 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 NodeAnnotations

use of gov.sandia.n2a.ui.eq.tree.NodeAnnotations 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 3 with NodeAnnotations

use of gov.sandia.n2a.ui.eq.tree.NodeAnnotations 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 static void updateOrder(JTree tree, 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;
    NodeBase a = AddAnnotation.findExact(metadataNode, false, "gui", "order");
    if (// found
    a != null) {
        MNode m = ((NodeAnnotation) a).folded;
        // Value is in last column, so no need to invalidate columns.
        m.set(order);
        if (tree != null) {
            // Cause gui.order to update it's text.
            a.setUserObject();
            ((FilteredTreeModel) tree.getModel()).nodeChanged(a);
        }
    }
}
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) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) MNode(gov.sandia.n2a.db.MNode)

Example 4 with NodeAnnotations

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

the class AddAnnotation method update.

/**
 *        Do related record-keeping.
 *        This function is shared by all undo classes that modify $metadata.
 */
public static void update(NodeBase parent, boolean touchesPin, boolean touchesCategory) {
    while (parent instanceof NodeAnnotation || parent instanceof NodeAnnotations) parent = (NodeBase) parent.getParent();
    NodeVariable binding = null;
    if (parent instanceof NodeVariable && ((NodeVariable) parent).isBinding) {
        binding = (NodeVariable) parent;
        // So arrowhead can update.
        parent = (NodeBase) parent.getParent();
    }
    if (!(parent instanceof NodePart))
        return;
    NodePart p = (NodePart) parent;
    boolean touchesImage = p.iconCustom != null || p.source.child("$metadata", "gui", "icon") != null;
    if (touchesImage)
        p.setIcon();
    PanelEquations pe = PanelModel.instance.panelEquations;
    if (touchesPin) {
        p.updatePins();
        // A change in pin structure can affect any level of graph above the current node,
        // so always refresh display.
        pe.panelEquationGraph.updatePins();
        pe.panelEquationGraph.reconnect();
        pe.panelEquationGraph.repaint();
    }
    if (// It's either the parent node, or a node below the current level of graph.
    p.graph == null) {
        if (p == pe.part)
            pe.updateGUI();
    } else {
        if (// Target is parent itself.
        binding == null) {
            // PanelEquationGraph.reconnect() must come before updateGUI(). Otherwise, graph node might
            // operate on edges that no longer have pin metadata.
            p.graph.updateGUI();
        } else // Target is variable under parent, likely a connection binding.
        {
            if (!touchesPin) {
                String alias = binding.source.key();
                p.graph.updateEdge(alias, p.connectionBindings.get(alias));
            }
        // otherwise all edges in the graph have been updated above, so no need to do incremental update here.
        }
    }
    // Update categories in search list.
    if (touchesCategory)
        PanelModel.instance.panelSearch.search();
}
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) NodeVariable(gov.sandia.n2a.ui.eq.tree.NodeVariable) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart)

Example 5 with NodeAnnotations

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

the class ChangeOrder method apply.

public void apply(int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
    NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
    model.removeNodeFromParent(moveNode);
    NodeAnnotations metadataNode = (NodeAnnotations) parent.child("$metadata");
    boolean needBuild = false;
    if (createOrder) {
        if (metadataNode == null) {
            metadataNode = new NodeAnnotations((MPart) parent.source.childOrCreate("$metadata"));
            model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
        }
        metadataNode.source.childOrCreate("gui", "order");
        needBuild = true;
    }
    if (destroyOrder) {
        MNode mparent = metadataNode.source;
        mparent.clear("gui", "order");
        if (mparent.child("gui").size() == 0)
            mparent.clear("gui");
        if (mparent.size() == 0) {
            parent.source.clear("$metadata");
            model.removeNodeFromParent(metadataNode);
        } else {
            needBuild = true;
        }
    }
    if (needBuild) {
        List<String> expanded = AddAnnotation.saveExpandedNodes(pet.tree, metadataNode);
        metadataNode.build();
        metadataNode.filter();
        if (metadataNode.visible()) {
            model.nodeStructureChanged(metadataNode);
            AddAnnotation.restoreExpandedNodes(pet.tree, metadataNode, expanded);
        }
    }
    model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
    TreeNode[] movePath = moveNode.getPath();
    if (!destroyOrder)
        pet.updateOrder(movePath);
    pet.updateVisibility(movePath);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) MPart(gov.sandia.n2a.eqset.MPart) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel) MNode(gov.sandia.n2a.db.MNode)

Aggregations

NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)10 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)9 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)6 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)6 TreeNode (javax.swing.tree.TreeNode)6 MPart (gov.sandia.n2a.eqset.MPart)5 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)5 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)5 CannotUndoException (javax.swing.undo.CannotUndoException)5 MNode (gov.sandia.n2a.db.MNode)4 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)4 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)3 TreePath (javax.swing.tree.TreePath)3 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)2 FontMetrics (java.awt.FontMetrics)2 ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)1 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)1 PanelSearch (gov.sandia.n2a.ui.eq.PanelSearch)1 StoredPath (gov.sandia.n2a.ui.eq.StoredPath)1 JTree (javax.swing.JTree)1