use of gov.sandia.n2a.ui.eq.tree.NodeAnnotation 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;
}
}
}
use of gov.sandia.n2a.ui.eq.tree.NodeAnnotation in project n2a by frothga.
the class ChangeAnnotation method undo.
public void undo() {
super.undo();
apply(path, nameAfter, nameBefore, valueBefore, "$metadata", new NodeFactory() {
public NodeBase create(MPart part) {
return new NodeAnnotation(part);
}
});
}
use of gov.sandia.n2a.ui.eq.tree.NodeAnnotation 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);
}
use of gov.sandia.n2a.ui.eq.tree.NodeAnnotation in project n2a by frothga.
the class ChangeAnnotation method redo.
public void redo() {
super.redo();
apply(path, nameBefore, nameAfter, valueAfter, "$metadata", new NodeFactory() {
public NodeBase create(MPart part) {
return new NodeAnnotation(part);
}
});
}
Aggregations