An abstract class that minimizes the effort required to implement
the
ValueModel
interface. It provides convenience methods
to convert boolean, double, float, int, and long to their
corresponding Object values and vice versa.
Subclasses must implement
getValue()
and
setValue(Object)
to get and set this model's value.
String toString
public @Override String toString()
Returns a string representation of this value model.
Answers the print string of the observed value.
- a string representation of this value model
addValueChangeListener
public final void addValueChangeListener(PropertyChangeListener l)
Registers the given PropertyChangeListener with this model.
The listener will be notified if the value has changed.
The PropertyChangeEvents delivered to the listener have the name
set to "value". In other words, the listeners won't get notified
when a PropertyChangeEvent is fired that has a null object as
the name to indicate an arbitrary set of the event source's
properties have changed.
In the rare case, where you want to notify a PropertyChangeListener
even with PropertyChangeEvents that have no property name set,
you can register the listener with #addPropertyChangeListener,
not #addValueChangeListener.
- addValueChangeListener in interface ValueModel
booleanValue
public final boolean booleanValue()
Converts this model's value and returns it as a boolean
.
doubleValue
public final double doubleValue()
Converts this model's value and returns it as a double
.
fireValueChange
public final void fireValueChange(Object oldValue,
Object newValue)
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
oldValue
- the value before the changenewValue
- the value after the change
java.beans.PropertyChangeSupport
fireValueChange
public final void fireValueChange(Object oldValue,
Object newValue,
boolean checkIdentity)
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
The boolean parameter specifies whether differences between the old
and new value are tested using
==
or
#equals
.
oldValue
- the value before the changenewValue
- the value after the changecheckIdentity
- true to compare the old and new value using
==
, false to use #equals
java.beans.PropertyChangeSupport
fireValueChange
public final void fireValueChange(boolean oldValue,
boolean newValue)
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
oldValue
- the boolean value before the changenewValue
- the boolean value after the change
java.beans.PropertyChangeSupport
fireValueChange
public final void fireValueChange(double oldValue,
double newValue)
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
oldValue
- the double value before the changenewValue
- the double value after the change
java.beans.PropertyChangeSupport
fireValueChange
public final void fireValueChange(float oldValue,
float newValue)
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
oldValue
- the float value before the changenewValue
- the float value after the change
java.beans.PropertyChangeSupport
fireValueChange
public final void fireValueChange(int oldValue,
int newValue)
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
oldValue
- the int value before the changenewValue
- the int value after the change
java.beans.PropertyChangeSupport
fireValueChange
public final void fireValueChange(long oldValue,
long newValue)
Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the parameters passed into
the fire method.
oldValue
- the long value before the changenewValue
- the long value after the change
java.beans.PropertyChangeSupport
floatValue
public final float floatValue()
Converts this model's value and returns it as a float
.
getString
public String getString()
Converts this model's value and returns it as a String
.
- this model's value as String
intValue
public final int intValue()
Converts this model's value and returns it as an int
.
longValue
public final long longValue()
Converts this model's value and returns it as a long
.
paramString
protected String paramString()
Returns a string representing the state of this model.
This method is intended to be used only for debugging purposes,
and the content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null
.
- a string representation of this model's state
removeValueChangeListener
public final void removeValueChangeListener(PropertyChangeListener l)
Removes the given PropertyChangeListener from the model.
- removeValueChangeListener in interface ValueModel
l
- the listener to remove
setValue
public final void setValue(boolean b)
Converts the given boolean
to a Boolean
and
sets it as new value.
b
- the value to be converted and set as new value
setValue
public final void setValue(double d)
Converts the given double
to a Double
and
sets it as new value.
d
- the value to be converted and set as new value
setValue
public final void setValue(float f)
Converts the given float
to a Float
and
sets it as new value.
f
- the value to be converted and set as new value
setValue
public final void setValue(int i)
Converts the given int
to an Integer
and
sets it as new value.
i
- the value to be converted and set as new value
setValue
public final void setValue(long l)
Converts the given long
to a Long
and
sets it as new value.
l
- the value to be converted and set as new value
valueString
protected String valueString()
Returns a string representing the value of this model.
This method is intended to be used for debugging purposes only.
- a string representation of this model's value