use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class FilteredTreeModel method insertNodeInto.
public void insertNodeInto(MutableTreeNode newChild, MutableTreeNode parent, int filteredIndex) {
NodeBase p = (NodeBase) parent;
NodeBase c = (NodeBase) newChild;
int childrenIndex;
List<Integer> filtered = p.getFiltered();
if (filtered == null)
childrenIndex = filteredIndex;
else if (filteredIndex < filtered.size())
childrenIndex = filtered.get(filteredIndex).intValue();
else
childrenIndex = p.getChildCount();
p.insert(c, childrenIndex);
c.filter(filterLevel);
if (!c.visible(filterLevel)) {
p.insertFiltered(-1, childrenIndex, true);
return;
}
p.insertFiltered(filteredIndex, childrenIndex, true);
int[] filteredIndices = new int[1];
filteredIndices[0] = filteredIndex;
nodesWereInserted(parent, filteredIndices);
}
use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class FilteredTreeModel method removeNodeFromParent.
public void removeNodeFromParent(MutableTreeNode child) {
NodeBase parent = (NodeBase) child.getParent();
if (parent == null)
throw new IllegalArgumentException("node does not have a parent.");
int filteredIndex = parent.getIndexFiltered((NodeBase) child);
parent.remove(child);
// No need to send event, because this node was not visible.
if (filteredIndex < 0)
return;
parent.removeFiltered(filteredIndex, true);
int[] removedIndices = new int[1];
Object[] removedObjects = new Object[1];
removedIndices[0] = filteredIndex;
removedObjects[0] = child;
nodesWereRemoved(parent, removedIndices, removedObjects);
}
use of gov.sandia.n2a.ui.eq.tree.NodeBase 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));
}
}
}
use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class PanelEquationTree method updateVisibility.
/**
* Ensure that the tree down to the changed node is displayed with correct visibility and override coloring.
* @param path Every node from root to changed node, including changed node itself.
* The trailing nodes are allowed to be disconnected from root in the filtered view of the model,
* and they are allowed to be deleted nodes. Note: deleted nodes will have null parents.
* Deleted nodes should already be removed from tree by the caller, with proper notification.
* @param index Position of the last node in its parent node. Only used if the last node has been deleted.
* A value less than 0 causes selection to shift up to the parent.
*/
public void updateVisibility(TreeNode[] path, int index) {
// Prepare list of indices for final selection
int[] selectionIndices = new int[path.length];
for (int i = 1; i < path.length; i++) {
NodeBase p = (NodeBase) path[i - 1];
NodeBase c = (NodeBase) path[i];
// Could be -1, if c has already been deleted.
selectionIndices[i] = model.getIndexOfChild(p, c);
}
// Adjust visibility
int inserted = path.length;
int removed = path.length;
int removedIndex = -1;
for (int i = path.length - 1; i > 0; i--) {
NodeBase p = (NodeBase) path[i - 1];
NodeBase c = (NodeBase) path[i];
// skip deleted nodes
if (c.getParent() == null)
continue;
int filteredIndex = model.getIndexOfChild(p, c);
boolean filteredOut = filteredIndex < 0;
if (c.visible(model.filterLevel)) {
if (filteredOut) {
// silently adjust the filtering
p.unhide(c, model, false);
// promise to notify model
inserted = i;
}
} else {
if (!filteredOut) {
p.hide(c, model, false);
removed = i;
removedIndex = filteredIndex;
}
}
}
// update color to indicate override state
int lastChange = Math.min(inserted, removed);
for (int i = 1; i < lastChange; i++) {
// Since it is hard to measure current color, just assume everything needs updating.
NodeBase c = (NodeBase) path[i];
if (c.getParent() == null)
continue;
model.nodeChanged(c);
Rectangle bounds = tree.getPathBounds(new TreePath(c.getPath()));
if (bounds != null)
tree.paintImmediately(bounds);
}
if (lastChange < path.length) {
NodeBase p = (NodeBase) path[lastChange - 1];
NodeBase c = (NodeBase) path[lastChange];
int[] childIndices = new int[1];
if (inserted < removed) {
childIndices[0] = p.getIndexFiltered(c);
model.nodesWereInserted(p, childIndices);
} else {
childIndices[0] = removedIndex;
Object[] childObjects = new Object[1];
childObjects[0] = c;
model.nodesWereRemoved(p, childIndices, childObjects);
}
repaintSouth(new TreePath(p.getPath()));
}
// select last visible node
int i = 1;
for (; i < path.length; i++) {
NodeBase c = (NodeBase) path[i];
if (c.getParent() == null)
break;
if (!c.visible(model.filterLevel))
break;
}
// Choose the last good node
i--;
NodeBase c = (NodeBase) path[i];
if (i == path.length - 2) {
index = Math.min(index, model.getChildCount(c) - 1);
if (index >= 0)
c = (NodeBase) model.getChild(c, index);
} else if (i < path.length - 2) {
int childIndex = Math.min(selectionIndices[i + 1], model.getChildCount(c) - 1);
if (childIndex >= 0)
c = (NodeBase) model.getChild(c, childIndex);
}
TreePath selectedPath = new TreePath(c.getPath());
tree.scrollPathToVisible(selectedPath);
tree.setSelectionPath(selectedPath);
if (lastChange >= path.length) {
boolean expanded = tree.isExpanded(selectedPath);
// Should this be more targeted?
model.nodeStructureChanged(c);
if (expanded)
tree.expandPath(selectedPath);
repaintSouth(selectedPath);
}
}
Aggregations