Gridarta Editor
LightVisibleAction.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.action;
21 
22 import javax.swing.Action;
26 import net.sf.japi.swing.action.ActionMethod;
27 import net.sf.japi.swing.action.ToggleAction;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
30 
35 public class LightVisibleAction implements EditorAction {
36 
40  @NotNull
42 
47  @Nullable
48  private ToggleAction action;
49 
54  @NotNull
56 
57  @Override
58  public void gridVisibleChanged(final boolean gridVisible) {
59  }
60 
61  @Override
62  public void lightVisibleChanged(final boolean lightVisible) {
63  updateAction();
64  }
65 
66  @Override
67  public void smoothingChanged(final boolean smoothing) {
68  }
69 
70  @Override
71  public void tileStretchingChanged(final boolean tileStretching) {
72  }
73 
74  @Override
75  public void doubleFacesChanged(final boolean doubleFaces) {
76  }
77 
78  @Override
79  public void alphaTypeChanged(final int alphaType) {
80  }
81 
82  @Override
83  public void editTypeChanged(final int editType) {
84  }
85 
86  @Override
87  public void autojoinChanged(final boolean autojoin) {
88  }
89 
90  };
91 
96  public LightVisibleAction(@NotNull final MapViewSettings mapViewSettings) {
97  this.mapViewSettings = mapViewSettings;
98  mapViewSettings.addMapViewSettingsListener(mapViewSettingsListener);
99  }
100 
106  @ActionMethod
107  public boolean isLightVisible() {
108  return doLightVisible(false, false) && mapViewSettings.isLightVisible();
109  }
110 
117  @ActionMethod
118  public void setLightVisible(final boolean lightVisible) {
119  doLightVisible(true, lightVisible);
120  }
121 
122  @Override
123  public void setAction(@NotNull final Action action, @NotNull final String name) {
124  this.action = (ToggleAction) action;
125  }
126 
135  private boolean doLightVisible(final boolean performAction, final boolean lightVisible) {
136  if (performAction) {
137  mapViewSettings.setLightVisible(lightVisible);
138  }
139 
140  return true;
141  }
142 
146  private void updateAction() {
147  if (action != null) {
148  //noinspection ConstantConditions
149  action.setEnabled(doLightVisible(false, false));
150  //noinspection ConstantConditions
151  action.setSelected(isLightVisible());
152  }
153  }
154 
155 }
An EditorAction that toggles whether map lighting is visible.
ToggleAction action
The ToggleAction associated with this editor action.
void setLightVisible(final boolean lightVisible)
Sets whether the light of the current map should be visible.
final MapViewSettings mapViewSettings
The MapViewSettings instance to use.
LightVisibleAction(@NotNull final MapViewSettings mapViewSettings)
Creates a new instance.
boolean isLightVisible()
Get the visibility of the light.
final MapViewSettingsListener mapViewSettingsListener
The MapViewSettingsListener attached to mapViewSettings.
void addMapViewSettingsListener(@NotNull MapViewSettingsListener listener)
Register a MapViewSettingsListener.
Base package of all Gridarta classes.
void setAction(@NotNull final Action action, @NotNull final String name)
Sets the Action instance for this editor action.
A global editor action.
Interface for event listeners that are interested in changes on MapViewSettings.
void setLightVisible(boolean lightVisible)
Set the visibility of the light.
Container for settings that affect the rendering of maps.
boolean isLightVisible()
Action method for "light visible".
void updateAction()
Updates the action's state.
boolean doLightVisible(final boolean performAction, final boolean lightVisible)
Executes the "light visible" action.