Search in sources :

Example 1 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddGroupManagerDialog method newGroup.

/**
 ********************************************************************************************
 * Add a new group to the group tree
 ********************************************************************************************
 */
private void newGroup() {
    // Create a panel to contain the dialog components
    JPanel dialogPnl = new JPanel(new GridBagLayout());
    // Create the group name input dialog label and field
    GridBagConstraints gbc = addGroupNameField("Enter new group name", "", dialogPnl);
    // Create the group description label
    JLabel descriptionLbl = new JLabel("Description");
    descriptionLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    descriptionLbl.setForeground(ModifiableColorInfo.LABEL_TEXT.getColor());
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
    gbc.insets.bottom = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 2;
    gbc.weighty = 0.0;
    gbc.gridy++;
    dialogPnl.add(descriptionLbl, gbc);
    // Create the group description input field
    final JTextArea descriptionFld = new JTextArea("", 3, 1);
    descriptionFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
    descriptionFld.setEditable(true);
    descriptionFld.setLineWrap(true);
    descriptionFld.setWrapStyleWord(true);
    descriptionFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
    descriptionFld.setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
    descriptionFld.setBorder(emptyBorder);
    descriptionFld.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, null);
    descriptionFld.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, null);
    JScrollPane descScrollPane = new JScrollPane(descriptionFld);
    descScrollPane.setBorder(border);
    // Add the description field to the dialog panel
    gbc.insets.top = 0;
    gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy++;
    dialogPnl.add(descScrollPane, gbc);
    // Create a check box for setting the group as an application
    JCheckBox appCb = new JCheckBox("Group represents a CFS application");
    appCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
    appCb.setBorder(emptyBorder);
    gbc.insets.top = ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing();
    gbc.gridy++;
    dialogPnl.add(appCb, gbc);
    // Create a dialog for the new group information
    CcddDialogHandler groupDlg = new CcddDialogHandler() {

        /**
         ************************************************************************************
         * Verify that the dialog content is valid
         *
         * @return true if the input values are valid
         ************************************************************************************
         */
        @Override
        protected boolean verifySelection() {
            descriptionFld.setText(descriptionFld.getText().trim());
            return verifyGroupName(this);
        }
    };
    // Display a dialog for the user to provide a group name and description
    if (groupDlg.showOptionsDialog(groupMgr, dialogPnl, "New Group", DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
        // Disable automatically ending the edit sequence. This allows the added group's edits
        // to be grouped into a single sequence so that if undone, all edits are removed
        // together
        undoHandler.setAutoEndEditSequence(false);
        // Add the new group information
        groupHandler.addGroupInformation(groupNameFld.getText(), descriptionFld.getText(), appCb.isSelected());
        // Insert the new group into the group tree
        groupTree.addInformationNode(groupNameFld.getText(), descriptionFld.getText(), appCb.isSelected());
        // Check if the check box indicating this group represents an application is selected
        if (appCb.isSelected()) {
            // Get the field information and data fields for the new group
            GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupNameFld.getText());
            List<FieldInformation> fieldInfo = CcddFieldHandler.getFieldInformationCopy(groupInfo.getFieldInformation());
            // Step through each default application data field
            for (DefaultApplicationField field : DefaultApplicationField.values()) {
                // Add the field to the group
                fieldInfo.add(field.createFieldInformation(CcddFieldHandler.getFieldGroupName(groupNameFld.getText())));
            }
        }
        // Update the group dialog's change indicator
        updateChangeIndicator();
        // Re-enable automatic edit sequence ending, then end the edit sequence to group the
        // added group's edits
        undoHandler.setAutoEndEditSequence(true);
        undoManager.endEditSequence();
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) JTextArea(javax.swing.JTextArea) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) DefaultApplicationField(CCDD.CcddConstants.DefaultApplicationField) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 2 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddJSONHandler method getDataFields.

