Search in sources :

Example 1 with CustomSplitPane

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

the class CcddLinkManagerHandler method initialize.

/**
 ********************************************************************************************
 * Create the variable link manager dialog
 *
 * @param availableRates
 *            array of sample rates available to this stream
 ********************************************************************************************
 */
private void initialize(String[] availableRates) {
    isNodeSelectionChanging = false;
    // Create borders for the dialog components
    border = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing()));
    emptyBorder = BorderFactory.createEmptyBorder();
    selectedLink = null;
    currentLinks = new ArrayList<String[]>();
    // Set the initial layout manager characteristics
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, 0, 0), 0, 0);
    // Add an undo edit manager
    undoManager = new CcddUndoManager() {

        /**
         ************************************************************************************
         * Update the change indicator if the link manager has changed
         ************************************************************************************
         */
        @Override
        protected void ownerHasChanged() {
            linkDialog.updateChangeIndicator();
        }
    };
    // Create the undo handler for the components with undoable actions. Disable storage of
    // edit actions during dialog creation
    undoHandler = new CcddUndoHandler(undoManager);
    pathSelect = undoHandler.new UndoableTreePathSelection();
    undoHandler.setAllowUndo(false);
    // Build the link tree
    linkTree = new CcddLinkTreeHandler(ccddMain, undoHandler, rateName, ccddMain.getMainFrame()) {

        /**
         ************************************************************************************
         * Respond to changes in selection of a node in the link tree
         ************************************************************************************
         */
        @Override
        protected void updateTableSelection() {
            // Check that a node selection change is not in progress
            if (!isNodeSelectionChanging) {
                // Set the flag to prevent link tree updates
                isNodeSelectionChanging = true;
                // Deselect any nodes that are disabled
                clearDisabledNodes();
                // Check if a link was selected
                if (selectedLink != null) {
                    // Store the description with the previous link
                    selectedLink.setDescription(descriptionFld.getText().trim());
                }
                // Update the description field text so that it can be undone/redone. The focus
                // change, which is usually used to perform the update, occurs after the node
                // selection edit and would cause the wrong description field to be changed
                descriptionFld.updateText(true);
                // Get the name of the selected link(s)
                String[] selected = getTopLevelSelectedNodeNames();
                // If a single link is selected then set the selected link, enable and populate
                // the description, rate, and size in bytes fields; otherwise clear the
                // selected link, disable and clear the description, rate, and size in bytes
                // fields
                setLinkAndFields(selected.length == 1 ? selected[0] : null, selected.length != 0);
                // the undo/redo stack
                if (undoHandler.isAllowUndo()) {
                    // Add the node path selection change to the undo/redo stack
                    pathSelect.selectTreePath(getSelectedPaths());
                }
                // Reset the flag to allow link tree updates
                isNodeSelectionChanging = false;
            }
        }
    };
    // Set the link tree reference in the undo handler so that tree edits can be undone/redone
    undoHandler.setTree(linkTree);
    // Store the initial link definitions. These are filtered so that only those with the same
    // data stream rate are represented
    updateCommittedLinks();
    // Create panels to hold the components of the dialog
    managerPnl = new JPanel(new GridBagLayout());
    JPanel titlePnl = new JPanel(new GridBagLayout());
    JPanel treePnl = new JPanel(new GridBagLayout());
    JPanel infoPnl = new JPanel(new GridBagLayout());
    JPanel descPnl = new JPanel(new GridBagLayout());
    JPanel rateAndSizePnl = new JPanel(new FlowLayout(FlowLayout.LEFT));
    JPanel rateSelectPnl = new JPanel(new GridBagLayout());
    managerPnl.setBorder(emptyBorder);
    titlePnl.setBorder(emptyBorder);
    treePnl.setBorder(emptyBorder);
    infoPnl.setBorder(BorderFactory.createEtchedBorder());
    descPnl.setBorder(emptyBorder);
    rateSelectPnl.setBorder(emptyBorder);
    rateSelectPnl.setBorder(emptyBorder);
    // Create the link manager dialog labels and fields
    JLabel dlgLabel = new JLabel("Assign variables to links");
    dlgLabel.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    titlePnl.add(dlgLabel, gbc);
    // Add the upper panel components to the dialog panel
    managerPnl.add(titlePnl, gbc);
    // Initialize the currently selected rate to 1 Hz if present in the list of available
    // rates; otherwise choose the first rate if any rates exist, and if none exist set the
    // rate to a dummy value
    selectedRate = Arrays.asList(availableRates).contains("1") ? "1" : (availableRates.length != 0 ? CcddUtilities.removeHTMLTags(availableRates[0]) : "0");
    // Build the variable tree that shows tables and their variables for the selected rate. Use
    // the first rate in the available rates array to determine which variables to display in
    // the tree, or, if none, create the tree showing no variables
    variableTree = new CcddTableTreeHandler(ccddMain, new CcddGroupHandler(ccddMain, undoHandler, ccddMain.getMainFrame()), TableTreeType.INSTANCE_STRUCTURES_WITH_PRIMITIVES_AND_RATES, rateName, selectedRate, linkTree.getLinkVariables(null), ccddMain.getMainFrame()) {

        /**
         ************************************************************************************
         * Respond to changes in selection of a node in the variable tree
         ************************************************************************************
         */
        @Override
        protected void updateTableSelection() {
            // Check that a node selection change is not in progress
            if (!isNodeSelectionChanging) {
                // Select the associated link in the link tree if a linked variable is selected
                // in the variable tree. Note that below any linked variables are deselected,
                // so this call must occur first
                selectLinkByVariable();
                // Set the flag to prevent variable tree updates
                isNodeSelectionChanging = true;
                // Deselect any nodes that are disabled
                clearDisabledNodes();
                // Deselect any nodes that don't represent a table or the level immediately
                // above the table level
                clearNonTableNodes(1);
                // Reset the flag to allow variable tree updates
                isNodeSelectionChanging = false;
            }
        }

        /**
         ************************************************************************************
         * Override building the table tree in order to apply the rate filter and change the
         * instances node name
         ************************************************************************************
         */
        @Override
        protected void buildTableTree(Boolean isExpanded, String rateName, String rateFilter, Component parent) {
            super.buildTableTree(isExpanded, rateName, rateFilter, parent);
            // Rename the instances node. Indicate that the node changed so that the tree
            // redraws the name
            getInstancesNode().setUserObject("Structures & Variables");
            ((DefaultTreeModel) getModel()).nodeChanged(getInstancesNode());
            // Clean up the links following rebuilding the tree
            variableTree = this;
            cleanUpLinks(null);
        }
    };
    // Add the title panel components to the dialog panel
    managerPnl.add(titlePnl, gbc);
    // Create a table tree panel and add it to another panel (in order to control spacing)
    gbc.insets.top = 0;
    gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.weighty = 1.0;
    treePnl.add(variableTree.createTreePanel("Variables", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, ccddMain.getMainFrame()), gbc);
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.insets.bottom = 0;
    // Create a split pane containing the variable tree in the left pane and the link tree in
    // the right pane and add it to the panel. The arrow button panel is used as the split pane
    // divider
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
    gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
    gbc.gridy++;
    managerPnl.add(new CustomSplitPane(treePnl, linkTree.createTreePanel("Links", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION), createArrowButtonPanel(), JSplitPane.HORIZONTAL_SPLIT), gbc);
    // Create the link description label
    JLabel descriptionLbl = new JLabel("Description");
    descriptionLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    descriptionLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
    gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
    gbc.weighty = 0.0;
    descPnl.add(descriptionLbl, gbc);
    // Create the link description input field
    descriptionFld = undoHandler.new UndoableTextArea("", 3, 1);
    descriptionFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
    descriptionFld.setEditable(false);
    descriptionFld.setLineWrap(true);
    descriptionFld.setWrapStyleWord(true);
    descriptionFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
    descriptionFld.setBackground(ModifiableColorInfo.INPUT_DISABLE_BACK.getColor());
    descriptionFld.setBorder(emptyBorder);
    descriptionFld.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    descriptionFld.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
    // Add a listener to detect addition or deletion of text in the input field
    descriptionFld.getDocument().addDocumentListener(new DocumentListener() {

        /**
         ************************************************************************************
         * Update the change indicator when text is added
         ************************************************************************************
         */
        @Override
        public void insertUpdate(DocumentEvent de) {
            linkDialog.updateChangeIndicator();
        }

        /**
         ************************************************************************************
         * Update the change indicator when text is removed
         ************************************************************************************
         */
        @Override
        public void removeUpdate(DocumentEvent de) {
            linkDialog.updateChangeIndicator();
        }

        /**
         ************************************************************************************
         * Handle updates to a attribute change (unused)
         ************************************************************************************
         */
        @Override
        public void changedUpdate(DocumentEvent de) {
        }
    });
    descScrollPane = new JScrollPane(descriptionFld);
    descScrollPane.setBackground(ModifiableColorInfo.INPUT_DISABLE_BACK.getColor());
    descScrollPane.setBorder(border);
    // Add the description field to the dialog panel
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy++;
    descPnl.add(descScrollPane, gbc);
    // Add the description panel to the link information panel
    gbc.gridy++;
    infoPnl.add(descPnl, gbc);
    // Create the link rate labels and fields
    JLabel rateLbl = new JLabel("Link rate (Hz):");
    rateLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    rateLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
    rateAndSizePnl.add(rateLbl);
    updateRateFld = new JTextField(2);
    updateRateFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
    updateRateFld.setEditable(false);
    updateRateFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
    updateRateFld.setBackground(ModifiableColorInfo.INPUT_DISABLE_BACK.getColor());
    updateRateFld.setBorder(border);
    updateRateFld.setHorizontalAlignment(SwingConstants.CENTER);
    rateAndSizePnl.add(updateRateFld);
    JLabel bytesLbl = new JLabel("   Size in bytes:");
    bytesLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    bytesLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
    rateAndSizePnl.add(bytesLbl);
    sizeInBytesFld = new JTextField(2);
    sizeInBytesFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
    sizeInBytesFld.setEditable(false);
    sizeInBytesFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
    sizeInBytesFld.setBackground(ModifiableColorInfo.INPUT_DISABLE_BACK.getColor());
    sizeInBytesFld.setBorder(border);
    sizeInBytesFld.setHorizontalAlignment(SwingConstants.CENTER);
    rateAndSizePnl.add(sizeInBytesFld);
    // Add the rate panel to the link information panel
    gbc.weighty = 0.0;
    gbc.gridy++;
    infoPnl.add(rateAndSizePnl, gbc);
    // Add the link information panel to the dialog
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
    managerPnl.add(infoPnl, gbc);
    // Create the rate selection label
    JLabel rateSelectLbl = new JLabel("Select rate:");
    rateSelectLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    rateSelectLbl.setForeground(ModifiableColorInfo.LABEL_TEXT.getColor());
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    rateSelectPnl.add(rateSelectLbl, gbc);
    // Create the combo box that displays the variable rates and add it to the dialog panel
    rateFilter = new PaddedComboBox(availableRates, ModifiableFontInfo.INPUT_TEXT.getFont()) {

        /**
         ************************************************************************************
         * Override so that items flagged as disabled (grayed out) can't be selected
         ************************************************************************************
         */
        @Override
        public void setSelectedItem(Object anObject) {
            // Check if the item isn't flagged as disabled
            if (!anObject.toString().startsWith(DISABLED_TEXT_COLOR)) {
                // Set the selected item to the specified item, if it exists in the list
                super.setSelectedItem(anObject);
            }
        }
    };
    gbc.fill = GridBagConstraints.NONE;
    gbc.gridx++;
    rateSelectPnl.add(rateFilter, gbc);
    // Add a listener for rate filter selection changes
    rateFilter.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Rebuild the table tree using the selected rate filter
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            // Get the rate selected in the combo box
            String newRate = ((JComboBox<?>) ae.getSource()).getSelectedItem().toString();
            // Check if the rate changed
            if (!selectedRate.equals(newRate)) {
                // Set the new rate as the selected rate
                selectedRate = newRate;
                // Rebuild the variable tree using the selected rate as a filter
                variableTree.buildTableTree(null, rateName, selectedRate, linkDialog);
            }
            // Get the list of all variable tree paths in the variable tree and set these in
            // the links tree. This is used to maintain the correct variable order in the links
            // tree
            linkTree.setTreePathOrder(variableTree.getTableTreePathList(null, variableTree.getNodeByNodeName("Structures & Variables"), -1));
            // Check if this is the first time the rate selection occurs
            if (firstRateChange) {
                // Force the link tree to be rebuilt now that the tree path order is
                // established (via setting the rate filter). This forces the link variables to
                // appear in the same order as they are listed in their prototype tables
                linkTree.buildTree(false, false, rateName, false, linkDialog);
                // Set the flag to prevent rebuilding the link tree when subsequent rate
                // selection changes are made
                firstRateChange = false;
            }
            // Set the rate in the link tree to flag compatible links
            linkTree.setSelectedRate(selectedRate);
            // Add the rate and size to the link nodes and set the color based on the selected
            // rate
            linkTree.adjustNodeText(linkTree.getRootNode());
        }
    });
    // Set the flag so that the rate change executed below triggers a rebuilding of the links
    // tree using the tree path order in the variables tree
    firstRateChange = true;
    // Set the rate filter to the selected rate. This initial setting updates the link tree,
    // but skips rebuilding the variable tree unnecessarily
    rateFilter.setSelectedItem(selectedRate);
    // Re-enable storage of edit actions now that dialog creation is complete
    undoHandler.setAllowUndo(true);
    // Create the rate units label and add it to the dialog panel
    JLabel rateUnitsLbl = new JLabel("samples/second");
    rateUnitsLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    rateUnitsLbl.setForeground(ModifiableColorInfo.LABEL_TEXT.getColor());
    gbc.gridx++;
    rateSelectPnl.add(rateUnitsLbl, gbc);
    // Add the rate selection panel to the dialog panel
    gbc.gridx = 0;
    gbc.gridy++;
    managerPnl.add(rateSelectPnl, gbc);
}
Also used : JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) FlowLayout(java.awt.FlowLayout) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) CustomSplitPane(CCDD.CcddClassesComponent.CustomSplitPane) JTextField(javax.swing.JTextField) PaddedComboBox(CCDD.CcddClassesComponent.PaddedComboBox) UndoableTextArea(CCDD.CcddUndoHandler.UndoableTextArea) Component(java.awt.Component) JScrollPane(javax.swing.JScrollPane) UndoableTreePathSelection(CCDD.CcddUndoHandler.UndoableTreePathSelection) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) DocumentEvent(javax.swing.event.DocumentEvent) ActionListener(java.awt.event.ActionListener)

