20 package net.sf.gridarta.gui.map.mapview;
22 import java.awt.BorderLayout;
23 import java.awt.Component;
24 import java.awt.Point;
25 import java.beans.PropertyVetoException;
27 import javax.swing.Action;
28 import javax.swing.JComponent;
29 import javax.swing.JInternalFrame;
30 import javax.swing.JScrollPane;
31 import javax.swing.KeyStroke;
32 import javax.swing.WindowConstants;
54 import net.
sf.japi.swing.action.ActionBuilder;
55 import net.
sf.japi.swing.action.ActionBuilderFactory;
56 import org.apache.log4j.Category;
57 import org.apache.log4j.Logger;
58 import org.jetbrains.annotations.NotNull;
59 import org.jetbrains.annotations.Nullable;
77 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
128 public void mapSizeChanged(@NotNull
final Size2D newSize) {
138 public void mapObjectsChanged(@NotNull
final Set<G> gameObjects, @NotNull
final Set<G> transientGameObjects) {
148 public void mapFileChanged(@Nullable
final MapFile oldMapFile) {
153 public void modifiedChanged() {
167 public void mapMetaChanged() {
172 public void mapSizeChanged(@NotNull
final Size2D mapSize) {
205 public DefaultMapView(@NotNull
final MapControl<G, A, R> mapControl,
final int number, @NotNull
final PathManager pathManager, @NotNull
final MapGrid mapGrid, @NotNull
final MapCursor<G, A, R> mapCursor, @NotNull
final AbstractMapRenderer<G, A, R> renderer, @Nullable
final Point viewPosition,
final int xScrollDistance,
final int yScrollDistance) {
207 internalFrame =
new JInternalFrame(
getWindowTitle(mapControl, number, pathManager),
true,
true,
true,
true);
215 mapModel.addMapModelListener(mapModelListener);
216 mapModel.getMapArchObject().addMapArchObjectListener(mapArchObjectListener);
217 mapControl.addMapControlListener(mapControlListener);
218 internalFrame.getContentPane().setLayout(
new BorderLayout());
219 internalFrame.getContentPane().add(mapCursorTracker.getScrollPane(), BorderLayout.CENTER);
220 internalFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
221 internalFrame.setAutoscrolls(
true);
222 internalFrame.setFocusable(
true);
239 final Action action = ACTION_BUILDER.getAction(key);
240 if (action != null) {
242 if (keyStroke1 != null) {
243 internalFrame.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke1, key);
246 if (keyStroke2 != null) {
247 internalFrame.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke2, key);
249 internalFrame.getActionMap().put(key, action);
255 internalFrame.getContentPane().remove(mapCursorTracker.
getScrollPane());
261 mapModel.
getMapArchObject().removeMapArchObjectListener(mapArchObjectListener);
289 final MapFile mapFile = mapControl.getMapModel().getMapFile();
290 final String mapPath;
291 if (mapFile == null) {
292 mapPath =
"<unsaved>";
296 return mapPath +
" [ " + mapControl.getMapModel().getMapArchObject().getMapName() +
" ] (" + number +
")" + (mapControl.getMapModel().isModified() ?
" *" :
"");
314 internalFrame.setSelected(
true);
315 }
catch (
final PropertyVetoException e) {
316 LOG.warn(
"Unexpected exception", e);
318 internalFrame.setVisible(
true);
319 internalFrame.requestFocus();
320 internalFrame.restoreSubcomponentFocus();
final PathManager pathManager
The PathManager for converting path names.
Interface for listeners listening on map arch object changes.
static KeyStroke getAlternativeShortcut(@NotNull final Action action)
Returns the alternative shortcut of an Action.
final JInternalFrame internalFrame
The JInternalFrame instance associated with this map view.
This class contains methods for converting relative map paths to absolute map paths and vice versa...
void updateTitle()
Update the Map-Window Title (according to name and changeFlag).
A MapModel reflects the data of a map.
Graphical User Interface of Gridarta.
Reading and writing of maps, handling of paths.
MapRenderer getRenderer()
This package contains the framework for validating maps.
AbsoluteMapPath getMapPath()
Returns the map path within getMapsDir().
final MapArchObjectListener mapArchObjectListener
The MapArchObjectListener used to detect changes in the map model that should be reflected in the win...
Interface for listeners listening on MapModel events.
Utility class implementing Action related functions.
MapCursor provides methods to move and drag on map.
final MapControl< G, A, R > mapControl
The controller of this view.
final MapCursor< G, A, R > mapCursor
The MapCursor of this map view.
MapModel< G, A, R > getMapModel()
Returns the map model.
JScrollPane getScrollPane()
void closeNotify()
Must be called when this instance is not used anymore.
Base package of all Gridarta classes.
Abstract base class for classes implementing MapRenderer.
Reflects a game object (object on a map).
final ErroneousMapSquares< G, A, R > erroneousMapSquares
The erroneous MapSquares.
final AbstractMapRenderer< G, A, R > renderer
The AbstractMapRenderer for rendering the map model.
final MapCursorTracker< G, A, R > mapCursorTracker
The erroneous MapSquares.
Interface for listeners listening on changes in MapControl instances.
abstract void closeNotify()
Must be called when this renderer is not used anymore.
GameObjects are the objects based on Archetypes found on maps.
JInternalFrame getInternalFrame()
static final ActionBuilder ACTION_BUILDER
Action Builder to create Actions.
final MapModel< G, A, R > mapModel
The MapModel of this map view.
2D-Grid containing flags for selection, pre-selection, cursor, warnings and errors.
void installAccelerator(@NotNull final String key)
Installs accelerator keys for an action.
JScrollPane getScrollPane()
Returns the JScrollPane of the renderer.
Base classes for rendering maps.
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
static KeyStroke getShortcut(@NotNull final Action action)
Returns the shortcut of an Action.
static final Category LOG
The Logger for printing log messages.
MapControl< G, A, R > getMapControl()
void closeNotify()
Must be called when this instance is not used anymore.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
final MapGrid mapGrid
The MapGrid of this map view.
Abstract base class for MapView implementations.
final int number
View number.
Currently nothing more than a marker interface for unification.
final MapControlListener< G, A, R > mapControlListener
The MapControlListener used to detect changes in the map control that should be reflected in the wind...
static String getWindowTitle(@NotNull final MapControl<?, ?, ?> mapControl, final int number, @NotNull final PathManager pathManager)
Returns the title for the map window.
An interface for classes that collect errors.
Common interface for renderers of map control instances.
DefaultMapView(@NotNull final MapControl< G, A, R > mapControl, final int number, @NotNull final PathManager pathManager, @NotNull final MapGrid mapGrid, @NotNull final MapCursor< G, A, R > mapCursor, @NotNull final AbstractMapRenderer< G, A, R > renderer, @Nullable final Point viewPosition, final int xScrollDistance, final int yScrollDistance)
Create a new instance.
final MapModelListener< G, A, R > mapModelListener
The MapModelListener used to detect changes in the map model that should be reflected in the window t...
Default MapView implementation.
The location of a map file with a map directory.
Interface for MapArchObjects.
The class Size2D represents a 2d rectangular area.
void removeMapControlListener(@NotNull MapControlListener< G, A, R > listener)
Unregisters a MapControlListener.