20 package net.sf.gridarta.gui.dialog.golocation;
22 import java.awt.GridBagConstraints;
23 import java.awt.GridBagLayout;
24 import java.awt.Insets;
25 import java.awt.Point;
26 import java.awt.Window;
27 import javax.swing.Box;
28 import javax.swing.BoxLayout;
29 import javax.swing.JButton;
30 import javax.swing.JComponent;
31 import javax.swing.JDialog;
32 import javax.swing.JLabel;
33 import javax.swing.JOptionPane;
34 import javax.swing.JPanel;
35 import javax.swing.JTextField;
36 import javax.swing.WindowConstants;
37 import javax.swing.border.CompoundBorder;
38 import javax.swing.border.EtchedBorder;
39 import javax.swing.border.TitledBorder;
40 import javax.swing.text.JTextComponent;
50 import net.
sf.japi.swing.action.ActionBuilder;
51 import net.
sf.japi.swing.action.ActionBuilderFactory;
52 import net.
sf.japi.swing.action.ActionMethod;
53 import org.jetbrains.annotations.NotNull;
54 import org.jetbrains.annotations.Nullable;
71 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
101 private final JButton
okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"goLocationOkay",
this));
107 private final JButton
cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"goLocationCancel",
this));
123 okButton.setDefaultCapable(
true);
124 final JButton applyButton =
new JButton(ACTION_BUILDER.createAction(
false,
"goLocationApply",
this));
125 setOptions(
new Object[] {
okButton, applyButton, cancelButton });
135 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
136 dialog.getRootPane().setDefaultButton(okButton);
137 dialog.setModal(
false);
140 dialog.setVisible(
true);
149 final JPanel mainPanel =
new JPanel();
150 mainPanel.setLayout(
new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
155 mainPanel.add(Box.createVerticalStrut(5));
157 final JComponent coordinatesPanel =
new JPanel(
new GridBagLayout());
158 final GridBagConstraints gbcLabel =
new GridBagConstraints();
159 final GridBagConstraints gbcField =
new GridBagConstraints();
160 gbcLabel.insets =
new Insets(2, 2, 2, 2);
161 gbcField.insets =
new Insets(2, 2, 2, 2);
162 gbcLabel.anchor = GridBagConstraints.EAST;
163 gbcField.gridwidth = GridBagConstraints.REMAINDER;
169 xCoordinateField.setText(Integer.toString(point.x));
170 xCoordinateField.setColumns(3);
171 coordinatesPanel.add(xCoordinateField, gbcField);
174 yCoordinateField.setText(Integer.toString(point.y));
175 yCoordinateField.setColumns(3);
176 coordinatesPanel.add(yCoordinateField, gbcField);
178 mainPanel.add(coordinatesPanel);
179 mainPanel.add(Box.createVerticalStrut(5));
217 final Point point =
new Point();
221 }
catch (
final IllegalArgumentException ignored) {
236 private int parseCoordinate(@NotNull
final JTextComponent textField,
final int range) {
239 result = Integer.parseInt(textField.getText());
240 }
catch (
final NumberFormatException e) {
241 ACTION_BUILDER.showMessageDialog(
this,
"goLocationCoordinateNotANumber");
242 textField.requestFocus();
244 }
catch (
final IllegalArgumentException e) {
245 ACTION_BUILDER.showMessageDialog(
this,
"goLocationCoordinateOutOfRange");
246 textField.requestFocus();
249 if (result < 0 || result >= range) {
250 ACTION_BUILDER.showMessageDialog(
this,
"goLocationCoordinateOutOfRange");
251 textField.requestFocus();
252 throw new IllegalArgumentException(
"invalid coordinate value: " + result);
259 public void setValue(@Nullable
final Object newValue) {
260 super.setValue(newValue);
261 if (newValue != UNINITIALIZED_VALUE) {
GoLocationDialog(@NotNull final AbstractPerMapDialogManager< G, A, R, GoLocationDialog< G, A, R >> goLocationDialogManager, @NotNull final MapView< G, A, R > mapView)
Creates a new instance.
void goLocationOkay()
Action method for okay.
void setValue(@Nullable final Object newValue)
final JDialog dialog
The JDialog instance.
Graphical User Interface of Gridarta.
void goLocationCancel()
Action method for cancel.
final JTextField xCoordinateField
The text input field for the x coordinate.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
final JButton cancelButton
The JButton for cancel.
static final long serialVersionUID
The serial Version UID.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
Point getLocation()
Get position of cursor.
MapModel< G, A, R > getMapModel()
Returns the map model.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
final JButton okButton
The JButton for ok.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Utility class for JTextComponent related functions.
void disposeDialog(final MapView< G, A, R > mapView)
Dispose a dialog.
final AbstractPerMapDialogManager< G, A, R, GoLocationDialog< G, A, R > > goLocationDialogManager
The dialog manager for this dialog.
GameObjects are the objects based on Archetypes found on maps.
Maintains (dialog) instance associated to map view instances.
final MapView< G, A, R > mapView
The affected map view this go location dialog affects.
int getWidth()
Returns the width of the area.
static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent)
Selects all text of a JTextComponent when the component gains the focus.
Window getDialog()
Returns the Window for this instance.
Base classes for rendering maps.
void setCursorLocation(@NotNull Point point)
Sets the cursor location.
final JTextField yCoordinateField
The text input field for the y coordinate.
Utility class for ActionBuilder related functions.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
A map view consists of a map grid and a map cursor, and is attached to a map control.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
int parseCoordinate(@NotNull final JTextComponent textField, final int range)
Parses a coordinate input field.
A dialog to ask the user for coordinates to move the cursor to.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
JPanel createPanel()
Creates the GUI.
int getHeight()
Returns the height of the area.
boolean goLocation()
Moves the cursor to the given coordinates.
Interface for MapArchObjects.
Defines common UI constants used in different dialogs.
void goLocationApply()
Action method for apply.
The class Size2D represents a 2d rectangular area.
static void setActionNextFocus(@NotNull final JTextField textField, @NotNull final Component nextComponent)
Transfers the focus to another component when ENTER is pressed.