1 |
/* |
2 |
* jlscp - a java LinuxSampler control protocol API |
3 |
* |
4 |
* Copyright (C) 2005 Grigor Kirilov Iliev |
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<Boolean></code> interface. |
27 |
* @author Grigor Iliev |
28 |
*/ |
29 |
public class BoolParameter extends AbstractParameter<Boolean> { |
30 |
/** Creates a new instance of <code>BoolParameter</code> */ |
31 |
public |
32 |
BoolParameter() { |
33 |
setType(ParameterType.BOOL); |
34 |
setMultiplicity(false); |
35 |
} |
36 |
|
37 |
/** |
38 |
* Creates a <code>BoolParameter</code> instance with the specified name. |
39 |
* @param name The parameter name. |
40 |
*/ |
41 |
public |
42 |
BoolParameter(String name) { |
43 |
this(name, null); |
44 |
} |
45 |
|
46 |
/** |
47 |
* Creates a <code>BoolParameter</code> instance with the specified name and value. |
48 |
* @param name The parameter name. |
49 |
* @param value The parameter value. |
50 |
*/ |
51 |
public |
52 |
BoolParameter(String name, Boolean value) { |
53 |
this(); |
54 |
setName(name); |
55 |
setValue(value); |
56 |
} |
57 |
|
58 |
/** |
59 |
* Creates a new instance of <code>BoolParameter</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 |
public |
65 |
BoolParameter(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("DEFAULT: ")) { |
80 |
s = s.substring("DEFAULT: ".length(), s.length()); |
81 |
setDefault(Boolean.parseBoolean(s)); |
82 |
return true; |
83 |
} else if(s.startsWith("POSSIBILITIES: ")) { |
84 |
s = s.substring("POSSIBILITIES: ".length(), s.length()); |
85 |
setPossibilities(Parser.parseBoolList(s)); |
86 |
return true; |
87 |
} |
88 |
|
89 |
return false; |
90 |
} |
91 |
|
92 |
/** |
93 |
* Parses the specified character string and sets the value of this parameter |
94 |
* with the parsed result. |
95 |
* @param s A character string containing the value to be parsed. |
96 |
*/ |
97 |
public void |
98 |
parseValue(String s) { setValue(Boolean.parseBoolean(s)); } |
99 |
|
100 |
/** |
101 |
* Gets a character string representation of the parameter's value. |
102 |
* @return A character string representation of the parameter's value. |
103 |
*/ |
104 |
public String |
105 |
getStringValue() { return String.valueOf(getValue()); } |
106 |
} |