/**
 ********************************************************************************************
 * Get the data field information for the specified owner (table, table type, or group)
 *
 * @param ownerName
 *            table name and path in the format rootTable[,dataType1.variable1[,...]] (if blank
 *            then every data table's data fields are returned), table type name in the format
 *            tableTypeTag:tableTypepName, or group owner in the format groupTag:groupName
 *
 * @param outputJO
 *            JSON object to which the data fields are added
 *
 * @return The supplied JSON object, with the data field(s) added (if any)
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
protected JSONObject getDataFields(String ownerName, String tagName, JSONObject outputJO) {
    JSONArray dataFieldDefnJA = new JSONArray();
    // Get the existing data fields for the specified owner
    fieldHandler.buildFieldInformation(ownerName);
    // Check if the owner has any fields
    if (!fieldHandler.getFieldInformation().isEmpty()) {
        JSONObject fieldJO = new JSONObject();
        // Step through the data fields for this owner
        for (FieldInformation fieldInfo : fieldHandler.getFieldInformation()) {
            fieldJO = new JSONObject();
            // Add the data field column values to the output
            fieldJO.put(FieldEditorColumnInfo.NAME.getColumnName(), fieldInfo.getFieldName());
            fieldJO.put(FieldEditorColumnInfo.DESCRIPTION.getColumnName(), fieldInfo.getDescription());
            fieldJO.put(FieldEditorColumnInfo.SIZE.getColumnName(), fieldInfo.getSize());
            fieldJO.put(FieldEditorColumnInfo.INPUT_TYPE.getColumnName(), fieldInfo.getInputType().getInputName());
            fieldJO.put(FieldEditorColumnInfo.REQUIRED.getColumnName(), fieldInfo.isRequired());
            fieldJO.put(FieldEditorColumnInfo.APPLICABILITY.getColumnName(), fieldInfo.getApplicabilityType().getApplicabilityName());
            fieldJO.put(FieldEditorColumnInfo.VALUE.getColumnName(), fieldInfo.getValue());
            dataFieldDefnJA.add(fieldJO);
        }
        // Check if any data field exists
        if (!dataFieldDefnJA.isEmpty()) {
            // Add the data field(s) to the JSON output
            outputJO.put(tagName, dataFieldDefnJA);
        }
    }
    return outputJO;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 3 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddJTableHandler method printTable.

/**
 ********************************************************************************************
 * Output the table to the user-selected printer (or file)
 *
 * @param tableName
 *            table name; displayed at the top of each printed page
 *
 * @param fieldHandler
 *            data field handler; null if no data fields are associated with the table
 *
 * @param parent
 *            parent window for this table
 *
 * @param orientation
 *            page orientation; e.g., PageFormat.LANDSCAPE or PageFormat.PORTRAIT
 ********************************************************************************************
 */
protected void printTable(String tableName, CcddFieldHandler fieldHandler, Component parent, int orientation) {
    try {
        GraphicsConfiguration gc;
        // Create a printer job
        PrinterJob printerJob = PrinterJob.getPrinterJob();
        // The native print dialog does not allow simple positioning on the screen relative to
        // another component. However, the ServiceUI.printDialog() method, which calls
        // PrinterJob.printDialog(), does allow setting the dialog's x and y coordinates. The
        // dimensions of the print dialog must be known in order to center it over its parent,
        // but the size is unknown until the dialog is instantiated. Therefore, a dummy dialog
        // is created using the same call within ServiceUI.printDialog() and the dialog's size
        // is taken from it. The dialog's x, y coordinates can then be determined
        PrintRequestAttributeSet attributes = new HashPrintRequestAttributeSet();
        DocFlavor flavor = null;
        PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, attributes);
        PrintService defaultService = printerJob.getPrintService();
        // Get the dialog/frame that contains the table
        Component comp = table.getTopLevelAncestor();
        // Create a dummy dialog in order to obtain the print dialog's dimensions
        ServiceDialog dialog = new ServiceDialog(comp.getGraphicsConfiguration(), 0, 0, services, 0, flavor, attributes, (Dialog) null);
        Rectangle newDlgSize = dialog.getBounds();
        dialog.dispose();
        // Get the array of graphics devices (this accounts for multiple screens)
        GraphicsDevice[] gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        // Check if more than one screen exists
        if (gd.length > 1) {
            // Get the graphics configuration for the screen on which the component resides
            gc = gd[0].getDefaultConfiguration();
        } else // Only one screen is present
        {
            // Get the component's graphics configuration
            gc = comp.getGraphicsConfiguration();
        }
        // Now that the dialog's size is known the print dialog's position can be calculated so
        // as to center it over calling component, adjusting the location so that the dialog
        // appears fully on the screen in which the component resides
        Dimension compSize = comp.getSize();
        Point adjLocation = CcddDialogHandler.adjustDialogLocationForScreen(new Rectangle(comp.getX() + ((compSize.width - newDlgSize.width) / 2), comp.getY() + ((compSize.height - newDlgSize.height) / 2), newDlgSize.width, newDlgSize.height));
        // selected printer
        if (ServiceUI.printDialog(gc, adjLocation.x, adjLocation.y, services, defaultService, flavor, attributes) != null) {
            // Set the page format
            PageFormat pageFormat = new PageFormat();
            pageFormat.setOrientation(orientation);
            // Create a book object for the table and data fields (if applicable)
            Book book = new Book();
            // Determine the number of pages to print the table. The printable object is
            // altered during the page counting process, so it cannot be reused when creating
            // the page wrapper below
            int tblPages = getNumberOfPages(getPrintable(JTable.PrintMode.FIT_WIDTH, new MessageFormat(tableName), new MessageFormat("page {0}")), pageFormat);
            // Add the table to the book object
            book.append(new PageWrapper(getPrintable(JTable.PrintMode.FIT_WIDTH, new MessageFormat(tableName), new MessageFormat("page {0}")), 0), pageFormat, tblPages);
            // Check if data fields are provided
            if (fieldHandler != null && !fieldHandler.getFieldInformation().isEmpty()) {
                String fields = "";
                // Step through each data field
                for (FieldInformation fieldInfo : fieldHandler.getFieldInformation()) {
                    // Append the field name and value to the output string
                    fields += "   " + fieldInfo.getFieldName() + ":  " + fieldInfo.getValue() + "\n";
                }
                // Place the field information into a text area
                JTextArea fldTxtArea = new JTextArea(fields);
                // Get the printable object for the text area
                Printable fldPrintable = fldTxtArea.getPrintable(new MessageFormat("Data Fields for " + tableName), new MessageFormat("page {0}"));
                // Add the fields to the book object
                book.append(new PageWrapper(fldPrintable, tblPages), pageFormat, getNumberOfPages(fldPrintable, pageFormat));
            }
            // Output the book object to the selected printer or file
            printerJob.setPageable(book);
            printerJob.print();
        }
    } catch (PrinterException pe) {
        // Inform the user that printing failed
        new CcddDialogHandler().showMessageDialog(parent, "<html><b>Table '" + tableName + "' printing failed; cause '" + pe.getMessage() + "'", "Print Fail", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
    }
}
Also used : ServiceDialog(sun.print.ServiceDialog) JTextArea(javax.swing.JTextArea) Rectangle(java.awt.Rectangle) PrinterException(java.awt.print.PrinterException) GraphicsConfiguration(java.awt.GraphicsConfiguration) PrinterJob(java.awt.print.PrinterJob) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) PrintRequestAttributeSet(javax.print.attribute.PrintRequestAttributeSet) PrintService(javax.print.PrintService) PageFormat(java.awt.print.PageFormat) GraphicsDevice(java.awt.GraphicsDevice) Book(java.awt.print.Book) Component(java.awt.Component) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) MessageFormat(java.text.MessageFormat) Dimension(java.awt.Dimension) Point(java.awt.Point) TableInsertionPoint(CCDD.CcddConstants.TableInsertionPoint) Point(java.awt.Point) TableInsertionPoint(CCDD.CcddConstants.TableInsertionPoint) Printable(java.awt.print.Printable) DocFlavor(javax.print.DocFlavor) HashPrintRequestAttributeSet(javax.print.attribute.HashPrintRequestAttributeSet) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 4 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddLinkHandler method getApplicationNames.

