Search in sources :

Example 6 with PanelEquations

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

the class AddPart method centerOf.

/**
 *        Determine the anchor position for a set of new parts.
 *        The main approach is to approximate the center of the viewport when the parent part is displayed.
 *        If that is not possible, the fallback is the average position of existing parts.
 *        If there are no existing parts, the position is set arbitrarily to (100,100). This gives a small
 *        margin from the edge for nice appearance, while not straying far from (0,0).
 */
public static Point centerOf(NodePart parent) {
    PanelEquations pe = PanelModel.instance.panelEquations;
    PanelEquationGraph peg = pe.panelEquationGraph;
    Dimension d = peg.getExtentSize();
    Point location = new Point(d.width / 2, d.height / 2);
    // Base on active viewport.
    if (parent == pe.part) {
        Point vp = peg.getViewPosition();
        Point offset = peg.getOffset();
        location.x += vp.x - offset.x;
        location.y += vp.y - offset.y;
        return location;
    }
    // Base on stored position of viewport.
    MNode boundsParent = parent.source.child("$metadata", "gui", "bounds", "parent");
    if (boundsParent != null) {
        location.x += boundsParent.getInt("x");
        location.y += boundsParent.getInt("y");
        return location;
    }
    // Base on average position of existing parts.
    Point center = new Point();
    int count = 0;
    Enumeration<?> children = parent.children();
    while (children.hasMoreElements()) {
        Object o = children.nextElement();
        if (!(o instanceof NodePart))
            continue;
        NodePart p = (NodePart) o;
        MNode bounds = p.source.child("$metadata", "gui", "bounds");
        if (bounds == null)
            continue;
        count++;
        center.x += bounds.getInt("x");
        center.y += bounds.getInt("y");
    }
    if (count == 1) {
        location.x = center.x + 100;
        location.y = center.y + 100;
    } else if (count > 1) {
        location.x = center.x / count;
        location.y = center.y / count;
    }
    return new Point(100, 100);
}
Also used : PanelEquationGraph(gov.sandia.n2a.ui.eq.PanelEquationGraph) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) Dimension(java.awt.Dimension) Point(java.awt.Point) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) MNode(gov.sandia.n2a.db.MNode) Point(java.awt.Point)

Example 7 with PanelEquations

use of gov.sandia.n2a.ui.eq.PanelEquations 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 8 with PanelEquations

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

the class AddInherit method create.

public static void create(List<String> path, String value) {
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotRedoException();
    NodePart grandparent = (NodePart) parent.getTrueParent();
    PanelEquations pe = PanelModel.instance.panelEquations;
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
    PanelEquationGraph peg = pe.panelEquationGraph;
    parent.source.set(value, "$inherit");
    parent.build();
    if (grandparent == null)
        parent.findConnections();
    else
        grandparent.findConnections();
    parent.rebuildPins();
    parent.filter();
    if (parent == pe.part) {
        peg.reloadPart();
        parent.filter();
    }
    // Since $inherit is being added, parent will almost certainly become visible, if it's not already.
    model.nodeStructureChanged(parent);
    TreeNode[] createdPath = parent.child("$inherit").getPath();
    pet.updateOrder(createdPath);
    pet.updateVisibility(createdPath);
    pet.animate();
    if (parent != pe.part) {
        peg.updatePins();
        peg.reconnect();
        peg.repaint();
    }
    if (// root node, so update categories in search list
    parent.getTrueParent() == null) {
        PanelModel.instance.panelSearch.search();
    }
}
Also used : PanelEquationGraph(gov.sandia.n2a.ui.eq.PanelEquationGraph) TreeNode(javax.swing.tree.TreeNode) CannotRedoException(javax.swing.undo.CannotRedoException) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 9 with PanelEquations

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

the class AddInherit method destroy.

