20 package net.sf.gridarta.mainactions;
22 import java.awt.Component;
23 import java.awt.Dialog;
24 import java.awt.event.WindowEvent;
25 import java.awt.event.WindowListener;
26 import java.util.StringTokenizer;
27 import javax.swing.Box;
28 import javax.swing.BoxLayout;
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JOptionPane;
32 import javax.swing.JPanel;
33 import javax.swing.JTextField;
34 import javax.swing.event.DocumentEvent;
35 import javax.swing.event.DocumentListener;
36 import javax.swing.text.JTextComponent;
41 import net.
sf.japi.swing.action.ActionBuilder;
42 import net.
sf.japi.swing.action.ActionBuilderFactory;
43 import net.
sf.japi.swing.action.ActionMethod;
44 import net.
sf.japi.swing.action.ToggleAction;
45 import org.jetbrains.annotations.NotNull;
46 import org.jetbrains.annotations.Nullable;
59 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
65 private final JOptionPane
optionPane =
new JOptionPane();
71 private final JButton
okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"tileStretchingOkay",
this));
77 private final JButton
cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"tileStretchingCancel",
this));
106 okButton.setDefaultCapable(
true);
107 optionPane.setOptions(
new Object[] {
okButton, cancelButton });
108 final JPanel panel =
new JPanel();
109 panel.setLayout(
new BoxLayout(panel, BoxLayout.Y_AXIS));
112 panel.add(heightValueTextField);
114 panel.add(subLayerTextField);
115 panel.add(Box.createVerticalStrut(5));
116 final ToggleAction isAbsoluteAction = (ToggleAction) ACTION_BUILDER.createToggle(
false,
"tileStretchingAbsolute",
this);
117 panel.add(isAbsoluteAction.createCheckBox());
118 optionPane.setMessage(panel);
123 isAbsoluteAction.setSelected(isAbsolute);
124 final DocumentListener documentListener =
new DocumentListener() {
127 public void insertUpdate(@NotNull
final DocumentEvent e) {
132 public void removeUpdate(@NotNull
final DocumentEvent e) {
137 public void changedUpdate(@NotNull
final DocumentEvent e) {
143 heightValueTextField.getDocument().addDocumentListener(documentListener);
154 public void windowOpened(
final WindowEvent e) {
159 public void windowClosing(
final WindowEvent e) {
164 public void windowClosed(
final WindowEvent e) {
169 public void windowIconified(
final WindowEvent e) {
174 public void windowDeiconified(
final WindowEvent e) {
179 public void windowActivated(
final WindowEvent e) {
180 heightValueTextField.requestFocusInWindow();
181 assert dialog != null;
182 dialog.removeWindowListener(windowListener);
186 public void windowDeactivated(
final WindowEvent e) {
206 final JDialog tmpDialog;
207 if (dialog == null) {
210 tmpDialog.getRootPane().setDefaultButton(okButton);
211 optionPane.selectInitialValue();
212 tmpDialog.setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
217 tmpDialog.addWindowListener(windowListener);
218 tmpDialog.setVisible(
true);
219 tmpDialog.removeWindowListener(windowListener);
220 return optionPane.getValue() ==
okButton;
229 optionPane.setValue(okButton);
256 optionPane.setValue(cancelButton);
264 return !heightValueTextField.getText().isEmpty();
281 final StringTokenizer st =
new StringTokenizer(subLayerTextField.getText(),
",");
282 final Integer[] subLayers =
new Integer[st.countTokens()];
284 for (
int i = 0; st.hasMoreTokens(); i++) {
JDialog dialog
The JDialog instance or.
Graphical User Interface of Gridarta.
boolean isTileStretchingAbsolute()
Action method for "absolute" action.
Integer [] getSubLayers()
Returns the sub-layers to affect.
final JTextComponent subLayerTextField
The text field for specifying the sub-layer value.
Utility class for parsing strings into numbers.
void setTileStretchingAbsolute(final boolean isAbsolute)
Action method for "absolute" action.
int getHeightValue()
Returns the height value.
final WindowListener windowListener
The WindowListener attached to dialog to call JOptionPane#selectInitialValue() after the dialog has b...
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Base package of all Gridarta classes.
Utility class for JTextComponent related functions.
static int parseInt(@NotNull final String s)
Parses an integer string.
static final ActionBuilder ACTION_BUILDER
Action Builder to create Actions.
Displays a dialog asking for parameters for the "tile stretching set" function.
boolean showTileStretchingDialog(@NotNull final Component parent)
Displays the tile stretching dialog.
static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent)
Selects all text of a JTextComponent when the component gains the focus.
final JButton okButton
The "OK" button.
boolean isOkButtonEnabled()
Returns whether the "OK" button is enabled.
final JOptionPane optionPane
The JOptionPane instance used to create dialogs.
void updateOkButton()
Updates the enabled state of the "OK" button depending on the dialog's contents.
void tileStretchingCancel()
Action method to close the dialog with "Cancel".
Utility class for ActionBuilder related functions.
boolean isAbsolute
Whether adjacent squares are checked.
final JButton cancelButton
The "Cancel" button.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
static boolean getBoolean(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Returns the value of a key as a.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
final JTextComponent heightValueTextField
The text field for specifying the height value.
void tileStretchingOkay()
Action method to close the dialog with "OK".
TileStretchingDialog()
Creates a new instance.
Defines common UI constants used in different dialogs.