Search in sources :

Example 11 with NodeBase

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;
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) Font(java.awt.Font)

Example 12 with NodeBase

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);
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase)

Example 13 with NodeBase

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);
    }
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase)

Example 14 with NodeBase

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;
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) TreePath(javax.swing.tree.TreePath)

Example 15 with NodeBase

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);
    }
}
Also used : NodeBase(gov.sandia.n2a.ui.eq.tree.NodeBase) TreePath(javax.swing.tree.TreePath) AddDoc(gov.sandia.n2a.ui.eq.undo.AddDoc)

Aggregations

NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)39 MPart (gov.sandia.n2a.eqset.MPart)20 JTree (javax.swing.JTree)19 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)18 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)15 TreeNode (javax.swing.tree.TreeNode)15 FontMetrics (java.awt.FontMetrics)12 CannotRedoException (javax.swing.undo.CannotRedoException)12 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)11 CannotUndoException (javax.swing.undo.CannotUndoException)8 TreePath (javax.swing.tree.TreePath)7 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)5 ExtensionPoint (gov.sandia.n2a.plugins.ExtensionPoint)4 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)4 NodeAnnotation (gov.sandia.n2a.ui.eq.tree.NodeAnnotation)4 NodeEquation (gov.sandia.n2a.ui.eq.tree.NodeEquation)3 NodeAnnotations (gov.sandia.n2a.ui.eq.tree.NodeAnnotations)2 NodeContainer (gov.sandia.n2a.ui.eq.tree.NodeContainer)2 NodeReference (gov.sandia.n2a.ui.eq.tree.NodeReference)2 Font (java.awt.Font)2