use of CCDD.CcddConstants.ModifiablePathInfo in project CCDD by nasa.
the class CcddPreferencesDialog method initialize.
/**
********************************************************************************************
* Create the preferences dialog
********************************************************************************************
*/
private void initialize() {
maxScrollPaneHeight = 0;
// Create an empty border for use with the dialog components
emptyBorder = BorderFactory.createEmptyBorder();
// Create a tabbed pane
tabbedPane = new DnDTabbedPane(SwingConstants.TOP);
tabbedPane.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
// Add the tabs to the tabbed pane
addLafTab();
addFontTab();
addColorTab();
addSizeTab();
addSpacingTab();
addPathTab();
addOtherTab();
// Create a panel for the preference dialog buttons
JPanel buttonPnl = new JPanel();
// Update button
final JButton btnUpdateAll = CcddButtonPanelHandler.createButton("Update", STORE_ICON, KeyEvent.VK_U, "Update the program preference values");
// Add a listener for the Update button
btnUpdateAll.addActionListener(new ActionListener() {
/**
************************************************************************************
* Update the program preference values
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
int index = 0;
// Base the action on the name of the tab selected
switch(tabbedPane.getTitleAt(tabbedPane.getSelectedIndex())) {
case LAF:
case FONT:
case COLOR:
// preference value
break;
case SIZE:
// size
for (ModifiableSizeInfo modSize : ModifiableSizeInfo.values()) {
// Get the current value from the size text field
int currentValue = Integer.valueOf(sizeFld[index].getText());
// Check if the size has changed
if (modSize.getSize() != currentValue) {
// Update the size to the new value
modSize.setSize(currentValue, ccddMain.getProgPrefs());
}
index++;
}
break;
case SPACING:
// modifiable spacing
for (ModifiableSpacingInfo modSpacing : ModifiableSpacingInfo.values()) {
// Get the current value from the spacing text field
int currentValue = Integer.valueOf(spacingFld[index].getText());
// Check if the spacing has changed
if (modSpacing.getSpacing() != currentValue) {
// Update the spacing to the new value
modSpacing.setSpacing(currentValue, ccddMain.getProgPrefs());
}
index++;
}
break;
case PATH:
// Update the program path preference. Step through each modifiable path
for (ModifiablePathInfo modPath : ModifiablePathInfo.values()) {
// Get the current path from the path text field
String currentPath = pathFld[index].getText().trim();
// Check if the path has changed
if (!modPath.getPath().equals(currentPath)) {
// Store the path in the program preferences backing store
CcddFileIOHandler.storePath(ccddMain, currentPath, false, modPath);
}
index++;
}
break;
case OTHER:
// setting
for (ModifiableOtherSettingInfo modOther : ModifiableOtherSettingInfo.values()) {
// Get the current setting value from the other setting text field
String currentValue = otherFld[index].getText().trim();
// Check if the setting value has changed
if (!modOther.getValue().equals(currentValue)) {
// Update the other setting to the new value
modOther.setValue(currentValue, ccddMain.getProgPrefs());
}
index++;
}
break;
}
}
});
// Close button
JButton btnCloseDlg = CcddButtonPanelHandler.createButton("Close", CLOSE_ICON, KeyEvent.VK_C, "Close the program preferences dialog");
// Add a listener for the Close button
btnCloseDlg.addActionListener(new ActionListener() {
/**
************************************************************************************
* Close the program preferences dialog
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Close the dialog
closeDialog();
}
});
// Listen for tab selection changes
tabbedPane.addChangeListener(new ChangeListener() {
/**
************************************************************************************
* Handle a tab selection change
************************************************************************************
*/
@Override
public void stateChanged(ChangeEvent ce) {
// Get the index of the selected tab
int tabIndex = tabbedPane.getSelectedIndex();
// Check if a tab is selected
if (tabIndex != -1) {
// Base the action of the name of the tab selected
switch(tabbedPane.getTitleAt(tabIndex)) {
case LAF:
case FONT:
case COLOR:
// Hide the update button
btnUpdateAll.setVisible(false);
break;
case SIZE:
case SPACING:
case PATH:
case OTHER:
// Show the update button
btnUpdateAll.setVisible(true);
break;
}
}
}
});
// Add the buttons to the dialog panel
buttonPnl.add(btnUpdateAll);
buttonPnl.add(btnCloseDlg);
// Toggle the tab selection so that the first tab is selected and the Update button
// visibility is set accordingly
tabbedPane.setSelectedIndex(-1);
tabbedPane.setSelectedIndex(0);
// Set the initial size of the preferences dialog based on the individual panes' contents
tabbedPane.setPreferredSize(new Dimension(tabbedPane.getPreferredSize().width + LAF_SCROLL_BAR_WIDTH, maxScrollPaneHeight));
// Display the Preferences dialog
showOptionsDialog(ccddMain.getMainFrame(), tabbedPane, buttonPnl, btnCloseDlg, "Preferences", true);
}
use of CCDD.CcddConstants.ModifiablePathInfo in project CCDD by nasa.
the class CcddPreferencesDialog method addPathTab.
/**
********************************************************************************************
* Add the path update tab to the tabbed pane
********************************************************************************************
*/
private void addPathTab() {
// Set the initial layout manager characteristics
GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2), 0, 0);
// Create a border for the input fields
Border 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()));
// Create storage for the description and input field representing each modifiable path
JLabel[] pathLbl = new JLabel[ModifiablePathInfo.values().length];
JButton[] pathBtn = new JButton[ModifiablePathInfo.values().length];
pathFld = new JTextField[ModifiablePathInfo.values().length];
// Create a panel to contain the path components
JPanel innerPathPnl = new JPanel(new GridBagLayout());
innerPathPnl.setBorder(emptyBorder);
// Use an outer panel so that the components can be forced to the top of the tab area
JPanel pathPnl = new JPanel(new BorderLayout());
pathPnl.setBorder(emptyBorder);
pathPnl.add(innerPathPnl, BorderLayout.PAGE_START);
// Create a scroll pane in which to display the path labels and fields
JScrollPane pathScrollPane = new JScrollPane(pathPnl);
pathScrollPane.setBorder(emptyBorder);
pathScrollPane.setViewportBorder(emptyBorder);
// Add the path update tab to the tabbed pane
tabbedPane.addTab(PATH, null, pathScrollPane, "Change program paths");
// Create a listener for the path selection buttons
ActionListener defaultListener = new ActionListener() {
/**
************************************************************************************
* Update the path to the selection
************************************************************************************
*/
@Override
public void actionPerformed(ActionEvent ae) {
// Get the index of the path field array, which is stored as the button's name
int index = Integer.valueOf(((JButton) ae.getSource()).getName());
// Allow the user to select the script file path + name
FileEnvVar[] pathFile = new CcddDialogHandler().choosePathFile(ccddMain, CcddPreferencesDialog.this, "Select Path", pathFld[index].getText(), DialogOption.OK_CANCEL_OPTION);
// Check if a path is selected
if (pathFile != null && pathFile[0] != null) {
// Display the file name in the path name field
pathFld[index].setText(pathFile[0].getAbsolutePathWithEnvVars());
}
}
};
int index = 0;
// Step through each modifiable path
for (final ModifiablePathInfo modPath : ModifiablePathInfo.values()) {
// Create the path label and input field
pathLbl[index] = new JLabel(modPath.getName());
pathLbl[index].setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
pathLbl[index].setToolTipText(CcddUtilities.wrapText(modPath.getDescription(), ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
innerPathPnl.add(pathLbl[index], gbc);
pathFld[index] = new JTextField(String.valueOf(modPath.getPath()), 40);
pathFld[index].setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
pathFld[index].setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
pathFld[index].setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
pathFld[index].setBorder(border);
pathFld[index].setName(modPath.getPreferenceKey());
pathFld[index].setToolTipText(CcddUtilities.wrapText(modPath.getDescription(), ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
// Add the path field to the path panel
gbc.gridx++;
innerPathPnl.add(pathFld[index], gbc);
pathBtn[index] = new JButton("Select...");
pathBtn[index].setFont(ModifiableFontInfo.DIALOG_BUTTON.getFont());
pathBtn[index].setName(String.valueOf(index));
pathBtn[index].addActionListener(defaultListener);
gbc.insets.right = 0;
gbc.gridx++;
innerPathPnl.add(pathBtn[index], gbc);
gbc.insets.left = 0;
gbc.weightx = 1.0;
gbc.gridx++;
innerPathPnl.add(new JLabel(""), gbc);
gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
gbc.weightx = 0.0;
gbc.gridx = 0;
gbc.gridy++;
index++;
}
// Set the scroll bar scroll increment
pathScrollPane.getVerticalScrollBar().setUnitIncrement(pathFld[0].getPreferredSize().height / 2 + ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing());
// Calculate the maximum required height of the panel containing the path labels and fields
// (= # of rows * row height)
maxScrollPaneHeight = Math.max(maxScrollPaneHeight, 10 * pathScrollPane.getPreferredSize().height / pathFld.length);
}
Aggregations