157 |
kaklik |
1 |
/*
|
|
|
2 |
AVRcamVIEW: A PC application to test out the functionallity of the
|
|
|
3 |
AVRcam real-time image processing engine.
|
|
|
4 |
Copyright (C) 2004 Brent A. Taylor
|
|
|
5 |
|
|
|
6 |
This program is free software; you can redistribute it and/or
|
|
|
7 |
modify it under the terms of the GNU General Public
|
|
|
8 |
License as published by the Free Software Foundation; either
|
|
|
9 |
version 2 of the License, or (at your option) any later version.
|
|
|
10 |
|
|
|
11 |
This program is distributed in the hope that it will be useful,
|
|
|
12 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
14 |
General Public License for more details.
|
|
|
15 |
|
|
|
16 |
You should have received a copy of the GNU General Public
|
|
|
17 |
License along with this program; if not, write to the Free Software
|
|
|
18 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
19 |
|
|
|
20 |
For more information on the AVRcamVIEW, please contact:
|
|
|
21 |
|
|
|
22 |
taylorba@comcast.net
|
|
|
23 |
|
|
|
24 |
or go to www.jrobot.net for more details regarding the system.
|
|
|
25 |
*/
|
|
|
26 |
|
|
|
27 |
package avr.lang;
|
|
|
28 |
|
|
|
29 |
import java.util.*;
|
|
|
30 |
|
|
|
31 |
/***************************************************************
|
|
|
32 |
* This is a convience class wrapped around a ResourceBundle.
|
|
|
33 |
*/
|
|
|
34 |
public class Resource {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* The ResourceBundle to retrieve the key=value mappings.
|
|
|
38 |
*/
|
|
|
39 |
private final ResourceBundle BUNDLE;
|
|
|
40 |
|
|
|
41 |
/**
|
|
|
42 |
* Create an instance of this resource bundle to retrieve the
|
|
|
43 |
* key=value pairs from the given file.
|
|
|
44 |
* @param file The file containing the key=value pairs.
|
|
|
45 |
*/
|
|
|
46 |
public Resource(String file) {
|
|
|
47 |
BUNDLE = ResourceBundle.getBundle(file);
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
/**
|
|
|
51 |
* Gets a String for the given key from this resource bundle
|
|
|
52 |
* @param key The key for the desired string
|
|
|
53 |
* @return The string for the given key
|
|
|
54 |
*/
|
|
|
55 |
public String getString(String key) {
|
|
|
56 |
return BUNDLE.getString(key);
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* Convience method to convert the returned value for the key into
|
|
|
61 |
* an integer.
|
|
|
62 |
* @param key The key for the desired integer
|
|
|
63 |
* @return The integer for the given key.
|
|
|
64 |
*/
|
|
|
65 |
public int getInt(String key) {
|
|
|
66 |
return Integer.parseInt(getString(key));
|
|
|
67 |
}
|
|
|
68 |
|
|
|
69 |
/**
|
|
|
70 |
* Convience method to convert the returned value for the key into
|
|
|
71 |
* an character.
|
|
|
72 |
* @param key The key for the desired character
|
|
|
73 |
* @return The character for the given key.
|
|
|
74 |
*/
|
|
|
75 |
public char getChar(String key) {
|
|
|
76 |
return getString(key).charAt(0);
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
/**
|
|
|
80 |
* Convience method to convert the returned value for the key into
|
|
|
81 |
* an boolean.
|
|
|
82 |
* @param key The key for the desired boolean
|
|
|
83 |
* @return The boolean for the given key.
|
|
|
84 |
*/
|
|
|
85 |
public boolean getBoolean(String key) {
|
|
|
86 |
return new Boolean(getString(key)).booleanValue();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
/**
|
|
|
90 |
* Convience method to convert the returned value for the key into
|
|
|
91 |
* an array of Strings.
|
|
|
92 |
* @param key The key for the desired array of Strings
|
|
|
93 |
* @return The array of Strings for the given key.
|
|
|
94 |
*/
|
|
|
95 |
public String[] getStrings(String key) {
|
|
|
96 |
// split the value string on every "," or ", "
|
|
|
97 |
return getString(key).split(",\\s*");
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Convience method to convert the returned value for the key into
|
|
|
102 |
* an array of Integers.
|
|
|
103 |
* @param key The key for the desired array of Integers
|
|
|
104 |
* @return The array of Integers for the given key.
|
|
|
105 |
*/
|
|
|
106 |
public Integer[] getIntegers(String key) {
|
|
|
107 |
|
|
|
108 |
String[] strValues = getStrings(key);
|
|
|
109 |
|
|
|
110 |
Integer[] values = new Integer[strValues.length];
|
|
|
111 |
|
|
|
112 |
for(int i = 0; i < strValues.length; i++) {
|
|
|
113 |
values[i] = new Integer(strValues[i]);
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
return values;
|
|
|
117 |
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
}
|