Search in sources :

Example 1 with GraphPanel

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

the class GraphNode method nudge.

public void nudge(ActionEvent e, int dx, int dy) {
    if (container.locked)
        return;
    if ((e.getModifiers() & ActionEvent.CTRL_MASK) != 0) {
        dx *= 10;
        dy *= 10;
    }
    List<GraphNode> selection = container.panelEquationGraph.getSelection();
    selection.remove(this);
    MNode metadata = new MVolatile();
    NodePart np;
    MNode bounds;
    GraphPanel gp = container.panelEquationGraph.graphPanel;
    if (this == gp.pinIn) {
        np = container.part;
        bounds = metadata.childOrCreate("gui", "pin", "bounds", "in");
    } else if (this == gp.pinOut) {
        np = container.part;
        bounds = metadata.childOrCreate("gui", "pin", "bounds", "out");
    } else {
        np = node;
        bounds = metadata.childOrCreate("gui", "bounds");
    }
    Rectangle now = getBounds();
    if (dx != 0 || np != node)
        metadata.set(now.x - parent.offset.x + dx, "gui", "bounds", "x");
    if (dy != 0 || np != node)
        metadata.set(now.y - parent.offset.y + dy, "gui", "bounds", "y");
    ChangeAnnotations ca = new ChangeAnnotations(np, metadata);
    ca.graph = true;
    UndoManager um = MainFrame.instance.undoManager;
    if (selection.isEmpty()) {
        um.apply(ca);
    } else {
        CompoundEditView compound = new CompoundEditView(CompoundEditView.CLEAR_GRAPH);
        um.addEdit(compound);
        // delayed execution
        compound.addEdit(ca);
        if (np == node)
            compound.leadPath = np.getKeyPath();
        for (GraphNode g : selection) {
            metadata = new MVolatile();
            if (g == gp.pinIn) {
                np = container.part;
                bounds = metadata.childOrCreate("gui", "pin", "bounds", "in");
            } else if (g == gp.pinOut) {
                np = container.part;
                bounds = metadata.childOrCreate("gui", "pin", "bounds", "out");
            } else {
                np = g.node;
                bounds = metadata.childOrCreate("gui", "bounds");
                if (compound.leadPath == null)
                    compound.leadPath = np.getKeyPath();
            }
            now = g.getBounds();
            if (dx != 0 || np != node)
                bounds.set(now.x - parent.offset.x + dx, "x");
            if (dy != 0 || np != node)
                bounds.set(now.y - parent.offset.y + dy, "y");
            ca = new ChangeAnnotations(np, metadata);
            ca.graph = true;
            compound.addEdit(ca);
        }
        um.endCompoundEdit();
        compound.redo();
    }
}
Also used : UndoManager(gov.sandia.n2a.ui.UndoManager) GraphPanel(gov.sandia.n2a.ui.eq.PanelEquationGraph.GraphPanel) Rectangle(java.awt.Rectangle) ChangeAnnotations(gov.sandia.n2a.ui.eq.undo.ChangeAnnotations) CompoundEditView(gov.sandia.n2a.ui.eq.undo.CompoundEditView) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) MNode(gov.sandia.n2a.db.MNode) MVolatile(gov.sandia.n2a.db.MVolatile)

Example 2 with GraphPanel

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

the class GraphEdge method animate.

public void animate(Point p) {
    if (p == null) {
        tipDrag = false;
    } else {
        tipDrag = true;
        tip.x = p.x;
        tip.y = p.y;
    }
    Rectangle paintRegion = bounds;
    if (edgeOther != null)
        paintRegion = paintRegion.union(edgeOther.bounds);
    updateShape(true);
    paintRegion = paintRegion.union(bounds);
    GraphPanel parent = nodeFrom.parent;
    parent.layout.componentMoved(bounds);
    if (edgeOther != null) {
        paintRegion = paintRegion.union(edgeOther.bounds);
        parent.layout.componentMoved(edgeOther.bounds);
    }
    parent.repaint(paintRegion);
}
Also used : GraphPanel(gov.sandia.n2a.ui.eq.PanelEquationGraph.GraphPanel) Rectangle(java.awt.Rectangle)

Aggregations

GraphPanel (gov.sandia.n2a.ui.eq.PanelEquationGraph.GraphPanel)2 Rectangle (java.awt.Rectangle)2 MNode (gov.sandia.n2a.db.MNode)1 MVolatile (gov.sandia.n2a.db.MVolatile)1 UndoManager (gov.sandia.n2a.ui.UndoManager)1 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)1 ChangeAnnotations (gov.sandia.n2a.ui.eq.undo.ChangeAnnotations)1 CompoundEditView (gov.sandia.n2a.ui.eq.undo.CompoundEditView)1