use of gov.sandia.n2a.ui.eq.tree.NodeAnnotations 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.NodeAnnotations 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.NodeAnnotations 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 static void updateOrder(JTree tree, 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;
NodeBase a = AddAnnotation.findExact(metadataNode, false, "gui", "order");
if (// found
a != null) {
MNode m = ((NodeAnnotation) a).folded;
// Value is in last column, so no need to invalidate columns.
m.set(order);
if (tree != null) {
// Cause gui.order to update it's text.
a.setUserObject();
((FilteredTreeModel) tree.getModel()).nodeChanged(a);
}
}
}
use of gov.sandia.n2a.ui.eq.tree.NodeAnnotations 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();
}
use of gov.sandia.n2a.ui.eq.tree.NodeAnnotations in project n2a by frothga.
the class ChangeOrder method apply.
public void apply(int indexBefore, int indexAfter, int indexMetadata, boolean createOrder, boolean destroyOrder) {
NodeBase parent = NodeBase.locateNode(path);
if (parent == null)
throw new CannotUndoException();
PanelEquationTree pet = parent.getTree();
FilteredTreeModel model = (FilteredTreeModel) pet.tree.getModel();
NodeBase moveNode = (NodeBase) parent.getChildAt(indexBefore);
model.removeNodeFromParent(moveNode);
NodeAnnotations metadataNode = (NodeAnnotations) parent.child("$metadata");
boolean needBuild = false;
if (createOrder) {
if (metadataNode == null) {
metadataNode = new NodeAnnotations((MPart) parent.source.childOrCreate("$metadata"));
model.insertNodeIntoUnfiltered(metadataNode, parent, indexMetadata);
}
metadataNode.source.childOrCreate("gui", "order");
needBuild = true;
}
if (destroyOrder) {
MNode mparent = metadataNode.source;
mparent.clear("gui", "order");
if (mparent.child("gui").size() == 0)
mparent.clear("gui");
if (mparent.size() == 0) {
parent.source.clear("$metadata");
model.removeNodeFromParent(metadataNode);
} else {
needBuild = true;
}
}
if (needBuild) {
List<String> expanded = AddAnnotation.saveExpandedNodes(pet.tree, metadataNode);
metadataNode.build();
metadataNode.filter();
if (metadataNode.visible()) {
model.nodeStructureChanged(metadataNode);
AddAnnotation.restoreExpandedNodes(pet.tree, metadataNode, expanded);
}
}
model.insertNodeIntoUnfiltered(moveNode, parent, indexAfter);
TreeNode[] movePath = moveNode.getPath();
if (!destroyOrder)
pet.updateOrder(movePath);
pet.updateVisibility(movePath);
}
Aggregations