Gridarta Editor
MapFolderTreeAction.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.mapfiles;
21 
22 import java.awt.event.ActionEvent;
23 import javax.swing.AbstractAction;
24 import javax.swing.AbstractButton;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
36 public class MapFolderTreeAction<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends AbstractAction {
37 
41  private static final long serialVersionUID = 1L;
42 
46  @NotNull
48 
52  @NotNull
54 
58  @NotNull
59  private final AbstractButton menuItem;
60 
67  public MapFolderTreeAction(@NotNull final MapFolderTree<G, A, R> mapFolderTree, @NotNull final MapFolder<G, A, R> mapFolder, @NotNull final AbstractButton menuItem) {
68  super(mapFolder.getName());
69  this.mapFolderTree = mapFolderTree;
70  this.mapFolder = mapFolder;
71  this.menuItem = menuItem;
72  }
73 
74  @Override
75  public void actionPerformed(@NotNull final ActionEvent e) {
76  mapFolderTree.setActiveMapFolder(mapFolder);
77  menuItem.setSelected(mapFolderTree.getActiveMapFolder() == mapFolder);
78  }
79 
80  @Override
81  public boolean equals(@Nullable final Object obj) {
82  return !(obj == null || !(obj instanceof MapFolderTreeAction)) && mapFolder == ((MapFolderTreeAction<?, ?, ?>) obj).mapFolder;
83  }
84 
85  @Override
86  public int hashCode() {
87  return mapFolder.getDir().hashCode();
88  }
89 
90  @NotNull
91  @Override
92  protected Object clone() {
93  try {
94  return super.clone();
95  } catch (final CloneNotSupportedException ex) {
96  throw new AssertionError(ex);
97  }
98  }
99 
100 }
final MapFolderTree< G, A, R > mapFolderTree
The model the mapFolder is part of.
void actionPerformed(@NotNull final ActionEvent e)
File getDir()
Returns the base directory.
Definition: MapFolder.java:143
final MapFolder< G, A, R > mapFolder
The folder to activate.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
MapFolderTreeAction(@NotNull final MapFolderTree< G, A, R > mapFolderTree, @NotNull final MapFolder< G, A, R > mapFolder, @NotNull final AbstractButton menuItem)
Creates a new instance.
GameObjects are the objects based on Archetypes found on maps.
synchronized void setActiveMapFolder(@NotNull final MapFolder< G, A, R > mapFolder)
Sets the active map folder.
final AbstractButton menuItem
The associated menu item.
static final long serialVersionUID
The serial version UID.
MapFolder< G, A, R > getActiveMapFolder()
Returns the active map folder.
An action for the entry in the pickmaps folder menu.