public abstract class IlvFormattedNumberProperty extends IlvAbstractStringProperty
IlvFormattedNumberProperty is an abstract adapter, whose
subclasses allow a numerical property of arbitrary objects to be accessed as
a String via the generic IlvStringProperty
interface.
Here is an example of a subclass which adapts a Float property:
// Adapter representing the Bar property of Foo objects. Bar values
// are of type Float.
public class FooBarProperty extends IlvAbstractStringProperty {
public FooBarProperty () {
}
public FooBarProperty (NumberFormat formatter) {
super(formatter);
}
public FooBarProperty (String pattern) {
super(pattern);
}
protected Object getValueImpl (Object aFoo) {
return ((Foo)aFoo).getBar();
}
protected Object setValueImpl (Object aFoo, Object newValue) {
((Foo)aFoo).setBar((Float)newValue);
}
...
}
If the property is a primitive numerical type, then the get and
set methods would need to be changed like this:
// Adapter representing the Bar property of Foo objects. Bar values
// are primitive float's.
public class FooBarProperty extends IlvAbstractStringProperty {
//.. Constructors same as above
protected Object getValueImpl (Object aFoo) {
return new Float(((Foo)aFoo).getBar());
}
protected Object setValueImpl (Object aFoo, Object newValue) {
((Foo)aFoo).setBar(((Number)newValue).floatValue());
}
...
}
_formatter| Constructor and Description |
|---|
IlvFormattedNumberProperty()
Constructs a new
IlvFormattedNumberProperty with a
default NumberFormat. |
IlvFormattedNumberProperty(NumberFormat formatter)
Constructs a new
IlvFormattedNumberProperty with the
specified number formatter. |
IlvFormattedNumberProperty(String pattern)
Constructs a new
IlvFormattedNumberProperty with
a DecimalFormat which uses the specified formatting
string in the default locale. |
| Modifier and Type | Method and Description |
|---|---|
void |
setFormat(String pattern)
Sets the adapter's formatter to be a
DecimalFormat which
uses the specified formatting string in the default locale. |
changedRowsIterator, getFormat, getValue, getValueImpl, isPropertyChangedEvent, setFormat, setValue, setValueImplclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetEventClasspublic IlvFormattedNumberProperty()
IlvFormattedNumberProperty with a
default NumberFormat.public IlvFormattedNumberProperty(NumberFormat formatter)
IlvFormattedNumberProperty with the
specified number formatter.formatter - The number formatter.public IlvFormattedNumberProperty(String pattern)
IlvFormattedNumberProperty with
a DecimalFormat which uses the specified formatting
string in the default locale.public void setFormat(String pattern)
DecimalFormat which
uses the specified formatting string in the default locale.pattern - The DecimalFormat formatting pattern.© Copyright Rogue Wave Software, Inc. 1997, 2017. All Rights Reserved.