public class IlvFormatBehavior extends IlvSingleBehavior
IlvFormatBehavior
formats a numeric value
as a string and stores the result in another value.
The formats supported are the formats defined by the
java.text.DecimalNumber
class and a subset
of the formats defined by
the printf
function of the C standard library.
Only the %f
and
%g
specifiers are supported.
Constructor and Description |
---|
IlvFormatBehavior(IlvFormatBehavior source)
Creates a new behavior object by copying an existing one.
|
IlvFormatBehavior(IlvInputStream in)
Reads the behavior from an
IlvInputStream stream. |
IlvFormatBehavior(String name,
String format,
String max,
String target)
Creates a new format behavior object.
|
Modifier and Type | Method and Description |
---|---|
IlvBehavior |
copy()
Returns a copy of the behavior.
|
static String |
formatValue(String format,
double d,
int max)
Formats
d using the specified format. |
String |
getFormat()
Gets the
format parameter for this behavior object. |
String |
getMax()
Gets the
max parameter for this behavior object. |
String |
getTarget()
Gets the
target parameter of this behavior object. |
boolean |
isReadable()
Returns
false . |
protected void |
set(IlvGroup group,
String name,
Object value)
Formats
value (which is converted to a
double )
with the format parameter passed to the constructor. |
void |
setFormat(String format)
Sets the
format parameter for this behavior object. |
void |
setMax(String max)
Sets the
max parameter for this behavior object. |
void |
setTarget(String target)
Sets the
target parameter for this behavior object. |
String |
toString()
Returns a short text describing this behavior object.
|
void |
write(IlvOutputStream out)
Writes the behavior to an
IlvOutputStream . |
get, get, getName, getValueNames, set, setName
attach, detach, getParameter, isOutput, isWritable
public IlvFormatBehavior(String name, String format, String max, String target)
name
- the name of the behavior object.format
- a string containing a format as defined by the
class java.text.DecimalNumber
, or containing
one %f
or
%g
specifier (as defined by the printf
function of the C standard library). This value
can be either a direct value, the
name of another property, or an expression.max
- the maximum number of characters that the formatted
string can contain. If the string is longer than max
, it is replaced
by a string containing as many star ('*'
) characters as
specified by max
.target
- the name of the property where the formatted string
will be stored.public IlvFormatBehavior(IlvFormatBehavior source)
source
- the behavior object to be copied.public IlvFormatBehavior(IlvInputStream in) throws IlvReadFileException
IlvInputStream
stream.
This constructor must be called by the
input constructors of subclasses.in
- The input stream.IlvReadFileException
- if the stream format is not correct.public void write(IlvOutputStream out) throws IOException
IlvOutputStream
.write
in interface IlvPersistentObject
write
in class IlvSingleBehavior
out
- The output stream.IOException
- thrown when an exception occurs during
the write operation for this object.public IlvBehavior copy()
copy
in class IlvBehavior
public String toString()
toString
in class IlvBehavior
public boolean isReadable()
false
.isReadable
in class IlvBehavior
protected void set(IlvGroup group, String name, Object value) throws IlvValueException
value
(which is converted to a
double
)
with the format
parameter passed to the constructor.
The resulting string is stored in the value specified by
the target
parameter passed to the constructor.set
in class IlvSingleBehavior
group
- the group to which this behavior object is attached.name
- the name of this behavior object.value
- the new value to be formatted.IlvValueException
- if an error occurred while setting a property.IlvSingleBehavior.set(ilog.views.prototypes.IlvGroup,
java.lang.String[], java.lang.Object[], boolean[])
public static String formatValue(String format, double d, int max)
d
using the specified format. The format is
as defined by the class java.text.DecimalNumber
.
It can also be a printf
-like
format
. Only the %f
and %g
specifiers are supported. If the formatted string is longer than
max
, it is replaced by a string containing as many star
('*'
) characters as specified by max
.format
- the format.d
- the value to be formatted.max
- the maximum number of characters in the formatted string.public void setFormat(String format)
format
parameter for this behavior object.public String getFormat()
format
parameter for this behavior object.public void setMax(String max)
max
parameter for this behavior object.public String getMax()
max
parameter for this behavior object.public void setTarget(String target)
target
parameter for this behavior object.public String getTarget()
target
parameter of this behavior object.© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.