info.monitorenter.gui.chart.labelformatters
Class LabelFormatterUnit

java.lang.Object
  extended by info.monitorenter.gui.chart.labelformatters.ALabelFormatter
      extended by info.monitorenter.gui.chart.labelformatters.LabelFormatterUnit
All Implemented Interfaces:
IAxisLabelFormatter, java.io.Serializable

public class LabelFormatterUnit
extends ALabelFormatter

A label formatter that adds a constructor given AUnit of the unit SI prefix to a decorated IAxisLabelFormatter.

The formatted Strings will be divided by a factor according to the chosen unit.

Version:
$Revision: 1.7 $
Author:
Achim Westermann
See Also:
Serialized Form

Field Summary
 
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
LabelFormatterUnit(AUnit unit)
          Default constructor that uses a LabelFormatterSimple to add the unit feature to.
LabelFormatterUnit(AUnit unit, ALabelFormatter delegate)
          Creates an instance that will add "unit-functionality" to the given formatter.
 
Method Summary
 void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
          Registers a property change listener that will be informed about changes of the property identified by the given propertyName.
 boolean equals(java.lang.Object obj)
           
 java.lang.String format(double value)
          Provide a String for the value.
 IAxis<?> getAxis()
          Intended for AAxis only.
 int getMaxAmountChars()
          Returns the maximum amount of characters that will be returned from IAxisLabelFormatter.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.
 AUnit getUnit()
          Returns ALabelFormatter.UNIT_UNCHANGED.
 int hashCode()
           
 void initPaintIteration()
          Void adapter method implementation - optional to override.
 java.lang.Number parse(java.lang.String formatted)
          The reverse operation to IAxisLabelFormatter.format(double).
 void removePropertyChangeListener(java.lang.String property, java.beans.PropertyChangeListener listener)
          Deregisters a property change listener that has been registerd for listening on the given property.
 void setAxis(IAxis<?> axis)
          Intended for AAxis only.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LabelFormatterUnit

public LabelFormatterUnit(AUnit unit)
Default constructor that uses a LabelFormatterSimple to add the unit feature to.

Parameters:
unit - the unit to use.

LabelFormatterUnit

public LabelFormatterUnit(AUnit unit,
                          ALabelFormatter delegate)
Creates an instance that will add "unit-functionality" to the given formatter.

Parameters:
unit - the unit to use.
delegate - the formatter that will be decorated with units.
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(java.lang.String propertyName,
                                      java.beans.PropertyChangeListener listener)
Description copied from interface: IAxisLabelFormatter
Registers a property change listener that will be informed about changes of the property identified by the given propertyName.

Specified by:
addPropertyChangeListener in interface IAxisLabelFormatter
Overrides:
addPropertyChangeListener in class ALabelFormatter
Parameters:
propertyName - the name of the property the listener is interested in
listener - a listener that will only be informed if the property identified by the argument propertyName changes
See Also:
IAxisLabelFormatter.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class ALabelFormatter
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,...).

Parameters:
value - the value to format.
Returns:
the formatted value.
See Also:
IAxisLabelFormatter.format(double)

getAxis

public IAxis<?> getAxis()
Description copied from class: ALabelFormatter
Intended for AAxis only.

Overrides:
getAxis in class ALabelFormatter
Returns:
Returns the axis.
See Also:
ALabelFormatter.getAxis()

getMaxAmountChars

public int getMaxAmountChars()
Description copied from class: ALabelFormatter
Returns the maximum amount of characters that will be returned from IAxisLabelFormatter.format(double).

Specified by:
getMaxAmountChars in interface IAxisLabelFormatter
Overrides:
getMaxAmountChars in class ALabelFormatter
Returns:
the maximum amount of characters that will be returned from IAxisLabelFormatter.format(double).
See Also:
ALabelFormatter.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).

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.

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)

getUnit

public AUnit getUnit()
Description copied from class: ALabelFormatter
Returns ALabelFormatter.UNIT_UNCHANGED.

Specified by:
getUnit in interface IAxisLabelFormatter
Overrides:
getUnit in class ALabelFormatter
Returns:
ALabelFormatter.UNIT_UNCHANGED
See Also:
IAxisLabelFormatter.getUnit()

hashCode

public int hashCode()
Overrides:
hashCode in class ALabelFormatter
See Also:
Object.hashCode()

initPaintIteration

public void initPaintIteration()
Description copied from class: ALabelFormatter
Void adapter method implementation - optional to override.

Specified by:
initPaintIteration in interface IAxisLabelFormatter
Overrides:
initPaintIteration in class ALabelFormatter
See Also:
IAxisLabelFormatter.initPaintIteration()

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.

Parameters:
formatted - a String 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(String)

removePropertyChangeListener

public void removePropertyChangeListener(java.lang.String property,
                                         java.beans.PropertyChangeListener listener)
Description copied from interface: IAxisLabelFormatter
Deregisters a property change listener that has been registerd for listening on the given property.

Specified by:
removePropertyChangeListener in interface IAxisLabelFormatter
Overrides:
removePropertyChangeListener in class ALabelFormatter
Parameters:
property - the property the listener was registered to.
listener - a listener that will only be informed if the property identified by the argument propertyName changes
See Also:
ALabelFormatter.removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)

setAxis

public void setAxis(IAxis<?> axis)
Description copied from class: ALabelFormatter
Intended for AAxis only.

Do never invoke this! This is only public for package sorting reasons.

Specified by:
setAxis in interface IAxisLabelFormatter
Overrides:
setAxis in class ALabelFormatter
Parameters:
axis - The m_axis to set.
See Also:
ALabelFormatter.setAxis(IAxis)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()


Copyright © 2001 - 2010 LGPL, All Rights Footloose.