]> git.xonotic.org Git - xonotic/xonotic.git/blob - misc/tools/NexuizDemoRecorder/main/src/main/java/com/nexuiz/demorecorder/application/NDRPreferences.java
Merge branch 'master' of ssh://git.xonotic.org/xonotic
[xonotic/xonotic.git] / misc / tools / NexuizDemoRecorder / main / src / main / java / com / nexuiz / demorecorder / application / NDRPreferences.java
1 package com.nexuiz.demorecorder.application;
2
3 import java.util.Properties;
4
5 /**
6  * Class that stores the application and global plug-in preferences of the Nexuiz
7  * Demo Recorder application. Set and Get property methods have been modified to 
8  * now supply a category.
9  */
10 public class NDRPreferences extends Properties {
11         
12         private static final long serialVersionUID = 4363913054294979418L;
13         private static final String CONCATENATOR = ".";
14         /**
15          * Category that defines a setting to be a setting of the NDR application itself
16          * (and not of one of the plugins).
17          */
18         public static final String MAIN_APPLICATION = "NDR";
19
20         /**
21      * Searches for the property with the specified key in this property list.
22      * If the key is not found in this property list, the default property list,
23      * and its defaults, recursively, are then checked. The method returns
24      * <code>null</code> if the property is not found.
25      *
26      * @param   category the category of the setting
27      * @param   key   the property key.
28      * @return  the value in this property list with the specified category+key value.
29      */
30         public String getProperty(String category, String key) {
31                 return getProperty(getConcatenatedKey(category, key));
32         }
33         
34         /**
35      * Calls the <tt>Hashtable</tt> method <code>put</code>. Provided for
36      * parallelism with the <tt>getProperty</tt> method. Enforces use of
37      * strings for property keys and values. The value returned is the
38      * result of the <tt>Hashtable</tt> call to <code>put</code>.
39      *
40      * @param category the category of the setting
41      * @param key the key to be placed into this property list.
42      * @param value the value corresponding to <tt>key</tt>.
43      * @return     the previous value of the specified key in this property
44      *             list, or <code>null</code> if it did not have one.
45      */
46         public void setProperty(String category, String key, String value) {
47                 setProperty(getConcatenatedKey(category, key), value);
48         }
49         
50         /**
51          * Returns only the category of a key that is a concatenated string of category and key.
52          * @param concatenatedString
53          * @return
54          */
55         public static String getCategory(String concatenatedString) {
56                 return concatenatedString.substring(0, concatenatedString.indexOf(CONCATENATOR));
57         }
58         
59         public static String getKey(String concatenatedString) {
60                 return concatenatedString.substring(concatenatedString.indexOf(CONCATENATOR) + 1, concatenatedString.length());
61         }
62         
63         public static String getConcatenatedKey(String category, String key) {
64                 return category + CONCATENATOR + key;
65         }
66 }