util
Class DoubleBean

java.lang.Object
  extended by util.DoubleBean

public abstract class DoubleBean
extends java.lang.Object

A "bean" (class with get/set methods) that records a double. Useful with the Beanshell syntactic sugar that turns bean.value into bean.getValue() and bean.value=x into bean.setValue(x). Also includes a convenience methods to create a JTextfield, a labelled JTextfield, a TableCellRenderer and a TableCellEditor that reflects the value.

Author:
Daniel Wachsstock

Field Summary
static double LOG10
          the natural logarithm of 10, for calculating log base 10
static java.lang.String MAX_STRING
          a String that is larger than anything produced by toString()
 
Constructor Summary
DoubleBean()
           
 
Method Summary
 javax.swing.Box box(java.lang.String label)
          Create a Swing Box that reflects this value.
static javax.swing.table.TableCellEditor cellEditor()
          create a cell editor that uses a DoubleBean.textfield.
static javax.swing.table.TableCellRenderer cellRenderer()
          create a table cell renderer that displays a number in the same format as a DoubleBean.textfield.
abstract  double getValue()
           
abstract  void setValue(double x)
           
 javax.swing.JTextField textfield()
          Create a Swing JTextField that reflects this value.
 java.lang.String toString()
          the value as a String.
static java.lang.String toString(double d)
          the value as a String.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOG10

public static final double LOG10
the natural logarithm of 10, for calculating log base 10


MAX_STRING

public static final java.lang.String MAX_STRING
a String that is larger than anything produced by toString()

See Also:
Constant Field Values
Constructor Detail

DoubleBean

public DoubleBean()
Method Detail

getValue

public abstract double getValue()

setValue

public abstract void setValue(double x)

toString

public java.lang.String toString()
the value as a String. Formats numbers to a string in a way that I like--limited significant digits, scientific notation if they are too large or small. Formats a NaN as " " (one space) Decimal Format is just too inflexible.

Overrides:
toString in class java.lang.Object
Returns:
the String

toString

public static java.lang.String toString(double d)
the value as a String. Formats numbers to a string in a way that I like--limited significant digits, scientific notation if they are too large or small. Formats a NaN as " " (one space). Decimal Format is just too inflexible.
This is synchronized, so multiple threads can use it.

Parameters:
d - the double to format
Returns:
the String

box

public javax.swing.Box box(java.lang.String label)
Create a Swing Box that reflects this value. It is composed of a JLabel and a JTextfield under that, with the value in the textbox. Editing the text box will call setValue but the reverse is not automatically true; if setValue is called, the text box does not change unless the subclass's setValue explicitly does so. However, each repaint of this component calls getValue, so calling box.repaint() after setValue will accomplish that. Imposes an input verifier such that, if the edited text does not represent a number, the text reverts to the original.

Parameters:
label - the initial label on the box
Returns:
the Box

textfield

public javax.swing.JTextField textfield()
Create a Swing JTextField that reflects this value. Editing the text box will call setValue but the reverse is not automatically true; if setValue is called, the text box does not change unless the subclass's setValue explicitly does so. However, each repaint of this component calls getValue, so calling text.repaint() after setValue will accomplish that. Imposes an input verifier such that, if the edited text does not represent a number, the text reverts to the original.

Returns:
the JTextField

cellRenderer

public static javax.swing.table.TableCellRenderer cellRenderer()
create a table cell renderer that displays a number in the same format as a DoubleBean.textfield.

Returns:
the TableCellRenderer
Throws:
java.lang.NumberFormatException - if the value of the cell is not a Number

cellEditor

public static javax.swing.table.TableCellEditor cellEditor()
create a cell editor that uses a DoubleBean.textfield.

Returns:
the TableCellEditor. This is guaranteed to also implement TreeCellEditor, if you want to cast it that way.
Throws:
java.lang.NumberFormatException - if the value of the cell is not a Number