Gridarta Editor
AppPreferencesModel.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.gui.dialog.prefs;
21 
22 import java.util.prefs.Preferences;
23 import net.sf.gridarta.MainControl;
25 import org.jetbrains.annotations.NotNull;
26 
31 public class AppPreferencesModel {
32 
36  private static final String PREFERENCES_APP_SERVER = "appServer";
37 
41  private static final String PREFERENCES_APP_CLIENT = "appClient";
42 
46  private static final String PREFERENCES_APP_EDITOR = "appEditor";
47 
51  private static final Preferences PREFERENCES = Preferences.userNodeForPackage(MainControl.class);
52 
56  @NotNull
57  private final String serverDefault;
58 
62  @NotNull
63  private final String clientDefault;
64 
68  @NotNull
69  private final String editorDefault;
70 
77  public AppPreferencesModel(@NotNull final String serverDefault, @NotNull final String clientDefault, @NotNull final String editorDefault) {
78  this.serverDefault = serverDefault;
79  this.clientDefault = clientDefault;
80  this.editorDefault = editorDefault;
81  }
82 
87  public static void setServer(@NotNull final CharSequence server) {
88  PREFERENCES.put(PREFERENCES_APP_SERVER, PathManagerUtils.path(server));
89  }
90 
95  public static void setClient(@NotNull final CharSequence client) {
96  PREFERENCES.put(PREFERENCES_APP_CLIENT, PathManagerUtils.path(client));
97  }
98 
103  public static void setEditor(@NotNull final CharSequence editor) {
104  PREFERENCES.put(PREFERENCES_APP_EDITOR, PathManagerUtils.path(editor));
105  }
106 
111  @NotNull
112  public String getServer() {
113  return PREFERENCES.get(PREFERENCES_APP_SERVER, serverDefault);
114  }
115 
120  @NotNull
121  public String getClient() {
122  return PREFERENCES.get(PREFERENCES_APP_CLIENT, clientDefault);
123  }
124 
129  @NotNull
130  public String getEditor() {
131  return PREFERENCES.get(PREFERENCES_APP_EDITOR, editorDefault);
132  }
133 
138  @NotNull
139  public String getServerDefault() {
140  return serverDefault;
141  }
142 
147  @NotNull
148  public String getClientDefault() {
149  return clientDefault;
150  }
151 
156  @NotNull
157  public String getEditorDefault() {
158  return editorDefault;
159  }
160 
161 }
static String path(@NotNull final CharSequence str)
Create a reasonable path.
Reading and writing of maps, handling of paths.
static final Preferences PREFERENCES
Preferences.
Utility class for converting relative map paths to absolute map paths and vice versa.
static void setEditor(@NotNull final CharSequence editor)
Sets the editor setting.
Maintains the application preferences state.
AppPreferencesModel(@NotNull final String serverDefault, @NotNull final String clientDefault, @NotNull final String editorDefault)
Creates a new instance.
Base package of all Gridarta classes.
static void setClient(@NotNull final CharSequence client)
Sets the client setting.
final String clientDefault
The default value for the client setting.
String getClientDefault()
Returns the client setting's default value.
final String editorDefault
The default value for the editor setting.
Interface used as preferences location.
static final String PREFERENCES_APP_CLIENT
Preferences key for client application.
String getEditorDefault()
Returns the editor setting's default value.
static void setServer(@NotNull final CharSequence server)
Sets the server setting.
static final String PREFERENCES_APP_SERVER
Preferences key for server application.
final String serverDefault
The default value for the server setting.
String getServerDefault()
Returns the server setting's default value.
static final String PREFERENCES_APP_EDITOR
Preferences key for editor application.