Search in sources :

Example 6 with ToolTipTreeNode

use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.

the class CcddLinkTreeHandler method getLinksMatchingRate.

/**
 ********************************************************************************************
 * Create a subtree with only the links that contain variables with sample rates matching the
 * selected rate
 *
 * @param rootNodeName
 *            name of the root node for the matching links
 *
 * @param rootNodeDescription
 *            tool tip text for the root node
 *
 * @return Node with only the links that contain variables with sample rates matching the
 *         selected rate
 ********************************************************************************************
 */
protected ToolTipTreeNode getLinksMatchingRate(String rootNodeName, String rootNodeDescription) {
    // Create a node to contain the matching links
    ToolTipTreeNode validLinks = new ToolTipTreeNode(rootNodeName, rootNodeDescription);
    // Copy the current links tree to the new node
    copySubTree(getRootNode(), validLinks);
    // removed during the processing
    for (int index = validLinks.getChildCount() - 1; index >= 0; index--) {
        // Get the link information for this link
        LinkInformation linkInfo = getLinkInformation(validLinks.getChildAt(index).toString());
        // Check if the link exists and if the link's rate doesn't match the selected rate
        if (linkInfo != null && !linkInfo.getSampleRate().equals(selectedRate)) {
            // Remove this link's node from the valid links tree
            validLinks.remove(index);
        }
    }
    return validLinks;
}
Also used : LinkInformation(CCDD.CcddClassesDataTable.LinkInformation) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 7 with ToolTipTreeNode

use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.

the class CcddLinkTreeHandler method adjustNodeText.

/**
 ********************************************************************************************
 * Append the sample rate and size in bytes to the nodes representing a link name. Set the node
 * text color based on the currently selected sample rate and the rate of the link to which the
 * node belongs: black for a match and gray for a mismatch
 *
 * @param startNode
 *            starting node for which to adjust the text and color
 ********************************************************************************************
 */
protected void adjustNodeText(ToolTipTreeNode startNode) {
    // Step through the elements and children of this node
    for (Enumeration<?> element = startNode.preorderEnumeration(); element.hasMoreElements(); ) {
        // Get the node reference
        ToolTipTreeNode node = (ToolTipTreeNode) element.nextElement();
        // Get the tree level for this node
        int level = node.getLevel();
        // called when no nodes exist
        if (level > 0) {
            // Get the link name from the node path
            String linkName = removeExtraText(node.getPath()[1].toString());
            // Get the reference to the link's information. The link name is the second node in
            // the path for this node
            LinkInformation linkInfo = getLinkInformation(linkName);
            // Check that the node references a link
            if (linkInfo != null) {
                // Get the node name
                String nodeName = removeExtraText(node.getUserObject().toString());
                // Check if this node represents a link name
                if (level == 1) {
                    // Assign the link name formatted as HTML
                    nodeName = "<html>" + linkName + " <i>(";
                    // Get the link size in bytes
                    int sizeInBytes = linkHandler.getLinkSizeInBytes(linkInfo.getRateName(), linkName);
                    // Check if the size is non-zero; i.e., variables are assigned to this link
                    if (sizeInBytes != 0) {
                        // Append the link size to the link name
                        nodeName += linkInfo.getSampleRate() + " Hz, " + sizeInBytes + (sizeInBytes == 1 ? " byte)" : " bytes)");
                    } else // No variables are assigned to this link
                    {
                        // Indicate that the link is empty
                        nodeName += "empty)";
                    }
                }
                // Check if the selected sample rate doesn't match the link's rate
                if (!linkInfo.getSampleRate().equals("0") && !selectedRate.equals(linkInfo.getSampleRate())) {
                    // Gray out the node text
                    nodeName = DISABLED_TEXT_COLOR + nodeName;
                }
                // Update the node name. Indicate that the node changed so that the tree
                // redraws the name
                node.setUserObject(nodeName);
                ((UndoableTreeModel) getModel()).nodeChanged(node);
            }
        }
    }
}
Also used : UndoableTreeModel(CCDD.CcddUndoHandler.UndoableTreeModel) LinkInformation(CCDD.CcddClassesDataTable.LinkInformation) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 8 with ToolTipTreeNode

use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.

the class CcddLinkTreeHandler method buildTree.

/**
 ********************************************************************************************
 * Build the link tree from the database
 *
 * @param filterByType
 *            true if the tree is filtered by table type. This is not applicable to the link
 *            tree, which can only contain structure references
 *
 * @param filterByApp
 *            true if the tree is filtered by application. This is not applicable to the link
 *            tree, which can only contain structure references
 *
 * @param filterValue
 *            string value that may be used to modify the tree building method; null or blank
 *            if not filtering
 *
 * @param filterFlag
 *            flag used to filter the tree content. Not used for the link tree
 *
 * @param parent
 *            GUI component calling this method
 ********************************************************************************************
 */
