Search in sources :

Example 11 with PaddedComboBox

use of CCDD.CcddClassesComponent.PaddedComboBox 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)

Example 12 with PaddedComboBox

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

the class CcddTableTypeEditorHandler method setUpInputTypeColumn.

/**
 ********************************************************************************************
 * Set up the combo box containing the available table type input data types for display in the
 * table's Input Type cells
 ********************************************************************************************
 */
private void setUpInputTypeColumn() {
    // Create a combo box for displaying table type input types
    comboBox = new PaddedComboBox(getInputTypeNames(), InputDataType.getDescriptions(true), ModifiableFontInfo.DATA_TABLE_CELL.getFont()) {

        /**
         ************************************************************************************
         * Override so that items flagged as disabled (grayed out) are correctly identified and
         * selected
         ************************************************************************************
         */
        @Override
        public void setSelectedItem(Object anObject) {
            // list
            if (getIndexOfItem(DISABLED_TEXT_COLOR + anObject.toString()) != -1) {
                // Update the specified item to include the disable tag
                anObject = DISABLED_TEXT_COLOR + anObject;
            }
            // Set the selected item to the specified item, if it exists in the list
            super.setSelectedItem(anObject);
        }
    };
    // Add a listener to the combo box for focus changes
    comboBox.addFocusListener(new FocusAdapter() {

        /**
         ************************************************************************************
         * Handle a focus gained event so that the combo box automatically expands when
         * selected
         ************************************************************************************
         */
        @Override
        public void focusGained(FocusEvent fe) {
            comboBox.showPopup();
        }
    });
    // Get the index of the input data type column in view coordinates
    inputTypeIndex = table.convertColumnIndexToView(TableTypeEditorColumnInfo.INPUT_TYPE.ordinal());
    // Set the column table editor to the combo box
    table.getColumnModel().getColumn(inputTypeIndex).setCellEditor(new DefaultCellEditor(comboBox));
    // Set the default selected type
    comboBox.setSelectedItem(InputDataType.TEXT.getInputName());
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) PaddedComboBox(CCDD.CcddClassesComponent.PaddedComboBox) FocusEvent(java.awt.event.FocusEvent) DefaultCellEditor(javax.swing.DefaultCellEditor)

Aggregations

PaddedComboBox (CCDD.CcddClassesComponent.PaddedComboBox)12 DefaultCellEditor (javax.swing.DefaultCellEditor)8 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 FocusAdapter (java.awt.event.FocusAdapter)4 FocusEvent (java.awt.event.FocusEvent)4 JComboBox (javax.swing.JComboBox)4 Dimension (java.awt.Dimension)3 TableColumn (javax.swing.table.TableColumn)3 CustomSplitPane (CCDD.CcddClassesComponent.CustomSplitPane)2 RateInformation (CCDD.CcddClassesDataTable.RateInformation)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 Point (java.awt.Point)2 KeyAdapter (java.awt.event.KeyAdapter)2 KeyEvent (java.awt.event.KeyEvent)2 WindowEvent (java.awt.event.WindowEvent)2 WindowFocusListener (java.awt.event.WindowFocusListener)2 JDialog (javax.swing.JDialog)2