Gridarta Editor
FilePreferencesFactory.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.preferences;
21 
22 import java.io.File;
23 import java.util.prefs.Preferences;
24 import java.util.prefs.PreferencesFactory;
25 import org.jetbrains.annotations.NotNull;
26 import org.jetbrains.annotations.Nullable;
27 
33 public class FilePreferencesFactory implements PreferencesFactory {
34 
38  @Nullable
39  private static Preferences userRoot;
40 
44  @Nullable
45  private static Preferences systemRoot;
46 
54  public static void initialize(@NotNull final String defaultName, @Nullable final File file) {
55  final Storage storage = new Storage(defaultName, file);
56  userRoot = new FilePreferencesRoot(NodeType.USER, storage);
58  }
59 
60  @NotNull
61  @Override
62  public Preferences userRoot() {
63  if (userRoot == null) {
64  throw new IllegalStateException("user root is unset");
65  }
66  return userRoot;
67  }
68 
69  @NotNull
70  @Override
71  public Preferences systemRoot() {
72  if (systemRoot == null) {
73  throw new IllegalStateException("system root is unset");
74  }
75  return systemRoot;
76  }
77 
78 }
net.sf.gridarta.preferences.FilePreferencesFactory.userRoot
static Preferences userRoot
The user preferences as returned by userRoot().
Definition: FilePreferencesFactory.java:39
net.sf.gridarta.preferences.NodeType.SYSTEM
SYSTEM
System Node.
Definition: NodeType.java:38
net.sf.gridarta.preferences.FilePreferencesRoot
An FilePreferences that represents a root node.
Definition: FilePreferencesRoot.java:28
net.sf.gridarta.preferences.FilePreferencesFactory
A PreferencesFactory which creates FilePreferences instances.
Definition: FilePreferencesFactory.java:33
net.sf.gridarta.preferences.FilePreferencesFactory.userRoot
Preferences userRoot()
Definition: FilePreferencesFactory.java:62
net.sf.gridarta.preferences.NodeType.USER
USER
User Node.
Definition: NodeType.java:33
net.sf.gridarta.preferences.NodeType
The type of a FilePreferences node.
Definition: NodeType.java:28
net.sf.gridarta.preferences.Storage
Maintains a set of preference values.
Definition: Storage.java:50
net.sf.gridarta.preferences.FilePreferencesFactory.systemRoot
static Preferences systemRoot
The system preferences as returned by userRoot().
Definition: FilePreferencesFactory.java:45
net.sf.gridarta.preferences.FilePreferencesFactory.systemRoot
Preferences systemRoot()
Definition: FilePreferencesFactory.java:71
net.sf.gridarta.preferences.FilePreferencesFactory.initialize
static void initialize(@NotNull final String defaultName, @Nullable final File file)
Initialize the module.
Definition: FilePreferencesFactory.java:54