use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class EquationTreeCellRenderer method getTreeCellRendererComponent.
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
if (baseFont == null) {
baseFont = getFont().deriveFont(Font.PLAIN);
baseFontSize = baseFont.getSize2D();
}
NodeBase n = (NodeBase) value;
setForeground(n.getForegroundColor());
setIcon(getIconFor(n, expanded, leaf));
Font f = getFontFor(n);
setFont(f);
if (n.needsInitTabs()) {
n.initTabs(tree.getGraphics().getFontMetrics(f));
// convertValueToText() is called first thing in super.getTreeCellRendererComponent(),
// but text very likely has changed, so we need to call it again here.
setText(tree.convertValueToText(value, selected, expanded, leaf, row, hasFocus));
}
return this;
}
use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class FilteredTreeModel method insertNodeIntoUnfiltered.
public void insertNodeIntoUnfiltered(MutableTreeNode newChild, MutableTreeNode parent, int childrenIndex) {
NodeBase p = (NodeBase) parent;
NodeBase c = (NodeBase) newChild;
p.insert(c, childrenIndex);
// If c brings a new subtree, ensure it is filtered.
c.filter(filterLevel);
if (// Don't send any event
!c.visible(filterLevel)) {
p.insertFiltered(-1, childrenIndex, true);
return;
}
// Determine filtered index
int filteredIndex;
List<Integer> filtered = p.getFiltered();
if (filtered == null) {
filteredIndex = childrenIndex;
} else {
int count = filtered.size();
for (filteredIndex = 0; filteredIndex < count; filteredIndex++) {
if (filtered.get(filteredIndex).intValue() >= childrenIndex)
break;
}
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 nodeChanged.
public void nodeChanged(TreeNode node) {
if (listenerList == null || node == null)
return;
NodeBase parent = (NodeBase) node.getParent();
if (parent != null) {
int filteredIndex = parent.getIndexFiltered(node);
if (filteredIndex >= 0) {
int[] changedIndices = new int[1];
changedIndices[0] = filteredIndex;
nodesChanged(parent, changedIndices);
}
} else if (node == getRoot()) {
nodesChanged(node, null);
}
}
use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class PanelEquationTree method getSelected.
public NodeBase getSelected() {
NodeBase result = null;
TreePath path = tree.getSelectionPath();
if (path != null)
result = (NodeBase) path.getLastPathComponent();
if (result == null)
return root;
return result;
}
use of gov.sandia.n2a.ui.eq.tree.NodeBase in project n2a by frothga.
the class PanelEquationTree method addAtSelected.
public void addAtSelected(String type) {
if (locked)
return;
NodeBase selected = getSelected();
if (// only happens when root is null
selected == null) {
PanelModel.instance.undoManager.add(new AddDoc());
// Since root is itself a Part, don't create another one. For anything else, fall through and add it to the newly-created model.
if (type.equals("Part"))
return;
selected = root;
}
NodeBase editMe = selected.add(type, tree, null);
if (editMe != null) {
TreePath path = new TreePath(editMe.getPath());
tree.scrollPathToVisible(path);
tree.setSelectionPath(path);
tree.startEditingAtPath(path);
}
}
Aggregations