20 package net.sf.gridarta.gui.dialog.newmap;
22 import java.awt.Component;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
25 import java.awt.Insets;
26 import java.awt.event.FocusEvent;
27 import java.awt.event.FocusListener;
28 import java.util.prefs.Preferences;
29 import javax.swing.BoxLayout;
30 import javax.swing.JButton;
31 import javax.swing.JDialog;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.WindowConstants;
35 import javax.swing.border.CompoundBorder;
36 import javax.swing.border.EtchedBorder;
37 import javax.swing.border.TitledBorder;
38 import javax.swing.event.DocumentEvent;
39 import javax.swing.event.DocumentListener;
40 import javax.swing.text.JTextComponent;
47 import net.
sf.japi.swing.action.ActionBuilder;
48 import net.
sf.japi.swing.action.ActionBuilderFactory;
49 import net.
sf.japi.swing.action.ActionMethod;
50 import org.jetbrains.annotations.NotNull;
51 import org.jetbrains.annotations.Nullable;
73 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
85 private final JButton
okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"mapOkay",
this));
91 private final JButton
cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"mapCancel",
this));
104 public void insertUpdate(@NotNull
final DocumentEvent e) {
109 public void removeUpdate(@NotNull
final DocumentEvent e) {
114 public void changedUpdate(@NotNull
final DocumentEvent e) {
131 protected void init1(@NotNull
final Component parentComponent, @NotNull
final String dialogTitle) {
132 okButton.setDefaultCapable(
true);
133 setOptions(
new Object[] {
okButton, cancelButton });
136 dialog = createDialog(parentComponent, dialogTitle);
137 assert dialog != null;
138 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
139 assert dialog != null;
140 dialog.getRootPane().setDefaultButton(okButton);
141 assert dialog != null;
142 dialog.setModal(
false);
149 assert dialog != null;
150 dialog.setVisible(
true);
155 final JPanel panel =
new JPanel();
156 panel.setLayout(
new BoxLayout(panel, BoxLayout.Y_AXIS));
160 if (parametersPanel != null) {
161 panel.add(parametersPanel);
171 final JPanel panel =
new JPanel(
new GridBagLayout());
173 final GridBagConstraints gbcLabel =
new GridBagConstraints();
174 gbcLabel.insets =
new Insets(2, 2, 2, 2);
175 gbcLabel.anchor = GridBagConstraints.EAST;
177 final GridBagConstraints gbcField =
new GridBagConstraints();
178 gbcField.insets =
new Insets(2, 2, 2, 2);
179 gbcField.gridwidth = GridBagConstraints.REMAINDER;
193 protected abstract void addFields(@NotNull JPanel panel, @NotNull GridBagConstraints gbcLabel, @NotNull GridBagConstraints gbcField);
214 public void setValue(@Nullable
final Object newValue) {
215 super.setValue(newValue);
216 if (dialog != null && newValue != UNINITIALIZED_VALUE) {
251 textComponent.getDocument().addDocumentListener(documentListener);
252 textComponent.addFocusListener(
new FocusListener() {
255 public void focusGained(@NotNull
final FocusEvent e) {
256 textComponent.selectAll();
260 public void focusLost(@NotNull
final FocusEvent e) {
261 textComponent.select(0, 0);
265 textComponent.selectAll();
final JButton okButton
JButton for ok.
Graphical User Interface of Gridarta.
abstract JPanel createMapNamePanel()
final DocumentListener documentListener
The DocumentListener attached to input fields for detecting changes.
abstract boolean createNew()
Checks the given values and creates a new map.
static final ActionBuilder ACTION_BUILDER
Action Builder.
void setValue(@Nullable final Object newValue)
AbstractNewMapDialog()
Constructs a new map dialog.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
void updateOkButton()
Updates the enabled state of the "OK" button depending on the dialog's contents.
Base package of all Gridarta classes.
void init2()
Initializes the dialog.
Reflects a game object (object on a map).
boolean isOkButtonEnabled()
Returns whether the "OK" button is enabled depending on the dialog's contents.
final JButton cancelButton
JButton for cancel.
GameObjects are the objects based on Archetypes found on maps.
Interface used as preferences location.
void mapOkay()
Action method for okay.
JPanel createMapParametersPanel()
void mapCancel()
Action method for cancel.
Utility class for ActionBuilder related functions.
void addDocumentListener(@NotNull final JTextComponent textComponent)
Watches for text changes in a text component and enables the "OK" button accordingly.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
static final Preferences PREFERENCES
Preferences.
Dialog used to ask the user the properties for the new level.
static final long serialVersionUID
Serial Version UID.
abstract void addFields(@NotNull JPanel panel, @NotNull GridBagConstraints gbcLabel, @NotNull GridBagConstraints gbcField)
Adds additional fields to the dialog.
Interface for MapArchObjects.
Defines common UI constants used in different dialogs.
void init1(@NotNull final Component parentComponent, @NotNull final String dialogTitle)
Initializes the dialog.