java: isac.util.tactics .. end renamed, formatted, inst_var_, import cleaned
2 * Created on Feb 22, 2005
4 * @author Alan Krempler
7 package isac.util.users;
9 import java.io.FileInputStream;
10 import java.io.FileNotFoundException;
11 import java.io.FileOutputStream;
12 import java.io.IOException;
13 import java.util.Enumeration;
14 import java.util.HashMap;
16 import java.util.Properties;
19 * Class for storing/retrieving user settings, i.e. settings which can be set
20 * manually by the user as opposed to the
21 * {@link isac.util.usersettings.UserModel#}, which is an abstraction of the
22 * system's expeience with a user and canot be altered manually. As there is no
23 * fixed set of user settings, you can regard this class as a simple storage
24 * backend for key/value pairs.
26 * @author Alan Krempler
29 public class UserSettings extends Properties implements IUserSettings {
31 private HashMap storage_;
37 public static Map valstr_valint_;
40 * connect the String-representation of a UserSettings-value with the
41 * respective Integer-representation
43 * @see isac.uti.users.IUserSettings
45 private HashMap createValstrValint() {
46 HashMap m = new HashMap();
47 m.put("DUMMY", new Integer(IUserSettings.DUMMY));
48 m.put("VAL1_SKIP_SPECIFY_TO_START_SOLVE", new Integer(
49 IUserSettings.VAL1_SKIP_SPECIFY_TO_START_SOLVE));
50 m.put("VAL1_POP_CALCHEAD_WITH_DESCRIPTIONS", new Integer(
51 IUserSettings.VAL1_POP_CALCHEAD_WITH_DESCRIPTIONS));
52 m.put("VAL2_FORMULAE_ONLY", new Integer(
53 IUserSettings.VAL2_FORMULAE_ONLY));
54 m.put("VAL2_FORMULA_TACTIC_FORMULA_", new Integer(
55 IUserSettings.VAL2_FORMULA_TACTIC_FORMULA_));
57 // new Integer(IUserSettings.));
61 public UserSettings(String userpath, String username) {
65 //load Properties (keystr, valstr) temporarily
66 Properties keystr_valstr = new Properties();
67 String filename = userpath_ + username + "_settings.txt";
69 FileInputStream propInFile = new FileInputStream(filename);
70 keystr_valstr.load(propInFile);
71 keystr_valstr.list(System.out);
72 } catch (FileNotFoundException e) {
73 System.err.println("Can?t find " + filename);
74 } catch (IOException e) {
75 System.err.println("I/O failed.");
78 //create HashMap (valstr, valint) temporarily
79 HashMap valstr_valint = new HashMap();
80 valstr_valint = this.createValstrValint();
82 //create HashMap (keystr, \\valstr\\ valint) and store it
83 storage_ = new HashMap();
84 Enumeration keystrs = keystr_valstr.propertyNames();//WN050311 how
89 while (keystrs.hasMoreElements()) {
90 keystr = (String) keystrs.nextElement();
91 valstr = keystr_valstr.getProperty(keystr);
92 valint = valstr_valint.get(valstr);
93 storage_.put(keystr, valint);
100 * @return The string value associated with the key parameter; null, if
101 * nothing is stored under this key
103 public int getValue(String key) {
104 return ((Integer) storage_.get(key)).intValue();
109 * The key under which "value" is to be stored. Existing data
110 * unde the same key will be replaced.
112 * The value to be stored under "key"
113 * @return true in case of success, false in case of error, for example if
114 * trying to replace stored values without proper permissions
116 public boolean setValue(String key, int value) {
117 //TODO.WN050311 storage_.put(key, value);
121 //WN050311 just for creation of the first file
122 //beware of the fix path !
123 public static void main(String[] args) {
124 UserSettings s = new UserSettings("isac/xmldata/users/", "x");
125 s.setProperty("start_worksheet", "SKIP_SPECIFY_START_SOLVE");
126 s.setProperty("enter_specify", "SKIP_SPECIFY_START_SOLVE");
127 s.setProperty("next_button", "FORMULAE_ONLY");
129 String filename = "isac/xmldata/users/x_settings.txt";
131 FileOutputStream propOutFile = new FileOutputStream(filename);
132 s.store(propOutFile, "static dialog data of user 'x'");
134 } catch (IOException e) {
135 System.err.println("I/O failed.");