Gridarta Editor
AddBookmarkAction.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.action;
21 
22 import javax.swing.Action;
35 import net.sf.japi.swing.action.ActionMethod;
36 import org.jetbrains.annotations.NotNull;
37 import org.jetbrains.annotations.Nullable;
38 
43 public class AddBookmarkAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction, MapViewManagerListener<G, A, R> {
44 
48  @NotNull
50 
54  @Nullable
56 
61  @Nullable
62  private Action action;
63 
69  public AddBookmarkAction(@NotNull final AbstractMapMenuPreferences bookmarksMapMenuPreferences) {
70  this.bookmarksMapMenuPreferences = bookmarksMapMenuPreferences;
71  }
72 
77  @ActionMethod
78  public void addBookmark() {
79  doAddBookmark(true);
80  }
81 
82  @Override
83  public void setAction(@NotNull final Action action, @NotNull final String name) {
84  this.action = action;
85  updateAction();
86  }
87 
91  private void updateAction() {
92  if (action != null) {
93  //noinspection ConstantConditions
94  action.setEnabled(doAddBookmark(false));
95  }
96  }
97 
103  private boolean doAddBookmark(final boolean performAction) {
104  final MapView<G, A, R> mapView = currentMapView;
105  if (mapView == null) {
106  return false;
107  }
108 
109  final MapControl<G, A, R> mapControl = mapView.getMapControl();
110  final MapModel<G, A, R> mapModel = mapControl.getMapModel();
111  final MapFile mapFile = mapModel.getMapFile();
112  if (mapFile == null) {
113  return false;
114  }
115 
116  if (performAction) {
117  final A mapArchObject = mapModel.getMapArchObject();
118  final EditBookmarkDialog editBookmarkDialog = new EditBookmarkDialog(mapView.getInternalFrame(), mapArchObject.getMapName());
119  if (editBookmarkDialog.showDialog()) {
120  final MapMenuEntryMap mapMenuEntry = new MapMenuEntryMap(mapFile, editBookmarkDialog.getDescription());
121  bookmarksMapMenuPreferences.addEntry(mapMenuEntry);
122  }
123  }
124 
125  return true;
126  }
127 
128  @Override
129  public void activeMapViewChanged(@Nullable final MapView<G, A, R> mapView) {
130  currentMapView = mapView;
131  updateAction();
132  }
133 
134  @Override
135  public void mapViewCreated(@NotNull final MapView<G, A, R> mapView) {
136  }
137 
138  @Override
139  public void mapViewClosing(@NotNull final MapView<G, A, R> mapView) {
140  }
141 
142 }
Action action
The action associated with this editor action.
void addBookmark()
Action method for "addBookmark".
MapView< G, A, R > currentMapView
The currently active MapView or.
A MapModel reflects the data of a map.
Definition: MapModel.java:75
Graphical User Interface of Gridarta.
Abstract base class for MapMenuPreferences implementations.
final AbstractMapMenuPreferences bookmarksMapMenuPreferences
The AbstractMapMenuPreferences for adding new bookmarks.
AddBookmarkAction(@NotNull final AbstractMapMenuPreferences bookmarksMapMenuPreferences)
Creates a new instance.
MapControl< G, A, R > getMapControl()
Return the controller of this view.
void updateAction()
Updates the enabled state of all actions.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
MapModel< G, A, R > getMapModel()
Returns the map model.
Base package of all Gridarta classes.
void addEntry(@NotNull MapMenuEntryMap mapMenuEntry)
Adds a new entry to the menu.
An EditorAction that creates a new bookmark for the current map.
Reflects a game object (object on a map).
Definition: GameObject.java:36
A global editor action.
void mapViewClosing(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view is to be closed.
A dialog that displays one bookmark and allows to edit the values.
GameObjects are the objects based on Archetypes found on maps.
Interface for listeners interested in events related to MapViewManager instances. ...
boolean doAddBookmark(final boolean performAction)
Preforms the action "add bookmark".
Base classes for rendering maps.
void activeMapViewChanged(@Nullable final MapView< G, A, R > mapView)
This event handler is called when the current map view has changed.
A getMapArchObject()
Returns the Map Arch Object with the meta information about the map.
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
A map view consists of a map grid and a map cursor, and is attached to a map control.
Definition: MapView.java:43
MapFile getMapFile()
Returns the map file.
A MapMenuEntry that represents a map.
void mapViewCreated(@NotNull final MapView< G, A, R > mapView)
This event handler is called when a map view was created.
The location of a map file with a map directory.
Definition: MapFile.java:31
JInternalFrame getInternalFrame()
Returns the JInternalFrame instance for this map view.