20 package net.sf.gridarta.mainactions;
22 import java.awt.Component;
23 import java.awt.Dialog;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.Insets;
27 import java.awt.event.WindowEvent;
28 import java.awt.event.WindowListener;
29 import java.util.StringTokenizer;
30 import javax.swing.Box;
31 import javax.swing.JButton;
32 import javax.swing.JDialog;
33 import javax.swing.JOptionPane;
34 import javax.swing.JPanel;
35 import javax.swing.JScrollPane;
36 import javax.swing.JTextArea;
37 import javax.swing.JTextField;
38 import javax.swing.event.DocumentEvent;
39 import javax.swing.event.DocumentListener;
40 import javax.swing.text.JTextComponent;
45 import net.
sf.japi.swing.action.ActionBuilder;
46 import net.
sf.japi.swing.action.ActionBuilderFactory;
47 import net.
sf.japi.swing.action.ActionMethod;
48 import org.jetbrains.annotations.NotNull;
49 import org.jetbrains.annotations.Nullable;
61 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
67 private final JOptionPane
optionPane =
new JOptionPane();
73 private final JButton
okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"massChangeOkay",
this));
79 private final JButton
cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"massChangeCancel",
this));
122 okButton.setDefaultCapable(
true);
123 optionPane.setOptions(
new Object[] {
okButton, cancelButton });
124 final JPanel panel =
new JPanel(
new GridBagLayout());
125 final GridBagConstraints labelGbc =
new GridBagConstraints();
126 labelGbc.anchor = GridBagConstraints.EAST;
127 labelGbc.insets =
new Insets(2, 10, 2, 2);
128 final GridBagConstraints gbc =
new GridBagConstraints();
129 gbc.insets =
new Insets(2, 2, 2, 2);
130 gbc.fill = GridBagConstraints.HORIZONTAL;
131 gbc.gridwidth = GridBagConstraints.REMAINDER;
135 panel.add(archNamesTextField, gbc);
137 panel.add(namesTextField, gbc);
139 panel.add(layersTextField, gbc);
141 panel.add(subLayersTextField, gbc);
143 changesTextArea.setRows(10);
144 changesTextArea.setColumns(50);
145 final JScrollPane scrollPane =
new JScrollPane(changesTextArea);
146 panel.add(scrollPane, gbc);
147 panel.add(Box.createVerticalStrut(5));
148 optionPane.setMessage(panel);
154 final DocumentListener documentListener =
new DocumentListener() {
157 public void insertUpdate(@NotNull
final DocumentEvent e) {
162 public void removeUpdate(@NotNull
final DocumentEvent e) {
167 public void changedUpdate(@NotNull
final DocumentEvent e) {
173 changesTextArea.getDocument().addDocumentListener(documentListener);
185 public void windowOpened(@NotNull
final WindowEvent e) {
190 public void windowClosing(@NotNull
final WindowEvent e) {
195 public void windowClosed(@NotNull
final WindowEvent e) {
200 public void windowIconified(@NotNull
final WindowEvent e) {
205 public void windowDeiconified(@NotNull
final WindowEvent e) {
210 public void windowActivated(@NotNull
final WindowEvent e) {
211 changesTextArea.requestFocusInWindow();
212 assert dialog != null;
213 dialog.removeWindowListener(windowListener);
217 public void windowDeactivated(@NotNull
final WindowEvent e) {
237 final JDialog tmpDialog;
238 if (dialog == null) {
241 tmpDialog.getRootPane().setDefaultButton(okButton);
242 optionPane.selectInitialValue();
243 tmpDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
247 changesTextArea.setText(
"");
248 changesTextArea.setCaretPosition(0);
250 tmpDialog.addWindowListener(windowListener);
251 tmpDialog.setVisible(
true);
252 tmpDialog.removeWindowListener(windowListener);
253 return optionPane.getValue() ==
okButton;
262 optionPane.setValue(okButton);
271 optionPane.setValue(cancelButton);
279 return !changesTextArea.getText().isEmpty();
288 final StringTokenizer st =
new StringTokenizer(archNamesTextField.getText(),
",");
289 final String[] archNames =
new String[st.countTokens()];
291 for (
int i = 0; st.hasMoreTokens(); i++) {
292 archNames[i] = st.nextToken();
304 final StringTokenizer st =
new StringTokenizer(namesTextField.getText(),
",");
305 final String[] names =
new String[st.countTokens()];
307 for (
int i = 0; st.hasMoreTokens(); i++) {
308 names[i] = st.nextToken();
320 final StringTokenizer st =
new StringTokenizer(layersTextField.getText(),
",");
321 final Integer[] layers =
new Integer[st.countTokens()];
323 for (
int i = 0; st.hasMoreTokens(); i++) {
336 final StringTokenizer st =
new StringTokenizer(subLayersTextField.getText(),
",");
337 final Integer[] subLayers =
new Integer[st.countTokens()];
339 for (
int i = 0; st.hasMoreTokens(); i++) {
352 return changesTextArea.getText();
final JTextArea changesTextArea
The text area for specifying the changes to add.
Displays a dialog asking for parameters for the "mass change" function.
String [] getArchNames()
Returns the arch names to affect.
Graphical User Interface of Gridarta.
boolean showMassChangeDialog(@NotNull final Component parent)
Displays the mass change dialog.
Utility class for parsing strings into numbers.
void massChangeCancel()
Action method to close the dialog with "Cancel".
Integer [] getLayers()
Returns the layers to affect.
final JButton okButton
The "OK" button.
final JTextComponent namesTextField
The text field for specifying the object names to match.
boolean isOkButtonEnabled()
Returns whether the "OK" button is enabled.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
static final ActionBuilder ACTION_BUILDER
Action Builder to create Actions.
Base package of all Gridarta classes.
Utility class for JTextComponent related functions.
static int parseInt(@NotNull final String s)
Parses an integer string.
JDialog dialog
The javax.swing.JDialog instance or.
final JTextComponent layersTextField
The text field for specifying the layers to match.
final JTextComponent subLayersTextField
The text field for specifying the sub-layers to match.
String [] getNames()
Returns the object names to affect.
static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent)
Selects all text of a JTextComponent when the component gains the focus.
final JTextComponent archNamesTextField
The text field for specifying the arch names to match.
Utility class for ActionBuilder related functions.
void massChangeOkay()
Action method to close the dialog with "OK".
String getChanges()
Returns the actual changes to apply.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
void updateOkButton()
Updates the enabled state of the "OK" button depending on the dialog's contents.
final JOptionPane optionPane
The javax.swing.JOptionPane instance used to create dialogs.
final WindowListener windowListener
The java.awt.event.WindowListener attached to dialog to call javax.swing.JOptionPane#selectInitialVal...
final JButton cancelButton
The "Cancel" button.
MassChangeDialog()
Creates a new instance.
Integer [] getSubLayers()
Returns the sub-layers to affect.
Defines common UI constants used in different dialogs.