com.jgoodies.binding.value
Class AbstractValueModel

java.lang.Object
  extended by AbstractBean
      extended by com.jgoodies.binding.beans.Model
          extended by com.jgoodies.binding.value.AbstractValueModel
All Implemented Interfaces:
Observable, ValueModel
Direct Known Subclasses:
AbstractConverter, AbstractVetoableValueModel, BeanAdapter.SimplePropertyAdapter, BufferedValueModel, ComponentValueModel, DelayedReadValueModel, DelayedWriteValueModel, NonNullValueModel, PreferencesAdapter, PropertyAdapter, Trigger, ValueHolder

public abstract class AbstractValueModel
extends Model
implements ValueModel

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.

Version:
$Revision: 1.11 $
Author:
Karsten Lentzsch
See Also:
ExtendedPropertyChangeSupport

Field Summary
static java.lang.String PROPERTYNAME_VALUE
          The name of the bound property value.
 
Constructor Summary
AbstractValueModel()
           
 
Method Summary
 void addValueChangeListener(java.beans.PropertyChangeListener l)
          Registers the given PropertyChangeListener with this model.
 boolean booleanValue()
          Converts this model's value and returns it as a boolean.
 double doubleValue()
          Converts this model's value and returns it as a double.
 void fireValueChange(boolean oldValue, boolean newValue)
          Notifies all listeners that have registered interest for notification on this event type.
 void fireValueChange(double oldValue, double newValue)
          Notifies all listeners that have registered interest for notification on this event type.
 void fireValueChange(float oldValue, float newValue)
          Notifies all listeners that have registered interest for notification on this event type.
 void fireValueChange(int oldValue, int newValue)
          Notifies all listeners that have registered interest for notification on this event type.
 void fireValueChange(long oldValue, long newValue)
          Notifies all listeners that have registered interest for notification on this event type.
 void fireValueChange(java.lang.Object oldValue, java.lang.Object newValue)
          Notifies all listeners that have registered interest for notification on this event type.
 void fireValueChange(java.lang.Object oldValue, java.lang.Object newValue, boolean checkIdentity)
          Notifies all listeners that have registered interest for notification on this event type.
 float floatValue()
          Converts this model's value and returns it as a float.
 java.lang.String getString()
          Converts this model's value and returns it as a String.
 int intValue()
          Converts this model's value and returns it as an int.
 long longValue()
          Converts this model's value and returns it as a long.
protected  java.lang.String paramString()
          Returns a string representing the state of this model.
 void removeValueChangeListener(java.beans.PropertyChangeListener l)
          Removes the given PropertyChangeListener from the model.
 void setValue(boolean b)
          Converts the given boolean to a Boolean and sets it as new value.
 void setValue(double d)
          Converts the given double to a Double and sets it as new value.
 void setValue(float f)
          Converts the given float to a Float and sets it as new value.
 void setValue(int i)
          Converts the given int to an Integer and sets it as new value.
 void setValue(long l)
          Converts the given long to a Long and sets it as new value.
 java.lang.String toString()
          Returns a string representation of this value model.
protected  java.lang.String valueString()
          Returns a string representing the value of this model.
 
Methods inherited from class com.jgoodies.binding.beans.Model
createPropertyChangeSupport, firePropertyChange
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.jgoodies.binding.value.ValueModel
getValue, setValue
 
Methods inherited from interface com.jgoodies.binding.beans.Observable
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

PROPERTYNAME_VALUE

public static final java.lang.String PROPERTYNAME_VALUE
The name of the bound property value.

See Also:
Constant Field Values
Constructor Detail

AbstractValueModel

public AbstractValueModel()
Method Detail

addValueChangeListener

public final void addValueChangeListener(java.beans.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.

Specified by:
addValueChangeListener in interface ValueModel
Parameters:
l - the listener to add
See Also:
ValueModel

removeValueChangeListener

public final void removeValueChangeListener(java.beans.PropertyChangeListener l)
Removes the given PropertyChangeListener from the model.

Specified by:
removeValueChangeListener in interface ValueModel
Parameters:
l - the listener to remove

fireValueChange

public final void fireValueChange(java.lang.Object oldValue,
                                  java.lang.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.

Parameters:
oldValue - the value before the change
newValue - the value after the change
See Also:
PropertyChangeSupport

fireValueChange

public final void fireValueChange(java.lang.Object oldValue,
                                  java.lang.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.

Parameters:
oldValue - the value before the change
newValue - the value after the change
checkIdentity - true to compare the old and new value using ==, false to use #equals
See Also:
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.

Parameters:
oldValue - the boolean value before the change
newValue - the boolean value after the change
See Also:
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.

Parameters:
oldValue - the int value before the change
newValue - the int value after the change
See Also:
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.

Parameters:
oldValue - the long value before the change
newValue - the long value after the change
See Also:
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.

Parameters:
oldValue - the double value before the change
newValue - the double value after the change
See Also:
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.

Parameters:
oldValue - the float value before the change
newValue - the float value after the change
See Also:
PropertyChangeSupport

booleanValue

public final boolean booleanValue()
Converts this model's value and returns it as a boolean.

Returns:
the boolean value
Throws:
java.lang.ClassCastException - if the observed value is not of type Boolean
java.lang.NullPointerException - if the value is null

doubleValue

public final double doubleValue()
Converts this model's value and returns it as a double.

Returns:
the double value
Throws:
java.lang.ClassCastException - if the observed value is not of type Double
java.lang.NullPointerException - if the value is null

floatValue

public final float floatValue()
Converts this model's value and returns it as a float.

Returns:
the float value
Throws:
java.lang.ClassCastException - if the observed value is not of type Float
java.lang.NullPointerException - if the value is null

intValue

public final int intValue()
Converts this model's value and returns it as an int.

Returns:
the int value
Throws:
java.lang.ClassCastException - if the observed value is not of type Integer
java.lang.NullPointerException - if the value is null

longValue

public final long longValue()
Converts this model's value and returns it as a long.

Returns:
the long value
Throws:
java.lang.ClassCastException - if the observed value is not of type Long
java.lang.NullPointerException - if the value is null

getString

public java.lang.String getString()
Converts this model's value and returns it as a String.

Returns:
this model's value as String
Throws:
java.lang.ClassCastException - if the observed value is not of type String

setValue

public final void setValue(boolean b)
Converts the given boolean to a Boolean and sets it as new value.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
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.

Parameters:
l - the value to be converted and set as new value

toString

public java.lang.String toString()
Returns a string representation of this value model. Answers the print string of the observed value.

Returns:
a string representation of this value model

paramString

protected java.lang.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.

Returns:
a string representation of this model's state
Since:
2.0.3

valueString

protected java.lang.String valueString()
Returns a string representing the value of this model. This method is intended to be used for debugging purposes only.

Returns:
a string representation of this model's value
Since:
2.0.3


Copyright © 2002-2010 JGoodies Karsten Lentzsch. All Rights Reserved.