Search in sources :

Example 86 with TreeNode

use of javax.swing.tree.TreeNode in project logisim-evolution by reds-heig.

the class SimulationTreeCircuitNode method computeChildren.

// returns true if changed
private boolean computeChildren() {
    ArrayList<TreeNode> newChildren = new ArrayList<TreeNode>();
    ArrayList<Component> subcircs = new ArrayList<Component>();
    for (Component comp : circuitState.getCircuit().getNonWires()) {
        if (comp.getFactory() instanceof SubcircuitFactory) {
            subcircs.add(comp);
        } else {
            TreeNode toAdd = model.mapComponentToNode(comp);
            if (toAdd != null) {
                newChildren.add(toAdd);
            }
        }
    }
    Collections.sort(newChildren, new CompareByName());
    Collections.sort(subcircs, this);
    for (Component comp : subcircs) {
        SubcircuitFactory factory = (SubcircuitFactory) comp.getFactory();
        CircuitState state = factory.getSubstate(circuitState, comp);
        SimulationTreeCircuitNode toAdd = null;
        for (TreeNode o : children) {
            if (o instanceof SimulationTreeCircuitNode) {
                SimulationTreeCircuitNode n = (SimulationTreeCircuitNode) o;
                if (n.circuitState == state) {
                    toAdd = n;
                    break;
                }
            }
        }
        if (toAdd == null) {
            toAdd = new SimulationTreeCircuitNode(model, this, state, comp);
        }
        newChildren.add(toAdd);
    }
    if (!children.equals(newChildren)) {
        children = newChildren;
        return true;
    } else {
        return false;
    }
}
Also used : CircuitState(com.cburch.logisim.circuit.CircuitState) TreeNode(javax.swing.tree.TreeNode) ArrayList(java.util.ArrayList) SubcircuitFactory(com.cburch.logisim.circuit.SubcircuitFactory) Component(com.cburch.logisim.comp.Component)

Example 87 with TreeNode

use of javax.swing.tree.TreeNode in project sis by apache.

the class Assert method assertTreeEquals.

/**
 * Ensures that a tree is equals to an other tree.
 * This method invokes itself recursively for every child nodes.
 *
 * @param  expected  the expected tree, or {@code null}.
 * @param  actual    the tree to compare with the expected one, or {@code null}.
 * @return the number of nodes.
 */
public static int assertTreeEquals(final TreeNode expected, final TreeNode actual) {
    if (expected == null) {
        assertNull(actual);
        return 0;
    }
    int n = 1;
    assertNotNull(actual);
    assertEquals("isLeaf()", expected.isLeaf(), actual.isLeaf());
    assertEquals("getAllowsChildren()", expected.getAllowsChildren(), actual.getAllowsChildren());
    assertEquals("getChildCount()", expected.getChildCount(), actual.getChildCount());
    @SuppressWarnings("unchecked") final Enumeration<? extends TreeNode> ec = expected.children();
    @SuppressWarnings("unchecked") final Enumeration<? extends TreeNode> ac = actual.children();
    int childIndex = 0;
    while (ec.hasMoreElements()) {
        assertTrue("hasMoreElements()", ac.hasMoreElements());
        final TreeNode nextExpected = ec.nextElement();
        final TreeNode nextActual = ac.nextElement();
        final String message = "getChildAt(" + childIndex + ')';
        assertSame(message, nextExpected, expected.getChildAt(childIndex));
        assertSame(message, nextActual, actual.getChildAt(childIndex));
        assertSame("getParent()", expected, nextExpected.getParent());
        assertSame("getParent()", actual, nextActual.getParent());
        assertSame("getIndex(TreeNode)", childIndex, expected.getIndex(nextExpected));
        assertSame("getIndex(TreeNode)", childIndex, actual.getIndex(nextActual));
        n += assertTreeEquals(nextExpected, nextActual);
        childIndex++;
    }
    assertFalse("hasMoreElements()", ac.hasMoreElements());
    assertEquals("toString()", expected.toString(), actual.toString());
    return n;
}
Also used : TreeNode(javax.swing.tree.TreeNode)

Example 88 with TreeNode

use of javax.swing.tree.TreeNode in project CCDD by nasa.

the class CcddCommonTreeHandler method collapseTreePath.

