Gridarta Editor
MainViewActions.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.misc;
21 
22 import javax.swing.Action;
31 import net.sf.japi.swing.action.ActionMethod;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
34 
39 public class MainViewActions<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements EditorAction {
40 
44  @NotNull
45  private final MainView mainView;
46 
50  @NotNull
52 
56  @NotNull
57  private final Tab gameObjectTab;
58 
63  @NotNull
65 
70  private boolean prevTabSaved;
71 
77  @Nullable
78  private Tab prevTab;
79 
86  @Nullable
88 
99  this.mainView = mainView;
100  this.gameObjectAttributesControl = gameObjectAttributesControl;
101  this.gameObjectTab = gameObjectTab;
102  this.textEditorTab = textEditorTab;
103  }
104 
108  @ActionMethod
109  public void gameObjectTextEditor() {
112  final boolean gameObjectTextEditorIsActive = activeTab == gameObjectTab && activeTab2 == textEditorTab;
113  if (!gameObjectTextEditorIsActive) {
114  // save state and activate game object text editor
115  prevTabSaved = true;
116  prevTab = activeTab;
117  prevTab2 = activeTab2;
118 
119  gameObjectTab.getButton().setSelected(true);
122  } else if (prevTabSaved) {
123  prevTabSaved = false;
124  // restore saved state
125  if (prevTab == null) {
126  gameObjectTab.getButton().setSelected(false);
127  } else {
128  prevTab.getButton().setSelected(true);
129  prevTab = null;
130  }
131  if (prevTab2 != null) {
133  prevTab2.activate();
134  prevTab2 = null;
135  }
136  }
137  }
138 
139  @Override
140  public void setAction(@NotNull final Action action, @NotNull final String name) {
141  }
142 
143 }
name
name
Definition: ArchetypeTypeSetParserTest-ignoreDefaultAttribute1-result.txt:2
net.sf.gridarta.gui.panel
net.sf.gridarta.gui.utils.tabbedpanel.Tab.isAlternativeLocation
boolean isAlternativeLocation()
Returns whether the button is shown in the alternative location.
Definition: Tab.java:339
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesControl
Common base class for the panel that allows users to edit a GameObject's attributes.
Definition: GameObjectAttributesControl.java:73
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.gui.misc.MainViewActions.gameObjectTextEditor
void gameObjectTextEditor()
Action method to open the game object text editor.
Definition: MainViewActions.java:109
net.sf.gridarta.gui.misc.MainViewActions.prevTab
Tab prevTab
The previously active Tab before the last switch to {}.
Definition: MainViewActions.java:78
net.sf.gridarta.gui.utils.tabbedpanel.Tab.getButton
AbstractButton getButton()
Returns the AbstractButton for showing or hiding the component.
Definition: Tab.java:304
net.sf.gridarta.gui.panel.gameobjectattributes.TextEditorTab.activate
void activate()
Definition: TextEditorTab.java:71
net.sf.gridarta.gui.misc.MainViewActions.gameObjectAttributesControl
final GameObjectAttributesControl< G, A, R > gameObjectAttributesControl
The GameObjectAttributesControl to display.
Definition: MainViewActions.java:51
net.sf
net.sf.gridarta.gui.misc.MainViewActions.prevTabSaved
boolean prevTabSaved
Whether a previously selected tab has been remembered.
Definition: MainViewActions.java:70
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.utils.tabbedpanel.Tab
A tab in a TabbedPanel component.
Definition: Tab.java:54
net.sf.gridarta.gui.misc.MainView.getActiveTab
Tab getActiveTab(@NotNull final Location location, final boolean alternativeLocation)
Returns the active Tab on a given Location of the main view.
Definition: MainView.java:177
net.sf.gridarta.gui
Graphical User Interface of Gridarta.
net.sf.gridarta.gui.misc.MainView
Main window of the level editor.
Definition: MainView.java:53
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
Definition: AbstractGameObjectAttributesTab.java:20
net.sf.gridarta.gui.utils.tabbedpanel.Tab.getLocation
Location getLocation()
Returns the tab's location.
Definition: Tab.java:361
net.sf.gridarta.gui.misc.MainViewActions.textEditorTab
final TextEditorTab< G, A, R > textEditorTab
The GameObjectAttributesTab that displays the game object text editor.
Definition: MainViewActions.java:64
net.sf.gridarta.model.maparchobject.MapArchObject
Interface for MapArchObjects.
Definition: MapArchObject.java:40
net.sf.gridarta.gui.utils.tabbedpanel
Definition: ButtonList.java:20
net.sf.gridarta.gui.misc.MainViewActions.mainView
final MainView mainView
The MainView instance.
Definition: MainViewActions.java:45
net.sf.gridarta.gui.misc.MainViewActions.gameObjectTab
final Tab gameObjectTab
The game object Tab to display.
Definition: MainViewActions.java:57
net.sf.gridarta.gui.misc.MainViewActions
Implements actions related to the MainView.
Definition: MainViewActions.java:39
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesControl.getSelectedTab
GameObjectAttributesTab< G, A, R > getSelectedTab()
Returns the selected tab.
Definition: GameObjectAttributesControl.java:472
net.sf.gridarta.model
net.sf.gridarta.model.archetype.Archetype
Reflects an Archetype.
Definition: Archetype.java:41
net.sf.gridarta.gui.misc.MainViewActions.MainViewActions
MainViewActions(@NotNull final MainView mainView, @NotNull final GameObjectAttributesControl< G, A, R > gameObjectAttributesControl, @NotNull final Tab gameObjectTab, @NotNull final TextEditorTab< G, A, R > textEditorTab)
Creates a new instance.
Definition: MainViewActions.java:98
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesTab.activate
void activate()
Sets the focus to this component.
net.sf.gridarta.gui.panel.gameobjectattributes.TextEditorTab
The tab containing the game object text editor.
Definition: TextEditorTab.java:35
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.gui.panel.gameobjectattributes.GameObjectAttributesControl.selectTab
void selectTab(@NotNull final GameObjectAttributesTab< G, A, R > tab)
Selects a tab.
Definition: GameObjectAttributesControl.java:459
net.sf.gridarta.gui.misc.MainViewActions.prevTab2
GameObjectAttributesTab< G, A, R > prevTab2
The previously active GameObjectAttributesTab in {} before the last switch to #textEditorTab}.
Definition: MainViewActions.java:87
net.sf.gridarta.gui.utils
Definition: AnimationComponent.java:20
net.sf.gridarta.utils.EditorAction
A global editor action.
Definition: EditorAction.java:29
net.sf.gridarta.gui.misc.MainViewActions.setAction
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
Definition: MainViewActions.java:140
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20