20 package net.sf.gridarta.gui.dialog.shrinkmapsize;
22 import java.awt.Component;
23 import java.awt.Window;
24 import javax.swing.AbstractButton;
25 import javax.swing.Box;
26 import javax.swing.BoxLayout;
27 import javax.swing.JButton;
28 import javax.swing.JCheckBox;
29 import javax.swing.JComponent;
30 import javax.swing.JDialog;
31 import javax.swing.JLabel;
32 import javax.swing.JOptionPane;
33 import javax.swing.JPanel;
34 import javax.swing.WindowConstants;
42 import net.
sf.japi.swing.action.ActionBuilder;
43 import net.
sf.japi.swing.action.ActionBuilderFactory;
44 import net.
sf.japi.swing.action.ActionMethod;
45 import org.jetbrains.annotations.NotNull;
46 import org.jetbrains.annotations.Nullable;
63 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
81 private final AbstractButton
eastCheckBox =
new JCheckBox(ACTION_BUILDER.createToggle(
false,
"shrinkMapSizeDialogEast",
this));
87 private final AbstractButton
southCheckBox =
new JCheckBox(ACTION_BUILDER.createToggle(
false,
"shrinkMapSizeDialogSouth",
this));
99 private final JButton
okButton =
new JButton(ACTION_BUILDER.createAction(
false,
"shrinkMapSizeDialogOk",
this));
105 private final JButton
cancelButton =
new JButton(ACTION_BUILDER.createAction(
false,
"shrinkMapSizeDialogCancel",
this));
121 okButton.setDefaultCapable(
true);
122 setOptions(
new Object[] {
okButton, cancelButton });
128 dialog.setVisible(
true);
133 public final JDialog
createDialog(@NotNull
final Component parentComponent, @NotNull
final String title) {
134 final JDialog result = super.createDialog(parentComponent, title);
135 result.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
136 result.getRootPane().setDefaultButton(okButton);
137 result.setModal(
false);
149 label.setAlignmentX(0.0F);
150 eastCheckBox.setAlignmentX(0.0F);
151 southCheckBox.setAlignmentX(0.0F);
152 warnings.setAlignmentX(0.0F);
153 final JPanel mainPanel =
new JPanel();
154 mainPanel.setLayout(
new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
156 mainPanel.add(label);
157 mainPanel.add(Box.createVerticalStrut(5));
158 mainPanel.add(eastCheckBox);
159 mainPanel.add(southCheckBox);
160 mainPanel.add(Box.createVerticalStrut(5));
161 mainPanel.add(warnings);
162 mainPanel.add(Box.createVerticalStrut(5));
176 final StringBuilder sb =
new StringBuilder(100);
177 if (!eastCheckBox.isEnabled() && !southCheckBox.isEnabled()) {
182 if (eastCheckBox.isEnabled() && eastCheckBox.isSelected()) {
192 if (southCheckBox.isEnabled() && southCheckBox.isSelected()) {
203 okButton.setEnabled(eastCheckBox.isSelected() || southCheckBox.isSelected());
204 if (sb.length() > 0) {
206 sb.insert(0,
"<html>");
207 warnings.setText(sb.toString());
209 warnings.setText(
"");
235 if (eastCheckBox.isSelected()) {
238 if (southCheckBox.isSelected()) {
245 public void setValue(@Nullable
final Object newValue) {
246 super.setValue(newValue);
247 if (newValue != UNINITIALIZED_VALUE) {
267 return eastCheckBox.isSelected();
276 eastCheckBox.setSelected(!flag);
286 return southCheckBox.isSelected();
295 southCheckBox.setSelected(!flag);
final AbstractButton southCheckBox
Checkbox to remove empty squares at the south edge.
Graphical User Interface of Gridarta.
void shrinkMapSizeDialogCancel()
Action method for cancel.
Utility class to remove empty squares from a map's border.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
void setShrinkMapSizeDialogEast(final boolean flag)
Action method for "shrinkMapSizeDialogEast".
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 JDialog dialog
The associated JDialog instance.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
static final ActionBuilder ACTION_BUILDER
Action Builder.
Dialog to ask which empty borders to remove from a map.
void shrinkMapSize()
Shrinks the map model.
void shrinkMapSizeDialogOk()
Action method for ok.
void disposeDialog(@NotNull final MapView< G, A, R > mapView)
Disposes a dialog.
GameObjects are the objects based on Archetypes found on maps.
static void shrinkMap(@NotNull final MapModel<?, ?, ?> mapModel, final int shrinkFlags)
Removes empty squares from a map's border.
boolean isShrinkMapSizeDialogSouth()
Action method for "shrinkMapSizeDialogSouth".
static final int SHRINK_EAST
Flag value: remove empty space from east border.
JPanel createPanel()
Creates the GUI.
Base classes for rendering maps.
final JLabel warnings
Text area for displaying warning messages.
Window getDialog()
Returns the JDialog for this instance.
final JDialog createDialog(@NotNull final Component parentComponent, @NotNull final String title)
boolean isShrinkMapSizeDialogEast()
Action method for "shrinkMapSizeDialogEast".
Utility class for ActionBuilder related functions.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
final JButton okButton
JButton for ok.
final MapView< G, A, R > mapView
The affected map view of this dialog.
A map view consists of a map grid and a map cursor, and is attached to a map control.
final ShrinkMapSizeDialogManager< G, A, R > shrinkMapSizeDialogManager
The manager for this dialog.
void setValue(@Nullable final Object newValue)
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
static final long serialVersionUID
Serial Version UID.
final JButton cancelButton
JButton for cancel.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
static int getShrinkFlags(@NotNull final MapModel<?, ?, ?> mapModel)
Returns which borders contain empty squares.
static final int SHRINK_SOUTH
Flag value: remove empty space from south border.
ShrinkMapSizeDialog(@NotNull final ShrinkMapSizeDialogManager< G, A, R > shrinkMapSizeDialogManager, @NotNull final MapView< G, A, R > mapView)
Creates a new instance.
String getTilePath(@NotNull Direction direction)
Returns a tile path.
Interface for MapArchObjects.
void setShrinkMapSizeDialogSouth(final boolean flag)
Action method for "shrinkMapSizeDialogSouth".
Defines common UI constants used in different dialogs.
void updateWarnings()
Updates the warnings label.
final AbstractButton eastCheckBox
Checkbox to remove empty squares at the east edge.