1 | package com.swabunga.spell.engine; |
---|
2 | |
---|
3 | import java.io.*; |
---|
4 | import java.net.URL; |
---|
5 | import java.util.Properties; |
---|
6 | |
---|
7 | |
---|
8 | /** |
---|
9 | * @author aim4min |
---|
10 | * |
---|
11 | * To change this generated comment edit the template variable "typecomment": |
---|
12 | * Window>Preferences>Java>Templates. |
---|
13 | * To enable and disable the creation of type comments go to |
---|
14 | * Window>Preferences>Java>Code Generation. |
---|
15 | */ |
---|
16 | public class PropertyConfiguration extends Configuration { |
---|
17 | |
---|
18 | public Properties prop; |
---|
19 | public URL filename; |
---|
20 | |
---|
21 | public PropertyConfiguration() { |
---|
22 | prop = new Properties(); |
---|
23 | try { |
---|
24 | filename = getClass().getClassLoader().getResource("com/swabunga/spell/engine/configuration.properties"); |
---|
25 | InputStream in = filename.openStream(); |
---|
26 | prop.load(in); |
---|
27 | } catch (Exception e) { |
---|
28 | System.out.println("Could not load Properties file :\n" + e); |
---|
29 | } |
---|
30 | } |
---|
31 | |
---|
32 | /** |
---|
33 | * @see com.swabunga.spell.engine.Configuration#getBoolean(String) |
---|
34 | */ |
---|
35 | public boolean getBoolean(String key) { |
---|
36 | return new Boolean(prop.getProperty(key)).booleanValue(); |
---|
37 | } |
---|
38 | |
---|
39 | /** |
---|
40 | * @see com.swabunga.spell.engine.Configuration#getInteger(String) |
---|
41 | */ |
---|
42 | public int getInteger(String key) { |
---|
43 | return new Integer(prop.getProperty(key)).intValue(); |
---|
44 | } |
---|
45 | |
---|
46 | /** |
---|
47 | * @see com.swabunga.spell.engine.Configuration#setBoolean(String, boolean) |
---|
48 | */ |
---|
49 | public void setBoolean(String key, boolean value) { |
---|
50 | String string = null; |
---|
51 | if (value) |
---|
52 | string = "true"; |
---|
53 | else |
---|
54 | string = "false"; |
---|
55 | |
---|
56 | prop.setProperty(key, string); |
---|
57 | save(); |
---|
58 | } |
---|
59 | |
---|
60 | /** |
---|
61 | * @see com.swabunga.spell.engine.Configuration#setInteger(String, int) |
---|
62 | */ |
---|
63 | public void setInteger(String key, int value) { |
---|
64 | prop.setProperty(key, Integer.toString(value)); |
---|
65 | save(); |
---|
66 | } |
---|
67 | |
---|
68 | public void save() { |
---|
69 | try { |
---|
70 | File file = new File(filename.getFile()); |
---|
71 | FileOutputStream fout = new FileOutputStream(file); |
---|
72 | prop.store(fout, "HEADER"); |
---|
73 | } catch (FileNotFoundException e) { |
---|
74 | } catch (IOException e) { |
---|
75 | } |
---|
76 | } |
---|
77 | |
---|
78 | } |
---|