/**
 ********************************************************************************************
 * Get the application name data field values associated with the specified link's variable
 * members
 *
 * @param fieldHandler
 *            field handler to access data fields
 *
 * @param applicationFieldName
 *            name of the application name data field
 *
 * @return Array containing the application name data field values associated with the
 *         specified link's variable members. Each application name is listed only once in the
 *         array
 ********************************************************************************************
 */
protected String[] getApplicationNames(CcddFieldHandler fieldHandler, String applicationFieldName) {
    List<String> appNames = new ArrayList<String>();
    // Step through each link definition
    for (String[] linkDefn : linkDefinitions) {
        // Extract the link rate/description or member
        String linkMember = linkDefn[LinksColumn.MEMBER.ordinal()];
        // link information entry
        if (!linkMember.matches("\\d.*")) {
            // Split the link definition's variable string into the parent structure name and
            // variable reference string
            String[] parentAndPath = linkMember.split(",", 2);
            // Get the information for the parent's application name data field
            FieldInformation fieldInfo = fieldHandler.getFieldInformationByName(parentAndPath[0], applicationFieldName);
            // Check that the data field exists
            if (fieldInfo != null) {
                // Get the application name field information
                String appName = fieldHandler.getFieldInformationByName(parentAndPath[0], applicationFieldName).getValue();
                // that this name hasn't already been added to the list
                if (appName != null && !appNames.contains(appName)) {
                    // Add the application name field name to the list
                    appNames.add(appName);
                }
            }
        }
    }
    return appNames.toArray(new String[0]);
}
Also used : ArrayList(java.util.ArrayList) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 5 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddCopyTableHandler method createCopyTable.

/**
 ********************************************************************************************
 * Create a copy table based on the message definitions
 *
 * @param fieldHandler
 *            field handler reference
 *
 * @param linkHandler
 *            link handler reference
 *
 * @param dataStreamName
 *            data stream name
 *
 * @param headerSize
 *            size of the packet header in bytes
 *
 * @param messageIDNameField
 *            name of the structure table data field containing the message ID name. If
 *            provided this is used instead of the tlmMessageIDs list
 *
 * @param tlmMessageIDs
 *            list containing string array entries giving the structure table path+name and the
 *            table's associated message ID name. Used if messageIDNameField is null
 *
 * @param optimize
 *            true to create copy table with memory copies optimized
 *
 * @param expandMacros
 *            true to expand any macro within the variable names
 *
 * @return Array containing the copy table entries
 ********************************************************************************************
 */
