001/* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2010 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020package net.sf.gridarta.model.settings; 021 022import java.io.File; 023import net.sf.gridarta.utils.EventListenerList2; 024import org.jetbrains.annotations.NotNull; 025 026/** 027 * Abstract base class for {@link GlobalSettings} implementations. 028 * @author Andreas Kirschbaum 029 */ 030public abstract class AbstractGlobalSettings implements GlobalSettings { 031 032 /** 033 * The {@link GlobalSettingsListener GlobalSettingsListeners} to inform of 034 * changes. 035 */ 036 @NotNull 037 private final EventListenerList2<GlobalSettingsListener> listenerList = new EventListenerList2<GlobalSettingsListener>(GlobalSettingsListener.class); 038 039 /** 040 * {@inheritDoc} 041 */ 042 @Override 043 public void addGlobalSettingsListener(@NotNull final GlobalSettingsListener listener) { 044 listenerList.add(listener); 045 } 046 047 /** 048 * {@inheritDoc} 049 */ 050 @Override 051 public void removeGlobalSettingsListener(@NotNull final GlobalSettingsListener listener) { 052 listenerList.remove(listener); 053 } 054 055 /** 056 * Notifies all listeners about a changed visibility of the main toolbar. 057 */ 058 protected void fireShowMainToolbarChanged() { 059 final boolean visible = isShowMainToolbar(); 060 for (final GlobalSettingsListener listener : listenerList.getListeners()) { 061 listener.showMainToolbarChanged(visible); 062 } 063 } 064 065 /** 066 * Notifies all listeners about a changed maps directory. 067 */ 068 protected void fireMapsDirectoryChanged() { 069 final File mapsDirectory = getMapsDirectory(); 070 for (final GlobalSettingsListener listener : listenerList.getListeners()) { 071 listener.mapsDirectoryChanged(mapsDirectory); 072 } 073 } 074 075}