Gridarta Editor
GameObjectAttributesModel.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.panel.gameobjectattributes;
21 
22 import java.util.ArrayList;
23 import java.util.Collection;
27 import org.jetbrains.annotations.NotNull;
28 import org.jetbrains.annotations.Nullable;
29 
34 public class GameObjectAttributesModel<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> {
35 
39  @Nullable
40  private G selectedGameObject;
41 
45  private final Collection<GameObjectAttributesModelListener<G, A, R>> listeners = new ArrayList<>();
46 
52  public void setSelectedGameObject(@Nullable final G selectedGameObject) {
53  if (this.selectedGameObject == selectedGameObject) {
54  return;
55  }
56 
57  assert selectedGameObject == null || selectedGameObject.isHead();
58  this.selectedGameObject = selectedGameObject;
60  listener.selectedGameObjectChanged(selectedGameObject);
61  }
62  }
63 
69  listener.refreshSelectedGameObject();
70  }
71  }
72 
77  @Nullable
78  public G getSelectedGameObject() {
79  return selectedGameObject;
80  }
81 
87  listeners.add(listener);
88  }
89 
95  listeners.add(listener);
96  }
97 
98 }
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel.listeners
final Collection< GameObjectAttributesModelListener< G, A, R > > listeners
The registered listeners.
Definition: GameObjectAttributesModel.java:45
net.sf
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel.setSelectedGameObject
void setSelectedGameObject(@Nullable final G selectedGameObject)
If a game object is selected, the MapArchPanels (bottom right windows) get updated.
Definition: GameObjectAttributesModel.java:52
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel.fireRefreshSelectedGameObject
void fireRefreshSelectedGameObject()
Notifies all listeners that the selected game object has changed.
Definition: GameObjectAttributesModel.java:67
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel.removeGameObjectAttributesModelListener
void removeGameObjectAttributesModelListener(@NotNull final GameObjectAttributesModelListener< G, A, R > listener)
Removes a listener to be notified.
Definition: GameObjectAttributesModel.java:94
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel
The model of the game object attributes dialog.
Definition: GameObjectAttributesModel.java:34
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel.selectedGameObject
G selectedGameObject
The selected game object.
Definition: GameObjectAttributesModel.java:40
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel.addGameObjectAttributesModelListener
void addGameObjectAttributesModelListener(@NotNull final GameObjectAttributesModelListener< G, A, R > listener)
Adds a listener to be notified.
Definition: GameObjectAttributesModel.java:86
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModelListener< G, A, R >
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel.getSelectedGameObject
G getSelectedGameObject()
Returns the selected game object.
Definition: GameObjectAttributesModel.java:78