Search in sources :

Example 1 with PaddedComboBox

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

the class CcddMacroHandler method insertMacroName.

/**
 ********************************************************************************************
 * Display a pop-up combo box containing the names of the defined macros. When the user selects
 * a macro insert it into the supplied text component
 *
 * @param owner
 *            dialog owning the pop-up combo box
 *
 * @param textComp
 *            text component over which to display the pop-up combo box and insert the selected
 *            macro name
 *
 * @param inputType
 *            input data type of the text component
 *
 * @param validDataTypes
 *            list of valid data types from which to choose
 ********************************************************************************************
 */
protected void insertMacroName(Window owner, final JTextComponent textComp, InputDataType inputType, List<String> validDataTypes) {
    comboDlg = new JDialog(owner);
    // Check if any macros exist
    if (!macros.isEmpty()) {
        List<String> validMacros = new ArrayList<String>();
        List<String> toolTips = new ArrayList<String>();
        // Step through each macro
        for (String[] macro : macros) {
            // Get the text component's text with the macro value replacing the macro name
            String text = getInsertedMacro(macro[MacrosColumn.VALUE.ordinal()], textComp);
            // Create a string version of the new value, replacing any macro in the text with
            // its corresponding value
            text = getMacroExpansion(text, validDataTypes);
            // in the target text component based on the component's input type
            if ((text.isEmpty() || text.matches(inputType.getInputMatch())) && !isMacroRecursive) {
                // Add the macro name to the list with its value as the item's tool tip text
                validMacros.add(macro[MacrosColumn.MACRO_NAME.ordinal()]);
                toolTips.add(macro[MacrosColumn.VALUE.ordinal()]);
            }
        }
        // Check if any of the macro's are applicable to the target text component
        if (!validMacros.isEmpty()) {
            // Create the pop-up combo box
            macroCbox = new PaddedComboBox(validMacros.toArray(new String[0]), toolTips.toArray(new String[0]), ModifiableFontInfo.DATA_TABLE_CELL.getFont());
            macroCbox.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
            // Set the first macro as initially selected
            macroCbox.setSelectedIndex(0);
            // Set the property to allow the arrow keys to be used to change the macro
            // selection in the combo box
            macroCbox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
            // Add a listener for selection events in the macro pop-up combo box
            macroCbox.addActionListener(new ActionListener() {

                /**
                 ****************************************************************************
                 * Handle a selection event in the macro combo box
                 ****************************************************************************
                 */
                @Override
                public void actionPerformed(ActionEvent ae) {
                    // Get the selected macro's name and enclose it in the macro identifier
                    // character(s)
                    String macroName = getFullMacroName(((JComboBox<?>) ae.getSource()).getSelectedItem().toString().trim());
                    // Get the starting index of the selected text in the component
                    int start = textComp.getSelectionStart();
                    // Insert the macro into the text component's existing text, overwriting
                    // any of the text that is highlighted
                    textComp.setText(getInsertedMacro(macroName, textComp));
                    textComp.setSelectionStart(start);
                    // Select the macro name that was inserted
                    textComp.setSelectionEnd(start + macroName.length());
                    // Remove the macro pop-up and return to the caller. Get the selected
                    // macro's name and enclose it in the macro identifier character(s)
                    exitMacroCombo();
                }
            });
            // Add a listener for key press events in the macro pop-up combo box
            macroCbox.addKeyListener(new KeyAdapter() {

                /**
                 ****************************************************************************
                 * Handle a key press event in the macro combo box
                 ****************************************************************************
                 */
                @Override
                public void keyPressed(KeyEvent ke) {
                    // Check if the escape key is pressed
                    if (ke.getKeyCode() == KeyEvent.VK_ESCAPE) {
                        // Remove the macro pop-up and return to the caller
                        exitMacroCombo();
                    }
                }
            });
            // Add a listener for changes to the expansion/contraction of the combo box
            macroCbox.addPopupMenuListener(new PopupMenuListener() {

                /**
                 ****************************************************************************
                 * Handle a combo box expansion event
                 ****************************************************************************
                 */
                @Override
                public void popupMenuWillBecomeVisible(PopupMenuEvent pme) {
                }

                /**
                 ****************************************************************************
                 * Handle a combo box contraction event
                 ****************************************************************************
                 */
                @Override
                public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) {
                }

                /**
                 ****************************************************************************
                 * Handle a combo box cancel event. This occurs if the mouse is clicked outside
                 * the combo box
                 ****************************************************************************
                 */
                @Override
                public void popupMenuCanceled(PopupMenuEvent pme) {
                    // Remove the macro pop-up and return to the caller
                    exitMacroCombo();
                }
            });
            // Create the dialog to contain the macro pop-up combo box. Set to modeless so that
            // pop-up dialog focus changes can be detected
            comboDlg.setModalityType(ModalityType.MODELESS);
            comboDlg.setUndecorated(true);
            comboDlg.add(macroCbox, BorderLayout.NORTH);
            comboDlg.setSize(new Dimension(macroCbox.getPreferredSize()));
            // Add a listener for focus changes to the pop-up dialog
            comboDlg.addWindowFocusListener(new WindowFocusListener() {

                /**
                 ****************************************************************************
                 * Handle a gain of pop-up dialog focus
                 ****************************************************************************
                 */
                @Override
                public void windowGainedFocus(WindowEvent we) {
                    // Create a runnable object to be executed
                    SwingUtilities.invokeLater(new Runnable() {

                        /**
                         ********************************************************************
                         * Delay showing the pop-up; if this isn't done then the pop-up isn't
                         * expanded consistently
                         ********************************************************************
                         */
                        @Override
                        public void run() {
                            // Expand the combo box when it appears
                            macroCbox.showPopup();
                        }
                    });
                }

                /**
                 ****************************************************************************
                 * Handle a loss of pop-up dialog focus
                 ****************************************************************************
                 */
                @Override
                public void windowLostFocus(WindowEvent we) {
                    // Remove the macro pop-up and return to the caller
                    exitMacroCombo();
                }
            });
            // Position and display the pop-up
            positionMacroPopup(textComp);
            comboDlg.setVisible(true);
        }
    }
}
Also used : JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) PopupMenuListener(javax.swing.event.PopupMenuListener) ArrayList(java.util.ArrayList) Dimension(java.awt.Dimension) PopupMenuEvent(javax.swing.event.PopupMenuEvent) KeyEvent(java.awt.event.KeyEvent) PaddedComboBox(CCDD.CcddClassesComponent.PaddedComboBox) ActionListener(java.awt.event.ActionListener) WindowEvent(java.awt.event.WindowEvent) JDialog(javax.swing.JDialog) WindowFocusListener(java.awt.event.WindowFocusListener)

