20 package net.sf.gridarta.gui.mapdesktop;
22 import java.beans.PropertyVetoException;
23 import java.util.IdentityHashMap;
24 import java.util.Iterator;
26 import javax.swing.Action;
27 import javax.swing.Icon;
28 import javax.swing.ImageIcon;
29 import javax.swing.JDesktopPane;
30 import javax.swing.JInternalFrame;
31 import javax.swing.JMenu;
32 import javax.swing.event.InternalFrameEvent;
33 import javax.swing.event.InternalFrameListener;
47 import net.
sf.japi.swing.action.ActionBuilder;
48 import net.
sf.japi.swing.action.ActionBuilderFactory;
49 import net.
sf.japi.swing.action.ActionMethod;
50 import org.apache.log4j.Category;
51 import org.apache.log4j.Logger;
52 import org.jetbrains.annotations.NotNull;
53 import org.jetbrains.annotations.Nullable;
72 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
141 public void mapCreated(@NotNull
final MapControl<G, A, R> mapControl,
final boolean interactive) {
185 while (it.hasNext()) {
199 public MapDesktop(@NotNull
final MapViewManager<G, A, R> mapViewManager, @NotNull
final MapManager<G, A, R> mapManager, @NotNull
final MapImageCache<G, A, R> mapImageCache, @NotNull
final MapViewsManager<G, A, R> mapViewsManager) {
204 mapManager.addMapManagerListener(mapManagerListener);
205 mapImageCache.addMapImageCacheListener(mapImageCacheListener);
216 final JInternalFrame internalFrame = mapView.getInternalFrame();
217 if (internalFrame.isIcon()) {
219 internalFrame.setIcon(
false);
220 }
catch (
final PropertyVetoException e) {
221 LOG.warn(ACTION_BUILDER.format(
"logUnexpectedException", e));
227 internalFrame.requestFocus();
228 internalFrame.restoreSubcomponentFocus();
236 final JInternalFrame internalFrame = mapView.getInternalFrame();
237 internalFrame.removeInternalFrameListener(mapViewFrameListeners.remove(mapView));
239 if (windowActions.remove(mapView) == null) {
242 remove(internalFrame);
246 if (getSelectedFrame() == mapView) {
247 setSelectedFrame(null);
249 internalFrame.dispose();
262 windowActions.put(mapView, windowAction);
265 final JInternalFrame internalFrame = mapView.getInternalFrame();
266 final MapViewFrameListener mapViewFrameListener =
new MapViewFrameListener(mapView);
267 if (mapViewFrameListeners.put(mapView, mapViewFrameListener) != null) {
270 internalFrame.addInternalFrameListener(mapViewFrameListener);
274 internalFrame.setVisible(
true);
275 internalFrame.setBounds(0, 0, getWidth(), getHeight());
277 internalFrame.setMaximum(
true);
278 }
catch (
final PropertyVetoException e) {
279 LOG.error(
"PropertyVetoException: " + e);
289 final Action windowAction = windowActions.get(mapView);
290 assert windowAction != null;
291 final Icon icon =
new ImageIcon(mapImageCache.
getOrCreateIcon(mapView.getMapControl()));
292 mapView.getInternalFrame().setFrameIcon(icon);
293 windowAction.putValue(Action.SMALL_ICON, icon);
304 assert windowAction != null;
306 menu.add(windowAction);
316 final JInternalFrame internalFrame = mapView.getInternalFrame();
317 internalFrame.moveToFront();
318 setSelectedFrame(internalFrame);
349 final JInternalFrame internalFrame = mapView.getInternalFrame();
350 if (internalFrame.isIcon()) {
351 if (!careAboutIconification) {
353 internalFrame.setIcon(
false);
354 }
catch (
final PropertyVetoException e) {
355 LOG.warn(ACTION_BUILDER.format(
"logUnexpectedException", e));
390 if (aPrevWindow != null) {
394 if (aNextWindow != null) {
435 public void setAction(@NotNull
final Action action, @NotNull
final String name) {
436 if (name.equals(
"prevWindow")) {
437 aPrevWindow = action;
438 }
else if (name.equals(
"nextWindow")) {
439 aNextWindow = action;
441 throw new IllegalArgumentException();
boolean doNextWindow(final boolean performAction)
Executes the "next window" action.
void addMapViewsListener(@NotNull final MapControl< G, A, R > mapControl, @NotNull final MapViewsListener< G, A, R > listener)
Adds a MapViewsListener to be notified of events.
void addMapView(@NotNull final MapView< G, A, R > mapView)
Adds a map view.
final MapManager< G, A, R > mapManager
The MapManager to use.
Image getOrCreateIcon(@NotNull final File mapFile)
Returns an icon Image for a given map file.
void removeMapViewsListener(@NotNull final MapControl< G, A, R > mapControl, @NotNull final MapViewsListener< G, A, R > listener)
Removes a MapViewsListener to be notified of events.
void mapViewFocusGainedNotify(@NotNull final MapView< G, A, R > mapView)
Notifies that the given map view is now set as the current one.
A MapManager manages all opened maps.
void closeMapView(@NotNull final MapView< G, A, R > mapView)
Invoked when the user wants to close a map view.
Graphical User Interface of Gridarta.
void internalFrameOpened(@NotNull final InternalFrameEvent e)
The JDesktopPane containing all map views.
void removeMapView(@NotNull final MapView< G, A, R > mapView)
Removes (closes) the map view.
static final long serialVersionUID
The serial version UID.
final MapViewsListener< G, A, R > mapViewsListener
The MapViewsListener attached to all existing MapControls for maps.
void internalFrameIconified(@NotNull final InternalFrameEvent e)
boolean doPrevWindow(final boolean performAction)
Executes the "prev window" action.
MapDesktop(@NotNull final MapViewManager< G, A, R > mapViewManager, @NotNull final MapManager< G, A, R > mapManager, @NotNull final MapImageCache< G, A, R > mapImageCache, @NotNull final MapViewsManager< G, A, R > mapViewsManager)
Creates a new instance.
Stores all existing MapViews.
void updateFrameIcon(@NotNull final MapView< G, A, R > mapView)
Updates the frame icon to the current icon image.
void internalFrameActivated(@NotNull final InternalFrameEvent e)
void internalFrameDeiconified(@NotNull final InternalFrameEvent e)
void nextWindow()
Gives focus to the previous window.
final Map< MapView< G, A, R >, MapViewFrameListener > mapViewFrameListeners
The MapViewFrameListeners associated with MapViews.
void prevWindow()
Gives focus to the next window.
void removeMapView(@NotNull final MapView< G, A, R > mapView)
Removes a map view.
void addMapView(@NotNull final MapView< G, A, R > mapView)
Adds the map view.
void addWindowAction(@NotNull final JMenu menu, @NotNull final MapView< G, A, R > mapView, final int index)
Adds an action for selecting this window to a menu.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
void internalFrameClosed(@NotNull final InternalFrameEvent e)
Action class for selecting this window.
Interface for listeners listening to MapManager changes.
Action aPrevWindow
The action for "prev window".
Action aNextWindow
The action for "next window".
void activateAndRaiseMapView(@NotNull final MapView< G, A, R > mapView)
Activates and raises the given map view.
void mapViewFocusLostNotify(@NotNull final MapView< G, A, R > mapView)
Notifies that the map views focus is lost it is inserted as the second in line to the map view vector...
final MapImageCache< G, A, R > mapImageCache
The MapImageCache to use.
The listener attached to map views.
void deactivateMapView(@NotNull final MapView< G, A, R > mapView)
Deactivates a map view.
GameObjects are the objects based on Archetypes found on maps.
void internalFrameClosing(@NotNull final InternalFrameEvent e)
void setActiveMapView(@NotNull final MapView< G, A, R > mapView)
Sets the active map view.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
static final ActionBuilder ACTION_BUILDER
The action builder.
Caches icon and preview images for map files.
final MapViewsManager< G, A, R > mapViewsManager
The MapViewsManager.
void refreshMenus()
Enables/disables the actions according to the current state.
Base classes for rendering maps.
boolean doNextWindow(final boolean performAction)
Performs or checks availability of the "next window" action.
final void setIndex(final int index)
Set the index of this action so this Action knows what Mnemonic and Accelerator to use...
void setCurrentMap(@Nullable MapControl< G, A, R > mapControl)
Sets the given map as the current one.
final Map< MapView< G, A, R >, WindowAction< G, A, R > > windowActions
The actions to select windows.
void updateFocus(final boolean careAboutIconification)
Updates the focus to the first non-iconified map window.
Interface for listeners interested in MapViewsManager related events.
final MapImageCacheListener< G, A, R > mapImageCacheListener
The MapImageCacheListener registered to mapImageCache.
void setCurrentMapView(@NotNull final MapView< G, A, R > mapView)
Sets the given level view as the current one.
final MapManagerListener< G, A, R > mapManagerListener
The MapManagerListener attached to mapManager.
final MapViewManager< G, A, R > mapViewManager
All open map views.
Currently nothing more than a marker interface for unification.
final MapView< G, A, R > mapView
The associated MapView.
A map view consists of a map grid and a map cursor, and is attached to a map control.
void internalFrameDeactivated(@NotNull final InternalFrameEvent e)
MapViewFrameListener(@NotNull final MapView< G, A, R > mapView)
Creates a new instance.
Interface for listeners interested in MapImageCache related events.
Iterator< MapView< G, A, R > > getMapViewIterator(@NotNull final MapControl< G, A, R > mapControl)
Returns an Iterator returning all MapViews of a MapControl.
boolean doPrevWindow(final boolean performAction)
Performs or checks availability of the "prev window" action.
Interface for MapArchObjects.
static final Category LOG
The Logger for printing log messages.
void activateMapView(@NotNull final MapView< G, A, R > mapView)
Activates a map view.
void setFocus(@NotNull final MapView< G, A, R > mapView)
Sets a MapView as the main view.