Gridarta Editor
AbstractGameObjectAttributesTab.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.awt.Component;
23 import java.awt.event.FocusEvent;
24 import java.awt.event.FocusListener;
25 import java.util.ArrayList;
26 import java.util.Collection;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
33 
38 public abstract class AbstractGameObjectAttributesTab<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements GameObjectAttributesTab<G, A, R> {
39 
43  private final Collection<GameObjectAttributesTabListener<G, A, R>> listeners = new ArrayList<>();
44 
48  @NotNull
50 
54  @Nullable
55  private G selectedGameObject;
56 
61  @NotNull
62  private final FocusListener focusListener = new FocusListener() {
63 
64  @Override
65  public void focusGained(final FocusEvent e) {
66  // ignore
67  }
68 
69  @Override
70  public void focusLost(final FocusEvent e) {
71  fireApply();
72  }
73 
74  };
75 
80  protected AbstractGameObjectAttributesTab(@NotNull final GameObjectAttributesModel<G, A, R> gameObjectAttributesModel) {
81  final GameObjectAttributesModelListener<G, A, R> gameObjectAttributesModelListener = new GameObjectAttributesModelListener<G, A, R>() {
82 
83  @Override
84  public void selectedGameObjectChanged(@Nullable final G selectedGameObject) {
87  }
88 
89  @Override
90  public void refreshSelectedGameObject() {
92  }
93 
94  };
95  gameObjectAttributesModel.addGameObjectAttributesModelListener(gameObjectAttributesModelListener);
96  }
97 
102  protected void setTabSeverity(@NotNull final Severity tabSeverity) {
103  if (this.tabSeverity == tabSeverity) {
104  return;
105  }
106 
107  this.tabSeverity = tabSeverity;
108  for (final GameObjectAttributesTabListener<G, A, R> listener : listeners) {
109  listener.tabSeverityChanged(this, tabSeverity);
110  }
111  }
112 
113  @Override
115  listeners.add(listener);
116  }
117 
118  @Override
120  listeners.add(listener);
121  }
122 
123  @NotNull
124  @Override
126  return tabSeverity;
127  }
128 
129  @Override
130  public void apply() {
131  if (selectedGameObject != null) {
133  }
134  }
135 
140  protected abstract void refresh(@Nullable G gameObject);
141 
146  protected abstract void apply(@NotNull G gameObject);
147 
151  private void fireApply() {
152  for (final GameObjectAttributesTabListener<G, A, R> listener : listeners) {
153  listener.apply();
154  }
155  }
156 
161  protected void addAutoApply(@NotNull final Component component) {
162  component.addFocusListener(focusListener);
163  }
164 
169  @Nullable
171  return selectedGameObject;
172  }
173 
174 }
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.getSelectedGameObject
GameObject< G, A, R > getSelectedGameObject()
Returns the currently selected GameObject.
Definition: AbstractGameObjectAttributesTab.java:170
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.getTabSeverity
Severity getTabSeverity()
Definition: AbstractGameObjectAttributesTab.java:125
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.selectedGameObject
G selectedGameObject
The currently selected game object.
Definition: AbstractGameObjectAttributesTab.java:55
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.listeners
final Collection< GameObjectAttributesTabListener< G, A, R > > listeners
The registered listeners.
Definition: AbstractGameObjectAttributesTab.java:43
net.sf
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.AbstractGameObjectAttributesTab
AbstractGameObjectAttributesTab(@NotNull final GameObjectAttributesModel< G, A, R > gameObjectAttributesModel)
Creates a new instance.
Definition: AbstractGameObjectAttributesTab.java:80
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesTab
A tab in the game object attributes panel.
Definition: GameObjectAttributesTab.java:33
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab
Base class for GameObjectAttributesTab implementations.
Definition: AbstractGameObjectAttributesTab.java:38
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.gui.utils.Severity
Severity levels for colors of tabs.
Definition: Severity.java:29
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.focusListener
final FocusListener focusListener
The focus listener to implement auto-applying.
Definition: AbstractGameObjectAttributesTab.java:62
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.removeGameObjectAttributesTabListener
void removeGameObjectAttributesTabListener(@NotNull final GameObjectAttributesTabListener< G, A, R > listener)
Definition: AbstractGameObjectAttributesTab.java:119
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.apply
void apply()
Definition: AbstractGameObjectAttributesTab.java:130
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModel< G, A, R >
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.refresh
abstract void refresh(@Nullable G gameObject)
Refreshes the display.
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.addAutoApply
void addAutoApply(@NotNull final Component component)
Registers a component that auto-applies when the focus is lost.
Definition: AbstractGameObjectAttributesTab.java:161
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.tabSeverity
Severity tabSeverity
The tab severity.
Definition: AbstractGameObjectAttributesTab.java:49
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesTabListener< G, A, R >
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.setTabSeverity
void setTabSeverity(@NotNull final Severity tabSeverity)
Sets the tab severity.
Definition: AbstractGameObjectAttributesTab.java:102
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.fireApply
void fireApply()
Notify all listeners to apply the changes.
Definition: AbstractGameObjectAttributesTab.java:151
net.sf.gridarta.gui.panel.gameobjectattributes.AbstractGameObjectAttributesTab.addGameObjectAttributesTabListener
void addGameObjectAttributesTabListener(@NotNull final GameObjectAttributesTabListener< G, A, R > listener)
Definition: AbstractGameObjectAttributesTab.java:114
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesModelListener< G, A, R >
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.utils
Definition: AnimationComponent.java:20
net.sf.gridarta.gui.utils.Severity.DEFAULT
DEFAULT
The tab contents are unchanged from defaults.
Definition: Severity.java:34