Gridarta Editor
GameObjectTextEditorTab.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.mainwindow;
21 
22 import java.awt.event.FocusEvent;
23 import java.awt.event.FocusListener;
24 import java.util.Set;
42 import net.sf.gridarta.utils.Size2D;
43 import org.jetbrains.annotations.NotNull;
44 import org.jetbrains.annotations.Nullable;
45 
50 public class GameObjectTextEditorTab<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends Tab {
51 
55  @NotNull
57 
61  @Nullable
63 
68 
72  @Nullable
73  private G selectedGameObject;
74 
79  private boolean isInMapTransaction;
80 
84  @NotNull
86 
87  @Override
88  public void currentMapChanged(@Nullable final MapControl<G, A, R> mapControl) {
89  if (currentMapControl != null) {
93  }
94  currentMapControl = mapControl;
95  if (currentMapControl != null) {
99  }
100  }
101 
102  @Override
103  public void mapCreated(@NotNull final MapControl<G, A, R> mapControl, final boolean interactive) {
104  // ignore
105  }
106 
107  @Override
108  public void mapClosing(@NotNull final MapControl<G, A, R> mapControl) {
109  // ignore
110  }
111 
112  @Override
113  public void mapClosed(@NotNull final MapControl<G, A, R> mapControl) {
114  // ignore
115  }
116 
117  };
118 
124  @NotNull
126 
127  @Override
128  public void preBeginTransaction() {
130  isInMapTransaction = true;
131  }
132 
133  @Override
134  public void beginTransaction(@NotNull final String name) {
135  // ignore
136  }
137 
138  @Override
139  public void endTransaction(@NotNull final SavedSquares<G, A, R> savedSquares) {
140  // ignore
141  }
142 
143  @Override
144  public void postEndTransaction() {
145  isInMapTransaction = false;
146  }
147 
148  };
149 
153  @NotNull
155 
156  @Override
157  public void mapSizeChanged(@NotNull final Size2D newSize) {
158  // ignore
159  }
160 
161  @Override
162  public void mapSquaresChanged(@NotNull final Set<MapSquare<G, A, R>> mapSquares) {
163  if (selectedGameObject == null) {
164  return;
165  }
166 
167  final G topGameObject = selectedGameObject.getTopContainer();
168  for (final Iterable<G> mapSquare : mapSquares) {
169  for (final G gameObject : mapSquare) {
170  if (gameObject == topGameObject) {
171  refreshDisplay();
172  }
173  }
174  }
175  }
176 
177  @Override
178  public void mapObjectsChanged(@NotNull final Set<G> gameObjects, @NotNull final Set<G> transientGameObjects) {
179  for (final GameObject<G, A, R> gameObject : gameObjects) {
180  if (selectedGameObject == gameObject.getHead()) {
181  refreshDisplay();
182  }
183  }
184  }
185 
186  @Override
187  public void errorsChanged(@NotNull final ErrorCollector<G, A, R> errors) {
188  // ignore
189  }
190 
191  @Override
192  public void mapFileChanged(@Nullable final MapFile oldMapFile) {
193  // ignore
194  }
195 
196  @Override
197  public void modifiedChanged() {
198  // ignore
199  }
200 
201  };
202 
215  public GameObjectTextEditorTab(@NotNull final String ident, @NotNull final GameObjectTextEditor gameObjectTextEditor, @NotNull final Location defaultLocation, final boolean alternativeLocation, final int index, final boolean defaultOpen, @NotNull final SelectedSquareModel<G, A, R> selectedSquareModel, @NotNull final MapManager<G, A, R> mapManager) {
216  super(ident, gameObjectTextEditor, defaultLocation, alternativeLocation, index, defaultOpen);
217  this.gameObjectTextEditor = gameObjectTextEditor;
218  selectedSquareModel.addSelectedSquareListener((mapSquare, gameObject) -> {
220  selectedGameObject = gameObject;
221  refreshDisplay();
222  });
223  currentMapControl = mapManager.getCurrentMap();
224  if (currentMapControl != null) {
228  }
229  mapManager.addMapManagerListener(mapManagerListener);
230  selectedGameObject = selectedSquareModel.getSelectedGameObject();
231  refreshDisplay();
232  gameObjectTextEditor.getTextPane().addFocusListener(new FocusListener() {
233 
234  @Override
235  public void focusGained(final FocusEvent e) {
236  // ignore
237  }
238 
239  @Override
240  public void focusLost(final FocusEvent e) {
242  }
243 
244  });
245  }
246 
250  private void autoApplyArchPanelChanges() {
251  final GameObject<G, A, R> gameObject = selectedGameObject;
252  if (gameObject == null || isInAutoApplyArchPanelChanges || isInMapTransaction) {
253  return;
254  }
255 
256  final MapSquare<G, A, R> mapSquare = gameObject.getMapSquareOptional();
257  if (mapSquare == null) {
258  return;
259  }
260 
261  final MapModel<G, A, R> mapModel = mapSquare.getMapModel();
262 
264  try {
265  mapModel.beginTransaction("Change object attributes");
266  try {
268  } finally {
269  mapModel.endTransaction();
270  }
271  } finally {
273  }
274  }
275 
279  private void refreshDisplay() {
281  }
282 
283 }
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.model.mapmanager
Definition: AbstractMapManager.java:20
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.refreshDisplay
void refreshDisplay()
Refreshes the tab's state from a selectedGameObject.
Definition: GameObjectTextEditorTab.java:279
net.sf.gridarta.model.mapmodel.MapModel
A MapModel reflects the data of a map.
Definition: MapModel.java:75
net.sf.gridarta.gui.panel
net.sf.gridarta.gui.utils.tabbedpanel.Tab.alternativeLocation
boolean alternativeLocation
Whether the tab is shown in the alternative location (.
Definition: Tab.java:160
net.sf.gridarta.model.mapmanager.MapManager
A MapManager manages all opened maps.
Definition: MapManager.java:37
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.selectedGameObject
G selectedGameObject
The currently selected game object.
Definition: GameObjectTextEditorTab.java:73
net.sf.gridarta.model.mapmodel.MapSquare
A single Map Square.
Definition: MapSquare.java:45
net.sf.gridarta.model.mapmodel.MapModel.endTransaction
void endTransaction()
End a transaction.
net.sf.gridarta.model.mapmodel.MapTransactionListener
Interface for listeners listening on map transactions of MapModels.
Definition: MapTransactionListener.java:33
net.sf
net.sf.gridarta.model.mapmodel.MapModel.beginTransaction
void beginTransaction(@NotNull String name)
Starts a new transaction.
net.sf.gridarta.model.mapmanager.MapManagerListener
Interface for listeners listening to MapManager changes.
Definition: MapManagerListener.java:42
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab
The Tab displaying the game object text editor.
Definition: GameObjectTextEditorTab.java:50
net.sf.gridarta.model.mapmodel
Definition: AboveFloorInsertionMode.java:20
net.sf.gridarta.gui.utils.tabbedpanel.Tab.index
final int index
The tab's index for ordering.
Definition: Tab.java:165
net.sf.gridarta.gui.panel.gameobjecttexteditor.GameObjectTextEditor
Implements the "Game Object Text Editor".
Definition: GameObjectTextEditor.java:53
net.sf.gridarta.gui.panel.gameobjecttexteditor
Definition: GameObjectTextEditor.java:20
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.GameObjectTextEditorTab
GameObjectTextEditorTab(@NotNull final String ident, @NotNull final GameObjectTextEditor gameObjectTextEditor, @NotNull final Location defaultLocation, final boolean alternativeLocation, final int index, final boolean defaultOpen, @NotNull final SelectedSquareModel< G, A, R > selectedSquareModel, @NotNull final MapManager< G, A, R > mapManager)
Creates a new instance.
Definition: GameObjectTextEditorTab.java:215
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.mainwindow.GameObjectTextEditorTab.mapModelListener
final MapModelListener< G, A, R > mapModelListener
The map model listener which is attached to currentMapControl.
Definition: GameObjectTextEditorTab.java:154
net.sf.gridarta.gui.panel.gameobjecttexteditor.GameObjectTextEditor.applyChanges
void applyChanges(@NotNull final GameObject<?, ?, ?> gameObject)
Updates a GameObject's attributes from the input field.
Definition: GameObjectTextEditor.java:107
net.sf.gridarta.model.mapcontrol
Definition: DefaultMapControl.java:20
net.sf.gridarta.model.mapmodel.MapModel.addMapModelListener
void addMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Register a map listener.
net.sf.gridarta.gui.utils.tabbedpanel.Tab
A tab in a TabbedPanel component.
Definition: Tab.java:54
net.sf.gridarta.gui.panel.gameobjecttexteditor.GameObjectTextEditor.getTextPane
Component getTextPane()
Returns the text input pane.
Definition: GameObjectTextEditor.java:168
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.model.mapmodel.SavedSquares
Records a set of changed map squares.
Definition: SavedSquares.java:41
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.isInMapTransaction
boolean isInMapTransaction
Records whether a map transaction is active.
Definition: GameObjectTextEditorTab.java:79
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
errors
errors
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:1
net.sf.gridarta.gui.utils.tabbedpanel.Tab.ident
final String ident
The tab's identification string.
Definition: Tab.java:106
net.sf.gridarta.model.mapmodel.MapModel.removeMapModelListener
void removeMapModelListener(@NotNull MapModelListener< G, A, R > listener)
Unregister a map listener.
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.panel.selectedsquare.SelectedSquareModel
The model component of the selected square control.
Definition: SelectedSquareModel.java:35
net.sf.gridarta.gui.utils.tabbedpanel
Definition: ButtonList.java:20
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.mapManagerListener
final MapManagerListener< G, A, R > mapManagerListener
The map manager listener.
Definition: GameObjectTextEditorTab.java:85
net.sf.gridarta.model.mapmodel.MapModel.removeMapTransactionListener
void removeMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Unregisters a map transaction listener.
net.sf.gridarta.model.validation.ErrorCollector
An interface for classes that collect errors.
Definition: ErrorCollector.java:33
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.gameObjectTextEditor
final GameObjectTextEditor gameObjectTextEditor
The displayed GameObjectTextEditor instance.
Definition: GameObjectTextEditorTab.java:56
net.sf.gridarta.model.validation
This package contains the framework for validating maps.
Definition: AbstractValidator.java:20
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.autoApplyArchPanelChanges
void autoApplyArchPanelChanges()
Applies pending changed.
Definition: GameObjectTextEditorTab.java:250
net.sf.gridarta.model.mapmodel.MapFile
The location of a map file with a map directory.
Definition: MapFile.java:31
net.sf.gridarta.model.mapmodel.MapModel.addMapTransactionListener
void addMapTransactionListener(@NotNull MapTransactionListener< G, A, R > listener)
Registers a map transaction listener.
net.sf.gridarta.model.mapmodel.MapSquare.getMapModel
MapModel< G, A, R > getMapModel()
Returns the MapModel this map square is part of.
Definition: MapSquare.java:99
net.sf.gridarta.gui.utils.borderpanel.Location
A location.
Definition: Location.java:33
net.sf.gridarta.model.mapmodel.MapModelListener
Interface for listeners listening on MapModel events.
Definition: MapModelListener.java:36
net.sf.gridarta.gui.panel.gameobjecttexteditor.GameObjectTextEditor.refreshDisplay
Severity refreshDisplay(@Nullable final GameObject<?, ?, ?> gameObject)
Refreshes the input field to show the attributes of a {}.
Definition: GameObjectTextEditor.java:118
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.currentMapControl
MapControl< G, A, R > currentMapControl
Last known active map.
Definition: GameObjectTextEditorTab.java:62
net.sf.gridarta.model.gameobject.GameObject.getMapSquareOptional
MapSquare< G, A, R > getMapSquareOptional()
Returns the MapSquare this game object is part of.
net.sf.gridarta.gui.utils.borderpanel
Definition: BorderPanel.java:20
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.isInAutoApplyArchPanelChanges
boolean isInAutoApplyArchPanelChanges
Whether autoApplyArchPanelChanges() is currently running.
Definition: GameObjectTextEditorTab.java:67
net.sf.gridarta.gui.mainwindow.GameObjectTextEditorTab.mapTransactionListener
final MapTransactionListener< G, A, R > mapTransactionListener
The map transaction listener which is attached to {}.
Definition: GameObjectTextEditorTab.java:125
net.sf.gridarta.gui.utils.tabbedpanel.Tab.setSeverity
void setSeverity(@NotNull final Severity severity)
Sets the tab's Severity.
Definition: Tab.java:437
net.sf.gridarta.model.mapcontrol.MapControl
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
net.sf.gridarta.model.mapcontrol.MapControl.getMapModel
MapModel< G, A, R > getMapModel()
Returns the map model.
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.utils
Definition: AnimationComponent.java:20
net.sf.gridarta.gui.panel.selectedsquare
Displays the contents of the currently selected map square.
Definition: CellRenderer.java:20
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20