Gridarta Editor
GameObjectAttributesDialogFactory.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 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.dialog.gameobjectattributes;
21 
22 import java.awt.Frame;
23 import java.awt.Window;
24 import java.util.HashMap;
25 import java.util.Map;
26 import javax.swing.ImageIcon;
27 import javax.swing.JDialog;
28 import javax.swing.filechooser.FileFilter;
44 import net.sf.japi.swing.action.ActionBuilder;
45 import net.sf.japi.swing.action.ActionBuilderFactory;
46 import org.jetbrains.annotations.NotNull;
47 
54 public class GameObjectAttributesDialogFactory<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
55 
59  @NotNull
60  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
61 
66  @NotNull
67  private final Map<G, JDialog> dialogs = new HashMap<>();
68 
72  @NotNull
74 
78  @NotNull
79  private final Frame parent;
80 
84  @NotNull
86 
90  @NotNull
92 
96  @NotNull
98 
102  @NotNull
104 
108  @NotNull
109  private final FileFilter mapFileFilter;
110 
114  @NotNull
115  private final FileFilter scriptFileFilter;
116 
120  @NotNull
121  private final FaceObjects faceObjects;
122 
126  @NotNull
128 
132  @NotNull
134 
138  private final int undefinedSpellIndex;
139 
143  @NotNull
144  private final TreasureTree treasureTree;
145 
149  @NotNull
150  private final ImageIcon noFaceSquareIcon;
151 
155  @NotNull
156  private final ImageIcon unknownSquareIcon;
157 
161  @NotNull
163 
167  @NotNull
169 
192  public GameObjectAttributesDialogFactory(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Frame parent, @NotNull final CFTreasureListTree treasureListTree, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects, @NotNull final ProjectSettings projectSettings, @NotNull final FileFilter mapFileFilter, @NotNull final FileFilter scriptFileFilter, @NotNull final FaceObjects faceObjects, @NotNull final Spells<GameObjectSpell<G, A, R>> gameObjectSpells, @NotNull final Spells<NumberSpell> numberSpells, final int undefinedSpellIndex, @NotNull final TreasureTree treasureTree, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon, @NotNull final TextAreaDefaults textAreaDefaults, @NotNull final MapManager<G, A, R> mapManager) {
193  this.archetypeTypeSet = archetypeTypeSet;
194  this.parent = parent;
195  this.treasureListTree = treasureListTree;
196  this.faceObjectProviders = faceObjectProviders;
197  this.animationObjects = animationObjects;
198  this.projectSettings = projectSettings;
199  this.mapFileFilter = mapFileFilter;
200  this.scriptFileFilter = scriptFileFilter;
201  this.faceObjects = faceObjects;
202  this.gameObjectSpells = gameObjectSpells;
203  this.numberSpells = numberSpells;
204  this.undefinedSpellIndex = undefinedSpellIndex;
205  this.treasureTree = treasureTree;
206  this.unknownSquareIcon = unknownSquareIcon;
207  this.noFaceSquareIcon = noFaceSquareIcon;
208  this.textAreaDefaults = textAreaDefaults;
209  this.mapManager = mapManager;
210  }
211 
217  public void showAttributeDialog(@NotNull final G gameObject) {
218  final G head = gameObject.getHead();
219 
220  if (head.hasUndefinedArchetype()) {
221  ACTION_BUILDER.showMessageDialog(parent, "openAttrDialogUndefinedArchetype");
222  return;
223  }
224 
225  synchronized (dialogs) {
226  if (dialogs.containsKey(head)) {
227  dialogs.get(head).toFront();
228  } else {
230  final JDialog dialog = pane.createDialog();
231  dialogs.put(head, dialog);
232  }
233  }
234  }
235 
241  public void hideAttributeDialog(@NotNull final G gameObject) {
242  final Window dialog = dialogs.remove(gameObject);
243  if (dialog != null) {
244  dialog.dispose();
245  }
246  }
247 
248 }
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.numberSpells
final Spells< NumberSpell > numberSpells
The numbered spells.
Definition: GameObjectAttributesDialogFactory.java:133
net.sf.gridarta.model.mapmanager
Definition: AbstractMapManager.java:20
net.sf.gridarta.model.archetypetype
Defines types of GameObjects with corresponding attributes.
Definition: AbstractArchetypeAttributeInvSpell.java:20
net.sf.gridarta.textedit.textarea.TextAreaDefaults
Encapsulates default settings for a text area.
Definition: TextAreaDefaults.java:26
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.dialogs
final Map< G, JDialog > dialogs
The gameObject objects that already are shown, to avoid opening a dialog twice.
Definition: GameObjectAttributesDialogFactory.java:67
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialog.createDialog
JDialog createDialog()
Creates a new JDialog instance for this dialog.
Definition: GameObjectAttributesDialog.java:504
net.sf.gridarta.model.mapmanager.MapManager
A MapManager manages all opened maps.
Definition: MapManager.java:37
net.sf.gridarta.textedit.textarea
This package contains the other part of the script editor.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.anim.AnimationObjects
AnimationObjects is a container for AnimationObjects.
Definition: AnimationObjects.java:30
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.showAttributeDialog
void showAttributeDialog(@NotNull final G gameObject)
Shows the game object attributes dialog for a given GameObject instance.
Definition: GameObjectAttributesDialogFactory.java:217
net.sf.gridarta.model.spells.GameObjectSpell
Describes a numbered in-game spell.
Definition: GameObjectSpell.java:33
net.sf
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialog
Common base class for game object attributes dialogs.
Definition: GameObjectAttributesDialog.java:103
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.treasureTree
final TreasureTree treasureTree
The TreasureTree to use.
Definition: GameObjectAttributesDialogFactory.java:144
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.parent
final Frame parent
The parent frame for showing dialog boxes.
Definition: GameObjectAttributesDialogFactory.java:79
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.faceObjects
final FaceObjects faceObjects
The FaceObjects instance for choosing face names.
Definition: GameObjectAttributesDialogFactory.java:121
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.archetypeTypeSet
final ArchetypeTypeSet archetypeTypeSet
The list of CF type-data.
Definition: GameObjectAttributesDialogFactory.java:73
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.face.FaceObjectProviders
Provider for faces of GameObjects and Archetypes.
Definition: FaceObjectProviders.java:46
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.noFaceSquareIcon
final ImageIcon noFaceSquareIcon
The ImageIcon for no animations.
Definition: GameObjectAttributesDialogFactory.java:150
net.sf.gridarta.textedit
net.sf.gridarta.model.archetypetype.ArchetypeTypeSet
Manages ArchetypeType instances, list, and bitmask definitions.
Definition: ArchetypeTypeSet.java:40
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.treasureListTree
final CFTreasureListTree treasureListTree
The CFTreasureListTree to display.
Definition: GameObjectAttributesDialogFactory.java:85
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.unknownSquareIcon
final ImageIcon unknownSquareIcon
The ImageIcon for undefined animations.
Definition: GameObjectAttributesDialogFactory.java:156
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.scriptFileFilter
final FileFilter scriptFileFilter
The FileFilter to use for script files.
Definition: GameObjectAttributesDialogFactory.java:115
net.sf.gridarta.model.treasurelist.TreasureTree
Stores all defined treasure lists.
Definition: TreasureTree.java:32
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.animationObjects
final AnimationObjects animationObjects
The AnimationObjects instance for choosing animation names.
Definition: GameObjectAttributesDialogFactory.java:97
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.model.spells.NumberSpell
Describes a numbered in-game spell.
Definition: NumberSpell.java:28
net.sf.gridarta.model.face.FaceObjects
FaceObjects is a container for FaceObjects.
Definition: FaceObjects.java:31
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.mapManager
final MapManager< G, A, R > mapManager
The MapManager instance.
Definition: GameObjectAttributesDialogFactory.java:168
net.sf.gridarta.model.settings.ProjectSettings
Settings that apply to a project.
Definition: ProjectSettings.java:29
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory
A factory that creates dialogs for editing game object attributes.
Definition: GameObjectAttributesDialogFactory.java:54
net.sf.gridarta.model.spells
Definition: ArchetypeSetSpellLoader.java:20
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.undefinedSpellIndex
final int undefinedSpellIndex
The index for "no spell".
Definition: GameObjectAttributesDialogFactory.java:138
net.sf.gridarta.model.face
The face is the appearance of an object.
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.model.anim
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
Definition: AbstractAnimationObjects.java:20
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.faceObjectProviders
final FaceObjectProviders faceObjectProviders
The FaceObjectProviders for looking up faces.
Definition: GameObjectAttributesDialogFactory.java:91
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.model.spells.Spells
Common base class for spells and spell lists.
Definition: Spells.java:33
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.textAreaDefaults
final TextAreaDefaults textAreaDefaults
The TextAreaDefaults for text fields.
Definition: GameObjectAttributesDialogFactory.java:162
net.sf.gridarta.gui.treasurelist
Definition: CFTreasureListTree.java:20
net.sf.gridarta.model.treasurelist
Definition: ArchTreasureObj.java:20
net.sf.gridarta.gui.treasurelist.CFTreasureListTree
The CFTreasureListTree class fully manages treasurelists.
Definition: CFTreasureListTree.java:61
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.GameObjectAttributesDialogFactory
GameObjectAttributesDialogFactory(@NotNull final ArchetypeTypeSet archetypeTypeSet, @NotNull final Frame parent, @NotNull final CFTreasureListTree treasureListTree, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects, @NotNull final ProjectSettings projectSettings, @NotNull final FileFilter mapFileFilter, @NotNull final FileFilter scriptFileFilter, @NotNull final FaceObjects faceObjects, @NotNull final Spells< GameObjectSpell< G, A, R >> gameObjectSpells, @NotNull final Spells< NumberSpell > numberSpells, final int undefinedSpellIndex, @NotNull final TreasureTree treasureTree, @NotNull final ImageIcon noFaceSquareIcon, @NotNull final ImageIcon unknownSquareIcon, @NotNull final TextAreaDefaults textAreaDefaults, @NotNull final MapManager< G, A, R > mapManager)
Creates a new instance.
Definition: GameObjectAttributesDialogFactory.java:192
net.sf.gridarta.model.settings
Definition: AbstractDefaultProjectSettings.java:20
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.ACTION_BUILDER
static final ActionBuilder ACTION_BUILDER
Action Builder.
Definition: GameObjectAttributesDialogFactory.java:60
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.hideAttributeDialog
void hideAttributeDialog(@NotNull final G gameObject)
Hides the game object attributes dialog for a given GameObject instance.
Definition: GameObjectAttributesDialogFactory.java:241
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.mapFileFilter
final FileFilter mapFileFilter
The FileFilter to use for map files.
Definition: GameObjectAttributesDialogFactory.java:109
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.projectSettings
final ProjectSettings projectSettings
The ProjectSettings instance.
Definition: GameObjectAttributesDialogFactory.java:103
net.sf.gridarta.gui.dialog.gameobjectattributes.GameObjectAttributesDialogFactory.gameObjectSpells
final Spells< GameObjectSpell< G, A, R > > gameObjectSpells
The game object spells to use.
Definition: GameObjectAttributesDialogFactory.java:127