Gridarta Editor
AbstractExitConnectorModel.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.model.exitconnector;
21 
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Nullable;
25 
30 public abstract class AbstractExitConnectorModel implements ExitConnectorModel {
31 
36 
41  @Nullable
43 
47  private boolean pasteExitName = loadPasteExitName();
48 
52  private boolean autoCreateExit = loadAutoCreateExit();
53 
57  @NotNull
59 
60  @Override
61  @Nullable
63  return exitLocation;
64  }
65 
66  @Override
67  public void setExitLocation(@Nullable final ExitLocation exitLocation) {
68  if (exitLocation == null ? this.exitLocation == null : exitLocation.equals(this.exitLocation)) {
69  return;
70  }
71 
72  this.exitLocation = exitLocation;
73  for (final ExitConnectorModelListener listener : listeners.getListeners()) {
74  listener.exitLocationChanged(exitLocation);
75  }
76  }
77 
78  @Override
79  public boolean isPasteExitName() {
80  return pasteExitName;
81  }
82 
83  @Override
84  public void setPasteExitName(final boolean pasteExitName) {
85  if (this.pasteExitName == pasteExitName) {
86  return;
87  }
88 
89  this.pasteExitName = pasteExitName;
90  savePasteExitName(pasteExitName);
91  for (final ExitConnectorModelListener listener : listeners.getListeners()) {
92  listener.pasteExitNameChanged(pasteExitName);
93  }
94  }
95 
96  @Override
97  public boolean isAutoCreateExit() {
98  return autoCreateExit;
99  }
100 
101  @Override
102  public void setAutoCreateExit(final boolean autoCreateExit) {
103  if (this.autoCreateExit == autoCreateExit) {
104  return;
105  }
106 
107  this.autoCreateExit = autoCreateExit;
108  saveAutoCreateExit(autoCreateExit);
109  for (final ExitConnectorModelListener listener : listeners.getListeners()) {
110  listener.autoCreateExitChanged(autoCreateExit);
111  }
112  }
113 
114  @Override
115  @NotNull
116  public String getExitArchetypeName() {
117  return exitArchetypeName;
118  }
119 
120  @Override
121  public void setExitArchetypeName(@NotNull final String exitArchetypeName) {
122  if (this.exitArchetypeName.equals(exitArchetypeName)) {
123  return;
124  }
125 
126  this.exitArchetypeName = exitArchetypeName;
127  saveExitArchetypeName(exitArchetypeName);
128  for (final ExitConnectorModelListener listener : listeners.getListeners()) {
129  listener.exitArchetypeNameChanged(exitArchetypeName);
130  }
131  }
132 
133  @Override
134  public void addExitConnectorModelListener(@NotNull final ExitConnectorModelListener listener) {
135  listeners.add(listener);
136  }
137 
138  @Override
139  public void removeExitConnectorModelListener(@NotNull final ExitConnectorModelListener listener) {
140  listeners.remove(listener);
141  }
142 
147  protected abstract boolean loadPasteExitName();
148 
153  protected abstract void savePasteExitName(boolean pasteExitName);
154 
159  protected abstract boolean loadAutoCreateExit();
160 
165  protected abstract void saveAutoCreateExit(boolean autoCreateExit);
166 
171  @NotNull
172  protected abstract String loadExitArchetypeName();
173 
178  protected abstract void saveExitArchetypeName(@NotNull String exitArchetypeName);
179 
180 }
abstract void savePasteExitName(boolean pasteExitName)
Sets the stored attribute value for pasteExitName.
abstract String loadExitArchetypeName()
Returns the stored attribute value for exitArchetypeName.
String getExitArchetypeName()
Returns the archetype name when creating exit game objects.
T [] getListeners()
Returns an array of all the listeners.
final EventListenerList2< ExitConnectorModelListener > listeners
The listeners to notify.
abstract void saveAutoCreateExit(boolean autoCreateExit)
Sets the stored attribute value for isAutoCreateExit().
Base package of all Gridarta classes.
boolean autoCreateExit
Whether exit game objects should be auto-created when needed.
void remove(@NotNull final T listener)
Removes a listener.
void add(@NotNull final T listener)
Adds a listener.
boolean isPasteExitName()
Returns whether the exit name should be updated.
void addExitConnectorModelListener(@NotNull final ExitConnectorModelListener listener)
Adds an ExitConnectorModelListener to be notified of changes.
void setAutoCreateExit(final boolean autoCreateExit)
Sets whether exit game objects should be auto-created when needed.
Type-safe version of EventListenerList.
Stores information needed by the exit connector.
ExitLocation exitLocation
Whether an exit has been remembered.
Stores information about a remembered exit location.
String exitArchetypeName
The archetype to insert when creating new exit game objects.
boolean pasteExitName
Whether the exit&#39;s name should be set when pasted.
void setExitLocation(@Nullable final ExitLocation exitLocation)
Sets the remembered exit location.
boolean isAutoCreateExit()
Returns whether exit game objects should be auto-created when needed.
abstract void saveExitArchetypeName(@NotNull String exitArchetypeName)
Sets the stored attribute value for setExitArchetypeName(String).
void setPasteExitName(final boolean pasteExitName)
Sets whether the exit name should be updated.
void setExitArchetypeName(@NotNull final String exitArchetypeName)
Sets the archetype name for creating exit game objects.
Interface for listeners interested in ExitConnectorModel related events.
abstract boolean loadAutoCreateExit()
Returns the stored attribute value for autoCreateExit.
ExitLocation getExitLocation()
Returns the remembered exit location.
void removeExitConnectorModelListener(@NotNull final ExitConnectorModelListener listener)
Removes an ExitConnectorModelListener to be notified of changes.
abstract boolean loadPasteExitName()
Returns the stored attribute value for pasteExitName.