annotate java/src/uk/ac/qmul/eecs/ccmi/utils/PreferencesService.java @ 8:ea7885bd9bff tip

fixed bug : render solid line as dotted/dashed when moving the stylus from dotted/dashed to solid
author ccmi-guest
date Thu, 03 Jul 2014 16:12:20 +0100
parents d66dd5880081
children
rev   line source
fiore@0 1 /*
fiore@0 2 CCmI Editor - A Collaborative Cross-Modal Diagram Editing Tool
fiore@0 3
fiore@0 4 Copyright (C) 2002 Cay S. Horstmann (http://horstmann.com)
fiore@0 5 Copyright (C) 2011 Queen Mary University of London (http://ccmi.eecs.qmul.ac.uk/)
fiore@0 6
fiore@0 7 This program is free software: you can redistribute it and/or modify
fiore@0 8 it under the terms of the GNU General Public License as published by
fiore@0 9 the Free Software Foundation, either version 3 of the License, or
fiore@0 10 (at your option) any later version.
fiore@0 11
fiore@0 12 This program is distributed in the hope that it will be useful,
fiore@0 13 but WITHOUT ANY WARRANTY; without even the implied warranty of
fiore@0 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fiore@0 15 GNU General Public License for more details.
fiore@0 16
fiore@0 17 You should have received a copy of the GNU General Public License
fiore@0 18 along with this program. If not, see <http://www.gnu.org/licenses/>.
fiore@0 19 */
fiore@0 20
fiore@0 21 package uk.ac.qmul.eecs.ccmi.utils;
fiore@0 22
fiore@0 23 import java.util.prefs.Preferences;
fiore@0 24
fiore@0 25 /**
fiore@0 26 * A service for storing and loading user preferences.
fiore@0 27 */
fiore@0 28 public abstract class PreferencesService
fiore@0 29 {
fiore@0 30 /**
fiore@0 31 * Gets an instance of the service, suitable for the package of the given class.
fiore@0 32 * @return an instance of the service
fiore@0 33 */
fiore@0 34 public static PreferencesService getInstance(){
fiore@0 35 if (service != null) return service;
fiore@0 36 try{
fiore@0 37 service = new DefaultPreferencesService();
fiore@0 38 return service;
fiore@0 39 }
fiore@0 40 catch (SecurityException exception){
fiore@5 41 throw new RuntimeException(exception);
fiore@0 42 }
fiore@0 43 }
fiore@0 44
fiore@0 45 /**
fiore@0 46 * Gets a previously stored string from the service.
fiore@0 47 * @param key the key of the string
fiore@0 48 * @param defval the value to return if no matching value was found
fiore@0 49 * @return the value stored with the given key, or defval if none was found
fiore@0 50 */
fiore@0 51 public abstract String get(String key, String defval);
fiore@0 52 /**
fiore@0 53 * Saves a key/value pair for later retrieval.
fiore@0 54 * @param key the key of the string to be stored
fiore@0 55 * @param value the value to to be stored
fiore@0 56 */
fiore@0 57 public abstract void put(String key, String value);
fiore@0 58
fiore@0 59 private static PreferencesService service;
fiore@0 60 }
fiore@0 61
fiore@0 62 /**
fiore@0 63 * The default preferences service that uses the java.util.prefs API.
fiore@0 64 */
fiore@0 65 class DefaultPreferencesService extends PreferencesService{
fiore@0 66
fiore@5 67 public DefaultPreferencesService(){
fiore@5 68 prefs = Preferences.userNodeForPackage(this.getClass());
fiore@5 69 }
fiore@5 70
fiore@5 71 @Override
fiore@5 72 public String get(String key, String defval) { return prefs.get(key, defval); }
fiore@5 73 @Override
fiore@5 74 public void put(String key, String defval) { prefs.put(key, defval); }
fiore@5 75
fiore@5 76 private Preferences prefs;
fiore@0 77 }