Search in sources :

Example 16 with NodeBase

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

the class PanelEquationTree method updateVisibility.

public void updateVisibility(TreeNode[] path) {
    if (path.length < 2) {
        updateVisibility(path, -1);
    } else {
        NodeBase c = (NodeBase) path[path.length - 1];
        NodeBase p = (NodeBase) path[path.length - 2];
        int index = p.getIndexFiltered(c);
        updateVisibility(path, index);
    }
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) ExtensionPoint(gov.sandia.n2a.plugins.ExtensionPoint)

Example 17 with NodeBase

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

the class StoredPath method restore.

public void restore(JTree tree) {
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    // goal is to find n closest to original selected node as possible
    NodeBase n = (NodeBase) model.getRoot();
    // First restore all previously expanded nodes
    for (String[] stringPath : others) {
        NodeBase c = n;
        for (String key : stringPath) {
            c = c.child(key);
            if (c == null)
                break;
        }
        if (c != null && c.visible(model.filterLevel))
            tree.expandPath(new TreePath(c.getPath()));
    }
    // Second, locate the focused node and pay special attention to its visibility
    for (String key : keys) {
        int childCount = n.getChildCount();
        int i;
        for (i = 0; i < childCount; i++) {
            NodeBase c = (NodeBase) n.getChildAt(i);
            if (c.source.key().equals(key)) {
                n = c;
                break;
            }
        }
        if (// The key was not found at all. n remains at parent node
        i >= childCount) {
            // Always expand the parent when a child is lost.
            expanded = true;
            break;
        }
        if (// The node we actually found is currently filtered out, so find nearest sibling
        !n.visible(model.filterLevel)) {
            // If nothing is found, n will remain at the parent.
            n = (NodeBase) n.getParent();
            // First walk forward
            boolean found = false;
            for (int j = i + 1; j < childCount; j++) {
                NodeBase c = (NodeBase) n.getChildAt(j);
                if (c.visible(model.filterLevel)) {
                    n = c;
                    found = true;
                    break;
                }
            }
            if (found)
                break;
            // Then if needed, walk backward.
            for (int j = i - 1; j >= 0; j--) {
                NodeBase c = (NodeBase) n.getChildAt(j);
                if (c.visible(model.filterLevel)) {
                    n = c;
                    found = true;
                    break;
                }
            }
            if (!found)
                expanded = true;
            break;
        }
    }
    TreePath path = new TreePath(n.getPath());
    tree.setSelectionPath(path);
    if (expanded)
        tree.expandPath(path);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) TreePath(javax.swing.tree.TreePath)

Example 18 with NodeBase

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

the class AddAnnotation method destroy.

public static void destroy(List<String> path, boolean canceled, String name, String blockName) {
    // Retrieve created node
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    NodeBase container = parent;
    if (parent instanceof NodePart)
        container = parent.child(blockName);
    NodeBase createdNode = container.child(name);
    PanelEquationTree pet = PanelModel.instance.panelEquations;
    JTree tree = pet.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    FontMetrics fm = createdNode.getFontMetrics(tree);
    boolean containerIsVisible = true;
    TreeNode[] createdPath = createdNode.getPath();
    int index = container.getIndexFiltered(createdNode);
    if (canceled)
        index--;
    MPart block = (MPart) parent.source.child(blockName);
    block.clear(name);
    if (// There is no overridden value, so this node goes away completely.
    block.child(name) == null) {
        model.removeNodeFromParent(createdNode);
        if (block.size() == 0) {
            // commit suicide
            parent.source.clear(blockName);
            if (parent instanceof NodePart) {
                model.removeNodeFromParent(container);
                // No need to update order, because we just destroyed $metadata, where order is stored.
                // No need to update tab stops in grandparent, because block nodes don't offer any tab stops.
                containerIsVisible = false;
            }
        }
    } else // Just exposed an overridden value, so update display.
    {
        if (// We are always visible, but our parent could disappear.
        container.visible(model.filterLevel)) {
            createdNode.updateColumnWidths(fm);
        } else {
            containerIsVisible = false;
        }
    }
    if (containerIsVisible) {
        container.updateTabStops(fm);
        container.allNodesChanged(model);
    }
    pet.updateVisibility(createdPath, index);
    if (path.size() == 1 && name.equals("lock"))
        pet.updateLock();
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) JTree(javax.swing.JTree) MPart(gov.sandia.n2a.eqset.MPart) FontMetrics(java.awt.FontMetrics) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 19 with NodeBase

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

the class AddAnnotations method create.

public static void create(List<String> path, int index, MNode saved, NodeFactory factory) {
    NodeBase parent = NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    String blockName = saved.key();
    NodeBase n = parent.child(blockName);
    if (n != null && !(n instanceof NodeContainer))
        throw new CannotRedoException();
    NodeContainer node = (NodeContainer) n;
    MPart block = (MPart) parent.source.childOrCreate(blockName);
    block.merge(saved);
    PanelModel mep = PanelModel.instance;
    JTree tree = mep.panelEquations.tree;
    FilteredTreeModel model = (FilteredTreeModel) tree.getModel();
    if (node == null) {
        node = (NodeContainer) factory.create(block);
        model.insertNodeIntoUnfiltered(node, parent, index);
    }
    // Replaces all nodes, so they are set to require tab initialization.
    node.build();
    node.filter(model.filterLevel);
    mep.panelEquations.updateVisibility(node.getPath());
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) MPart(gov.sandia.n2a.eqset.MPart) JTree(javax.swing.JTree) CannotRedoException(javax.swing.undo.CannotRedoException) NodeContainer(gov.sandia.n2a.ui.eq.tree.NodeContainer) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 20 with NodeBase

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

the class AddAnnotations method destroy.

public static void destroy(List<String> path, String blockName) {
    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();
    NodeContainer node = (NodeContainer) parent.child(blockName);
    TreeNode[] nodePath = node.getPath();
    int index = parent.getIndexFiltered(node);
    MPart mparent = parent.source;
    mparent.clear(blockName);
    if (mparent.child(blockName) == null) {
        model.removeNodeFromParent(node);
    } else // Just exposed an overridden node
    {
        // Necessary to remove all overridden nodes
        node.build();
        node.filter(model.filterLevel);
    }
    mep.panelEquations.updateVisibility(nodePath, index);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) PanelModel(gov.sandia.n2a.ui.eq.PanelModel) JTree(javax.swing.JTree) MPart(gov.sandia.n2a.eqset.MPart) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) NodeContainer(gov.sandia.n2a.ui.eq.tree.NodeContainer) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Aggregations

NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)39 MPart (gov.sandia.n2a.eqset.MPart)20 JTree (javax.swing.JTree)19 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)18 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)15 TreeNode (javax.swing.tree.TreeNode)15 FontMetrics (java.awt.FontMetrics)12 CannotRedoException (javax.swing.undo.CannotRedoException)12 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)11 CannotUndoException (javax.swing.undo.CannotUndoException)8 TreePath (javax.swing.tree.TreePath)7 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)5 ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)4 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)4 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)4 NodeEquation (gov.sandia.n2a.ui.eq.tree.NodeEquation)3 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)2 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)2 NodeReference (gov.sandia.n2a.ui.eq.tree.NodeReference)2 Font (java.awt.Font)2