Example 2 with PaddedComboBox

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

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

the class CcddFieldEditorDialog method setUpInputTypeColumn.

/**
 ********************************************************************************************
 * Set up the combo box containing the available field input input data types for display in
 * the table's Input Type cells
 ********************************************************************************************
 */
private void setUpInputTypeColumn() {
    // Step through each column in the editor
    for (inputTypeIndex = 0; inputTypeIndex < fieldTable.getColumnCount(); inputTypeIndex++) {
        // Check if the column name matches that for the field input type
        if (fieldTable.getColumnName(inputTypeIndex).equals(FieldEditorColumnInfo.INPUT_TYPE.getColumnName())) {
            // Stop searching
            break;
        }
    }
    // Create a combo box for displaying field input types
    inputTypeCbox = new PaddedComboBox(InputDataType.getInputNames(false), InputDataType.getDescriptions(true), ModifiableFontInfo.DATA_TABLE_CELL.getFont());
    // Add a listener to the combo box for focus changes
    inputTypeCbox.addFocusListener(new FocusAdapter() {

        /**
         ************************************************************************************
         * Handle a focus gained event so that the combo box automatically expands when
         * selected
         ************************************************************************************
         */
        @Override
        public void focusGained(FocusEvent fe) {
            inputTypeCbox.showPopup();
        }
    });
    // Set the column table editor to the combo box
    fieldTable.getColumnModel().getColumn(inputTypeIndex).setCellEditor(new DefaultCellEditor(inputTypeCbox));
    // Set the default selected type
    inputTypeCbox.setSelectedItem(InputDataType.TEXT.getInputName());
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) PaddedComboBox(CCDD.CcddClassesComponent.PaddedComboBox) FocusEvent(java.awt.event.FocusEvent) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 4 with PaddedComboBox

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

