Gridarta Editor
DefaultEditorSettings.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.settings;
21 
22 import java.io.File;
23 import java.util.prefs.PreferenceChangeEvent;
24 import java.util.prefs.PreferenceChangeListener;
25 import java.util.prefs.Preferences;
26 import net.sf.gridarta.MainControl;
28 import net.sf.japi.swing.action.ActionBuilder;
29 import net.sf.japi.swing.action.ActionBuilderFactory;
30 import org.jetbrains.annotations.NotNull;
31 
37 
41  @NotNull
42  private static final ActionBuilder ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder("net.sf.gridarta");
43 
47  @NotNull
48  private static final String SHOW_MAIN_TOOLBAR_KEY = "ShowMainToolbar";
49 
53  @NotNull
54  private static final String PREFERENCES_USER_NAME_DEFAULT = System.getProperty("user.name");
55 
59  @NotNull
60  private static final Preferences PREFERENCES = Preferences.userNodeForPackage(MainControl.class);
61 
65  @NotNull
66  private final String mapsDirectoryDefault;
67 
71  private final boolean hasMediaDirectory;
72 
76  @NotNull
77  private final String mediaDirectoryDefault;
78 
82  private final boolean hasImageSet;
83 
87  @NotNull
88  private final String imageSetDefault;
89 
93  @NotNull
94  private final String archDirectoryDefault;
95 
100  archDirectoryDefault = ActionBuilderUtils.getString(ACTION_BUILDER, "archDirectoryDefault", "");
101  mapsDirectoryDefault = ActionBuilderUtils.getString(ACTION_BUILDER, "mapsDirectoryDefault", "");
102  hasMediaDirectory = ActionBuilderUtils.getBoolean(ACTION_BUILDER, "mediaDirectory");
103  mediaDirectoryDefault = ActionBuilderUtils.getString(ACTION_BUILDER, "mediaDirectoryDefault", "");
104  hasImageSet = ActionBuilderUtils.getBoolean(ACTION_BUILDER, "imageSet");
105  imageSetDefault = ActionBuilderUtils.getString(ACTION_BUILDER, "imageSetDefault", "none");
106 
107  final PreferenceChangeListener preferenceChangeListener = new PreferenceChangeListener() {
108 
109  @Override
110  public void preferenceChange(final PreferenceChangeEvent evt) {
111  if (evt.getKey().equals(SHOW_MAIN_TOOLBAR_KEY)) {
113  }
114  }
115 
116  };
117  PREFERENCES.addPreferenceChangeListener(preferenceChangeListener);
118  }
119 
120  @NotNull
121  @Override
122  public File getArchDirectoryDefault() {
123  return new File(archDirectoryDefault);
124  }
125 
126  @NotNull
127  @Override
128  public File getMapsDirectoryDefault() {
129  return new File(mapsDirectoryDefault);
130  }
131 
132  @Override
133  public boolean hasMediaDirectory() {
134  return hasMediaDirectory;
135  }
136 
137  @NotNull
138  @Override
139  public File getMediaDirectoryDefault() {
140  return new File(mediaDirectoryDefault);
141  }
142 
143  @Override
144  public boolean hasImageSet() {
145  return hasImageSet;
146  }
147 
148  @NotNull
149  @Override
150  public String getImageSetDefault() {
151  return imageSetDefault;
152  }
153 
154  @Override
155  public boolean isShowMainToolbar() {
156  return PREFERENCES.getBoolean(SHOW_MAIN_TOOLBAR_KEY, SHOW_MAIN_TOOLBAR_DEFAULT);
157  }
158 
159  @Override
160  public void setShowMainToolbar(final boolean selected) {
161  PREFERENCES.putBoolean(SHOW_MAIN_TOOLBAR_KEY, selected);
162  }
163 
164  @NotNull
165  @Override
166  public String getUserNameDefault() {
168  }
169 
170  @Override
171  public String getKey(@NotNull final EditorSettingsKey key, @NotNull final String defaultValue) {
172  return PREFERENCES.get(key.getKey(), defaultValue);
173  }
174 
175  @Override
176  public void setKey(@NotNull final EditorSettingsKey key, @NotNull final String value) {
177  PREFERENCES.put(key.getKey(), value);
178  }
179 
180 }
void setKey(@NotNull final EditorSettingsKey key, @NotNull final String value)
Saves a settings value.
String getImageSetDefault()
Returns the default image set.
boolean hasMediaDirectory()
Returns whether a media directory is used.
Default implementation of EditorSettings.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
void fireShowMainToolbarChanged()
Notifies all listeners about a changed visibility of the main toolbar.
Base package of all Gridarta classes.
File getMediaDirectoryDefault()
Returns the default media directory.
static final String SHOW_MAIN_TOOLBAR_KEY
Key for info whether the main window's toolbar is shown.
final String archDirectoryDefault
The default value for the archetype directory.
boolean SHOW_MAIN_TOOLBAR_DEFAULT
Default value for whether the main window's toolbar is shown.
final boolean hasMediaDirectory
Whether a media directory is used.
Interface used as preferences location.
static final String PREFERENCES_USER_NAME_DEFAULT
Preferences default value for user name.
Utility class for ActionBuilder related functions.
File getMapsDirectoryDefault()
Returns the default maps directory.
boolean isShowMainToolbar()
Returns whether the main toolbar should be shown.
void setShowMainToolbar(final boolean selected)
Sets whether the main toolbar should be shown.
Abstract base class for EditorSettings implementations.
Possible keys for saving values in the EditorSettings.
final boolean hasImageSet
Whether an image set is used.
static final ActionBuilder ACTION_BUILDER
The ActionBuilder.
final String mediaDirectoryDefault
The default value for the media directory.
String getKey(@NotNull final EditorSettingsKey key, @NotNull final String defaultValue)
Returns a settings value.
static boolean getBoolean(@NotNull final ActionBuilder actionBuilder, @NotNull final String key)
Returns the value of a key as a.
final String imageSetDefault
The default value for the image set.
boolean hasImageSet()
Returns whether an image set is used.
final String mapsDirectoryDefault
The default value for the maps directory.
String getUserNameDefault()
Returns the default user name.
File getArchDirectoryDefault()
Returns the default archetype directory.