Example 2 with CustomSplitPane

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

the class CcddSchedulerEditorHandler method initialize.

/**
 ********************************************************************************************
 * Create a telemetry table
 ********************************************************************************************
 */
@SuppressWarnings("serial")
private void initialize() {
    // Create a border for the table and list panes, and an empty border
    Border border = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing()));
    Border emptyBorder = BorderFactory.createEmptyBorder();
    // Initialize the layout constraints
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0);
    // Initialize the telemetry scheduler
    initializeSchedulerTable();
    // Initialize the scheduler table object
    schedulerTable = new CcddJTableHandler(5) {

        /**
         ************************************************************************************
         * Allow multiple line display in the specified column only
         ************************************************************************************
         */
        @Override
        protected boolean isColumnMultiLine(int column) {
            return column == SchedulerColumn.NAME.ordinal();
        }

        /**
         ************************************************************************************
         * Allow resizing of the specified column only
         ************************************************************************************
         */
        @Override
        protected boolean isColumnResizable(int column) {
            return column == SchedulerColumn.NAME.ordinal();
        }

        /**
         ************************************************************************************
         * Allow editing of the table cells in the specified columns only
         ************************************************************************************
         */
        @Override
        public boolean isCellEditable(int row, int column) {
            return column == SchedulerColumn.NAME.ordinal() || (column == SchedulerColumn.ID.ordinal() && messages.get(row).getNumberOfSubMessages() <= 1) || (column > SchedulerColumn.ID.ordinal() && messages.get(row).getNumberOfSubMessages() > 1 && column <= SchedulerColumn.ID.ordinal() + messages.get(row).getNumberOfSubMessages());
        }

        /**
         ************************************************************************************
         * Validate changes to the data field value cells; e.g., verify cell content and, if
         * found invalid, revert to the original value
         *
         * @param tableData
         *            list containing the table data row arrays
         *
         * @param row
         *            table model row number
         *
         * @param column
         *            table model column number
         *
         * @param oldValue
         *            original cell contents
         *
         * @param newValue
         *            new cell contents
         *
         * @param showMessage
         *            unused
         *
         * @param isMultiple
         *            unused
         *
         * @return Value of ShowMessage
         ***********************************************************************************
         */
        @Override
        protected Boolean validateCellContent(List<Object[]> tableData, int row, int column, Object oldValue, Object newValue, Boolean showMessage, boolean isMultiple) {
            // Reset the flag that indicates the last edited cell's content is invalid
            setLastCellValid(true);
            // Create a string version of the new value
            String newValueS = newValue.toString();
            try {
                // Check if this is the name column
                if (column == SchedulerColumn.NAME.ordinal()) {
                    // Check if the value name is blank
                    if (newValueS.isEmpty()) {
                        // Inform the user that the message name cannot be blank
                        throw new CCDDException("Message name must be entered");
                    }
                    // Check if the message name is an alphanumeric
                    if (!newValueS.matches(InputDataType.ALPHANUMERIC.getInputMatch())) {
                        // Inform the user that the message name contains invalid characters
                        throw new CCDDException("Invalid characters in message name");
                    }
                    // Step through each message
                    for (Message message : messages) {
                        // Check if the new name matches an existing one
                        if (messages.indexOf(message) != row && message.getName().equals(newValueS)) {
                            // Inform the user that the message name already is in use
                            throw new CCDDException("Message name is already in use");
                        }
                    }
                    // Store the new message name
                    messages.get(row).setName(newValueS);
                    // Update the assigned variables tab and options list with the new name
                    tabbedPane.setTitleAt(tabbedPane.getSelectedIndex(), newValueS);
                    schedulerHndlr.getTelemetryOptions();
                    // Change references to the original message name to the new name in the
                    // assignment tree so that the tree builds correctly
                    assignmentTree.updateMessageName(oldValue.toString(), newValueS);
                } else // Check if this is an ID column
                if (column >= SchedulerColumn.ID.ordinal()) {
                    // Check if the message ID is a hexadecimal
                    if (!newValueS.matches(InputDataType.HEXADECIMAL.getInputMatch())) {
                        // Inform the user that the message name contains invalid characters
                        throw new CCDDException("Invalid characters in message ID");
                    }
                    // Format the hexadecimal value
                    newValueS = InputDataType.HEXADECIMAL.formatInput(newValueS);
                    // Check that the new value isn't a blank
                    if (!newValueS.isEmpty()) {
                        // Convert the ID to an integer
                        int id = Integer.decode(newValueS);
                        // Step through each row in the table
                        for (int checkRow = 0; checkRow < tableData.size(); checkRow++) {
                            // Step through each column containing an ID
                            for (int checkCol = SchedulerColumn.ID.ordinal(); checkCol < tableData.get(checkRow).length; checkCol++) {
                                // updated, and that the new ID matches that in another ID cell
                                if (!(row == checkRow && column == checkCol) && !tableData.get(checkRow)[checkCol].toString().isEmpty() && id == Integer.decode(tableData.get(checkRow)[checkCol].toString())) {
                                    // Inform the user that the message name already is in use
                                    throw new CCDDException("Message ID is already in use");
                                }
                            }
                        }
                    }
                    // Update the table with the formatted value
                    tableData.get(row)[column] = newValueS;
                    // Check if this is the parent message's ID
                    if (column == SchedulerColumn.ID.ordinal()) {
                        // Store the new message ID
                        messages.get(row).setID(newValueS);
                    } else // This is a sub-message ID
                    {
                        // Store the new sub-message ID
                        messages.get(row).getSubMessage(column - SchedulerColumn.ID.ordinal() - 1).setID(newValueS);
                    }
                }
            } catch (CCDDException ce) {
                // Set the flag that indicates the last edited cell's content is invalid
                setLastCellValid(false);
                // Inform the user that the input value is invalid
                new CcddDialogHandler().showMessageDialog(schedulerHndlr.getSchedulerDialog().getDialog(), "<html><b>" + ce.getMessage(), "Invalid Input", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
                // Restore the cell contents to its original value
                tableData.get(row)[column] = oldValue;
                getUndoManager().undoRemoveEdit();
            }
            return showMessage;
        }

        /**
         ************************************************************************************
         * Load the table data field definition values into the table and format the table
         * cells
         ************************************************************************************
         */
        @Override
        protected void loadAndFormatData() {
            // Place the data into the table model along with the column names, set up the
            // editors and renderers for the table cells, set up the table grid lines, and
            // calculate the minimum width required to display the table information
            setUpdatableCharacteristics(currentData, getColumnNames(), null, null, true, true, true);
        }

        /**
         ************************************************************************************
         * Override prepareRenderer to allow adjusting the background colors of table cells
         ************************************************************************************
         */
        @Override
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            JComponent comp = (JComponent) super.prepareRenderer(renderer, row, column);
            // color
            if (comp.getBackground() != ModifiableColorInfo.FOCUS_BACK.getColor() && comp.getBackground() != ModifiableColorInfo.SELECTED_BACK.getColor() && !isCellEditable(row, column)) {
                // Shade the cell's foreground and background colors
                comp.setForeground(getValueAt(row, column).toString().startsWith("-") ? ModifiableColorInfo.INVALID_TEXT.getColor() : ModifiableColorInfo.PROTECTED_TEXT.getColor());
                comp.setBackground(ModifiableColorInfo.PROTECTED_BACK.getColor());
            }
            return comp;
        }

        /**
         ************************************************************************************
         * Override the CcddJTableHandler method to handle sorting the Size column
         ************************************************************************************
         */
        @Override
        protected void setTableSortable() {
            // Remove the current sorter, if present. The number of columns may have changed
            // (due to adding/removing sub-messages) so the sorter must be rebuilt
            setRowSorter(null);
            super.setTableSortable();
            // Create a runnable object to be executed
            SwingUtilities.invokeLater(new Runnable() {

                /**
                 ****************************************************************************
                 * Execute after all pending Swing events are finished. This allows the number
                 * of viewable columns to catch up with the column model when a column is added
                 * or removed
                 ****************************************************************************
                 */
                @Override
                public void run() {
                    // Get the table's row sorter
                    TableRowSorter<?> sorter = (TableRowSorter<?>) getRowSorter();
                    // Check if the table has a sorter (i.e., has at least one row)
                    if (sorter != null) {
                        // the telemetry scheduler)
                        for (int column = SchedulerColumn.ID.ordinal(); column < getModel().getColumnCount(); column++) {
                            // Add a hexadecimal sort comparator
                            sorter.setComparator(column, new Comparator<String>() {

                                /**
                                 ************************************************************
                                 * Override the comparison when sorting columns with a
                                 * hexadecimal input type format
                                 ************************************************************
                                 */
                                @Override
                                public int compare(String cell1, String cell2) {
                                    int result;
                                    // Check if either cell is empty
                                    if (cell1.isEmpty() || cell2.isEmpty()) {
                                        // Compare as text (alphabetically)
                                        result = cell1.compareTo(cell2);
                                    } else // Neither cell is empty
                                    {
                                        // Get the hexadecimal cell values and convert them to
                                        // base 10 integers for comparison
                                        result = Integer.compare(Integer.decode(cell1), Integer.decode(cell2));
                                    }
                                    return result;
                                }
                            });
                        }
                    }
                }
            });
        }
    };
    // Create a listener for scheduler table row and column selection changes
    ListSelectionListener rowColListener = new ListSelectionListener() {

        /**
         ************************************************************************************
         * Handle a scheduler table row or column selection change
         ************************************************************************************
         */
        @Override
        public void valueChanged(ListSelectionEvent lse) {
            // Check if this is the last of the series of changes
            if (!lse.getValueIsAdjusting() && (schedulerTable.getSelectedRow() != previousRow || schedulerTable.getSelectedColumn() != previousColumn)) {
                // Update the tabbed pane for the selected message
                updateAssignedVariablesTabs();
                // Update the assignment tree/list
                updateAssignmentList();
                // Store the selected row and column indices for comparison when another cell
                // is selected
                previousRow = schedulerTable.getSelectedRow();
                previousColumn = schedulerTable.getSelectedColumn();
            }
        }
    };
    // Add a listener for changes to the table's row selection
    schedulerTable.getSelectionModel().addListSelectionListener(rowColListener);
    // Add a listener for changes to the table's column selection
    schedulerTable.getColumnModel().getSelectionModel().addListSelectionListener(rowColListener);
    // Place the table into a scroll pane
    JScrollPane schedulerScrollPane = new JScrollPane(schedulerTable);
    schedulerScrollPane.setBorder(border);
    // Set common table parameters and characteristics
    schedulerTable.setFixedCharacteristics(schedulerScrollPane, false, ListSelectionModel.SINGLE_SELECTION, TableSelectionMode.SELECT_BY_CELL, false, ModifiableColorInfo.TABLE_BACK.getColor(), true, true, ModifiableFontInfo.DATA_TABLE_CELL.getFont(), true);
    // Get the table model and undo manager to shorten later calls
    schTableModel = (UndoableTableModel) schedulerTable.getModel();
    // Create a scroll pane to contain the assignment tree/list
    JScrollPane assignScrollPane = null;
    // Check if this is the telemetry scheduler
    if (schedulerHndlr.getSchedulerOption() == TELEMETRY_SCHEDULER) {
        // Get a reference to the telemetry scheduler input to shorten subsequent calls
        CcddTelemetrySchedulerInput tlmInput = (CcddTelemetrySchedulerInput) schedulerHndlr.getSchedulerInput();
        // Create an assignment tree specifying a null rate & message so the tree is initially
        // empty
        assignmentTree = new CcddAssignmentTreeHandler(ccddMain, null, tlmInput.getLinkTree().getLinkHandler(), tlmInput.getVariableTree().getTableTreePathList(null, tlmInput.getVariableTree().getNodeByNodeName(UNLINKED_VARIABLES_NODE_NAME), -1), ccddMain.getMainFrame());
    } else // Check if this is the application scheduler
    if (schedulerHndlr.getSchedulerOption() == APPLICATION_SCHEDULER) {
        // Initialize the assignment list and add it to a scroll pane that will be placed next
        // to the variable list
        assignmentList = new JList<String>();
        assignmentList.setModel(new DefaultListModel<String>());
        assignmentList.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
        assignScrollPane = new JScrollPane(assignmentList);
        assignScrollPane.setBorder(border);
        // Set the size of the assignment scroll pane
        assignScrollPane.setPreferredSize(new Dimension(Math.min(Math.max(assignScrollPane.getPreferredSize().width, 150), 250), assignScrollPane.getPreferredSize().height));
        assignScrollPane.setMinimumSize(assignScrollPane.getPreferredSize());
    }
    // Create panels to hold the components tablePnl = new JPanel(new GridBagLayout());
    JPanel schedulerPnl = new JPanel(new GridBagLayout());
    JPanel assignmentPnl = new JPanel(new GridBagLayout());
    schedulerPnl.setBorder(emptyBorder);
    assignmentPnl.setBorder(emptyBorder);
    // Set the scheduler panel size so that the panel can't be resized in width less than that
    // needed to display the default columns
    int[] colWidths = schedulerTable.getColumnWidths();
    int prefWidth = 8 + colWidths[0] + colWidths[1] + (schedulerHndlr.getSchedulerOption() == TELEMETRY_SCHEDULER ? colWidths[2] : 0);
    schedulerScrollPane.setPreferredSize(new Dimension(prefWidth, schedulerScrollPane.getPreferredSize().height));
    schedulerPnl.setMinimumSize(schedulerScrollPane.getPreferredSize());
    // Create the scheduler table label
    JLabel schedulerLbl = new JLabel("Scheduler");
    schedulerLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    schedulerLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
    // Add the scheduler label and scroll pane to the panel
    schedulerPnl.add(schedulerLbl, gbc);
    gbc.weighty = 1.0;
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.gridy++;
    schedulerPnl.add(schedulerScrollPane, gbc);
    // Create the assignment list label and add it to the panel
    JLabel assignmentLbl = new JLabel("");
    assignmentLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    assignmentLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
    gbc.insets.top = 0;
    gbc.weighty = 0.0;
    gbc.gridx = 0;
    gbc.gridy = 0;
    assignmentPnl.add(assignmentLbl, gbc);
    gbc.weighty = 1.0;
    gbc.gridy = 1;
    // Check if this is the telemetry scheduler
    if (schedulerHndlr.getSchedulerOption() == TELEMETRY_SCHEDULER) {
        // Adjust the tab area's insets so that the scheduler and tabs are aligned. Note that
        // the Nimbus L&F has hard-coded insets, so can't be changed;
        UIManager.getDefaults().put("TabbedPane.tabAreaInsets", new Insets(0, 0, 0, 0));
        UIManager.getDefaults().put("TabbedPane.tabsOverlapBorder", true);
        // Create a tabbed pane to contain the variable tree for the message and any
        // sub-messages
        tabbedPane = new JTabbedPane(JTabbedPane.TOP);
        tabbedPane.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
        // Listen for tab selection changes
        tabbedPane.addChangeListener(new ChangeListener() {

            /**
             ********************************************************************************
             * Handle tab selection change
             ********************************************************************************
             */
            @Override
            public void stateChanged(ChangeEvent ce) {
                // update the assignment tree
                if (!isTabUpdate) {
                    // Get the currently selected tab index
                    int tabIndex = tabbedPane.getSelectedIndex();
                    // Check if a tab is selected
                    if (tabIndex != -1) {
                        // Get the currently selected message in the scheduler table
                        Message message = getSelectedMessage();
                        // Check if a message is selected
                        if (message != null) {
                            // Select the row and column in the scheduler table corresponding
                            // to the selected message tab
                            schedulerTable.changeSelection(schedulerTable.getSelectedRow(), SchedulerColumn.ID.ordinal() + tabIndex, false, false);
                        }
                    }
                    // Update the assignment tree/list
                    updateAssignmentList();
                }
            }
        });
        // Set the assignment tree title
        assignmentLbl.setText("Assigned Variables");
        // Create the assignment tree and place it within the tabbed pane
        tabbedPane.insertTab("<html><i>No message selected", null, assignmentTree.createTreePanel(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION), null, 0);
        // Add the tabbed pane to the panel
        assignmentPnl.add(tabbedPane, gbc);
    } else // Check if this is the application scheduler
    if (schedulerHndlr.getSchedulerOption() == APPLICATION_SCHEDULER) {
        // Set the assignment list title
        assignmentLbl.setText("Assigned Applications");
        // Add the assignment list to the panel
        gbc.insets.top = 0;
        assignmentPnl.add(assignScrollPane, gbc);
        // Set the tabbed pane to null so that the application scheduler ignores it
        tabbedPane = null;
    }
    // Add the scheduler table and assignment tree/list to the split pane
    tableSpltPn = new CustomSplitPane(schedulerPnl, assignmentPnl, null, JSplitPane.HORIZONTAL_SPLIT);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) CCDDException(CCDD.CcddClassesDataTable.CCDDException) Message(CCDD.CcddClassesDataTable.Message) GridBagLayout(java.awt.GridBagLayout) JTabbedPane(javax.swing.JTabbedPane) ListSelectionEvent(javax.swing.event.ListSelectionEvent) DefaultListModel(javax.swing.DefaultListModel) CustomSplitPane(CCDD.CcddClassesComponent.CustomSplitPane) ChangeListener(javax.swing.event.ChangeListener) Component(java.awt.Component) JComponent(javax.swing.JComponent) TableRowSorter(javax.swing.table.TableRowSorter) JScrollPane(javax.swing.JScrollPane) TableCellRenderer(javax.swing.table.TableCellRenderer) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) ListSelectionListener(javax.swing.event.ListSelectionListener) ChangeEvent(javax.swing.event.ChangeEvent) Border(javax.swing.border.Border) BevelBorder(javax.swing.border.BevelBorder) JList(javax.swing.JList)

