 |
Gridarta Editor
|
Go to the documentation of this file.
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");
124 final JButton applyButton =
new JButton(
ACTION_BUILDER.createAction(
false,
"goLocationApply",
this));
135 dialog.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
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;
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) {
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
int getWidth()
Returns the width of the area.
void setCursorLocation(@NotNull Point point)
Sets the cursor location.
void setValue(@Nullable final Object newValue)
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
Base package of all Gridarta classes.
Defines common UI constants used in different dialogs.
Component getComponent()
Returns the component associated with this MapView that can be used as parent for dialogs.
static void setActionNextFocus(@NotNull final JTextField textField, @NotNull final Component nextComponent)
Transfers the focus to another component when ENTER is pressed.
void goLocationOkay()
Action method for okay.
void goLocationApply()
Action method for apply.
Reflects a game object (object on a map).
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
GoLocationDialog(@NotNull final AbstractPerMapDialogManager< G, A, R, GoLocationDialog< G, A, R >> goLocationDialogManager, @NotNull final MapView< G, A, R > mapView)
Creates a new instance.
static final long serialVersionUID
The serial Version UID.
final JButton okButton
The JButton for ok.
Graphical User Interface of Gridarta.
MapCursor< G, A, R > getMapCursor()
Returns the MapCursor of this view.
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.
int getHeight()
Returns the height of the area.
final JTextField xCoordinateField
The text input field for the x coordinate.
Window getDialog()
Returns the Window for this instance.
Interface for MapArchObjects.
boolean goLocation()
Moves the cursor to the given coordinates.
Point getLocation()
Get position of cursor.
A map view consists of a map grid and a map cursor, and is attached to a map control.
final MapView< G, A, R > mapView
The affected map view this go location dialog affects.
Maintains (dialog) instance associated to map view instances.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
final JTextField yCoordinateField
The text input field for the y coordinate.
JPanel createPanel()
Creates the GUI.
int parseCoordinate(@NotNull final JTextComponent textField, final int range)
Parses a coordinate input field.
void disposeDialog(final MapView< G, A, R > mapView)
Dispose a dialog.
static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent)
Selects all text of a JTextComponent when the component gains the focus.
A dialog to ask the user for coordinates to move the cursor to.
final JDialog dialog
The JDialog instance.
Base classes for rendering maps.
void goLocationCancel()
Action method for cancel.
Utility class for ActionBuilder related functions.
MapModel< G, A, R > getMapModel()
Returns the map model.
final JButton cancelButton
The JButton for cancel.
Utility class for JTextComponent related functions.
The class Size2D represents a 2d rectangular area.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.