Search in sources :

Example 1 with Move

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

the class PanelEquationTree method moveSelected.

public void moveSelected(int direction) {
    if (locked)
        return;
    TreePath path = tree.getSelectionPath();
    if (path == null)
        return;
    NodeBase nodeBefore = (NodeBase) path.getLastPathComponent();
    NodeBase parent = (NodeBase) nodeBefore.getParent();
    if (// Only parts support $metadata.gui.order
    parent instanceof NodePart) {
        // First check if we can move in the filtered (visible) list.
        int indexBefore = model.getIndexOfChild(parent, nodeBefore);
        int indexAfter = indexBefore + direction;
        if (indexAfter >= 0 && indexAfter < model.getChildCount(parent)) {
            // Then convert to unfiltered indices.
            NodeBase nodeAfter = (NodeBase) model.getChild(parent, indexAfter);
            indexBefore = parent.getIndex(nodeBefore);
            indexAfter = parent.getIndex(nodeAfter);
            PanelModel.instance.undoManager.add(new Move((NodePart) parent, indexBefore, indexAfter));
        }
    }
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) TreePath(javax.swing.tree.TreePath) Move(gov.sandia.n2a.ui.eq.undo.Move) NodePart(gov.sandia.n2a.ui.eq.tree.NodePart) ExtensionPoint(gov.sandia.n2a.plugins.ExtensionPoint)

Aggregations

ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)1 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)1 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)1 Move (gov.sandia.n2a.ui.eq.undo.Move)1 TreePath (javax.swing.tree.TreePath)1