01: /*
02: * Koala Bean Markup Language - Copyright (C) 1999 Dyade
03: *
04: * Permission is hereby granted, free of charge, to any person obtaining a
05: * copy of this software and associated documentation files
06: * (the "Software"), to deal in the Software without restriction, including
07: * without limitation the rights to use, copy, modify, merge, publish,
08: * distribute, sublicense, and/or sell copies of the Software, and to permit
09: * persons to whom the Software is furnished to do so, subject to the
10: * following conditions:
11: * The above copyright notice and this permission notice shall be included
12: * in all copies or substantial portions of the Software.
13: *
14: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17: * IN NO EVENT SHALL Dyade BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20: * DEALINGS IN THE SOFTWARE.
21: *
22: * Except as contained in this notice, the name of Dyade shall not be
23: * used in advertising or otherwise to promote the sale, use or other
24: * dealings in this Software without prior written authorization from
25: * Dyade.
26: *
27: * $Id: DoubleEditor.java,v 1.1.1.1 1999/11/03 15:34:30 phk Exp $
28: * Author: Thierry.Kormann@sophia.inria.fr
29: */
30:
31: package fr.dyade.koala.xml.kbml.editors;
32:
33: import java.beans.*;
34:
35: /**
36: * A simple property editor for the <code>java.lang.Double</code> class.
37: *
38: * @author Thierry.Kormann@sophia.inria.fr
39: */
40: public class DoubleEditor extends PropertyEditorSupport {
41:
42: static final String POSITIVE_INFINITY_STRING = ""
43: + Double.POSITIVE_INFINITY;
44: static final String NEGATIVE_INFINITY_STRING = ""
45: + Double.NEGATIVE_INFINITY;
46: static final String NaN_STRING = "" + Double.NaN;
47: static final Double POSITIVE_INFINITY_DOUBLE = new Double(
48: Double.POSITIVE_INFINITY);
49: static final Double NEGATIVE_INFINITY_DOUBLE = new Double(
50: Double.NEGATIVE_INFINITY);
51: static final Double NaN_DOUBLE = new Double(Double.NaN);
52:
53: public String getJavaInitializationString() {
54: if (getValue().getClass() == Double.TYPE) {
55: // double primitive type
56: if (getValue() == POSITIVE_INFINITY_DOUBLE) {
57: return "Double.POSITIVE_INFINITY";
58: } else if (getValue() == NEGATIVE_INFINITY_DOUBLE) {
59: return "Double.NEGATIVE_INFINITY";
60: } else if (getValue() == NaN_DOUBLE) {
61: return "Double.NaN";
62: } else {
63: return "" + getValue();
64: }
65: } else {
66: // java.lang.Double
67: if (getValue() == POSITIVE_INFINITY_DOUBLE) {
68: return "new Double(Double.POSITIVE_INFINITY)";
69: } else if (getValue() == NEGATIVE_INFINITY_DOUBLE) {
70: return "new Double(Double.NEGATIVE_INFINITY)";
71: } else if (getValue() == NaN_DOUBLE) {
72: return "new Double(Double.NaN)";
73: } else {
74: return "" + getValue();
75: }
76: }
77: }
78:
79: public void setAsText(String s) {
80: if (POSITIVE_INFINITY_STRING.equals(s)) {
81: setValue(POSITIVE_INFINITY_DOUBLE);
82: } else if (NEGATIVE_INFINITY_STRING.equals(s)) {
83: setValue(NEGATIVE_INFINITY_DOUBLE);
84: } else if (NaN_STRING.equals(s)) {
85: setValue(NaN_DOUBLE);
86: } else {
87: setValue(Double.valueOf(s));
88: }
89: }
90: }
|