Gridarta Editor
AbstractPickmapSettings.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.model.pickmapsettings;
21 
22 import java.util.Collection;
23 import java.util.concurrent.CopyOnWriteArrayList;
24 import org.jetbrains.annotations.NotNull;
25 
30 public abstract class AbstractPickmapSettings implements PickmapSettings {
31 
35  @NotNull
36  private final Collection<PickmapSettingsListener> listenerList = new CopyOnWriteArrayList<>();
37 
41  private boolean locked = loadLocked();
42 
43  @Override
44  public void addPickmapSettingsListener(@NotNull final PickmapSettingsListener listener) {
45  listenerList.add(listener);
46  }
47 
48  @Override
49  public void removePickmapSettingsListener(@NotNull final PickmapSettingsListener listener) {
50  listenerList.remove(listener);
51  }
52 
53  @Override
54  public boolean isLocked() {
55  return locked;
56  }
57 
58  @Override
59  public void setLocked(final boolean locked) {
60  if (this.locked == locked) {
61  return;
62  }
63 
64  this.locked = locked;
67  }
68 
72  private void fireLockedChanged() {
73  for (final PickmapSettingsListener listener : listenerList) {
74  listener.lockedChanged(locked);
75  }
76  }
77 
82  protected abstract boolean loadLocked();
83 
88  protected abstract void saveLocked(boolean locked);
89 
90 }
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings.setLocked
void setLocked(final boolean locked)
Sets whether pickmaps are immutable.
Definition: AbstractPickmapSettings.java:59
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings
Abstract base class for PickmapSettings implementations.
Definition: AbstractPickmapSettings.java:30
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings.fireLockedChanged
void fireLockedChanged()
Informs all registered listeners that the immutable state has changed.
Definition: AbstractPickmapSettings.java:72
net.sf.gridarta.model.pickmapsettings.PickmapSettingsListener
Interface for event listeners that are interested in changes on {}.
Definition: PickmapSettingsListener.java:29
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings.listenerList
final Collection< PickmapSettingsListener > listenerList
The MapViewSettingsListeners to inform of changes.
Definition: AbstractPickmapSettings.java:36
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings.addPickmapSettingsListener
void addPickmapSettingsListener(@NotNull final PickmapSettingsListener listener)
Adds a PickmapSettingsListener to be notified about changes.
Definition: AbstractPickmapSettings.java:44
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings.removePickmapSettingsListener
void removePickmapSettingsListener(@NotNull final PickmapSettingsListener listener)
Removes a PickmapSettingsListener to be notified about changes.
Definition: AbstractPickmapSettings.java:49
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings.loadLocked
abstract boolean loadLocked()
Loads the default value for locked.
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings.locked
boolean locked
The immutable state.
Definition: AbstractPickmapSettings.java:41
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings.isLocked
boolean isLocked()
Returns whether pickmaps are immutable.
Definition: AbstractPickmapSettings.java:54
net.sf.gridarta.model.pickmapsettings.AbstractPickmapSettings.saveLocked
abstract void saveLocked(boolean locked)
Saves the locked value.
net.sf.gridarta.model.pickmapsettings.PickmapSettings
Container for settings that affect pickmaps.
Definition: PickmapSettings.java:28