public static void destroy(List<String> path, boolean canceled) {
    NodePart parent = (NodePart) NodeBase.locateNode(path);
    if (parent == null)
        throw new CannotUndoException();
    NodePart grandparent = (NodePart) parent.getTrueParent();
    NodeBase node = parent.child("$inherit");
    TreeNode[] nodePath = node.getPath();
    int index = parent.getIndexFiltered(node);
    if (canceled)
        index--;
    PanelEquations pe = PanelModel.instance.panelEquations;
    PanelEquationTree pet = parent.getTree();
    FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
    PanelEquationGraph peg = pe.panelEquationGraph;
    MPart mparent = parent.source;
    // Complex restructuring happens here.
    mparent.clear("$inherit");
    // Handles all cases (complete deletion or exposed hidden node)
    parent.build();
    if (grandparent == null)
        parent.findConnections();
    else
        grandparent.findConnections();
    parent.rebuildPins();
    parent.filter();
    if (parent == pe.part) {
        // safely disconnects old nodes, even though parent has been rebuilt with new nodes
        peg.reloadPart();
        // Ensure that parts are not visible in parent panel.
        parent.filter();
    }
    // Presumably, part node is still visible. Is there any harm in doing this if it is not?
    model.nodeStructureChanged(parent);
    pet.updateOrder(nodePath);
    pet.updateVisibility(nodePath, index);
    pet.animate();
    if (parent != pe.part) {
        peg.updatePins();
        peg.reconnect();
        peg.repaint();
    }
    if (// root node, so update categories in search list
    parent.getTrueParent() == null) {
        PanelModel.instance.panelSearch.search();
    }
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) MPart(gov.sandia.n2a.eqset.MPart) PanelEquationGraph(gov.sandia.n2a.ui.eq.PanelEquationGraph) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Example 10 with PanelEquations

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

the class ChangeCategory method apply.

public void apply(String key, List<String> selectionBefore, String categoryAfter, List<String> selectionAfter) {
    MNode doc = AppData.models.child(key);
    if (doc == null)
        throw new CannotUndoException();
    // Graph focus
    PanelSearch ps = PanelModel.instance.panelSearch;
    ps.lastSelection = selectionBefore;
    ps.takeFocus();
    // Update DB, and possibly equation tree.
    PanelEquations pe = PanelModel.instance.panelEquations;
    if (// direct to db
    doc != pe.record) {
        doc.set(categoryAfter, "$metadata", "gui", "category");
    } else // got through MPart
    {
        MNode source = pe.root.source;
        if (categoryAfter.isEmpty())
            source.clear("$metadata", "gui", "category");
        else
            source.set(categoryAfter, "$metadata", "gui", "category");
        PanelEquationTree pet = pe.root.getTree();
        FilteredTreeModel model = null;
        if (pet != null)
            model = (FilteredTreeModel) pet.tree.getModel();
        // See ChangeAnnotations for more general code.
        // To simplify things, we always rebuild the metadata block, even though that is often overkill.
        // For simplicity, assume this exists. DB models should always some metadata, such as "id". It is possible for the $metadata node to be deleted by user, so this is not guaranteed.
        NodeAnnotations metadataNode = (NodeAnnotations) pe.root.child("$metadata");
        List<String> expanded = null;
        if (model != null)
            expanded = AddAnnotation.saveExpandedNodes(pet.tree, metadataNode);
        metadataNode.build();
        metadataNode.filter();
        if (model != null && metadataNode.visible()) {
            model.nodeStructureChanged(metadataNode);
            AddAnnotation.restoreExpandedNodes(pet.tree, metadataNode, expanded);
        }
        if (pet != null) {
            TreeNode[] path = metadataNode.getPath();
            pet.updateVisibility(path, -2, false);
            pet.animate();
        }
    }
    // Update search panel.
    ps.lastSelection = selectionAfter;
    // This will apply lastSelection when done.
    ps.search();
}
Also used : NodeAnnotations(gov.sandia.n2a.ui.eq.tree.NodeAnnotations) PanelSearch(gov.sandia.n2a.ui.eq.PanelSearch) TreeNode(javax.swing.tree.TreeNode) CannotUndoException(javax.swing.undo.CannotUndoException) PanelEquations(gov.sandia.n2a.ui.eq.PanelEquations) MNode(gov.sandia.n2a.db.MNode) PanelEquationTree(gov.sandia.n2a.ui.eq.PanelEquationTree) FilteredTreeModel(gov.sandia.n2a.ui.eq.FilteredTreeModel)

Aggregations

PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)14 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)12 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)11 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)11 PanelEquationGraph (gov.sandia.n2a.ui.eq.PanelEquationGraph)10 TreeNode (javax.swing.tree.TreeNode)10 MPart (gov.sandia.n2a.eqset.MPart)7 CannotRedoException (javax.swing.undo.CannotRedoException)7 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)6 MNode (gov.sandia.n2a.db.MNode)5 CannotUndoException (javax.swing.undo.CannotUndoException)5 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)3 TreePath (javax.swing.tree.TreePath)3 EquationSet (gov.sandia.n2a.eqset.EquationSet)2 Variable (gov.sandia.n2a.eqset.Variable)2 AccessVariable (gov.sandia.n2a.language.AccessVariable)2 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)2 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)2 Point (java.awt.Point)2 ArrayList (java.util.ArrayList)2