Initial revision
[old-projects.git] / ekit / com / swabunga / spell / engine / PropertyConfiguration.java
CommitLineData
6dd70280
JL
1package com.swabunga.spell.engine;\r
2\r
3import java.io.File;\r
4import java.io.FileNotFoundException;\r
5import java.io.FileOutputStream;\r
6import java.io.IOException;\r
7import java.io.InputStream;\r
8import java.net.URL;\r
9import java.util.Properties;\r
10\r
11\r
12/**\r
13 * @author aim4min\r
14 *\r
15 * To change this generated comment edit the template variable "typecomment":\r
16 * Window>Preferences>Java>Templates.\r
17 * To enable and disable the creation of type comments go to\r
18 * Window>Preferences>Java>Code Generation.\r
19 */\r
20public class PropertyConfiguration extends Configuration {\r
21\r
22 public Properties prop;\r
23 public URL filename;\r
24 \r
25 public PropertyConfiguration() {\r
26 prop = new Properties();\r
27 try {\r
28/*\r
29 //original initalization code\r
30 filename = getClass().getClassLoader().getResource("com/swabunga/spell/engine/configuration.properties");\r
31 InputStream in = filename.openStream();\r
32 prop.load(in);\r
33*/\r
34 // new constructor code so that this works within JAR files (Howard Kistler)\r
35 InputStream is = this.getClass().getResourceAsStream("configuration.properties");\r
36 prop.load(is);\r
37 } catch (Exception e) {\r
38 System.out.println("Could not load Properties file :\n" + e);\r
39 }\r
40 }\r
41\r
42 /**\r
43 * @see com.swabunga.spell.engine.Configuration#getBoolean(String)\r
44 */\r
45 public boolean getBoolean(String key) {\r
46// return Boolean.getBoolean(prop.getProperty(key));\r
47// original breaks inside applets due to security, this version works fine (Howard Kistler)\r
48 return prop.getProperty(key).equalsIgnoreCase("true");\r
49 }\r
50\r
51 /**\r
52 * @see com.swabunga.spell.engine.Configuration#getInteger(String)\r
53 */\r
54 public int getInteger(String key) {\r
55 return Integer.parseInt(prop.getProperty(key));\r
56 }\r
57\r
58 /**\r
59 * @see com.swabunga.spell.engine.Configuration#setBoolean(String, boolean)\r
60 */\r
61 public void setBoolean(String key, boolean value) {\r
62 String string = null;\r
63 if (value)\r
64 string = "true";\r
65 else\r
66 string = "false";\r
67 \r
68 prop.setProperty(key, string);\r
69 save();\r
70 }\r
71\r
72 /**\r
73 * @see com.swabunga.spell.engine.Configuration#setInteger(String, int)\r
74 */\r
75 public void setInteger(String key, int value) {\r
76 prop.setProperty(key,Integer.toString(value));\r
77 save();\r
78 }\r
79 \r
80 public void save() {\r
81 try {\r
82 File file = new File(filename.getFile());\r
83 FileOutputStream fout = new FileOutputStream(file);\r
84 prop.store(fout,"HEADER");\r
85 } catch (FileNotFoundException e) {\r
86 } catch (IOException e) {\r
87 }\r
88 }\r
89\r
90}\r