20 package net.sf.gridarta.gui.map.maptilepane;
22 import java.awt.Component;
23 import java.awt.GridBagConstraints;
24 import java.awt.GridBagLayout;
26 import javax.swing.BorderFactory;
27 import javax.swing.JButton;
28 import javax.swing.JComponent;
29 import javax.swing.JPanel;
30 import javax.swing.border.CompoundBorder;
31 import javax.swing.filechooser.FileFilter;
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;
76 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
138 protected AbstractMapTilePane(@NotNull
final MapManager<G, A, R> mapManager, @NotNull
final ProjectSettings projectSettings, @NotNull
final MapModel<G, A, R> mapModel, @NotNull
final MapLink[][] tileLink, @NotNull
final Direction[] directionMapping, @NotNull
final int[] nextFocus, @NotNull
final FileFilter mapFileFilter) {
141 this.nextFocus = nextFocus.clone();
143 assert tileLink.length == 10;
144 tileLinks =
new TileLink[] {
newTileLink(
"mapNorth", tileLink[0],
Direction.
SOUTH),
newTileLink(
"mapEast", tileLink[1],
Direction.
WEST),
newTileLink(
"mapSouth", tileLink[2],
Direction.
NORTH),
newTileLink(
"mapWest", tileLink[3],
Direction.
EAST),
newTileLink(
"mapNorthEast", tileLink[4],
Direction.
SOUTH_WEST),
newTileLink(
"mapSouthEast", tileLink[5],
Direction.
NORTH_WEST),
newTileLink(
"mapSouthWest", tileLink[6],
Direction.
NORTH_EAST),
newTileLink(
"mapNorthWest", tileLink[7],
Direction.
SOUTH_EAST),
newTileLink(
"mapUp", tileLink[8],
Direction.
DOWN),
newTileLink(
"mapDown", tileLink[9],
Direction.
UP) };
146 canAttachMaps = tileLink[0].length + tileLink[1].length + tileLink[2].length + tileLink[3].length + tileLink[4].length + tileLink[5].length + tileLink[6].length + tileLink[7].length + tileLink[8].length + tileLink[9].length > 0;
147 mapArchObject = mapModel.getMapArchObject();
168 setLayout(
new GridBagLayout());
169 final GridBagConstraints gbc =
new GridBagConstraints();
170 gbc.gridwidth = GridBagConstraints.REMAINDER;
172 gbc.fill = GridBagConstraints.BOTH;
187 for (
int index = 0; index < tilePanels.length; index++) {
191 tilePanels[index] =
new MapTilePanel(index, nextFocus, tilePanel, tileLinks[index].getName());
206 for (
int index = 0; index < tilePanels.length; index++) {
207 panel.add(tilePanels[index].getTilePanel(), directionMapping[index]);
219 final JComponent subPanel =
new JPanel(
new GridBagLayout());
221 final GridBagConstraints gbc =
new GridBagConstraints();
222 gbc.fill = GridBagConstraints.NONE;
226 gbc.anchor = GridBagConstraints.EAST;
227 subPanel.add(
new JButton(ACTION_BUILDER.createAction(
false,
"mapTilesAttach",
this)), gbc);
229 gbc.gridwidth = GridBagConstraints.REMAINDER;
230 gbc.anchor = canAttachMaps ? GridBagConstraints.WEST : GridBagConstraints.CENTER;
231 subPanel.add(
new JButton(ACTION_BUILDER.createAction(
false,
"mapTilesClear",
this)), gbc);
240 final String[] tmpTilePaths =
new String[tilePaths.length];
241 for (
int i = 0; i < tmpTilePaths.length; i++) {
246 attachTiledMaps.
attachTiledMaps(mapModel, tmpTilePaths, mapsDirectory,
true);
248 ACTION_BUILDER.showMessageDialog(
this,
"mapErrorPath2", ex.
getMapPath());
251 ACTION_BUILDER.showMessageDialog(
this,
"mapErrorFatalWrite", ex.getMessage());
257 ACTION_BUILDER.showMessageDialog(
this,
"mapErrorUnsaved");
260 for (
int i = 0; i < tmpTilePaths.length; i++) {
271 tilePath.getTilePanel().setText(
"",
true);
280 for (
int i = 0; i < tilePaths.length; i++) {
290 tilePath.getTilePanel().mapTileRevert();
301 return tilePaths[direction];
Size2D getMapSize()
Returns the size of the first map.
A MapTilePanel extends a TilePanel with a border and makes focus traversal work within the map tile p...
Component buildSubPanel()
Creates the sub-panel that holds the buttons to attach maps or clear all paths.
A MapModel reflects the data of a map.
A MapManager manages all opened maps.
Graphical User Interface of Gridarta.
void restoreMapProperties()
Restores the settings from the map.
final TileLink [] tileLinks
The tile links for the attach map algorithm.
Settings that apply to a project.
AbstractMapTilePane(@NotNull final MapManager< G, A, R > mapManager, @NotNull final ProjectSettings projectSettings, @NotNull final MapModel< G, A, R > mapModel, @NotNull final MapLink[][] tileLink, @NotNull final Direction[] directionMapping, @NotNull final int[] nextFocus, @NotNull final FileFilter mapFileFilter)
Create an AbstractMapTilePane.
Exception thrown if a map file cannot be saved.
static Component buildTilePanels(@NotNull final MapTilePanel[] tilePanels, @NotNull final Direction[] directionMapping)
Builds the tile panel.
final int [] nextFocus
Indices of next focus.
A tile panel displays exactly one direction for map tiling.
static final long serialVersionUID
Serial Version UID.
final ProjectSettings projectSettings
The project settings instance.
void attachTiledMaps(@NotNull final MapModel< G, A, R > mapModel, @NotNull final String[] tilePaths, @NotNull final File mapsDirectory, final boolean performAction)
Updates tile paths of a map.
static TileLink newTileLink(@NotNull final String key, @NotNull final MapLink[] mapLinks, @NotNull final Direction revLink)
Creates a new TileLink.
MapTilePanel getTilePath(final int direction)
Returns one tile path.
MapTilePanel [] buildComponents(@NotNull final Direction[] directionMapping)
Builds the components of this panel.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
Exception thrown if a map file cannot be loaded.
A Panel for managing the tiling of maps.
Base package of all Gridarta classes.
void mapTilesAttach()
Action method for tiles attaching automatically.
Size2D getOtherMapSize()
Returns the size of the second map.
Reflects a game object (object on a map).
static final ActionBuilder ACTION_BUILDER
Action Builder.
String getText()
Returns the text.
final MapModel< G, A, R > mapModel
The map in context.
void setText(@NotNull final String text, final boolean keepRA)
Sets the text.
final MapTilePanel [] tilePaths
The JTextFields with the tile paths.
GameObjects are the objects based on Archetypes found on maps.
int getWidth()
Returns the width of the area.
void modifyMapProperties()
Invoke this method if the dialog using this pane is confirmed with OK to write the information from t...
Utility class for ActionBuilder related functions.
File getMapFile()
Returns the map File of the first map.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
final FileFilter mapFileFilter
Swing FileFilter for map files.
Exception thrown if an operation is attempted on an unsaved map.
MapTilePanel [] createTilePanels(final int directions)
Builds all MapTilePanels for all directions.
final boolean canAttachMaps
Whether "attach maps" function is available.
void mapTilesClear()
Action method for tiles clearing paths.
MapFile getMapFile()
Returns the map file.
Border DIALOG_BORDER
The Border object to be used when creating dialogs.
File getFile()
Returns a File for this map file.
File getMapsDirectory()
Returns the default maps directory.
void setTilePath(@NotNull Direction direction, @NotNull String tilePath)
Sets a tile path.
int getHeight()
Returns the height of the area.
String getTilePath(@NotNull Direction direction)
Returns a tile path.
The location of a map file with a map directory.
Exception thrown if the size of a map file is unexpected.
Interface for MapArchObjects.
final AttachTiledMaps< G, A, R > attachTiledMaps
Defines common UI constants used in different dialogs.
final MapArchObject< A > mapArchObject
The MapArchObject to show.
Attaches maps to adjacent tiled maps.
This class implements a layout that is similar to java.awt.BorderLayout but implements those directio...
String getMapPath()
Returns the map path that could not be loaded.