01: /*
02: $Id: DoubleParameter.java,v 1.4 2005/02/14 12:06:19 vauclair Exp $
03:
04: Copyright (C) 2002-2005 Sebastien Vauclair
05:
06: This file is part of Extensible Java Profiler.
07:
08: Extensible Java Profiler is free software; you can redistribute it and/or
09: modify it under the terms of the GNU General Public License as published by
10: the Free Software Foundation; either version 2 of the License, or
11: (at your option) any later version.
12:
13: Extensible Java Profiler is distributed in the hope that it will be useful,
14: but WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: GNU General Public License for more details.
17:
18: You should have received a copy of the GNU General Public License
19: along with Extensible Java Profiler; if not, write to the Free Software
20: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: */
22:
23: package ejp.presenter.api.filters.parameters;
24:
25: import java.awt.Dimension;
26: import java.text.DecimalFormat;
27: import java.text.Format;
28:
29: import javax.swing.JFormattedTextField;
30: import javax.swing.SwingConstants;
31:
32: import ejp.presenter.gui.Utils;
33:
34: public class DoubleParameter extends AbstractParameter {
35: private static final Format FORMAT = new DecimalFormat(
36: "#####0.0#####");
37:
38: private final JFormattedTextField m_jtfValue;
39:
40: public DoubleParameter(String aName, String aTitle,
41: String aToolTipText) {
42: super (aName, aTitle, aToolTipText);
43:
44: m_jtfValue = new JFormattedTextField(FORMAT);
45: m_jtfValue.setHorizontalAlignment(SwingConstants.RIGHT);
46: m_jtfValue.setValue(new Double(999999.999999D));
47: Dimension prefSize = m_jtfValue.getPreferredSize();
48: m_jtfValue.setValue(new Double(1));
49: m_jtfValue.setPreferredSize(prefSize);
50: m_jtfValue
51: .setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);
52: Utils.setCommonProperties(m_jtfValue);
53: addLine("Value", "Setup value.", m_jtfValue, null);
54: }
55:
56: public void setReadOnly() {
57: m_jtfValue.setEnabled(false);
58: }
59:
60: public Object getValue() {
61: Double result;
62: try {
63: result = new Double(Double.parseDouble(m_jtfValue
64: .getValue().toString()));
65: } catch (NumberFormatException nfe) {
66: throw new IllegalStateException("Value \""
67: + m_jtfValue.getValue()
68: + "\" does not parse as a double");
69: }
70: return result;
71: }
72:
73: public String getValueAsText() {
74: return getValue().toString();
75: }
76:
77: public void setValue(Object aObject) throws ClassCastException {
78: Double d = (Double) aObject;
79: m_jtfValue.setValue(d);
80: }
81:
82: public void setValueAsText(String aTextValue)
83: throws IllegalArgumentException {
84: double d;
85: try {
86: d = Double.parseDouble(aTextValue);
87: } catch (NumberFormatException nfe) {
88: throw new IllegalArgumentException("Value \"" + aTextValue
89: + "\" does not parse as a double");
90: }
91: setValue(new Double(d));
92: }
93: }
|