Example 3 with CustomSplitPane

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

the class CcddScriptManagerDialog method initialize.

/**
 ********************************************************************************************
 * Create the script association manager dialog. This is executed in a separate thread since it
 * can take a noticeable amount time to complete, and by using a separate thread the GUI is
 * allowed to continue to update. The GUI menu commands, however, are disabled until the
 * telemetry scheduler initialization completes execution
 ********************************************************************************************
 */
private void initialize() {
    // user confirms ignoring the changes
    if (ccddMain.ignoreUncommittedChanges("Script Manager", "Ignore changes?", false, null, CcddScriptManagerDialog.this)) {
        // Build the script association manager dialog in the background
        CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {

            // Create panels to hold the components of the dialog
            JPanel dialogPnl = new JPanel(new GridBagLayout());

            JPanel buttonPnl = new JPanel();

            /**
             ********************************************************************************
             * Build the script association manager dialog
             ********************************************************************************
             */
            @Override
            protected void execute() {
                isNodeSelectionChanging = false;
                // Create borders for the input fields
                border = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing()));
                Border emptyBorder = BorderFactory.createEmptyBorder();
                // Set the initial layout manager characteristics
                GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()), 0, 0);
                dialogPnl.setBorder(emptyBorder);
                // Create a panel to contain the script file name, association name, and
                // association description labels and fields
                JPanel inputPnl = new JPanel(new GridBagLayout());
                // Add the script file selection components to the input panel
                inputPnl.add(createScriptSelectionPanel(), gbc);
                // Create the name label and field, and add these to the input panel
                JLabel nameLbl = new JLabel("Script association name");
                nameLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
                gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
                gbc.gridy++;
                inputPnl.add(nameLbl, gbc);
                nameFld = new JTextField("", 1);
                nameFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
                nameFld.setEditable(true);
                nameFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
                nameFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
                nameFld.setBorder(border);
                gbc.insets.top = 0;
                gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
                gbc.weightx = 1.0;
                gbc.gridy++;
                inputPnl.add(nameFld, gbc);
                // Create the description label and field, and add these to the input panel
                JLabel descriptionLbl = new JLabel("Script association description");
                descriptionLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
                gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
                gbc.insets.left = 0;
                gbc.weightx = 0.0;
                gbc.gridy++;
                inputPnl.add(descriptionLbl, gbc);
                descriptionFld = new JTextArea("", 3, 1);
                descriptionFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
                descriptionFld.setEditable(true);
                descriptionFld.setWrapStyleWord(true);
                descriptionFld.setLineWrap(true);
                descriptionFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
                descriptionFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
                descriptionFld.setBorder(emptyBorder);
                JScrollPane scrollPane = new JScrollPane(descriptionFld);
                scrollPane.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
                scrollPane.setBorder(emptyBorder);
                scrollPane.setViewportBorder(border);
                scrollPane.setMinimumSize(scrollPane.getPreferredSize());
                gbc.insets.top = 0;
                gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
                gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() * 2;
                gbc.gridwidth = GridBagConstraints.REMAINDER;
                gbc.weightx = 1.0;
                gbc.weighty = 1.0;
                gbc.gridy++;
                inputPnl.add(scrollPane, gbc);
                // Add the input panel and the table selection components to the inputs pane
                // within a horizontally split pane. Use a separator to denote the split pane's
                // drag component
                JSeparator inputSep = new JSeparator(SwingConstants.VERTICAL);
                inputSep.setForeground(dialogPnl.getBackground().darker());
                CustomSplitPane inputsPane = new CustomSplitPane(inputPnl, createSelectionPanel("Select associated tables", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION), inputSep, JSplitPane.HORIZONTAL_SPLIT);
                // Add the inputs pane and the script association table components to the
                // dialog within a vertically split pane. Use a separator to denote the split
                // pane's drag component
                JSeparator assnSep = new JSeparator();
                assnSep.setForeground(dialogPnl.getBackground().darker());
                gbc.weighty = 1.0;
                gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
                gbc.insets.bottom = 0;
                gbc.gridy = 0;
                dialogPnl.add(new CustomSplitPane(inputsPane, scriptHandler.getAssociationsPanel("Script Associations", true, CcddScriptManagerDialog.this), assnSep, JSplitPane.VERTICAL_SPLIT), gbc);
                // Get a reference to the script associations table to shorten subsequent calls
                assnsTable = scriptHandler.getAssociationsTable();
                // Store the initial table data
                doAssnUpdatesComplete(false);
                // Add a listener for script association table row selection changes
                assnsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

                    /**
                     ************************************************************************
                     * Handle a table row selection change. Populate the script description
                     * field, file field, and table tree based on the first selected
                     * associations table row
                     ************************************************************************
                     */
                    @Override
                    public void valueChanged(ListSelectionEvent lse) {
                        // for a keyboard input this returns false)
                        if (!lse.getValueIsAdjusting()) {
                            // Get the first selected table row
                            int row = assnsTable.getSelectedRow();
                            // Check if a table row item is selected
                            if (row != -1) {
                                // Store the association name in the the name field
                                nameFld.setText(assnsTable.getValueAt(row, assnsTable.convertColumnIndexToView(AssociationsTableColumnInfo.NAME.ordinal())).toString());
                                // Store the association description in the the description
                                // field
                                descriptionFld.setText(assnsTable.getValueAt(row, assnsTable.convertColumnIndexToView(AssociationsTableColumnInfo.DESCRIPTION.ordinal())).toString());
                                // Store the script file name with path in the the script file
                                // field
                                scriptFld.setText(assnsTable.getValueAt(row, assnsTable.convertColumnIndexToView(AssociationsTableColumnInfo.SCRIPT_FILE.ordinal())).toString());
                                // Separate the table member portion into the individual table
                                // names. The line breaks used for HTML formatting must be
                                // replaced by line feed characters so that the split is made
                                // correctly
                                String[] tableNames = CcddUtilities.removeHTMLTags(assnsTable.getValueAt(row, assnsTable.convertColumnIndexToView(AssociationsTableColumnInfo.MEMBERS.ordinal())).toString().replaceAll("<br>", "\n")).split(Pattern.quote(ASSN_TABLE_SEPARATOR));
                                List<TreePath> paths = new ArrayList<>();
                                // Step through each table name
                                for (String tableName : tableNames) {
                                    ToolTipTreeNode node;
                                    // Check if the name refers to a group
                                    if (tableName.startsWith(GROUP_DATA_FIELD_IDENT)) {
                                        // Get the node in the table tree for this group
                                        node = tableTree.getNodeByNodeName(tableName.substring(GROUP_DATA_FIELD_IDENT.length()));
                                    } else // The name refers to a table
                                    {
                                        // Get the node in the table tree for this table name
                                        node = tableTree.getNodeByNodePath(tableName);
                                    }
                                    // Check if the table name is in the tree
                                    if (node != null) {
                                        // Add the path to the list
                                        paths.add(CcddCommonTreeHandler.getPathFromNode(node));
                                    }
                                }
                                // Select the associated tables in the table tree
                                tableTree.setSelectionPaths(paths.toArray(new TreePath[0]));
                            }
                        }
                    }
                });
                // Define the buttons for the lower panel: Add association button
                JButton btnAddAssn = CcddButtonPanelHandler.createButton("Add", INSERT_ICON, KeyEvent.VK_A, "Add the currently defined script association");
                // Add a listener for the Add button
                btnAddAssn.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Add a new script association
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        // Check that a script is specified
                        if (!scriptFld.getText().trim().isEmpty()) {
                            addAssociation(TableInsertionPoint.START);
                        } else // The script file field is blank
                        {
                            // Inform the user that a script must be selected
                            new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>Must enter or select a script", "Script Missing", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
                        }
                    }
                });
                // Remove script association(s) button
                JButton btnRemoveAssn = CcddButtonPanelHandler.createButton("Remove", DELETE_ICON, KeyEvent.VK_R, "Remove the selected script association(s)");
                // Add a listener for the Remove button
                btnRemoveAssn.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Remove the selected script association(s)
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        removeAssociations();
                    }
                });
                // Replace script association(s) button
                JButton btnReplaceAssn = CcddButtonPanelHandler.createButton("Replace", REPLACE_ICON, KeyEvent.VK_P, "Replace the selected script association");
                // Add a listener for the Replace button
                btnReplaceAssn.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Replace the selected script association
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        replaceAssociation();
                    }
                });
                // Move Up button
                JButton btnMoveUp = CcddButtonPanelHandler.createButton("Up", UP_ICON, KeyEvent.VK_U, "Move the selected row(s) up");
                // Create a listener for the Move Up command
                btnMoveUp.addActionListener(new ValidateCellActionListener() {

                    /**
                     ************************************************************************
                     * Move the selected row(s) up in the table
                     ************************************************************************
                     */
                    @Override
                    protected void performAction(ActionEvent ae) {
                        assnsTable.moveRowUp();
                    }

                    /**
                     ************************************************************************
                     * Get the reference to the currently displayed table
                     ************************************************************************
                     */
                    @Override
                    protected CcddJTableHandler getTable() {
                        return assnsTable;
                    }
                });
                // Move Down button
                JButton btnMoveDown = CcddButtonPanelHandler.createButton("Down", DOWN_ICON, KeyEvent.VK_W, "Move the selected row(s) down");
                // Create a listener for the Move Down command
                btnMoveDown.addActionListener(new ValidateCellActionListener() {

                    /**
                     ************************************************************************
                     * Move the selected row(s) down in the table
                     ************************************************************************
                     */
                    @Override
                    protected void performAction(ActionEvent ae) {
                        assnsTable.moveRowDown();
                    }

                    /**
                     ************************************************************************
                     * Get the reference to the currently displayed table
                     ************************************************************************
                     */
                    @Override
                    protected CcddJTableHandler getTable() {
                        return assnsTable;
                    }
                });
                // Undo button
                JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
                // Create a listener for the Undo command
                btnUndo.addActionListener(new ValidateCellActionListener() {

                    /**
                     ************************************************************************
                     * Undo the last addition to the script association table
                     ************************************************************************
                     */
                    @Override
                    protected void performAction(ActionEvent ae) {
                        assnsTable.getUndoManager().undo();
                    }

                    /**
                     ************************************************************************
                     * Get the reference to the currently displayed table
                     ************************************************************************
                     */
                    @Override
                    protected CcddJTableHandler getTable() {
                        return assnsTable;
                    }
                });
                // Redo button
                JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
                // Create a listener for the Redo command
                btnRedo.addActionListener(new ValidateCellActionListener() {

                    /**
                     ************************************************************************
                     * Redo the last addition to the script association table that was undone
                     ************************************************************************
                     */
                    @Override
                    protected void performAction(ActionEvent ae) {
                        assnsTable.getUndoManager().redo();
                    }

                    /**
                     ************************************************************************************
                     * Get the reference to the currently displayed table
                     ************************************************************************************
                     */
                    @Override
                    protected CcddJTableHandler getTable() {
                        return assnsTable;
                    }
                });
                // Script execution button
                btnExecute = CcddButtonPanelHandler.createButton("Execute", EXECUTE_ICON, KeyEvent.VK_E, "Execute the selected script association(s)");
                // Add a listener for the Execute button
                btnExecute.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Execute the selected script association(s)
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        // Execute the selected associations
                        scriptHandler.executeScriptAssociations(tableTree, CcddScriptManagerDialog.this);
                    }
                });
                // Store script associations button
                JButton btnStoreAssns = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store the updated script associations to the database");
                // Add a listener for the Store button
                btnStoreAssns.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Store the script associations in the database
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        // associations
                        if (assnsTable.isTableChanged(committedAssnsData, Arrays.asList(new Integer[] { AssociationsTableColumnInfo.AVAILABLE.ordinal() })) && new CcddDialogHandler().showMessageDialog(CcddScriptManagerDialog.this, "<html><b>Store script associations?", "Store Associations", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                            // Disable the dialog buttons until the updates complete
                            setControlsEnabled(false);
                            // Store the script associations list into the database
                            dbTable.storeInformationTableInBackground(InternalTable.ASSOCIATIONS, createAssociationsFromTable(), null, CcddScriptManagerDialog.this);
                        }
                    }
                });
                // Close button
                JButton btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the script association manager");
                // Add a listener for the Close button
                btnClose.addActionListener(new ActionListener() {

                    /**
                     ************************************************************************
                     * Close the script association dialog
                     ************************************************************************
                     */
                    @Override
                    public void actionPerformed(ActionEvent ae) {
                        // user elects to discard the changes
                        if (!isAssociationsChanged() || new CcddDialogHandler().showMessageDialog(CcddScriptManagerDialog.this, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                            // Reset the reference to the script associations manager in the
                            // script handler since the handler remains active)
                            scriptHandler.setScriptDialog(null);
                            // Close the dialog
                            closeFrame();
                        }
                    }
                });
                // Add buttons in the order in which they'll appear (left to right, top to
                // bottom)
                buttonPnl.add(btnAddAssn);
                buttonPnl.add(btnReplaceAssn);
                buttonPnl.add(btnMoveUp);
                buttonPnl.add(btnUndo);
                buttonPnl.add(btnStoreAssns);
                buttonPnl.add(btnRemoveAssn);
                buttonPnl.add(btnExecute);
                buttonPnl.add(btnMoveDown);
                buttonPnl.add(btnRedo);
                buttonPnl.add(btnClose);
                // Distribute the buttons across two rows
                setButtonRows(2);
            }

            /**
             ********************************************************************************
             * Script association manager dialog creation complete
             ********************************************************************************
             */
            @Override
            protected void complete() {
                // Display the script association management dialog
                createFrame(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnExecute, DIALOG_TITLE, null);
            }
        });
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JTextArea(javax.swing.JTextArea) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) ArrayList(java.util.ArrayList) JButton(javax.swing.JButton) JTextField(javax.swing.JTextField) CustomSplitPane(CCDD.CcddClassesComponent.CustomSplitPane) JSeparator(javax.swing.JSeparator) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) ToolTipTreeNode(CCDD.CcddClassesComponent.ToolTipTreeNode) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) TableInsertionPoint(CCDD.CcddConstants.TableInsertionPoint) ListSelectionListener(javax.swing.event.ListSelectionListener) TreePath(javax.swing.tree.TreePath) ActionListener(java.awt.event.ActionListener) ValidateCellActionListener(CCDD.CcddClassesComponent.ValidateCellActionListener) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand) Border(javax.swing.border.Border) BevelBorder(javax.swing.border.BevelBorder)

