Class LabelFormatterNumber
- java.lang.Object
-
- info.monitorenter.gui.chart.labelformatters.ALabelFormatter
-
- info.monitorenter.gui.chart.labelformatters.LabelFormatterNumber
-
- All Implemented Interfaces:
IAxisLabelFormatter
,java.io.Serializable
- Direct Known Subclasses:
LabelFormatterSimple
public class LabelFormatterNumber extends ALabelFormatter implements IAxisLabelFormatter
An ILabelFormatter that is based on aNumberFormat
To avoid loss of precision please choose a sufficient resolution for your constructor given NumberFormat. Example: If you add new
TracePoint2D
instances to theChart2D
every second, prefer using a NumberFormat that at least formats the seconds like (e.g.):NumberFormat format = new java.text.SimpleDateFormat("HH:mm:ss");
- Version:
- $Revision: 1.18 $
- Author:
- Achim Westermann
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.text.NumberFormat
m_numberFormat
The number format to use.-
Fields inherited from class info.monitorenter.gui.chart.labelformatters.ALabelFormatter
m_propertyChangeSupport, UNIT_UNCHANGED
-
Fields inherited from interface info.monitorenter.gui.chart.IAxisLabelFormatter
PROPERTY_FORMATCHANGE
-
-
Constructor Summary
Constructors Constructor Description LabelFormatterNumber()
Default constructor that uses the defalut constructor of
.DecimalFormat
LabelFormatterNumber(java.text.NumberFormat numberFormat)
Creates a label formatter that uses the given number format.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object obj)
java.lang.String
format(double value)
Provide a String for the value.int
getMaxAmountChars()
Returns the maximum amount of characters that will be returned fromIAxisLabelFormatter.format(double)
.double
getMinimumValueShiftForChange()
Returns the minimum change in the value to format that will cause to return a different formatted String.double
getNextEvenValue(double value, boolean ceiling)
Returns the next "even" value to the given one.java.text.NumberFormat
getNumberFormat()
Returns the internalNumberFormat
.int
hashCode()
java.lang.Number
parse(java.lang.String formatted)
The reverse operation to
.IAxisLabelFormatter.format(double)
void
setNumberFormat(java.text.NumberFormat numberFormat)
Sets the number formatter to use.-
Methods inherited from class info.monitorenter.gui.chart.labelformatters.ALabelFormatter
addPropertyChangeListener, getAxis, getUnit, initPaintIteration, removePropertyChangeListener, setAxis
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface info.monitorenter.gui.chart.IAxisLabelFormatter
addPropertyChangeListener, getUnit, initPaintIteration, removePropertyChangeListener, setAxis
-
-
-
-
Constructor Detail
-
LabelFormatterNumber
public LabelFormatterNumber()
Default constructor that uses the defalut constructor of
.DecimalFormat
-
LabelFormatterNumber
public LabelFormatterNumber(java.text.NumberFormat numberFormat)
Creates a label formatter that uses the given number format.- Parameters:
numberFormat
- the number format to use.
-
-
Method Detail
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classALabelFormatter
- See Also:
Object.equals(java.lang.Object)
-
format
public java.lang.String format(double value)
Description copied from interface:IAxisLabelFormatter
Provide a String for the value. Subclasses should override the label formatting here. The raw value is passed here to allow a general treatment. Transformations of this raw value should be done here (e.g. division by multiples of 1000 for scientific unit system display, date formatting,...).- Specified by:
format
in interfaceIAxisLabelFormatter
- Parameters:
value
- the value to format.- Returns:
- the formatted value.
- See Also:
IAxisLabelFormatter.format(double)
-
getMaxAmountChars
public int getMaxAmountChars()
Description copied from class:ALabelFormatter
Returns the maximum amount of characters that will be returned fromIAxisLabelFormatter.format(double)
.- Specified by:
getMaxAmountChars
in interfaceIAxisLabelFormatter
- Overrides:
getMaxAmountChars
in classALabelFormatter
- Returns:
- the maximum amount of characters that will be returned from
IAxisLabelFormatter.format(double)
. - See Also:
IAxisLabelFormatter.getMaxAmountChars()
-
getMinimumValueShiftForChange
public double getMinimumValueShiftForChange()
Description copied from interface:IAxisLabelFormatter
Returns the minimum change in the value to format that will cause to return a different formatted String.To achieve two different formatted Strings to be returned from the format method the corresponding values given to the format method have to differ at least by this value.
Some implementations (e.g. a formatter for date) have to use their own format method an increas a value to determine when the first change will occur. This is expensive and it's recommended that this action is performed once only and the result is stored. Additionally this routine has to start with an "even" (see
IAxisLabelFormatter.getNextEvenValue(double, boolean)
) value to get a correct result (the distance from even number to even number).- Specified by:
getMinimumValueShiftForChange
in interfaceIAxisLabelFormatter
- Returns:
- the minimum change in the value to format that will cause to return a different formatted String.
- See Also:
IAxisLabelFormatter.getMinimumValueShiftForChange()
-
getNextEvenValue
public double getNextEvenValue(double value, boolean ceiling)
Description copied from interface:IAxisLabelFormatter
Returns the next "even" value to the given one. "Even" means that the format method will exactly return the String for the value and not cut or round any information. A label String created with an "even" number will be exactly at the position it describes.- Specified by:
getNextEvenValue
in interfaceIAxisLabelFormatter
- Parameters:
value
- the value to get the next "even" value for.ceiling
- if true, the next higher number will returned, else the next lower one.- Returns:
- the next "even" value to the given one.
- See Also:
IAxisLabelFormatter.getNextEvenValue(double, boolean)
-
getNumberFormat
public java.text.NumberFormat getNumberFormat()
Returns the internalNumberFormat
.- Returns:
- the internal
NumberFormat
.
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classALabelFormatter
- See Also:
Object.hashCode()
-
parse
public java.lang.Number parse(java.lang.String formatted) throws java.lang.NumberFormatException
Description copied from interface:IAxisLabelFormatter
The reverse operation to
.IAxisLabelFormatter.format(double)
The given argument has to be in the format that will be generated by that method or exceptions may be thrown.
test.parse(test.format(d))== d
has to be true if no rounding occurs by the formatter.- Specified by:
parse
in interfaceIAxisLabelFormatter
- Parameters:
formatted
- aString
in the format that will be produced by method
.IAxisLabelFormatter.format(double)
- Returns:
- the parsed number.
- Throws:
java.lang.NumberFormatException
- if the format of the argument is invalid.- See Also:
IAxisLabelFormatter.parse(java.lang.String)
-
setNumberFormat
public final void setNumberFormat(java.text.NumberFormat numberFormat)
Sets the number formatter to use.Fires a
to the listeners added viaPropertyChangeEvent
with the property keyALabelFormatter.addPropertyChangeListener(String, java.beans.PropertyChangeListener)
.IAxisLabelFormatter.PROPERTY_FORMATCHANGE
- Parameters:
numberFormat
- the number formatter to use.
-
-