20 package net.sf.gridarta.model.settings;
23 import java.util.prefs.PreferenceChangeEvent;
24 import java.util.prefs.PreferenceChangeListener;
25 import java.util.prefs.Preferences;
28 import org.jetbrains.annotations.NotNull;
121 final PreferenceChangeListener preferenceChangeListener =
new PreferenceChangeListener() {
124 public void preferenceChange(
final PreferenceChangeEvent evt) {
125 if (evt.getKey().equals(ARCH_DIRECTORY_KEY)) {
126 archDirectory =
IOUtils.
getCanonicalFile(
new File(PREFERENCES.get(ARCH_DIRECTORY_KEY, editorSettings.getArchDirectoryDefault().toString())));
127 }
else if (evt.getKey().equals(MAP_DIRECTORY_KEY)) {
128 setMapsDirectoryInt(
new File(PREFERENCES.get(MAP_DIRECTORY_KEY, editorSettings.getMapsDirectoryDefault().toString())),
false);
129 }
else if (evt.getKey().equals(MEDIA_DIRECTORY_KEY)) {
130 mediaDirectory =
IOUtils.
getCanonicalFile(
new File(PREFERENCES.get(MEDIA_DIRECTORY_KEY, editorSettings.getMediaDirectoryDefault().toString())));
131 }
else if (evt.getKey().equals(IMAGE_SET_KEY)) {
132 imageSet = PREFERENCES.get(IMAGE_SET_KEY, editorSettings.getImageSetDefault());
133 }
else if (evt.getKey().equals(CONFIG_SOURCE_KEY)) {
134 configSourceName = PREFERENCES.get(CONFIG_SOURCE_KEY,
"");
139 PREFERENCES.addPreferenceChangeListener(preferenceChangeListener);
141 archDirectory =
IOUtils.
getCanonicalFile(
new File(PREFERENCES.get(ARCH_DIRECTORY_KEY, editorSettings.getArchDirectoryDefault().toString())));
142 mapsDirectory =
IOUtils.
getCanonicalFile(
new File(PREFERENCES.get(MAP_DIRECTORY_KEY, editorSettings.getMapsDirectoryDefault().toString())));
143 mediaDirectory =
IOUtils.
getCanonicalFile(
new File(PREFERENCES.get(MEDIA_DIRECTORY_KEY, editorSettings.getMediaDirectoryDefault().toString())));
144 imageSet = PREFERENCES.get(IMAGE_SET_KEY, editorSettings.getImageSetDefault());
145 configSourceName = PREFERENCES.get(CONFIG_SOURCE_KEY,
"");
157 if (this.archDirectory.equals(effectiveArchDirectory)) {
161 this.archDirectory = effectiveArchDirectory;
162 PREFERENCES.put(ARCH_DIRECTORY_KEY, effectiveArchDirectory.toString());
183 if (this.mapsDirectory.equals(effectiveMapsDirectory)) {
187 this.mapsDirectory = effectiveMapsDirectory;
188 if (updatePreferences) {
189 PREFERENCES.put(MAP_DIRECTORY_KEY, effectiveMapsDirectory.toString());
206 if (this.mediaDirectory.equals(effectiveMediaDirectory)) {
210 this.mediaDirectory = effectiveMediaDirectory;
211 PREFERENCES.put(MEDIA_DIRECTORY_KEY, effectiveMediaDirectory.getPath());
225 if (this.imageSet.equals(imageSet)) {
230 PREFERENCES.put(IMAGE_SET_KEY, imageSet);
241 if (this.configSourceName.equals(configSourceName)) {
246 PREFERENCES.put(CONFIG_SOURCE_KEY, configSourceName);
257 PREFERENCES.put(PREFERENCES_USER_NAME, userName);
File archDirectory
The archetype directory.
static final String MEDIA_DIRECTORY_KEY
The preferences key for the media directory.
void setUserName(@NotNull final String userName)
Sets the user name.
final EditorSettings editorSettings
The EditorSettings for retrieving default values.
static final String ARCH_DIRECTORY_KEY
The preferences key for the archetype directory.
String configSourceName
Do we load arches from the collected archives.
String getConfigSourceName()
Returns the name of the configuration source.
File mediaDirectory
The media directory.
static final String PREFERENCES_USER_NAME
Preferences key for user name.
void setConfigSourceName(@NotNull final String configSourceName)
Sets the name of the configuration source.
static File getCanonicalFile(@NotNull final File file)
Calls File#getCanonicalFile().
Base package of all Gridarta classes.
void setMediaDirectory(@NotNull final File mediaDirectory)
Sets the media directory.
void fireMapsDirectoryChanged()
Notifies all listeners about a changed maps directory.
static final Preferences PREFERENCES
Preferences.
boolean saveIndices()
Returns whether indices should be saved to disk.
static final String CONFIG_SOURCE_KEY
The preferences key for configuration source.
AbstractDefaultProjectSettings(@NotNull final EditorSettings editorSettings)
Creates a new instance.
Utility-class for Gridarta's I/O.
boolean hasMediaDirectory()
Returns whether a media directory is used.
String imageSet
The image set.
static final String IMAGE_SET_KEY
The preferences key for the selected image set.
Interface used as preferences location.
boolean hasImageSet()
Returns whether an image set is used.
void setImageSet(@NotNull final String imageSet)
Sets the image set.
String getUserName()
Returns the user name.
String getUserNameDefault()
Returns the default user name.
void setMapsDirectory(@NotNull final File mapsDirectory)
Sets the default maps directory.
void setMapsDirectoryInt(@NotNull final File mapsDirectory, final boolean updatePreferences)
Sets the mapsDirectory.
File getMapsDirectory()
Returns the default maps directory.
String getImageSet()
Returns the image set.
File getArchDirectory()
Returns the archetype directory.
Default implementation of ProjectSettings.
void setArchDirectory(@NotNull final File archDirectory)
Sets the archetype directory.
File getMediaDirectory()
Returns the media directory.
Settings that apply to the editor.
File mapsDirectory
The default maps directory.
static final String MAP_DIRECTORY_KEY
The preferences key for the archetype directory.
Abstract base class for ProjectSettings implementations.