Example 4 with CustomSplitPane

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

the class CcddGroupManagerDialog method initialize.

/**
 ********************************************************************************************
 * Create the group manager dialog. This is executed in a separate thread since it can take a
 * noticeable amount time to complete, and by using a separate thread the GUI is allowed to
 * continue to update. The GUI menu commands, however, are disabled until the telemetry
 * scheduler initialization completes execution
 ********************************************************************************************
 */
private void initialize() {
    // Build the group manager dialog in the background
    CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {

        // Create panels to hold the components of the dialog
        JPanel dialogPnl = new JPanel(new GridBagLayout());

        JPanel buttonPnl = new JPanel();

        JButton btnClose;

        /**
         ************************************************************************************
         * Build the group manager dialog
         ************************************************************************************
         */
        @Override
        protected void execute() {
            isNodeSelectionChanging = false;
            // Set the flag to indicate the group manager dialog is being initialized
            isInitializing = true;
            // Create borders for the dialog components
            border = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing()));
            emptyBorder = BorderFactory.createEmptyBorder();
            // Set the initial layout manager characteristics
            GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, 0, 0), 0, 0);
            selectedGroup = null;
            deletedGroups = new ArrayList<String>();
            // Add an undo edit manager
            undoManager = new CcddUndoManager() {

                /**
                 ****************************************************************************
                 * Update the change indicator if the editor panel has changed
                 ****************************************************************************
                 */
                @Override
                protected void ownerHasChanged() {
                    // during initialization are ignored
                    if (!isInitializing) {
                        updateChangeIndicator();
                    }
                }
            };
            // Create the undo handler for the components with undoable actions. Disable
            // storage of edit actions during dialog creation
            undoHandler = new CcddUndoHandler(undoManager);
            nodeSelect = undoHandler.new UndoableTreePathSelection();
            undoHandler.setAllowUndo(false);
            // Build the group tree
            groupTree = new CcddGroupTreeHandler(ccddMain, undoHandler, ccddMain.getMainFrame()) {

                /**
                 ****************************************************************************
                 * Respond to changes in selection of a node in the group tree
                 ****************************************************************************
                 */
                @Override
                protected void updateTableSelection() {
                    // Check that a node selection change is not in progress
                    if (!isNodeSelectionChanging) {
                        // Set the flag to prevent link tree updates
                        isNodeSelectionChanging = true;
                        // Needed for the group manager dialog's size to be adjusted for the
                        // data fields
                        groupMgr.setPreferredSize(null);
                        // Store any changes to the currently selected group, if applicable
                        updateSelectedGroupInformation();
                        // Update the description field text so that it can be undone/redone.
                        // The focus change, which is usually used to perform the update,
                        // occurs after the node selection edit and would cause the wrong
                        // description field to be changed
                        fieldPnlHndlr.updateDescriptionField(true);
                        // Get the name of the selected group(s)
                        String[] selected = getTopLevelSelectedNodeNames();
                        // If a single group is selected then set the selected group, enable
                        // and populate the description field, and display the group's data
                        // fields; otherwise clear the selected group, disable and clear the
                        // description field, and remove any data fields
                        setGroupAndFields(selected.length == 1 ? selected[0] : null);
                        // operation isn't recorded on the undo/redo stack
                        if (undoHandler.isAllowUndo()) {
                            // Add the node path selection change to the undo/redo stack and
                            // store the field information in the undo handler
                            nodeSelect.selectTreePath(getSelectedPaths());
                            fieldPnlHndlr.storeCurrentFieldInformation();
                        }
                        // Reset the flag to allow link tree updates
                        isNodeSelectionChanging = false;
                    }
                }
            };
            // Get the references to the group and data field handlers created by the group
            // tree. These are used to shorten subsequent calls
            groupHandler = groupTree.getGroupHandler();
            fieldHandler = groupTree.getFieldHandler();
            // Set the data field handler and group tree references in the undo handler so that
            // data field and tree edits can be undone/redone
            undoHandler.setFieldHandler(fieldHandler);
            undoHandler.setTree(groupTree);
            // Store the initial group information
            copyGroupInformation();
            // Create panels to hold the components of the dialog
            JPanel titlePnl = new JPanel(new GridBagLayout());
            JPanel treePnl = new JPanel(new GridBagLayout());
            dialogPnl.setBorder(emptyBorder);
            titlePnl.setBorder(emptyBorder);
            treePnl.setBorder(emptyBorder);
            // Create the group manager dialog labels and fields
            JLabel dlgLabel = new JLabel("Assign tables to groups");
            dlgLabel.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            titlePnl.add(dlgLabel, gbc);
            // Add the upper panel components to the dialog panel
            dialogPnl.add(titlePnl, gbc);
            // Build the table tree showing both table prototypes and table instances; i.e.,
            // parent tables with their child tables (i.e., parents with children)
            tableTree = new CcddTableTreeHandler(ccddMain, null, TableTreeType.TABLES, false, true, ccddMain.getMainFrame()) {

                /**
                 ****************************************************************************
                 * Respond to changes in selection of a node in the table tree
                 ****************************************************************************
                 */
                @Override
                protected void updateTableSelection() {
                    // Check that a node selection change is not in progress
                    if (!isNodeSelectionChanging) {
                        // Select the associated group in the group tree if a table is selected
                        // in the table tree. Note that below any linked variables are
                        // deselected, so this call must occur first
                        selectGroupByTable();
                        // Set the flag to prevent variable tree updates
                        isNodeSelectionChanging = true;
                        // Deselect any nodes that don't represent a table or the level
                        // immediately above the table level
                        clearNonTableNodes(1);
                        // Reset the flag to allow variable tree updates
                        isNodeSelectionChanging = false;
                    }
                }
            };
            // Create a table tree panel and add it to another panel (in order to control
            // spacing)
            gbc.insets.top = 0;
            gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
            gbc.weighty = 1.0;
            treePnl.add(tableTree.createTreePanel("Tables", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, ccddMain.getMainFrame()), gbc);
            gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
            gbc.insets.bottom = 0;
            // Create a split pane containing the table tree in the left pane and the group
            // tree in the right pane and add it to the panel. The arrow button panel is used
            // as the split pane divider
            gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
            gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
            gbc.gridy++;
            dialogPnl.add(new CustomSplitPane(treePnl, groupTree.createTreePanel("Groups", TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION, false, ccddMain.getMainFrame()), createArrowButtonPanel(), JSplitPane.HORIZONTAL_SPLIT), gbc);
            // Create the field panel for the description and data fields
            fieldPnlHndlr = new CcddInputFieldPanelHandler() {

                /**
                 ****************************************************************************
                 * Update the group manager change indicator
                 ****************************************************************************
                 */
                @Override
                protected void updateOwnerChangeIndicator() {
                    updateChangeIndicator();
                }
            };
            // Set the undo/redo manager and handler for the description and data field values
            fieldPnlHndlr.setEditPanelUndo(undoManager, undoHandler);
            // Create the description and data fields
            fieldPnlHndlr.createDescAndDataFieldPanel(groupMgr, null, null, null, fieldHandler);
            // Set the modal undo manager in the keyboard handler while the group manager is
            // active
            ccddMain.getKeyboardHandler().setModalDialogReference(undoManager, null);
            // Re-enable storage of edit actions
            undoHandler.setAllowUndo(true);
            // Add the field panel to the dialog
            gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
            gbc.insets.left = 0;
            gbc.insets.bottom = 0;
            gbc.insets.right = 0;
            gbc.weighty = 0.0;
            gbc.gridy++;
            dialogPnl.add(fieldPnlHndlr.getFieldPanel(), gbc);
            // Create a check box for showing/changing the group CFS application status
            applicationCb = undoHandler.new UndoableCheckBox("Group represents a CFS application", false);
            applicationCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
            applicationCb.setBorder(emptyBorder);
            applicationCb.setEnabled(false);
            gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
            gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
            gbc.gridy = 0;
            fieldPnlHndlr.getFieldPanel().add(applicationCb, gbc, 0);
            // Add a listener for the application check box
            applicationCb.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Handle a change in the application check box status
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // Check if the application check box is selected and a group is selected
                    if (((JCheckBox) ae.getSource()).isSelected() && selectedGroup != null) {
                        // The application check box selection and the added CFS application
                        // data fields should be a single edit action so that both are removed
                        // if an undo is performed. Remove the check box selection from the
                        // undo stack, disable automatic edit sequence ending, then perform the
                        // check box selection again so that it's added to the undo stack
                        // without ending the edit sequence
                        undoManager.undoRemoveEdit();
                        undoHandler.setAutoEndEditSequence(false);
                        applicationCb.setSelected(true);
                        // Get the field information for the group
                        GroupInformation groupInfo = groupHandler.getGroupInformationByName(selectedGroup.getName());
                        List<FieldInformation> fieldInformation = groupInfo.getFieldInformation();
                        // Step through each default application data field
                        for (DefaultApplicationField field : DefaultApplicationField.values()) {
                            // Create a new data field
                            FieldInformation newField = field.createFieldInformation(CcddFieldHandler.getFieldGroupName(selectedGroup.getName()));
                            boolean isExists = false;
                            // Step through the group's existing data fields
                            for (FieldInformation fieldInfo : fieldInformation) {
                                // Check if the data field already exists
                                if (newField.getFieldName().equals(fieldInfo.getFieldName())) {
                                    // Set the flag indicating the field exists and stop
                                    // searching
                                    isExists = true;
                                    break;
                                }
                            }
                            // Check if the field doesn't exists
                            if (!isExists) {
                                // Add the field to the group
                                fieldInformation.add(newField);
                            }
                        }
                        // Needed for the group manager dialog's size to be adjusted for the
                        // data fields
                        groupMgr.setPreferredSize(null);
                        // Store the data field additions so that the added fields appear in
                        // the dialog
                        fieldHandler.setFieldInformation(CcddFieldHandler.getFieldInformationCopy(fieldInformation));
                        // Rebuild the data field panel and update the dialog's size
                        recreateDataFieldPanel(true);
                        // Re-enable automatic edit sequence ending, then end the edit sequence
                        // to group the check box and added data fields
                        undoHandler.setAutoEndEditSequence(true);
                        undoManager.endEditSequence();
                    }
                }
            });
            // Define the buttons for the lower panel: New group button
            JButton btnNewGroup = CcddButtonPanelHandler.createButton("New", INSERT_ICON, KeyEvent.VK_N, "Create a new group");
            // Add a listener for the New button
            btnNewGroup.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Add a new group
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    newGroup();
                }
            });
            // Delete group button
            JButton btnDeleteGroup = CcddButtonPanelHandler.createButton("Delete", DELETE_ICON, KeyEvent.VK_D, "Delete an existing group");
            // Add a listener for the Delete button
            btnDeleteGroup.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Delete the selected group(s)
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    deleteGroup();
                }
            });
            // Rename group button
            btnRenameGroup = CcddButtonPanelHandler.createButton("Rename", RENAME_ICON, KeyEvent.VK_D, "Rename an existing group");
            // Add a listener for the Rename button
            btnRenameGroup.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Rename the selected group
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    renameGroup();
                }
            });
            // Copy group button
            btnCopyGroup = CcddButtonPanelHandler.createButton("Copy", COPY_ICON, KeyEvent.VK_P, "Copy an existing group");
            // Add a listener for the Copy button
            btnCopyGroup.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Copy the selected group
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    copyGroup();
                }
            });
            // Manage fields button
            btnManageFields = CcddButtonPanelHandler.createButton("Fields", FIELD_ICON, KeyEvent.VK_F, "Manage the data fields");
            // Add a listener for the Manage Fields command
            btnManageFields.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Manage the data fields
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // Create the field editor dialog showing the fields for this group
                    new CcddFieldEditorDialog(ccddMain, fieldPnlHndlr, CcddFieldHandler.getFieldGroupName(selectedGroup.getName()), false, ModifiableSizeInfo.MIN_DIALOG_WIDTH.getSize());
                    // Set the undo manager in the keyboard handler back to the group manager
                    ccddMain.getKeyboardHandler().setModalDialogReference(undoManager, null);
                    // Enable/disable the Clear values button depending on if any data fields
                    // remain
                    btnClearValues.setEnabled(!fieldHandler.getFieldInformation().isEmpty());
                }
            });
            // Clear fields button
            btnClearValues = CcddButtonPanelHandler.createButton("Clear", CLEAR_ICON, KeyEvent.VK_C, "Clear the data fields");
            // Add a listener for the Clear values command
            btnClearValues.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Clear the table data field values
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // Clear all of the data field values for the group
                    fieldPnlHndlr.clearFieldValues();
                }
            });
            // Undo button
            JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
            // Create a listener for the Undo command
            ActionListener undoAction = new ActionListener() {

                /**
                 ****************************************************************************
                 * Undo the last edit
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    undoManager.undo();
                    // Update the group selection following an undo
                    undoHandler.setAllowUndo(false);
                    groupTree.updateTableSelection();
                    undoHandler.setAllowUndo(true);
                    // Update the data field background colors
                    fieldPnlHndlr.setFieldBackgound();
                }
            };
            // Add the undo listener to the Undo button and menu command
            btnUndo.addActionListener(undoAction);
            // Redo button
            JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
            // Create a listener for the Redo command
            ActionListener redoAction = new ActionListener() {

                /**
                 ****************************************************************************
                 * Redo the last cell that was undone
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    undoManager.redo();
                    // Update the data field background colors
                    fieldPnlHndlr.setFieldBackgound();
                }
            };
            // Add the redo listener to the Redo button and menu command
            btnRedo.addActionListener(redoAction);
            // Store groups button
            JButton btnStoreGroups = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store group updates in the database");
            // Add a listener for the Store button
            btnStoreGroups.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Store the groups in the database
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // editor is open and has changes that the user confirms discarding them
                    if (isGroupsChanged() && new CcddDialogHandler().showMessageDialog(groupMgr, "<html><b>Store groups?", "Store Groups", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON && ignoreFieldTableChanges()) {
                        // Store the group list into the database
                        dbTable.storeInformationTableInBackground(InternalTable.GROUPS, currentGroups, updateFields, deletedGroups, null, null, groupMgr);
                    }
                }
            });
            // Close button
            btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the group manager");
            // Add a listener for the Close button
            btnClose.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Close the group selection dialog
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // discard the changes
                    if (!isGroupsChanged() || new CcddDialogHandler().showMessageDialog(groupMgr, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
                        // Close the dialog
                        closeDialog();
                        // Clear the modal dialog references in the keyboard handler
                        ccddMain.getKeyboardHandler().setModalDialogReference(null, null);
                    }
                }
            });
            // Set the initial enable status of the buttons
            setGroupButtonsEnabled(false);
            // Add buttons in the order in which they'll appear (left to right, top to bottom)
            buttonPnl.add(btnNewGroup);
            buttonPnl.add(btnRenameGroup);
            buttonPnl.add(btnManageFields);
            buttonPnl.add(btnUndo);
            buttonPnl.add(btnStoreGroups);
            buttonPnl.add(btnDeleteGroup);
            buttonPnl.add(btnCopyGroup);
            buttonPnl.add(btnClearValues);
            buttonPnl.add(btnRedo);
            buttonPnl.add(btnClose);
            // Distribute the buttons across two rows
            setButtonRows(2);
            // Update the undo manager so that all group manager edits up to the press of the
            // Store button can be undone/redone
            fieldPnlHndlr.storeCurrentFieldInformation();
            undoManager.endEditSequence();
            // Reset the flag now that initialization is complete
            isInitializing = false;
        }

        /**
         ************************************************************************************
         * Group manager dialog creation complete
         ************************************************************************************
         */
        @Override
        protected void complete() {
            // Display the group manager dialog
            showOptionsDialog(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnClose, DIALOG_TITLE, true);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) ArrayList(java.util.ArrayList) DefaultApplicationField(CCDD.CcddConstants.DefaultApplicationField) CustomSplitPane(CCDD.CcddClassesComponent.CustomSplitPane) UndoableCheckBox(CCDD.CcddUndoHandler.UndoableCheckBox) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) UndoableTreePathSelection(CCDD.CcddUndoHandler.UndoableTreePathSelection) JLabel(javax.swing.JLabel) ActionListener(java.awt.event.ActionListener) BackgroundCommand(CCDD.CcddBackgroundCommand.BackgroundCommand) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 5 with CustomSplitPane

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

