00001 /* 00002 * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc. 00003 * All rights reserved. This program is made available under the terms of the 00004 * Eclipse Public License v1.0 which accompanies this distribution, and is 00005 * available at http://www.eclipse.org/legal/epl-v10.html 00006 * Contributors: 00007 * General Robotix Inc. 00008 * National Institute of Advanced Industrial Science and Technology (AIST) 00009 */ 00016 package com.generalrobotix.ui.view.graph; 00017 00018 import java.text.DecimalFormat; 00019 00020 public class SEDouble implements StringExchangeable { 00021 Double value_; 00022 DecimalFormat df_; 00023 boolean isNaN_; 00024 00030 public SEDouble(double value) { 00031 value_ = new Double(value); 00032 df_ = new DecimalFormat("0.######"); 00033 }; 00034 00035 public SEDouble(String value) { 00036 if (value.equals("NaN") || value.equals("")) { 00037 isNaN_ = true; 00038 value_ = new Double(Double.NaN); 00039 } else { 00040 value_ = new Double(value); 00041 } 00042 df_ = new DecimalFormat("0.######"); 00043 } 00044 00050 public String toString() { 00051 if (isNaN_) { 00052 return ""; 00053 } else { 00054 return df_.format(value_.doubleValue()); 00055 } 00056 } 00057 00063 public Object fromString(String str) { 00064 if (str.equals("NaN") || str.equals("")) { 00065 isNaN_ = true; 00066 value_ = new Double(Double.NaN); 00067 } else { 00068 value_ = new Double(str); 00069 } 00070 return (Object)value_; 00071 } 00072 00077 public void setValue(Object value) { 00078 value_ = (Double)value; 00079 } 00080 00085 public void setValue(String str) { 00086 value_ = new Double(str); 00087 } 00088 00089 public void setValue(double value) { 00090 value_ = new Double(value); 00091 } 00092 00097 public Object getValue() { 00098 return (Object)value_; 00099 } 00100 00101 public double doubleValue() { 00102 return value_.doubleValue(); 00103 } 00104 00105 public float floatValue() { 00106 return value_.floatValue(); 00107 } 00108 }