Gridarta Editor
MapMenuAction.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.gui.mapmenu;
21 
22 import java.awt.Image;
23 import java.awt.event.ActionEvent;
24 import java.io.IOException;
25 import javax.swing.AbstractAction;
26 import javax.swing.ImageIcon;
31 import net.sf.japi.swing.action.ActionBuilder;
32 import net.sf.japi.swing.action.ActionBuilderFactory;
33 import org.jetbrains.annotations.NotNull;
34 
39 public class MapMenuAction extends AbstractAction {
40 
44  private static final long serialVersionUID = 1L;
45 
49  @NotNull
50  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
51 
55  @NotNull
57 
61  @NotNull
63 
67  @NotNull
69 
76  public MapMenuAction(@NotNull final MapMenuEntryMap mapMenuEntryMap, @NotNull final MapViewsManager<?, ?, ?> mapViewsManager, @NotNull final FileControl<?, ?, ?> fileControl) {
77  this.mapMenuEntryMap = mapMenuEntryMap;
78  this.mapViewsManager = mapViewsManager;
79  this.fileControl = fileControl;
80  }
81 
82  @Override
83  public void actionPerformed(@NotNull final ActionEvent e) {
84  final MapFile mapFile = mapMenuEntryMap.getMapFile();
85  try {
86  mapViewsManager.openMapFileWithView(mapFile, null, null);
87  } catch (final IOException ex) {
88  fileControl.reportLoadError(mapFile.getFile(), ex.getMessage());
89  }
90  }
91 
96  public void update(@NotNull final MapImageCache<?, ?, ?> mapImageCache) {
97  final MapFile mapFile = mapMenuEntryMap.getMapFile();
98  final String title = mapMenuEntryMap.getTitle();
99  final String shortDescription = ACTION_BUILDER.format("mapItem.shortdescriptionformat", title, mapFile);
100  putValue(SHORT_DESCRIPTION, shortDescription);
101  putValue(MNEMONIC_KEY, null);
102  putValue(NAME, title);
103  final Image icon = mapImageCache.getOrCreateIcon(mapFile.getFile());
104  if (icon != null) {
105  putValue(SMALL_ICON, new ImageIcon(icon));
106  } else {
107  putValue(SMALL_ICON, null);
108  }
109  }
110 
111  @NotNull
112  @Override
113  public Object clone() throws CloneNotSupportedException {
114  return super.clone();
115  }
116 
117 }
MapMenuAction(@NotNull final MapMenuEntryMap mapMenuEntryMap, @NotNull final MapViewsManager<?, ?, ?> mapViewsManager, @NotNull final FileControl<?, ?, ?> fileControl)
Creates a new instance.
Graphical User Interface of Gridarta.
String getTitle()
Returns the entry&#39;s title.
void update(@NotNull final MapImageCache<?, ?, ?> mapImageCache)
Updates properties.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
static final long serialVersionUID
The serial version UID.
Base package of all Gridarta classes.
void reportLoadError(@Nullable File file, @NotNull String message)
MapView< G, A, R > openMapFileWithView(@NotNull final MapFile mapFile, @Nullable final Point viewPosition, @Nullable final Point centerSquare)
Load a map file and create a map view.
final FileControl<?, ?, ?> fileControl
The FileControl for reporting errors.
final MapMenuEntryMap mapMenuEntryMap
The associated MapMenuEntryMap instance.
MapFile getMapFile()
Returns the map file.
Caches icon and preview images for map files.
Base classes for rendering maps.
An AbstractAction for a MapMenuEntryMap instance.
void actionPerformed(@NotNull final ActionEvent e)
final MapViewsManager<?, ?, ?> mapViewsManager
The MapViewsManager for opening map files.
A MapMenuEntry that represents a map.
File getFile()
Returns a File for this map file.
Definition: MapFile.java:102
The location of a map file with a map directory.
Definition: MapFile.java:31