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<Boolean[]></code> interface. |
27 |
* @author Grigor Iliev |
28 |
*/ |
29 |
public class BoolListParameter extends AbstractParameter<Boolean[]> { |
30 |
private boolean[] val = null; |
31 |
private boolean[] dflt = null; |
32 |
private boolean[] possibilities = null; |
33 |
|
34 |
|
35 |
/** Creates a new instance of <code>BoolListParameter</code> */ |
36 |
public |
37 |
BoolListParameter() { |
38 |
setType(ParameterType.BOOL_LIST); |
39 |
setMultiplicity(true); |
40 |
} |
41 |
|
42 |
/** |
43 |
* Creates a <code>BoolListParameter</code> instance with the specified name. |
44 |
* @param name The parameter name. |
45 |
*/ |
46 |
public |
47 |
BoolListParameter(String name) { |
48 |
this(name, null); |
49 |
} |
50 |
|
51 |
/** |
52 |
* Creates a <code>BoolListParameter</code> instance with the specified name and value. |
53 |
* @param name The parameter name. |
54 |
* @param value The parameter value. |
55 |
*/ |
56 |
public |
57 |
BoolListParameter(String name, Boolean[] value) { |
58 |
this(); |
59 |
setName(name); |
60 |
setValue(value); |
61 |
} |
62 |
|
63 |
/** |
64 |
* Creates a new instance of <code>BoolListParameter</code> |
65 |
* and parses the specified lines. |
66 |
* @param lnS A <code>String</code> array with lines to be parsed. |
67 |
* @throws LscpException If the parse fail. |
68 |
*/ |
69 |
protected |
70 |
BoolListParameter(String[] lnS) throws LscpException { |
71 |
this(); |
72 |
parseLines(lnS); |
73 |
} |
74 |
|
75 |
/** |
76 |
* Parses a line of text. |
77 |
* @param s The string to be parsed. |
78 |
* @return <code>true</code> if the line has been processed, <code>false</code> otherwise. |
79 |
* @throws LscpException If some error occurs. |
80 |
*/ |
81 |
public boolean |
82 |
parse(String s) throws LscpException { |
83 |
if(super.parse(s)) return true; |
84 |
else if(s.startsWith("DEFAULT: ")) { |
85 |
s = s.substring("DEFAULT: ".length(), s.length()); |
86 |
setDefault(Parser.parseBoolList(s)); |
87 |
return true; |
88 |
} else if(s.startsWith("POSSIBILITIES: ")) { |
89 |
// Possible problems here??? |
90 |
s = s.substring("POSSIBILITIES: ".length(), s.length()); |
91 |
|
92 |
String[] sS = Parser.parseQuotedStringList(s); |
93 |
Boolean[][] b2S = new Boolean[sS.length][]; |
94 |
for(int i = 0; i < sS.length; i++) b2S[i] = Parser.parseBoolList(sS[i]); |
95 |
setPossibilities(b2S); |
96 |
|
97 |
return true; |
98 |
} |
99 |
|
100 |
return false; |
101 |
} |
102 |
|
103 |
/** |
104 |
* Parses the specified character string and sets the value of this parameter |
105 |
* with the parsed result. |
106 |
* @param s A character string containing the value to be parsed. |
107 |
*/ |
108 |
public void |
109 |
parseValue(String s) { setValue(Parser.parseBoolList(s)); } |
110 |
|
111 |
/** |
112 |
* Gets a character string representation of the parameter's value. |
113 |
* @return A character string representation of the parameter's value. |
114 |
*/ |
115 |
public String |
116 |
getStringValue() { |
117 |
Boolean[] ar = getValue(); |
118 |
|
119 |
if(ar == null || ar.length == 0) return ""; |
120 |
|
121 |
StringBuffer sb = new StringBuffer(); |
122 |
sb.append(ar[0]); |
123 |
|
124 |
for(int i = 1; i < ar.length; i++) sb.append(',').append(ar[i]); |
125 |
|
126 |
return sb.toString(); |
127 |
} |
128 |
} |