use of CCDD.CcddClassesComponent.PaddedComboBox in project CCDD by nasa.
the class CcddTableEditorHandler method setUpMsgNamesAndIDsColumn.
/**
********************************************************************************************
* Set up or update the combo box containing the available message ID names and corresponding
* message IDs for display in table column cells
*
* @param msgIDs
* list of message ID names and the associated ID values
********************************************************************************************
*/
protected void setUpMsgNamesAndIDsColumn(List<String[]> msgIDs) {
// Check if a cell is currently being edited
if (table.getCellEditor() != null) {
// Incorporate any cell changes and terminate editing
table.getCellEditor().stopCellEditing();
}
// Check if the table has a message name & ID column
if (!msgIDNameIndex.isEmpty()) {
// Check if no message name & ID list is provided
if (msgIDs == null) {
// Create a message ID handler and get the list of message ID names and associated
// ID values
CcddMessageIDHandler msgIDHandler = new CcddMessageIDHandler(ccddMain, false);
msgIDs = msgIDHandler.getMessageIDsAndNames(MessageIDSortOrder.BY_NAME, true, editorDialog);
}
// Create a combo box for displaying message ID names & IDs
PaddedComboBox comboBox = new PaddedComboBox(table.getFont());
// Step through each message ID name & ID pair
for (String[] msgID : msgIDs) {
// Check if the message ID name isn't blank
if (!msgID[MsgIDListColumnIndex.MESSAGE_ID_NAME.ordinal()].isEmpty()) {
// Get the message name & ID to display in the list
String item = msgID[MsgIDListColumnIndex.MESSAGE_ID_NAME.ordinal()] + " (" + msgID[MsgIDListColumnIndex.MESSAGE_ID.ordinal()] + ")";
// Check if the message name & ID isn't already in the list
if (((DefaultComboBoxModel<String>) comboBox.getModel()).getIndexOf(item) == -1) {
// Add the message ID name & ID to the combo box list
comboBox.addItem(item);
}
}
}
// Step through each message ID names column
for (Integer column : msgIDNameIndex) {
// Get the column reference for the message ID names & IDs column
TableColumn msgNameIDColumn = table.getColumnModel().getColumn(table.convertColumnIndexToView(column));
// Set the table column editor to the combo box
msgNameIDColumn.setCellEditor(new DefaultCellEditor(comboBox));
}
}
}
use of CCDD.CcddClassesComponent.PaddedComboBox in project CCDD by nasa.
the class CcddDataTypeHandler method insertDataTypeName.
/**
********************************************************************************************
* Display a pop-up combo box containing the names of the defined data types: primitive data
* types (dependent on the input flag) and structures. When the user selects a data type insert
* it into the supplied text field
*
* @param owner
* dialog owning the pop-up combo box
*
* @param textArea
* text field over which to display the pop-up combo box and insert the selected
* data type name
*
* @param includePrimitives
* true to include primitive data types in the list; false to include only
* structures
*
* @param structures
* Array containing the data types to display in the pop-up; null to build the array
********************************************************************************************
*/
protected void insertDataTypeName(Window owner, final JTextArea textArea, boolean includePrimitives, String[] structures) {
comboDlg = new JDialog(owner);
// Check if the data type array isn't supplied
if (structures == null) {
// Get the array of prototype structure table names
structures = dbTable.getPrototypeTablesOfType(TYPE_STRUCTURE);
// Check if any structures exist
if (structures.length != 0) {
// Sort the structure names alphabetically, ignoring case
Arrays.sort(structures, String.CASE_INSENSITIVE_ORDER);
}
// Check if primitive data types are to be included
if (includePrimitives) {
String[] primitives = new String[dataTypes.size()];
// Step through each primitive data type
for (int index = 0; index < dataTypes.size(); index++) {
// Add the data type name to the array
primitives[index] = getDataTypeName(dataTypes.get(index));
}
// Combine the primitive data types and structures arrays
structures = CcddUtilities.concatenateArrays(primitives, structures);
}
}
// Check if any data types exist
if (structures.length != 0) {
// Create the pop-up combo box
structureCbox = new PaddedComboBox(structures, ModifiableFontInfo.DATA_TABLE_CELL.getFont());
// Set the first structure as initially selected
structureCbox.setSelectedIndex(0);
// Set the property to allow the arrow keys to be used to change the structure
// selection in the combo box
structureCbox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE);
// Add a listener for selection events in the structure pop-up combo box
structureCbox.addActionListener(new ActionListener() {
/**
********************************************************************************
* Handle a selection event in the structure combo box
********************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Get the selected structure's name and enclose it in the structure identifier
// character(s)
String structureName = ((JComboBox<?>) ae.getSource()).getSelectedItem().toString();
// Get the starting index of the selected text in the field
int start = textArea.getSelectionStart();
// Insert the structure into the text field's existing text, overwriting any of
// the text that is highlighted
textArea.setText(getInsertedStructure(structureName, textArea));
textArea.setSelectionStart(start);
// Select the structure name that was inserted
textArea.setSelectionEnd(start + structureName.length());
// Remove the structure pop-up and return to the caller. Get the selected
// structure's name and enclose it in the structure identifier character(s)
exitStructCombo();
}
});
// Add a listener for key press events in the structure pop-up combo box
structureCbox.addKeyListener(new KeyAdapter() {
/**
********************************************************************************
* Handle a key press event in the structure combo box
********************************************************************************
*/
@Override
public void keyPressed(KeyEvent ke) {
// Check if the escape key is pressed
if (ke.getKeyCode() == KeyEvent.VK_ESCAPE) {
// Remove the structure pop-up and return to the caller
exitStructCombo();
}
}
});
// Add a listener for changes to the expansion/contraction of the combo box
structureCbox.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 structure pop-up and return to the caller
exitStructCombo();
}
});
// Create the dialog to contain the structure 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(structureCbox, BorderLayout.NORTH);
comboDlg.setSize(new Dimension(structureCbox.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() {
/**
************************************************************************
* Execute after all pending Swing events are finished. This ensures the
* pop-up is showing and can be expanded
************************************************************************
*/
@Override
public void run() {
// Expand the combo box when it appears
structureCbox.showPopup();
}
});
}
/**
********************************************************************************
* Handle a loss of pop-up dialog focus
********************************************************************************
*/
@Override
public void windowLostFocus(WindowEvent we) {
// Remove the structure pop-up and return to the caller
exitStructCombo();
}
});
// Position and display the pop-up
positionStructurePopup(textArea);
comboDlg.setVisible(true);
}
}
use of CCDD.CcddClassesComponent.PaddedComboBox in project CCDD by nasa.
the class CcddTableEditorHandler method setDataTypeColumns.
/**
********************************************************************************************
* Set up or update the combo box(es) for table columns that display the available primitive
* data types, or both the primitive data types and existing structure tables
*
* @param allStructTbls
* array containing all structure table names; null to load the table names from the
* database
*
* @param tblTree
* reference to the CcddTableTreeHandler table tree; null to create the table tree
********************************************************************************************
*/
private void setDataTypeColumns(String[] allStructTbls, CcddTableTreeHandler tblTree) {
validDataTypes = null;
invalidDataTypes = null;
// Get the lists of columns that display primitive data types and primitive & structure
// data types
List<Integer> primColumns = typeDefn.getColumnIndicesByInputType(InputDataType.PRIMITIVE);
List<Integer> primAndStructColumns = typeDefn.getColumnIndicesByInputType(InputDataType.PRIM_AND_STRUCT);
// Check if any columns displaying primitive data types only exist
if (!primColumns.isEmpty()) {
// Create a combo box for displaying data types
PaddedComboBox comboBox = new PaddedComboBox(table.getFont());
// Add the primitive data types to the combo box list
addPrimitivesToComboBox(comboBox);
// Step through each primitive column defined for this table's type
for (int index : primColumns) {
// Get the column reference for this data type column
TableColumn dataTypeColumn = table.getColumnModel().getColumn(table.convertColumnIndexToView(index));
// Set the column table editor to the combo box
dataTypeColumn.setCellEditor(new DefaultCellEditor(comboBox));
}
// Create the enumerated data type cell editor
createEnumDataTypeCellEditor();
}
// Check if any columns displaying both primitive & structure data types exist
if (!primAndStructColumns.isEmpty()) {
validDataTypes = new ArrayList<String>();
invalidDataTypes = new ArrayList<String>();
// Create a combo box for displaying data types
PaddedComboBox comboBox = new PaddedComboBox(table.getFont());
// Add the primitive data types to the combo box list
addPrimitivesToComboBox(comboBox);
// Get the array of structure tables, if any
allStructureTables = (allStructTbls == null) ? dbTable.getPrototypeTablesOfType(TYPE_STRUCTURE) : allStructTbls;
// Get the table tree
tableTree = (tblTree == null) ? new CcddTableTreeHandler(ccddMain, TableTreeType.INSTANCE_TABLES, editorDialog) : tblTree;
// Add the structure data types to the combo box list
addStructuresToComboBox(comboBox);
// Step through each primitive & structure column defined for this table's type
for (int index : primAndStructColumns) {
// Get the column reference for this data type column
TableColumn dataTypeColumn = table.getColumnModel().getColumn(table.convertColumnIndexToView(index));
// Set the column table editor to the combo box
dataTypeColumn.setCellEditor(new DefaultCellEditor(comboBox));
}
// Create the enumerated data type cell editor
createEnumDataTypeCellEditor();
}
}
use of CCDD.CcddClassesComponent.PaddedComboBox in project CCDD by nasa.
the class CcddTableEditorHandler method setUpSampleRateColumn.
/**
********************************************************************************************
* Set up or update the combo box containing the allowable sample rates for display in the
* table's "Rate" column cells
********************************************************************************************
*/
protected void setUpSampleRateColumn() {
// Step through each rate column defined for this table
for (int index = 0; index < rateIndex.size(); index++) {
// Get the column reference for the rate column
TableColumn rateColumn = table.getColumnModel().getColumn(table.convertColumnIndexToView(rateIndex.get(index)));
// Set to true if this is an update to the combo box content update and not the
// original combo box setup at table creation)
boolean isUpdate = (DefaultCellEditor) rateColumn.getCellEditor() != null && ((DefaultCellEditor) rateColumn.getCellEditor()).getComponent() instanceof PaddedComboBox;
// Check if this is a combo box content update
if (isUpdate) {
// End editing on the rate cell in case a rate cell is selected. This causes the
// selected cell to be updated with the new rates
((DefaultCellEditor) rateColumn.getCellEditor()).stopCellEditing();
}
// Create a combo box and set the color and font
PaddedComboBox comboBox = new PaddedComboBox(table.getFont());
// Set the column table editor to the combo box
rateColumn.setCellEditor(new DefaultCellEditor(comboBox));
// Get the rate information for this rate column
RateInformation rateInfo = rateHandler.getRateInformationByRateName(typeDefn.getColumnNamesUser()[rateIndex.get(index)]);
// Check if the rate information exists for this column
if (rateInfo != null) {
// Make the first item a blank
comboBox.addItem("");
// Step through each sample rate
for (String rate : rateInfo.getSampleRates()) {
// Add the sample rate to the combo box list
comboBox.addItem(rate);
}
}
// Check if this is a combo box content update
if (isUpdate) {
// Force the table to redraw in case the rates have been altered such that a rate
// cell's validity changes and the background color needs to be updated
table.repaint();
}
}
}
use of CCDD.CcddClassesComponent.PaddedComboBox in project CCDD by nasa.
the class CcddTableEditorHandler method createEnumDataTypeCellEditor.
/**
********************************************************************************************
* Create the cell editor for enumerated data types if it doesn't already exist
********************************************************************************************
*/
private void createEnumDataTypeCellEditor() {
// Check if the data type cell editor for enumerations hasn't been created
if (enumDataTypeCellEditor == null) {
// Create a combo box for displaying data types for enumerations (integer and unsigned
// integers only)
PaddedComboBox enumComboBox = new PaddedComboBox(table.getFont());
// Step through each primitive data type
for (String[] dataType : dataTypeHandler.getDataTypeData()) {
// unsigned integer
if (enumComboBox != null && dataTypeHandler.isInteger(CcddDataTypeHandler.getDataTypeName(dataType))) {
// Add the data type to the combo box list
enumComboBox.addItem(CcddDataTypeHandler.getDataTypeName(dataType));
}
}
// Create the data type cell editor for enumerations
enumDataTypeCellEditor = new DefaultCellEditor(enumComboBox);
}
}
Aggregations