the class CcddFieldEditorDialog method setUpApplicabilityColumn.

/**
 ********************************************************************************************
 * Set up the combo box containing the available field applicability types for display in the
 * table's Applicability cells
 ********************************************************************************************
 */
private void setUpApplicabilityColumn() {
    // Check if the applicability column is to be displayed
    if (includeApplicability) {
        int applicabilityIndex;
        // Step through each column in the editor
        for (applicabilityIndex = 0; applicabilityIndex < fieldTable.getColumnCount(); applicabilityIndex++) {
            // Check if the column name matches that for the field applicability
            if (fieldTable.getColumnName(applicabilityIndex).equals(FieldEditorColumnInfo.APPLICABILITY.getColumnName())) {
                // Stop searching
                break;
            }
        }
        // Create a combo box for displaying field applicability types
        applicabilityCBox = new PaddedComboBox(ApplicabilityType.getApplicabilityNames(), ModifiableFontInfo.DATA_TABLE_CELL.getFont());
        // Add a listener to the combo box for focus changes
        applicabilityCBox.addFocusListener(new FocusAdapter() {

            /**
             ********************************************************************************
             * Handle a focus gained event so that the combo box automatically expands when
             * selected
             ********************************************************************************
             */
            @Override
            public void focusGained(FocusEvent fe) {
                applicabilityCBox.showPopup();
            }
        });
        // Set the column table editor to the combo box
        fieldTable.getColumnModel().getColumn(applicabilityIndex).setCellEditor(new DefaultCellEditor(applicabilityCBox));
        // Set the default selected type
        applicabilityCBox.setSelectedItem(ApplicabilityType.ALL.getApplicabilityName());
    }
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) PaddedComboBox(CCDD.CcddClassesComponent.PaddedComboBox) FocusEvent(java.awt.event.FocusEvent) TableInsertionPoint(CCDD.CcddConstants.TableInsertionPoint) DefaultCellEditor(javax.swing.DefaultCellEditor)

Example 5 with PaddedComboBox

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

the class CcddDataTypeEditorDialog method createBasePrimitiveTypeCellEditor.

/**
 ********************************************************************************************
 * Create the cell editor for base data types
 ********************************************************************************************
 */
private void createBasePrimitiveTypeCellEditor() {
    // Create a combo box for displaying the base data types
    final PaddedComboBox baseComboBox = new PaddedComboBox(dataTypeTable.getFont());
    // Step through each base data type
    for (BaseDataTypeInfo type : BaseDataTypeInfo.values()) {
        // Add the data type to the list
        baseComboBox.addItem(type.getName().toLowerCase());
    }
    // Add a listener to the combo box for focus changes
    baseComboBox.addFocusListener(new FocusAdapter() {

        /**
         ************************************************************************************
         * Handle a focus gained event so that the combo box automatically expands when
         * selected
         ************************************************************************************
         */
        @Override
        public void focusGained(FocusEvent fe) {
            baseComboBox.showPopup();
        }
    });
    // Create the data type cell editor for enumerations
    baseTypeCellEditor = new DefaultCellEditor(baseComboBox);
}
Also used : FocusAdapter(java.awt.event.FocusAdapter) PaddedComboBox(CCDD.CcddClassesComponent.PaddedComboBox) BaseDataTypeInfo(CCDD.CcddConstants.BaseDataTypeInfo) 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