protected String[][] createCopyTable(CcddFieldHandler fieldHandler, CcddLinkHandler linkHandler, String dataStreamName, int headerSize, String messageIDNameField, ArrayListMultiple tlmMessageIDs, boolean optimize, boolean expandMacros) {
    List<String[]> messageTable = new ArrayList<String[]>();
    // Empty the copy table in case a previous one exists
    copyTable.clear();
    // Step through each message for the specified rate
    for (Message message : getStoredMessages(dataStreamName)) {
        // Step through the message's sub-messages
        for (Message subMsg : message.getSubMessages()) {
            // Step through each packet definition
            for (Variable variable : subMsg.getVariablesWithParent()) {
                String tlmMsgID = null;
                // Split the packet definition's variable string into the parent structure name
                // and variable reference string
                String[] parentAndPath = variable.getFullName().split(",", 2);
                // Check if macro in the variable names are to be expanded
                if (expandMacros) {
                    // Replace any macros with their corresponding values
                    parentAndPath[1] = macroHandler.getMacroExpansion(parentAndPath[1]);
                }
                // Get the offset in the root structure of the variable indicated by the packet
                // definition
                int structureOffset = variableHandler.getVariableOffset(variable.getFullName());
                // Check if the message ID name field name is provided
                if (messageIDNameField != null) {
                    // Get the field information for the message ID name field
                    FieldInformation msgIDNameFieldInfo = fieldHandler.getFieldInformationByName(parentAndPath[0], messageIDNameField);
                    // Check that the message ID name field exists for the specified table
                    if (msgIDNameFieldInfo != null) {
                        // Get the message ID name associated with the table
                        tlmMsgID = msgIDNameFieldInfo.getValue();
                    }
                } else // Check if the telemetry message ID names list is provided
                if (tlmMessageIDs != null) {
                    // Get the index of the table in the list provided
                    int index = tlmMessageIDs.indexOf(parentAndPath[0]);
                    // Check if the table exists in the list
                    if (index != -1) {
                        // Get the message ID name associated with the table
                        tlmMsgID = tlmMessageIDs.get(index)[1];
                    }
                }
                if (tlmMsgID != null) {
                    // Build the copy table entry array for this variable. The fields are:
                    // Input message ID name, input offset, output message ID name (the
                    // sub-message separator character, a period, is replaced with an
                    // underscore), output offset (initialized to a blank; the value is
                    // computed later), variable size, variable root table, and variable path
                    messageTable.add(new String[] { tlmMsgID, String.valueOf(structureOffset), subMsg.getName().replace(".", "_"), "", String.valueOf(variable.getSize()), parentAndPath[0], parentAndPath[1] });
                }
            }
            // Consolidate the bit-packed variables
            combineBitPackedVariables(messageTable);
            // Check if this copy table should be optimized
            if (optimize) {
                // Combine consecutive memory copies
                combineMemoryCopies(messageTable);
            }
            // Add the input and output offset to the list
            addInputAndOutputOffset(messageTable, headerSize);
            // Add this message's copy table entries to the list of all copy table entries
            copyTable.addAll(messageTable);
            // Clear out this message's entries to allow storage for the next message
            messageTable.clear();
        }
    }
    return copyTable.toArray(new String[0][0]);
}
Also used : Variable(CCDD.CcddClassesDataTable.Variable) Message(CCDD.CcddClassesDataTable.Message) ArrayList(java.util.ArrayList) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Aggregations

FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)35 ArrayList (java.util.ArrayList)16 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)7 GridBagLayout (java.awt.GridBagLayout)4 Point (java.awt.Point)4 JPanel (javax.swing.JPanel)4 CCDDException (CCDD.CcddClassesDataTable.CCDDException)3 TableInformation (CCDD.CcddClassesDataTable.TableInformation)3 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)3 UndoableCheckBox (CCDD.CcddUndoHandler.UndoableCheckBox)3 TableTypeDefinition (CCDD.CcddClassesDataTable.TableTypeDefinition)2 Variable (CCDD.CcddClassesDataTable.Variable)2 DefaultApplicationField (CCDD.CcddConstants.DefaultApplicationField)2 InputDataType (CCDD.CcddConstants.InputDataType)2 UndoableTextField (CCDD.CcddUndoHandler.UndoableTextField)2 Component (java.awt.Component)2 GridBagConstraints (java.awt.GridBagConstraints)2 JComponent (javax.swing.JComponent)2 JLabel (javax.swing.JLabel)2 JTextArea (javax.swing.JTextArea)2