/[svn]/jlscp/trunk/src/org/linuxsampler/lscp/FloatParameter.java
ViewVC logotype

Annotation of /jlscp/trunk/src/org/linuxsampler/lscp/FloatParameter.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1139 - (hide annotations) (download)
Mon Apr 2 20:43:58 2007 UTC (17 years, 1 month ago) by iliev
File size: 3864 byte(s)
* upgraded to version 0.4a

1 iliev 596 /*
2     * jlscp - a java LinuxSampler control protocol API
3     *
4 iliev 1139 * Copyright (C) 2005-2006 Grigor Iliev <grigor@grigoriliev.com>
5 iliev 596 *
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&lt;Float&gt;</code> interface.
27     *
28     * @author Grigor Iliev
29     */
30     public class FloatParameter extends AbstractParameter<Float> {
31     /** Creates a new instance of <code>FloatParameter</code> */
32     public
33     FloatParameter() {
34     setType(ParameterType.FLOAT);
35     setMultiplicity(false);
36     }
37    
38     /**
39     * Creates a <code>FloatParameter</code> instance with the specified name.
40     * @param name The parameter name.
41     */
42     public
43     FloatParameter(String name) {
44     this(name, null);
45     }
46    
47     /**
48     * Creates a <code>FloatParameter</code> instance with the specified name and value.
49     * @param name The parameter name.
50     * @param value The parameter value.
51     */
52     public
53     FloatParameter(String name, Float value) {
54     this();
55     setName(name);
56     setValue(value);
57     }
58    
59     /**
60     * Creates a new instance of <code>FloatParameter</code>
61     * and parses the specified lines.
62     * @param lnS A <code>String</code> array with lines to be parsed.
63     * @throws LscpException If the parse fail.
64     */
65     protected
66     FloatParameter(String[] lnS) throws LscpException {
67     this();
68     parseLines(lnS);
69     }
70    
71     /**
72     * Parses a line of text.
73     * @param s The string to be parsed.
74     * @return <code>true</code> if the line has been processed, <code>false</code> otherwise.
75     * @throws LscpException If some error occurs.
76     */
77     public boolean
78     parse(String s) throws LscpException {
79     if(super.parse(s)) return true;
80     else if(s.startsWith("RANGE_MIN: ")) {
81     s = s.substring("RANGE_MIN: ".length(), s.length());
82     try {
83     setRangeMin(Float.parseFloat(s));
84     return true;
85     } catch(NumberFormatException x) { throw new LscpException (
86     LscpI18n.getLogMsg("notFloat!", "RANGE_MIN"), x
87     );}
88     } else if(s.startsWith("RANGE_MAX: ")) {
89     s = s.substring("RANGE_MAX: ".length(), s.length());
90     try {
91     setRangeMax(Float.parseFloat(s));
92     return true;
93     } catch(NumberFormatException x) { throw new LscpException (
94     LscpI18n.getLogMsg("notFloat!", "RANGE_MAX"), x
95     );}
96     } else if(s.startsWith("DEFAULT: ")) {
97     s = s.substring("DEFAULT: ".length(), s.length());
98     try {
99     setDefault(Float.parseFloat(s));
100     return true;
101     } catch(NumberFormatException x) { throw new LscpException (
102     LscpI18n.getLogMsg("notFloat!", "DEFAULT"), x
103     );}
104     } else if(s.startsWith("POSSIBILITIES: ")) {
105     s = s.substring("POSSIBILITIES: ".length(), s.length());
106     setPossibilities(Parser.parseFloatList(s));
107     return true;
108     }
109    
110     return false;
111     }
112    
113     /**
114     * Parses the specified character string and sets the value of this parameter
115     * with the parsed result.
116     * @param s A character string containing the value to be parsed.
117     * @throws LscpException If the parsing failed.
118     */
119     public void
120     parseValue(String s) throws LscpException {
121     setValue(Parser.parseFloat(s));
122     }
123    
124     /**
125     * Gets a character string representation of the parameter's value.
126     * @return A character string representation of the parameter's value.
127     */
128     public String
129     getStringValue() { return String.valueOf(getValue()); }
130     }

  ViewVC Help
Powered by ViewVC