@Override
protected void buildTree(boolean filterByType, boolean filterByApp, String filterValue, boolean filterFlag, Component parent) {
    super.buildTree(false, false, filterValue, filterFlag, parent);
    // Get the tree's root node
    ToolTipTreeNode root = getRootNode();
    // Create the storage for the link information
    linkInformation = undoHandler.new UndoableArrayList<LinkInformation>();
    // Register the tool tip manager for the link tree (otherwise the tool tips aren't
    // displayed)
    ToolTipManager.sharedInstance().registerComponent(this);
    // Set the flag to indicate that the link tree is being built. This flag is used to inhibit
    // actions involving tree selection value changes during the build process
    isBuilding = true;
    // Set the renderer for the tree so that the link information can be displayed, and so that
    // custom icons can be used for the various node types
    setCellRenderer(new TableTreeCellRenderer() {

        /**
         ************************************************************************************
         * Display the variable nodes using a special icon in the tree
         ************************************************************************************
         */
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
            // Display the node name
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            // Get the tree level for this node
            int level = ((ToolTipTreeNode) value).getLevel();
            // is called when no nodes exist
            if (level != 0) {
                // Get the reference to the link's information. The link name is the second
                // node in the path for this node
                LinkInformation linkInfo = getLinkInformation(((ToolTipTreeNode) value).getPath()[1].toString());
                // Check that the link information exists
                if (linkInfo != null) {
                    // Check if this node represents a link name
                    if (level == 1) {
                        // Get the rate for this link
                        String linkRate = linkInfo.getSampleRate();
                        // has no assigned rate
                        if (linkRate.equals("0") || selectedRate.equals(linkRate)) {
                            setIcon(validLinkIcon);
                        } else // The link rate doesn't match the selected rate
                        {
                            setIcon(invalidLinkIcon);
                        }
                    } else // Check if this node represents a variable
                    if (leaf) {
                        // Set the icon for the variable node
                        setVariableNodeIcon(this, (ToolTipTreeNode) value, row, true);
                    }
                }
            }
            return this;
        }
    });
    // Step through each link
    for (String[] linkDefn : linkDefinitions) {
        // Check if the link definition matches the target data stream rate column name
        if (linkDefn[LinksColumn.RATE_NAME.ordinal()].equals(filterValue)) {
            // Extract the rate name, link name, and rate/description or member
            String linkRate = linkDefn[LinksColumn.RATE_NAME.ordinal()];
            String linkName = linkDefn[LinksColumn.LINK_NAME.ordinal()];
            String linkMember = linkDefn[LinksColumn.MEMBER.ordinal()];
            // character is a digit, which is the link rate
            if (linkMember.matches(InputDataType.RATE.getInputMatch() + ",.*")) {
                // Split the entry into the rate and description
                String[] rateAndDesc = linkMember.split(",", 2);
                // Store the link information
                linkInformation.add(new LinkInformation(linkRate, linkName, rateAndDesc[0], rateAndDesc[1]));
                // Create a node for the link and add it to the link tree
                addInformationNode(linkName, rateAndDesc[1]);
            } else // This is a variable path
            {
                // Step through each current link node
                for (int index = 0; index < root.getChildCount(); index++) {
                    // Check if the link name matches the node name
                    if (linkName.equals(root.getChildAt(index).toString())) {
                        // Add the variable to the node and stop searching
                        addNodeToInfoNode((ToolTipTreeNode) root.getChildAt(index), linkMember.split(","), 0);
                        break;
                    }
                }
            }
        }
    }
    // Expand or collapse the tree based on the expansion flag
    setTreeExpansion(isExpanded);
    // Clear the flag that indicates the link tree is being built
    isBuilding = false;
}
Also used : JTree(javax.swing.JTree) LinkInformation(CCDD.CcddClassesDataTable.LinkInformation) Component(java.awt.Component) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 9 with ToolTipTreeNode

use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.

the class CcddLinkManagerHandler method removeVariableFromLink.

/**
 ********************************************************************************************
 * Remove the selected variable(s) from the link and reenable them in the variable tree
 *
 * @param linkNames
 *            array containing the name(s) of the link(s) from which to remove the variable(s)
 ********************************************************************************************
 */