/**
 ********************************************************************************************
 * Collapse the specified tree path and all of its child paths. This is a recursive method
 *
 * @param path
 *            tree path to collapse
 ********************************************************************************************
 */
private void collapseTreePath(TreePath path) {
    // Get the node for this path
    TreeNode node = (TreeNode) path.getLastPathComponent();
    // Check if the node has any child nodes
    if (node.getChildCount() >= 0) {
        // Step through each child node
        for (Enumeration<?> e = node.children(); e.hasMoreElements(); ) {
            // Get the child node's path and collapse it
            TreeNode childNode = (TreeNode) e.nextElement();
            TreePath childPath = path.pathByAddingChild(childNode);
            collapseTreePath(childPath);
        }
    }
    // the root's children when the root is invisible
    if (path.getParentPath() != null || isRootVisible()) {
        // Collapse the current path
        collapsePath(path);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 89 with TreeNode

use of javax.swing.tree.TreeNode in project CCDD by nasa.

the class CcddTableTreeHandler method buildNodes.

/**
 ********************************************************************************************
 * Build the table tree nodes. This is a recursive method. In order to prevent an infinite
 * loop, a check is made for a child node that exists in its own path; if found the recursion
 * is terminated for that node
 *
 * @param thisMember
 *            TableMember class
 *
 * @param parentNode
 *            current working node for the table tree
 *
 * @param childNode
 *            new child node to add to the working node
 ********************************************************************************************
 */
private void buildNodes(TableMembers thisMember, ToolTipTreeNode parentNode, ToolTipTreeNode childNode) {
    // Step through each node in the parent's path
    for (TreeNode node : parentNode.getPath()) {
        if (((ToolTipTreeNode) node).getLevel() >= getHeaderNodeLevel()) {
            // Check if the child is in the path
            if (((ToolTipTreeNode) node).getUserObject().toString().equals(childNode.getUserObject().toString())) {
                // Store the name of the recursively referenced node
                recursionTable = childNode.getUserObject().toString();
                break;
            }
        }
    }
    // Check that a recursion error wasn't found; this prevents an infinite loop from occurring
    if (recursionTable == null) {
        // Add the child node to its parent
        parentNode.add(childNode);
        // Get the parent table and variable path for this variable
        String fullTablePath = getFullVariablePath(childNode.getPath());
        // Step through each table/variable referenced by the table member
        for (int memIndex = 0; memIndex < thisMember.getDataTypes().size(); memIndex++) {
            // Check if this data type is a primitive
            if (dataTypeHandler.isPrimitive(thisMember.getDataTypes().get(memIndex))) {
                String tablePath = fullTablePath;
                // Set to true if the variable has a path (i.e., this is not a prototype's
                // variable)
                boolean isChildVariable = tablePath.contains(",");
                // Check if the variable has a path
                if (isChildVariable) {
                    // Add the data type and variable name to the variable path
                    tablePath += "," + thisMember.getDataTypes().get(memIndex) + "." + thisMember.getVariableNames().get(memIndex);
                }
                String rate = null;
                // Check if a rate filter is in effect
                if (rateFilter != null) {
                    // Get the rate value for this variable. Use the prototype's value if the
                    // variable doesn't have a specific rate assigned
                    int index = rateValues.indexOf(tablePath);
                    rate = isChildVariable && index != -1 ? rateValues.get(index)[2] : thisMember.getRates().get(memIndex)[rateIndex];
                }
                // specified rate filter
                if (rateFilter == null || rate.equals(rateFilter)) {
                    // Get the full variable name in the form
                    // data_type.variable_name[:bit_length]
                    String variable = thisMember.getFullVariableNameWithBits(memIndex);
                    // the variable, using its full path and name, is not in the exclusion list
                    if (excludedVariables == null || !excludedVariables.contains(tablePath)) {
                        // Add the primitive as a node to this child node
                        childNode.add(new ToolTipTreeNode(variable, ""));
                    } else // The variable is in the exclusion list
                    {
                        // Add the variable with the node text grayed out
                        childNode.add(new ToolTipTreeNode(DISABLED_TEXT_COLOR + variable, ""));
                    }
                }
            } else // Data type is not a primitive, it's a structure
            {
                // Step through the other tables
                for (TableMembers member : tableMembers) {
                    // Check if the table is a member of the target table
                    if (thisMember.getDataTypes().get(memIndex).equals(member.getTableName())) {
                        // Build the node name from the prototype and variable names
                        String nodeName = thisMember.getDataTypes().get(memIndex) + "." + thisMember.getVariableNames().get(memIndex);
                        // Get the variable name path to this node
                        String tablePath = fullTablePath + "," + nodeName;
                        // Add this table to the current table's node. The node name is in the
                        // format 'dataType.variableName<[arrayIndex]>'. If a specific
                        // description exists for the table then use it for the tool tip text;
                        // otherwise use the prototype's description
                        buildNodes(member, childNode, new ToolTipTreeNode(nodeName, getTableDescription(tablePath, thisMember.getDataTypes().get(memIndex))));
                    }
                }
            }
        }
        // (variables)
        if ((treeType == STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES || treeType == INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES) && childNode.getChildCount() == 0) {
            // Remove the node
            parentNode.remove(childNode);
        }
    }
}
Also used : ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) TableMembers(CCDD.CcddClassesDataTable.TableMembers) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 90 with TreeNode

use of javax.swing.tree.TreeNode in project freeplane by freeplane.

the class ImportAttributesDialog method setParentSelectionType.

private void setParentSelectionType(final DefaultMutableTreeNode selectedNode, final int newSelectionType) {
    final TreeNode parentNode = selectedNode.getParent();
    if (parentNode == null) {
        return;
    }
    final DefaultMutableTreeNode defaultMutableParentNode = (DefaultMutableTreeNode) parentNode;
    final TreeNodeInfo info = (TreeNodeInfo) (defaultMutableParentNode).getUserObject();
    if (newSelectionType == TreeNodeInfo.PARTIAL_SELECTED) {
        if (info.getSelected() != TreeNodeInfo.PARTIAL_SELECTED) {
            info.setSelected(TreeNodeInfo.PARTIAL_SELECTED);
            treeModel.nodeChanged(defaultMutableParentNode);
        }
        setParentSelectionType(defaultMutableParentNode, TreeNodeInfo.PARTIAL_SELECTED);
        return;
    }
    for (int i = 0; i < defaultMutableParentNode.getChildCount(); i++) {
        final TreeNodeInfo childInfo = (TreeNodeInfo) ((DefaultMutableTreeNode) defaultMutableParentNode.getChildAt(i)).getUserObject();
        if (childInfo.getSelected() != newSelectionType) {
            if (info.getSelected() != TreeNodeInfo.PARTIAL_SELECTED) {
                info.setSelected(TreeNodeInfo.PARTIAL_SELECTED);
                treeModel.nodeChanged(defaultMutableParentNode);
            }
            setParentSelectionType(defaultMutableParentNode, TreeNodeInfo.PARTIAL_SELECTED);
            return;
        }
    }
    if (info.getSelected() != newSelectionType) {
        info.setSelected(newSelectionType);
        treeModel.nodeChanged(defaultMutableParentNode);
    }
    setParentSelectionType(defaultMutableParentNode, newSelectionType);
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Aggregations

TreeNode (javax.swing.tree.TreeNode)313 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)146 TreePath (javax.swing.tree.TreePath)125 FilteredTreeModel (gov.sandia.n2a.ui.eq.FilteredTreeModel)31 Enumeration (java.util.Enumeration)30 PanelEquationTree (gov.sandia.n2a.ui.eq.PanelEquationTree)28 MPart (gov.sandia.n2a.eqset.MPart)27 ArrayList (java.util.ArrayList)27 NodeBase (gov.sandia.n2a.ui.eq.tree.NodeBase)25 JTree (javax.swing.JTree)23 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)23 Nullable (org.jetbrains.annotations.Nullable)23 MutableTreeNode (javax.swing.tree.MutableTreeNode)19 CannotRedoException (javax.swing.undo.CannotRedoException)18 NodePart (gov.sandia.n2a.ui.eq.tree.NodePart)16 CannotUndoException (javax.swing.undo.CannotUndoException)14 NodeVariable (gov.sandia.n2a.ui.eq.tree.NodeVariable)12 MouseEvent (java.awt.event.MouseEvent)11 NotNull (org.jetbrains.annotations.NotNull)11 PanelEquations (gov.sandia.n2a.ui.eq.PanelEquations)10