Search in sources :

Example 1 with UndoableDataFieldPanel

use of CCDD.CcddUndoHandler.UndoableDataFieldPanel in project CCDD by nasa.

the class CcddInputFieldPanelHandler method createDescAndDataFieldPanel.

/**
 ********************************************************************************************
 * Create the table input field panel
 *
 * @param fieldPnlHndlrOwner
 *            reference to the owner of this description and data field handler
 *
 * @param tableScrollPane
 *            scroll pane containing the table; null if this field panel handler does not
 *            contain a table
 *
 * @param ownerName
 *            name of the owner of this field panel handler; null if no owner name is
 *            associated with it
 *
 * @param description
 *            description field text; null if the description is initially blank and disabled
 *
 * @param fieldHandler
 *            field handler reference
 ********************************************************************************************
 */
protected void createDescAndDataFieldPanel(final Component fieldPnlHndlrOwner, final JScrollPane tableScrollPane, String ownerName, String description, CcddFieldHandler fieldHandler) {
    this.fieldPnlHndlrOwner = fieldPnlHndlrOwner;
    this.ownerName = ownerName;
    this.dataFieldHandler = fieldHandler;
    // Set the flag to indicate if this input field panel handler is a data table
    isDataTable = this instanceof CcddTableEditorHandler;
    // Create the handler for undoing/redoing data field changes
    undoFieldPnl = undoHandler.new UndoableDataFieldPanel();
    // Set the initial layout manager characteristics
    gbc = new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0);
    // Create an outer panel to put the editor panel in (the border doesn't appear without
    // this) and add the table description text field
    inputPnl = new JPanel(new GridBagLayout());
    // Check if this editor contains a table
    if (tableScrollPane != null) {
        // Define the editor panel to contain the table
        JPanel innerPanel = new JPanel();
        innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.X_AXIS));
        innerPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        innerPanel.add(tableScrollPane);
        inputPnl.add(innerPanel, gbc);
    }
    // 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();
    // Create a panel to hold the table's system name, description and, if applicable, message
    // ID information
    JPanel descriptionPnl = new JPanel(new GridBagLayout());
    // Create the description label
    JLabel descriptionLbl = new JLabel("Description");
    descriptionLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    descriptionLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
    // Check if this editor doesn't contain a table
    if (tableScrollPane == null) {
        gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
        gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    }
    // Add the table description label
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
    gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
    gbc.weightx = 0.0;
    gbc.weighty = 0.0;
    gbc.gridy++;
    descriptionPnl.add(descriptionLbl, gbc);
    // Create the description input field
    descriptionFld = undoHandler.new UndoableTextArea(3, 1);
    descriptionFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
    descriptionFld.setBorder(emptyBorder);
    descriptionFld.setEditable(true);
    descriptionFld.setLineWrap(true);
    descriptionFld.setWrapStyleWord(true);
    descriptionFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
    descriptionFld.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    descriptionFld.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
    descScrollPane = new JScrollPane(descriptionFld);
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    gbc.weightx = 1.0;
    // Check if the description field is initially disabled
    if (description == null) {
        // Set the description field and description field scroll pane background color to
        // indicate these are disabled
        descriptionFld.setBackground(ModifiableColorInfo.INPUT_DISABLE_BACK.getColor());
        descScrollPane.setBackground(ModifiableColorInfo.INPUT_DISABLE_BACK.getColor());
    } else {
        // Set the description field and description field scroll pane background color to
        // indicate these are enabled, and set the description field text
        descriptionFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
        descScrollPane.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
        descriptionFld.setText(description);
    }
    // Check if this editor doesn't contain a table
    if (tableScrollPane == null) {
        // Place the description field within a scroll pane and add the field to the editor
        inputPnl.setBorder(BorderFactory.createEtchedBorder());
        descScrollPane.setBorder(border);
        descScrollPane.setMinimumSize(descScrollPane.getPreferredSize());
        gbc.gridy++;
        descriptionPnl.add(descScrollPane, gbc);
    } else // The editor contains a table
    {
        // Place the description field within a scroll pane and add the field to the editor
        inputPnl.setBorder(emptyBorder);
        descriptionFld.setToolTipText(CcddUtilities.wrapText("Table description", ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
        descScrollPane.setBorder(emptyBorder);
        descScrollPane.setViewportBorder(border);
        descScrollPane.setMinimumSize(descScrollPane.getPreferredSize());
        gbc.gridx++;
        descriptionPnl.add(descScrollPane, gbc);
        gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
        gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    }
    // Add the description panel to the editor
    gbc.gridx = 0;
    gbc.gridy++;
    inputPnl.add(descriptionPnl, gbc);
    // Add the data field panel to the editor
    gbc.gridy++;
    gbc.insets.top = 0;
    gbc.insets.bottom = 0;
    createDataFieldPanel(false);
    // Check if this editor doesn't contain a table
    if (tableScrollPane == null) {
        // Add an invisible component in order to force the description panel and data fields
        // to the top of the panel
        JLabel invisibleLbl = new JLabel("");
        gbc.weighty = 1.0;
        gbc.gridy++;
        inputPnl.add(invisibleLbl, gbc);
        gbc.weighty = 0.0;
        gbc.gridy--;
    }
    // Add a listener for changes in the editor panel's size
    inputPnl.addComponentListener(new ComponentAdapter() {

        /**
         ************************************************************************************
         * Handle resizing of the editor panel
         ************************************************************************************
         */
        @Override
        public void componentResized(ComponentEvent ce) {
            // Create a runnable object to be executed
            SwingUtilities.invokeLater(new Runnable() {

                /**
                 ****************************************************************************
                 * Since the size returned by get___Size() can lag the actual size, use
                 * invokeLater to let the sizes "catch up"
                 ****************************************************************************
                 */
                @Override
                public void run() {
                    // Revalidate to force the editor panel to redraw to the new sizes, which
                    // causes the data fields to be correctly sized so that all of the fields
                    // are visible
                    inputPnl.revalidate();
                }
            });
        }
    });
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) UndoableTextArea(CCDD.CcddUndoHandler.UndoableTextArea) ComponentEvent(java.awt.event.ComponentEvent) UndoableDataFieldPanel(CCDD.CcddUndoHandler.UndoableDataFieldPanel) Border(javax.swing.border.Border) BevelBorder(javax.swing.border.BevelBorder) EtchedBorder(javax.swing.border.EtchedBorder) ComponentAdapter(java.awt.event.ComponentAdapter)

Aggregations

UndoableDataFieldPanel (CCDD.CcddUndoHandler.UndoableDataFieldPanel)1 UndoableTextArea (CCDD.CcddUndoHandler.UndoableTextArea)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 ComponentAdapter (java.awt.event.ComponentAdapter)1 ComponentEvent (java.awt.event.ComponentEvent)1 BoxLayout (javax.swing.BoxLayout)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 BevelBorder (javax.swing.border.BevelBorder)1 Border (javax.swing.border.Border)1 EtchedBorder (javax.swing.border.EtchedBorder)1