the class CcddSchedulerHandler method createDualScrollPanelwithButtons.

/**
 ********************************************************************************************
 * Create dual scroll panels
 *
 * @return Split pane containing the dual panels
 ********************************************************************************************
 */
@SuppressWarnings("serial")
private JSplitPane createDualScrollPanelwithButtons() {
    // Create an empty border
    Border emptyBorder = BorderFactory.createEmptyBorder();
    // Set the initial layout manager characteristics
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2, 0), 0, 0);
    // Create the scheduler input (variables or applications) handler
    schedulerInput = schedulerDlg.createSchedulerInput(rateName);
    int totalMsgs = 0;
    int totalBytes = 0;
    int msgsPerSec = 0;
    // Get the scheduler dialog type
    SchedulerType option = getSchedulerOption();
    // Check if this is the telemetry scheduler
    if (option == SchedulerType.TELEMETRY_SCHEDULER) {
        // Get the information for the rate
        RateInformation info = rateHandler.getRateInformationByRateName(rateName);
        // Get the rate parameters
        totalMsgs = info.getMaxMsgsPerCycle();
        totalBytes = info.getMaxBytesPerSec();
        msgsPerSec = rateHandler.getMaxMsgsPerSecond();
    } else // Check if this is an application scheduler
    if (option == SchedulerType.APPLICATION_SCHEDULER) {
        // Set the total number of messages to the largest rate
        totalMsgs = appHandler.getMsgsPerCycle();
        // Set messages per second to highest to ensure the cycle time is 1 second
        msgsPerSec = appHandler.getMaxMsgsPerSecond();
        totalBytes = (int) ((Float.valueOf(totalMsgs) / Float.valueOf(msgsPerSec)) * 1000);
    }
    // Create the scheduler editor handler
    schedulerEditor = new CcddSchedulerEditorHandler(ccddMain, this, totalMsgs, totalBytes, msgsPerSec);
    // Create the options model
    optionModel = new DefaultListModel<String>();
    // Set the cycle value label to the period
    cycleFld.setText(String.valueOf(Float.valueOf(totalMsgs) / Float.valueOf(msgsPerSec)));
    // Create panels to hold the components
    JPanel packPnl = new JPanel(new GridBagLayout());
    JPanel rateSelectPnl = new JPanel(new GridBagLayout());
    JPanel optionPnl = new JPanel(new GridBagLayout());
    packPnl.setBorder(emptyBorder);
    rateSelectPnl.setBorder(emptyBorder);
    optionPnl.setBorder(emptyBorder);
    // Create the options label and add it to the rate panel
    JLabel optionLbl = new JLabel("Options");
    optionLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    optionLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
    optionPnl.add(optionLbl, gbc);
    // Create the rate label and add it to the rate panel
    JLabel rateSelectLbl = new JLabel("Rate Filter ");
    rateSelectLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    rateSelectLbl.setForeground(ModifiableColorInfo.LABEL_TEXT.getColor());
    gbc.weighty = 1.0;
    gbc.gridx++;
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    rateSelectPnl.add(rateSelectLbl, gbc);
    // Create the combo box that displays the variable rates
    rateFilter = new PaddedComboBox(schedulerInput.getAvailableRates(), ModifiableFontInfo.INPUT_TEXT.getFont()) {

        /**
         ************************************************************************************
         * Override so that items flagged as disabled (grayed out) can't be selected. Only the
         * telemetry scheduler makes use of this; it has no effect on the application scheduler
         ************************************************************************************
         */
        @Override
        public void setSelectedItem(Object anObject) {
            // Check if the item isn't flagged as disabled
            if (!anObject.toString().startsWith(DISABLED_TEXT_COLOR)) {
                // Set the selected item to the specified item, if it exists in the list
                super.setSelectedItem(anObject);
            }
        }
    };
    rateFilter.setBorder(emptyBorder);
    rateFilter.setSelectedItem(schedulerInput.getSelectedRate());
    // Add a listener for rate filter selection changes
    rateFilter.addActionListener(new ActionListener() {

        /**
         ************************************************************************************
         * Rebuild the table tree using the selected rate filter
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            // Get the rate selected in the combo box
            String rate = ((JComboBox<?>) ae.getSource()).getSelectedItem().toString();
            // Update the variable tree to display variables with the given rate
            schedulerInput.updateVariableTree(rate);
            // Set the options panel to display the options for the selected rate
            getTelemetryOptions();
        }
    });
    // Add the rate filter to the rate panel
    gbc.gridx++;
    rateSelectPnl.add(rateFilter, gbc);
    // Create a list that will contain all the telemetry options for a variable
    optionList = new JList<String>(optionModel);
    optionList.setFont(ModifiableFontInfo.LABEL_PLAIN.getFont());
    optionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    // Add a listener to set the message availability given the selected option
    optionList.addListSelectionListener(new ListSelectionListener() {

        /**
         ************************************************************************************
         * Handle a selection change
         ************************************************************************************
         */
        @Override
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            // Update the scheduler table text highlighting
            updateSchedulerTableHighlight();
        }
    });
    // Add the list to a scroll pane that will be placed next to the variable list
    JScrollPane optionScroll = new JScrollPane(optionList);
    optionScroll.setBorder(border);
    // Set the preferred width of the tree's scroll pane
    optionScroll.setPreferredSize(new Dimension(Math.min(Math.max(optionScroll.getPreferredSize().width, 200), 200), optionScroll.getPreferredSize().height));
    // Set the minimum size to the preferred size
    optionScroll.setMinimumSize(optionScroll.getPreferredSize());
    // Add the option scroll pane to the option panel
    gbc.insets.top = 0;
    gbc.insets.bottom = 0;
    gbc.gridx = 0;
    gbc.gridy++;
    optionPnl.add(optionScroll, gbc);
    // Add the rate selection panel to the option panel
    gbc.gridy++;
    gbc.weighty = 0.0;
    gbc.fill = GridBagConstraints.NONE;
    optionPnl.add(rateSelectPnl, gbc);
    // Add the option panel to the pack panel
    gbc.weighty = 1.0;
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy = 0;
    gbc.gridx++;
    packPnl.add(optionPnl, gbc);
    // Create the split pane containing the input tree and options panel
    JSplitPane leftSpltPn = new CustomSplitPane(schedulerInput.getInputPanel(), packPnl, null, JSplitPane.HORIZONTAL_SPLIT);
    // Create the split pane containing the left split pane and the split pane containing the
    // scheduler and assignment tree/list. Use the arrow button panel as the split pane divider
    JSplitPane allSpltPn = new CustomSplitPane(leftSpltPn, schedulerEditor.getSchedulerAndAssignPanel(), createArrowButtonPanel(), JSplitPane.HORIZONTAL_SPLIT);
    // Set the options list to display the starting rate value
    getTelemetryOptions();
    return allSpltPn;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) RateInformation(CCDD.CcddClassesDataTable.RateInformation) CustomSplitPane(CCDD.CcddClassesComponent.CustomSplitPane) PaddedComboBox(CCDD.CcddClassesComponent.PaddedComboBox) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) SchedulerType(CCDD.CcddConstants.SchedulerType) Dimension(java.awt.Dimension) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener) JSplitPane(javax.swing.JSplitPane) Border(javax.swing.border.Border) BevelBorder(javax.swing.border.BevelBorder)

Aggregations

CustomSplitPane (CCDD.CcddClassesComponent.CustomSplitPane)5 GridBagConstraints (java.awt.GridBagConstraints)5 GridBagLayout (java.awt.GridBagLayout)5 Insets (java.awt.Insets)5 JLabel (javax.swing.JLabel)5 JPanel (javax.swing.JPanel)5 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 JScrollPane (javax.swing.JScrollPane)4 BevelBorder (javax.swing.border.BevelBorder)3 Border (javax.swing.border.Border)3 ListSelectionEvent (javax.swing.event.ListSelectionEvent)3 ListSelectionListener (javax.swing.event.ListSelectionListener)3 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)2 PaddedComboBox (CCDD.CcddClassesComponent.PaddedComboBox)2 UndoableTreePathSelection (CCDD.CcddUndoHandler.UndoableTreePathSelection)2 Component (java.awt.Component)2 Dimension (java.awt.Dimension)2 ArrayList (java.util.ArrayList)2 JButton (javax.swing.JButton)2