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-2015 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 
98  public MainViewActions(@NotNull final MainView mainView, @NotNull final GameObjectAttributesControl<G, A, R> gameObjectAttributesControl, @NotNull final Tab gameObjectTab, @NotNull final TextEditorTab<G, A, R> textEditorTab) {
99  this.mainView = mainView;
100  this.gameObjectAttributesControl = gameObjectAttributesControl;
101  this.gameObjectTab = gameObjectTab;
102  this.textEditorTab = textEditorTab;
103  }
104 
108  @ActionMethod
109  public void gameObjectTextEditor() {
110  final Tab activeTab = mainView.getActiveTab(gameObjectTab.getLocation(), gameObjectTab.isAlternativeLocation());
111  final GameObjectAttributesTab<G, A, R> activeTab2 = gameObjectAttributesControl.getSelectedTab();
112  final boolean gameObjectTextEditorIsActive = activeTab != null && 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);
120  gameObjectAttributesControl.selectTab(textEditorTab);
121  textEditorTab.activate();
122  } else if (prevTabSaved) {
123  prevTabSaved = false;
124  // restore saved state
125  if (prevTab != null) {
126  prevTab.getButton().setSelected(true);
127  prevTab = null;
128  } else {
129  gameObjectTab.getButton().setSelected(false);
130  }
131  if (prevTab2 != null) {
132  gameObjectAttributesControl.selectTab(prevTab2);
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 }
final GameObjectAttributesControl< G, A, R > gameObjectAttributesControl
The GameObjectAttributesControl to display.
void gameObjectTextEditor()
Action method to open the game object text editor.
Tab prevTab
The previously active Tab before the last switch to gameObjectTab.
Implements actions related to the MainView.
Graphical User Interface of Gridarta.
A tab in a TabbedPanel component.
Definition: Tab.java:53
GameObjectAttributesTab< G, A, R > prevTab2
The previously active GameObjectAttributesTab in gameObjectTab before the last switch to textEditorTa...
The tab containing the game object text editor.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
boolean prevTabSaved
Whether a previously selected tab has been remembered.
Main window of the level editor.
Definition: MainView.java:53
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.
final TextEditorTab< G, A, R > textEditorTab
The GameObjectAttributesTab that displays the game object text editor.
Base package of all Gridarta classes.
Location getLocation()
Returns the tab&#39;s location.
Definition: Tab.java:360
Reflects a game object (object on a map).
Definition: GameObject.java:36
Tab getActiveTab(@NotNull final Location location, final boolean alternativeLocation)
Returns the active Tab on a given Location of the main view.
Definition: MainView.java:184
A global editor action.
GameObjects are the objects based on Archetypes found on maps.
GameObjectAttributesTab< G, A, R > getSelectedTab()
Returns the selected tab.
Common base class for the panel that allows users to edit a GameObject&#39;s attributes.
final MainView mainView
The MainView instance.
AbstractButton getButton()
Returns the AbstractButton for showing or hiding the component.
Definition: Tab.java:303
boolean isAlternativeLocation()
Returns whether the button is shown in the alternative location.
Definition: Tab.java:338
void selectTab(@NotNull final GameObjectAttributesTab< G, A, R > tab)
Selects a tab.
final Tab gameObjectTab
The game object Tab to display.