private void removeVariableFromLink(String[] linkNames) {
    ToolTipTreeNode node = null;
    // Check if a single link is selected
    if (selectedLink != null) {
        // Store the selected group's node
        node = (ToolTipTreeNode) linkTree.getSelectionPath().getPathComponent(1);
    }
    // Remove the selected variable(s) from the links in the link tree
    linkTree.removeSelectedChildNodes(true);
    // Step through each on the links
    for (String linkName : linkNames) {
        // Check if the link has no member variables
        if (linkTree.getLinkVariables(linkName).size() == 0) {
            // Set the link's sample rate to zero (indicating it has no rate since it has no
            // members)
            linkTree.getLinkInformation(linkName).setSampleRate("0");
        }
    }
    // Clean up the links following removal of the variable
    cleanUpLinks(linkNames);
    // Check if a single link was selected prior to removing the selected variable(s)
    if (node != null) {
        // Select the node for the group that had the table(s) removed
        linkTree.setSelectionPath(new TreePath(node.getPath()));
    }
}
Also used : TreePath(javax.swing.tree.TreePath) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode)

Example 10 with ToolTipTreeNode

use of CCDD.CcddClassesComponent.ToolTipTreeNode in project CCDD by nasa.

the class CcddGroupTreeHandler method adjustNodeText.

/**
 ********************************************************************************************
 * Set the node text color based on the currently selected schedule rate and the rate of the
 * group to which the node belongs: black for a match and gray for a mismatch
 *
 * @param startNode
 *            starting node for which to adjust the text and color
 ********************************************************************************************
 */
protected void adjustNodeText(ToolTipTreeNode startNode, List<String> excludes) {
    // Step through the node's children, if any
    for (Enumeration<?> element = startNode.preorderEnumeration(); element.hasMoreElements(); ) {
        // Get the node reference
        ToolTipTreeNode node = (ToolTipTreeNode) element.nextElement();
        // Get the tree level for this node
        int level = node.getLevel();
        // called when no nodes exist
        if (level > 0) {
            // Get the group name from the node. The group name is the second node in the path
            // for this node
            String groupName = removeExtraText(node.getPath()[1].toString());
            // Get the reference to the group's information
            GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupName);
            // Check that the node references a group
            if (groupInfo != null) {
                // Get the node name
                String nodeName = node.getUserObject().toString();
                // Set to true if the group in this path is not excluded (as evidenced by
                // having a HTML tag)
                boolean wasExcluded = nodeName.contains(DISABLED_TEXT_COLOR);
                // Remove any HTML tags or other extra text from the node name
                nodeName = removeExtraText(nodeName);
                // Get the reference to the schedule rate field information
                fieldHandler.setFieldInformation(groupInfo.getFieldInformation());
                FieldInformation rateInfo = fieldHandler.getFieldInformationByName(CcddFieldHandler.getFieldGroupName(groupName), DefaultApplicationField.SCHEDULE_RATE.getFieldName());
                // Set the flag indicating the group is excluded if it's in the exclusion list
                boolean isExcluded = rateInfo == null || rateInfo.getValue().isEmpty() || !scheduleRate.equals(rateInfo.getValue()) || excludes.contains(nodeName);
                // Check if the group's exclusion state has changed
                if (wasExcluded != isExcluded) {
                    // Reset the node name to indicate its inclusion/exclusion state. If
                    // excluded, prepend the HTML tag to gray out the name. Indicate that the
                    // node changed so that the tree redraws the name
                    node.setUserObject((isExcluded ? DISABLED_TEXT_COLOR : "") + nodeName);
                    ((DefaultTreeModel) getModel()).nodeChanged(node);
                }
            }
        }
    }
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Aggregations

ToolTipTreeNode (CCDD.CcddClassesComponent.ToolTipTreeNode)44 ArrayList (java.util.ArrayList)15 TreePath (javax.swing.tree.TreePath)15 BitPackNodeIndex (CCDD.CcddClassesDataTable.BitPackNodeIndex)6 GridBagLayout (java.awt.GridBagLayout)6 JPanel (javax.swing.JPanel)6 Component (java.awt.Component)5 GridBagConstraints (java.awt.GridBagConstraints)5 LinkInformation (CCDD.CcddClassesDataTable.LinkInformation)4 JLabel (javax.swing.JLabel)4 JScrollPane (javax.swing.JScrollPane)4 JTree (javax.swing.JTree)4 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)3 TableMembers (CCDD.CcddClassesDataTable.TableMembers)3 Insets (java.awt.Insets)3 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)3 UndoableTreeModel (CCDD.CcddUndoHandler.UndoableTreeModel)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JTextArea (javax.swing.JTextArea)2