1 |
/* |
2 |
* jlscp - a java LinuxSampler control protocol API |
3 |
* |
4 |
* Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com> |
5 |
* |
6 |
* This file is part of jlscp. |
7 |
* |
8 |
* jlscp is free software; you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License version 2 |
10 |
* as published by the Free Software Foundation. |
11 |
* |
12 |
* jlscp is distributed in the hope that it will be useful, |
13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
* GNU General Public License for more details. |
16 |
* |
17 |
* You should have received a copy of the GNU General Public License |
18 |
* along with jlscp; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
20 |
* MA 02111-1307 USA |
21 |
*/ |
22 |
|
23 |
package org.linuxsampler.lscp; |
24 |
|
25 |
/** |
26 |
* This class implements the <code>Parameter<Integer></code> interface. |
27 |
* @author Grigor Iliev |
28 |
*/ |
29 |
public class IntParameter extends AbstractParameter<Integer> { |
30 |
/** Creates a new instance of <code>IntParameter</code> */ |
31 |
public |
32 |
IntParameter() { |
33 |
setType(ParameterType.INT); |
34 |
setMultiplicity(false); |
35 |
} |
36 |
|
37 |
/** |
38 |
* Creates an <code>IntParameter</code> instance with the specified name. |
39 |
* @param name The parameter name. |
40 |
*/ |
41 |
public |
42 |
IntParameter(String name) { |
43 |
this(name, null); |
44 |
} |
45 |
|
46 |
/** |
47 |
* Creates an <code>IntParameter</code> instance with the specified name and value. |
48 |
* @param name The parameter name. |
49 |
* @param value The parameter value. |
50 |
*/ |
51 |
public |
52 |
IntParameter(String name, Integer value) { |
53 |
this(); |
54 |
setName(name); |
55 |
setValue(value); |
56 |
} |
57 |
|
58 |
/** |
59 |
* Creates a new instance of <code>IntParameter</code> |
60 |
* and parses the specified lines. |
61 |
* @param lnS A <code>String</code> array with lines to be parsed. |
62 |
* @throws LscpException If the parse fail. |
63 |
*/ |
64 |
protected |
65 |
IntParameter(String[] lnS) throws LscpException { |
66 |
this(); |
67 |
parseLines(lnS); |
68 |
} |
69 |
|
70 |
/** |
71 |
* Parses a line of text. |
72 |
* @param s The string to be parsed. |
73 |
* @return <code>true</code> if the line has been processed, <code>false</code> otherwise. |
74 |
* @throws LscpException If some error occurs. |
75 |
*/ |
76 |
public boolean |
77 |
parse(String s) throws LscpException { |
78 |
if(super.parse(s)) return true; |
79 |
else if(s.startsWith("RANGE_MIN: ")) { |
80 |
s = s.substring("RANGE_MIN: ".length(), s.length()); |
81 |
try { |
82 |
setRangeMin(Integer.parseInt(s)); |
83 |
return true; |
84 |
} catch(NumberFormatException x) { throw new LscpException ( |
85 |
LscpI18n.getLogMsg("notInt!", "RANGE_MIN"), x |
86 |
);} |
87 |
} else if(s.startsWith("RANGE_MAX: ")) { |
88 |
s = s.substring("RANGE_MAX: ".length(), s.length()); |
89 |
try { |
90 |
setRangeMax(Integer.parseInt(s)); |
91 |
return true; |
92 |
} catch(NumberFormatException x) { throw new LscpException ( |
93 |
LscpI18n.getLogMsg("notInt!", "RANGE_MAX"), x |
94 |
);} |
95 |
} else if(s.startsWith("DEFAULT: ")) { |
96 |
s = s.substring("DEFAULT: ".length(), s.length()); |
97 |
try { |
98 |
setDefault(Integer.parseInt(s)); |
99 |
return true; |
100 |
} catch(NumberFormatException x) { throw new LscpException ( |
101 |
LscpI18n.getLogMsg("notInt!", "DEFAULT"), x |
102 |
);} |
103 |
} else if(s.startsWith("POSSIBILITIES: ")) { |
104 |
s = s.substring("POSSIBILITIES: ".length(), s.length()); |
105 |
setPossibilities(Parser.parseIntList(s)); |
106 |
return true; |
107 |
} |
108 |
|
109 |
return false; |
110 |
} |
111 |
|
112 |
/** |
113 |
* Parses the specified character string and sets the value of this parameter |
114 |
* with the parsed result. |
115 |
* @param s A character string containing the value to be parsed. |
116 |
* @throws LscpException If the parsing failed. |
117 |
*/ |
118 |
public void |
119 |
parseValue(String s) throws LscpException { setValue(Parser.parseInt(s)); } |
120 |
|
121 |
/** |
122 |
* Gets a character string representation of the parameter's value. |
123 |
* @return A character string representation of the parameter's value. |
124 |
*/ |
125 |
public String |
126 |
getStringValue() { return String.valueOf(getValue()); } |
127 |
|
128 |
|
129 |
} |