use of CCDD.CcddClassesComponent.DnDTabbedPane in project CCDD by nasa.
the class CcddLinkManagerDialog method initialize.
/**
********************************************************************************************
* Create the variable link manager dialog. This is executed in a separate thread since it can
* take a noticeable amount time to complete, and by using a separate thread the GUI is allowed
* to continue to update. The GUI menu commands, however, are disabled until the telemetry
* scheduler initialization completes execution
********************************************************************************************
*/
private void initialize() {
// Build the variable link manager dialog in the background
CcddBackgroundCommand.executeInBackground(ccddMain, new BackgroundCommand() {
// Create panels to hold the components of the dialog
JPanel dialogPnl = new JPanel(new GridBagLayout());
JPanel buttonPnl = new JPanel();
JButton btnClose;
/**
************************************************************************************
* Build the variable link manager dialog
************************************************************************************
*/
@Override
protected void execute() {
// Create a border 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()));
// Set the initial layout manager characteristics
GridBagConstraints 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 a tabbed pane to contain the rate parameters that are stream-specific
tabbedPane = new DnDTabbedPane(SwingConstants.TOP) {
/**
****************************************************************************
* Update the link manager list order following a tab move
****************************************************************************
*/
@Override
protected Object tabMoveCleanup(int oldTabIndex, int newTabIndex, Object tabContents) {
// Adjust the new tab index if moving the tab to a higher index
newTabIndex -= newTabIndex > oldTabIndex ? 1 : 0;
// Re-order the rate information based on the new tab order
RateInformation[] rateInfoArray = rateHandler.getRateInformation().toArray(new RateInformation[0]);
rateInfoArray = (RateInformation[]) CcddUtilities.moveArrayMember(rateInfoArray, oldTabIndex, newTabIndex);
List<RateInformation> rateInfoList = new ArrayList<RateInformation>(rateInfoArray.length);
rateInfoList.addAll(Arrays.asList(rateInfoArray));
rateHandler.setRateInformation(rateInfoList);
// Get the reference to the moved tab's original location in the list
CcddLinkManagerHandler editor = linkMgrs.get(oldTabIndex);
// Remove the tab
linkMgrs.remove(oldTabIndex);
// Add the tab at its new location
linkMgrs.add(newTabIndex, editor);
// Update the active tab pointer to the moved tab
activeHandler = linkMgrs.get(tabbedPane.getSelectedIndex());
return editor;
}
};
tabbedPane.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
// Listen for tab selection changes
tabbedPane.addChangeListener(new ChangeListener() {
/**
****************************************************************************
* Update the handler to the one associated with the selected tab
****************************************************************************
*/
@Override
public void stateChanged(ChangeEvent ce) {
// Set the active handler to the one indicated by the currently selected
// tab
activeHandler = linkMgrs.get(tabbedPane.getSelectedIndex());
// Get the number of selected links
int numSelectedLinks = activeHandler.getLinkTree().getSelectionCount();
// Update the manager controls state
setLinkButtonsEnabled(numSelectedLinks == 1, numSelectedLinks != 0);
// Set the modal undo manager reference in the keyboard handler while the
// link manager is active
ccddMain.getKeyboardHandler().setModalDialogReference(activeHandler.getUndoManager(), null);
}
});
gbc.gridwidth = 2;
gbc.gridx = 0;
gbc.gridy++;
dialogPnl.add(tabbedPane, gbc);
// Define the buttons for the lower panel: New link button
JButton btnNewLink = CcddButtonPanelHandler.createButton("New", INSERT_ICON, KeyEvent.VK_N, "Create a new link");
// Add a listener for the New button
btnNewLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Add a new link
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
createLink();
}
});
// Delete link button
JButton btnDeleteLink = CcddButtonPanelHandler.createButton("Delete", DELETE_ICON, KeyEvent.VK_D, "Delete an existing link");
// Add a listener for the Delete button
btnDeleteLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Delete the selected link(s)
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
deleteLink();
}
});
// Rename link button
btnRenameLink = CcddButtonPanelHandler.createButton("Rename", RENAME_ICON, KeyEvent.VK_D, "Rename an existing link");
// Add a listener for the Rename button
btnRenameLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Rename the selected link
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
renameLink();
}
});
// Copy link button
btnCopyLink = CcddButtonPanelHandler.createButton("Copy", COPY_ICON, KeyEvent.VK_P, "Copy an existing link");
// Add a listener for the Copy button
btnCopyLink.addActionListener(new ActionListener() {
/**
****************************************************************************
* Copy the selected link
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
copyLink();
}
});
// Undo button
JButton btnUndo = CcddButtonPanelHandler.createButton("Undo", UNDO_ICON, KeyEvent.VK_Z, "Undo the last edit action");
// Create a listener for the Undo command
ActionListener undoAction = new ActionListener() {
/**
****************************************************************************
* Undo the last edit
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
activeHandler.getUndoManager().undo();
// Update the link selection following an undo
activeHandler.getUndoHandler().setAllowUndo(false);
activeHandler.getLinkTree().updateTableSelection();
activeHandler.getUndoHandler().setAllowUndo(true);
// Update the link definitions, selected link, link fields, and link tree
// node names
activeHandler.cleanUpLinks();
}
};
// Add the undo listener to the Undo button and menu command
btnUndo.addActionListener(undoAction);
// Redo button
JButton btnRedo = CcddButtonPanelHandler.createButton("Redo", REDO_ICON, KeyEvent.VK_Y, "Redo the last undone edit action");
// Create a listener for the Redo command
ActionListener redoAction = new ActionListener() {
/**
****************************************************************************
* Redo the last edit that was undone
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
activeHandler.getUndoManager().redo();
// Update the link definitions, selected link, link fields, and link tree
// node names
activeHandler.cleanUpLinks();
}
};
// Add the redo listener to the Redo button and menu command
btnRedo.addActionListener(redoAction);
// Store links button
JButton btnStoreLinks = CcddButtonPanelHandler.createButton("Store", STORE_ICON, KeyEvent.VK_S, "Store the link updates in the database");
// Add a listener for the Store button
btnStoreLinks.addActionListener(new ActionListener() {
/**
****************************************************************************
* Store the links in the database
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// the user confirms storing the links
if (isLinksChanged() && new CcddDialogHandler().showMessageDialog(CcddLinkManagerDialog.this, "<html><b>Store links?", "Store Links", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Store the links in the project database
storeLinks();
}
}
});
// Close button
btnClose = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the link manager");
// Add a listener for the Close button
btnClose.addActionListener(new ActionListener() {
/**
****************************************************************************
* Close the link selection dialog
****************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// discard the changes
if (!isLinksChanged() || new CcddDialogHandler().showMessageDialog(CcddLinkManagerDialog.this, "<html><b>Discard changes?", "Discard Changes", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) == OK_BUTTON) {
// Close the dialog
closeDialog();
// Clear the modal dialog references in the keyboard handler
ccddMain.getKeyboardHandler().setModalDialogReference(null, null);
}
}
});
// Add buttons in the order in which they'll appear (left to right, top to bottom)
buttonPnl.add(btnNewLink);
buttonPnl.add(btnRenameLink);
buttonPnl.add(btnUndo);
buttonPnl.add(btnStoreLinks);
buttonPnl.add(btnDeleteLink);
buttonPnl.add(btnCopyLink);
buttonPnl.add(btnRedo);
buttonPnl.add(btnClose);
// Distribute the buttons across two rows
setButtonRows(2);
// Add the data stream link handlers
addLinkHandlerPanes();
}
/**
************************************************************************************
* Variable link manager dialog creation complete
************************************************************************************
*/
@Override
protected void complete() {
// Display the link management dialog
showOptionsDialog(ccddMain.getMainFrame(), dialogPnl, buttonPnl, btnClose, "Manage Links", true);
}
});
}
Aggregations