Mercurial > hg > ccmieditor
view java/src/uk/ac/qmul/eecs/ccmi/utils/PreferencesService.java @ 5:d66dd5880081
Added support for Falcon Haptic device and Tablet/Mouse as haptic device
author | Fiore Martin <fiore@eecs.qmul.ac.uk> |
---|---|
date | Tue, 10 Jul 2012 22:39:37 +0100 |
parents | 9418ab7b7f3f |
children |
line wrap: on
line source
/* CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool Copyright (C) 2002 Cay S. Horstmann (http://horstmann.com) Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package uk.ac.qmul.eecs.ccmi.utils; import java.util.prefs.Preferences; /** * A service for storing and loading user preferences. */ public abstract class PreferencesService { /** * Gets an instance of the service, suitable for the package of the given class. * @return an instance of the service */ public static PreferencesService getInstance(){ if (service != null) return service; try{ service = new DefaultPreferencesService(); return service; } catch (SecurityException exception){ throw new RuntimeException(exception); } } /** * Gets a previously stored string from the service. * @param key the key of the string * @param defval the value to return if no matching value was found * @return the value stored with the given key, or defval if none was found */ public abstract String get(String key, String defval); /** * Saves a key/value pair for later retrieval. * @param key the key of the string to be stored * @param value the value to to be stored */ public abstract void put(String key, String value); private static PreferencesService service; } /** * The default preferences service that uses the java.util.prefs API. */ class DefaultPreferencesService extends PreferencesService{ public DefaultPreferencesService(){ prefs = Preferences.userNodeForPackage(this.getClass()); } @Override public String get(String key, String defval) { return prefs.get(key, defval); } @Override public void put(String key, String defval) { prefs.put(key, defval); } private Preferences prefs; }