20 package net.sf.gridarta.gui.dialog.newmap;
22 import java.awt.Component;
23 import java.awt.FlowLayout;
24 import java.awt.GridBagConstraints;
25 import javax.swing.AbstractButton;
26 import javax.swing.JCheckBox;
27 import javax.swing.JPanel;
28 import javax.swing.JTextField;
29 import javax.swing.text.JTextComponent;
38 import net.
sf.japi.swing.action.ActionBuilder;
39 import net.
sf.japi.swing.action.ActionBuilderFactory;
40 import net.
sf.japi.swing.action.ActionMethod;
41 import org.jetbrains.annotations.NotNull;
42 import org.jetbrains.annotations.Nullable;
77 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
135 private final AbstractButton
mapSizeDefaultCheckbox =
new JCheckBox(ACTION_BUILDER.createToggle(
false,
"mapSizeDefault",
this));
154 public NewMapDialog(@NotNull
final MapViewsManager<G, A, R> mapViewsManager, @NotNull
final MapArchObjectFactory<A> mapArchObjectFactory, @NotNull
final Component parentComponent,
final boolean showMapSizeDefault,
final boolean showMapDifficulty,
final int defaultWidth,
final int defaultHeight,
final int defaultDifficulty) {
155 super(DEFAULT_LEVEL_WIDTH_KEY, DEFAULT_LEVEL_HEIGHT_KEY, defaultWidth, defaultHeight);
167 mapNameField.selectAll();
169 addDocumentListener(mapNameField);
170 addDocumentListener(mapDifficultyField);
176 if (showMapSizeDefault) {
185 final JPanel panel =
new JPanel(
new FlowLayout(FlowLayout.RIGHT));
187 panel.add(mapNameField);
192 protected void addFields(@NotNull
final JPanel panel, @NotNull
final GridBagConstraints gbcLabel, @NotNull
final GridBagConstraints gbcField) {
193 if (showMapSizeDefault) {
194 panel.add(mapSizeDefaultCheckbox, gbcField);
196 super.addFields(panel, gbcLabel, gbcField);
197 if (showMapDifficulty) {
198 mapDifficultyField.setText(Integer.toString(PREFERENCES.getInt(DEFAULT_DIFFICULTY_KEY, defaultDifficulty)));
200 mapDifficultyField.setColumns(3);
201 panel.add(mapDifficultyField, gbcField);
210 if (mapSize == null) {
213 mapArchObject.setMapSize(mapSize);
216 if (mapName == null) {
220 mapArchObject.setMapName(mapName);
221 if (showMapDifficulty) {
223 if (difficulty < 0) {
226 mapArchObject.setDifficulty(difficulty);
244 final String mapName = mapNameField.getText();
245 return !mapName.isEmpty() ? mapName : null;
253 final String text = mapDifficultyField.getText();
255 return difficulty >= 1 ? difficulty : -1;
274 mapSizeDefaultCheckbox.setSelected(mapSizeDefault);
287 return mapSizeDefault ?
new Size2D(defaultWidth, defaultHeight) : super.getMapSize();
static final ActionBuilder ACTION_BUILDER
Action Builder.
final boolean showMapSizeDefault
Whether to show the "mapSizeDefault" checkbox.
Graphical User Interface of Gridarta.
int getMapWidth()
Returns the current map width value.
NewMapDialog(@NotNull final MapViewsManager< G, A, R > mapViewsManager, @NotNull final MapArchObjectFactory< A > mapArchObjectFactory, @NotNull final Component parentComponent, final boolean showMapSizeDefault, final boolean showMapDifficulty, final int defaultWidth, final int defaultHeight, final int defaultDifficulty)
Creates a "new map" dialog.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager to use.
final boolean showMapDifficulty
Whether to show the "mapDifficulty" field.
final int defaultWidth
The default width for new maps.
Utility class for parsing strings into numbers.
Factory for creating MapArchObject instances.
Stores all existing MapViews.
void newMapWithView(@Nullable final List< G > objects, @NotNull final A mapArchObject, @Nullable final Point viewPosition, @Nullable final MapFile mapFile)
Create a new map control and an initial map view.
static final long serialVersionUID
Serial Version UID.
final int defaultHeight
The default height for new maps.
A newMapArchObject(boolean addDefaultAttributes)
Creates a new MapArchObject instance.
final JTextComponent mapNameField
Textfield for the name of the map.
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.
boolean mapSizeDefault
Whether to use the default map size.
Reflects a game object (object on a map).
void addFields(@NotNull final JPanel panel, @NotNull final GridBagConstraints gbcLabel, @NotNull final GridBagConstraints gbcField)
Size2D getMapSize()
Validate the map size fields and return the result.
static int parseInt(@NotNull final String s)
Parses an integer string.
final int defaultDifficulty
The default height for new maps.
int getDifficulty()
Returns the current difficulty value.
GameObjects are the objects based on Archetypes found on maps.
final MapArchObjectFactory< A > mapArchObjectFactory
The map arch object factory instance.
Dialog to create a new map file.
final AbstractButton mapSizeDefaultCheckbox
Checkbox to set whether the default width / height should be overridden.
Base classes for rendering maps.
static final String DEFAULT_LEVEL_HEIGHT_KEY
The key used to store the last used map height in preferences.
Utility class for ActionBuilder related functions.
An abstract base class implementing a AbstractNewMapDialog supporting map size input fields...
boolean isMapSizeDefault()
Set whether to override the default map size.
static JLabel newLabel(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Creates a new JLabel from a resource key.
void setMapSizeEnabled(final boolean enabled)
Enables or disables the map size input fields.
void setMapSizeDefault(final boolean mapSizeDefault)
Set whether to override the default map size.
String getMapName()
Returns the current map name value.
static final String DEFAULT_DIFFICULTY_KEY
The key used to store the last used difficulty in preferences.
boolean isOkButtonEnabled()
Interface for MapArchObjects.
int getMapHeight()
Returns the current map height value.
static final String DEFAULT_LEVEL_WIDTH_KEY
The key used to store the last used map width in preferences.
The class Size2D represents a 2d rectangular area.
final JTextField mapDifficultyField
Textfield for the difficulty of the new map.
JPanel createMapNamePanel()