Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class ncsa.horizon.coordinates.formatters.
MetricAxisPosFormatter

java.lang.Object
  |
  +--ncsa.horizon.coordinates.formatters.GenericAxisPosFormatter
        |
        +--ncsa.horizon.coordinates.formatters.MetricAxisPosFormatter
Subclasses:
FreqAxisPosFormatter, MetricVelocityFormatter

public class MetricAxisPosFormatter
extends GenericAxisPosFormatter
support for printing out double values as floating point numbers appended by a metric unit.

The base unit is usually specified in the constructor.

See Also:
Serialized Form

Inner classes inherited from class ncsa.horizon.coordinates.formatters.GenericAxisPosFormatter
GenericAxisPosFormatter.Modes
 
Field Summary
java.util.Hashtable abbmap
          a map that translates prefixes into powers
boolean abbreviate
          if true, use the abbreviation for the scale prefix
java.util.Vector abbreviations
          a container for the prefixes
static java.lang.String[] abbrevList
          prefix abbreviations
boolean fixed
          if true, the prefix to be used is fixed
int ipower
          the native base ten logarithmic scale; it is assumed that the input values to the toString(double) methods are in units of 10^ipower (relative to the base unit).
int minpow
          the smallest (most negative) power supported.
static java.lang.String myname
           
int opower
          the desired output base ten logarithmic scale; if fixed equals true, toString(double) will attempt to print the value in units of 10^opower (relative to the base unit), assuming there is a known prefix for that power.
static int[] powerList
          the prefix powers
java.util.Vector prefixes
          a container for the prefixes
static java.lang.String[] prefixList
          the supported prefixes
java.util.Hashtable prefmap
          a map that translates prefixes into powers
java.lang.String unit
          the base measurement unit (e.g.
 
Fields inherited from class ncsa.horizon.coordinates.formatters.GenericAxisPosFormatter
fmt, myname
 
Constructor Summary
MetricAxisPosFormatter(java.lang.String unit)
          format values of specified units.
MetricAxisPosFormatter()
          format values with no base unit (only prefix will appear).
MetricAxisPosFormatter(java.lang.String unit, int inPower)
          format values using the specified unit and the prefix abbreviation for the specified power
MetricAxisPosFormatter(java.lang.String unit, int inPower, boolean useAbbreviation)
          format values using the specified unit and the prefix abbreviation for the specified power
MetricAxisPosFormatter(java.lang.String unit, int inPower, int outPower, boolean useAbbreviation)
          format values using the specified unit and the prefix for the specified power
 
Method Summary
java.lang.String AbbrevFor(int power)
          return the prefix abbreviation that will be used for a given power, or null if one is not known.
java.lang.Object clone()
           
void fixPrefix(int power)
          when formatting values with toString(double), attempt to use the prefix associated with this power.
void fixPrefix()
          when formatting values with toString(double), attempt to use the current default output prefix (set either at construction or during the last call to fixPrefix(int).
void freePrefix()
          when formatting values with toString(double), attempt to use the current default output prefix (set either at construction or during the last call to fixPrefix(int).
int getDefPrefixPower()
          return the current default output prefix power that will be used by toString(double) when isFixed() = true.
void initialize()
          loads the prefix and abbreviation lists
boolean isAbbreviated()
          return whether abbreviations are used
boolean isFixed()
          return true if this formatter will use a fixed prefix
static void main(java.lang.String[] args)
           
static int maxPower(java.util.Vector list, int power, int minpow)
          return the higest power that is less than or equal to the requested power for which there is a name in the given list.
java.lang.String prefixFor(int power)
          return the prefix that will be used for a given power, or null if one is not known
void revmap()
          update the reverse maps
double scaleValue(double val, java.lang.StringBuffer unitBuf)
          scale the input value and return unit appropriate for that scale
void setAbbreviated(boolean useAbbreviation)
          set whether abbreviations are used
void setMinPower(int power)
          shift the lists of prefixes and abbreviations to use a new minimum power.
void setUnit(java.lang.String unitName)
          set the basic unit (word or abbreviation)
void setUnitPower(int power)
          assume that the values input to toString(double) will be in units of 10^power (relative to the current unit name).
java.lang.String toString(double val)
          return a value as a string with a specified precision
java.lang.String toString(double val, int prec)
          return a value as a string with a specified precision
void useAbbrev(int power, java.lang.String abbrev)
          use a given abbreviation for the specified power
void usePrefix(int power, java.lang.String prefix)
          use a given prefix for the specified power
double valueOf(java.lang.String s)
          parse the String representation of a floating point number
 
Methods inherited from class ncsa.horizon.coordinates.formatters.GenericAxisPosFormatter
clone, getFormat, getPrecision, main, setMode, setPrecision, toString, toString, toString, valueOf
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

unit

protected java.lang.String unit
the base measurement unit (e.g. "m", "g", "Gauss", etc.)

ipower

protected int ipower
the native base ten logarithmic scale; it is assumed that the input values to the toString(double) methods are in units of 10^ipower (relative to the base unit).

opower

protected int opower
the desired output base ten logarithmic scale; if fixed equals true, toString(double) will attempt to print the value in units of 10^opower (relative to the base unit), assuming there is a known prefix for that power.

fixed

protected boolean fixed
if true, the prefix to be used is fixed

abbreviate

protected boolean abbreviate
if true, use the abbreviation for the scale prefix

prefixList

protected static final java.lang.String[] prefixList
the supported prefixes

abbrevList

protected static final java.lang.String[] abbrevList
prefix abbreviations

powerList

protected static final int[] powerList
the prefix powers

prefixes

protected java.util.Vector prefixes
a container for the prefixes

abbreviations

protected java.util.Vector abbreviations
a container for the prefixes

prefmap

protected java.util.Hashtable prefmap
a map that translates prefixes into powers

abbmap

protected java.util.Hashtable abbmap
a map that translates prefixes into powers

minpow

protected int minpow
the smallest (most negative) power supported.

myname

protected static final java.lang.String myname
Constructor Detail

MetricAxisPosFormatter

public MetricAxisPosFormatter(java.lang.String unit)
format values of specified units. By default, it will be assumed that values input to toString will be in units of this unit, and the most appropriate prefix abbreviation will be used.
Parameters:
unit - the unit name, can be an abbreviation

MetricAxisPosFormatter

public MetricAxisPosFormatter()
format values with no base unit (only prefix will appear). By default, the most appropriate prefix abbreviation will be used.

MetricAxisPosFormatter

public MetricAxisPosFormatter(java.lang.String unit,
                              int inPower)
format values using the specified unit and the prefix abbreviation for the specified power
Parameters:
unit - the unit name, can be an abbreviation
inPower - assume that values input to toString(double) will be in units of 10^inPower, relative to unit

MetricAxisPosFormatter

public MetricAxisPosFormatter(java.lang.String unit,
                              int inPower,
                              boolean useAbbreviation)
format values using the specified unit and the prefix abbreviation for the specified power
Parameters:
unit - the unit name, can be an abbreviation
inPower - assume that values input to toString(double) will be in units of 10^inPower, relative to unit

MetricAxisPosFormatter

public MetricAxisPosFormatter(java.lang.String unit,
                              int inPower,
                              int outPower,
                              boolean useAbbreviation)
format values using the specified unit and the prefix for the specified power
Parameters:
unit - the unit name, can be an abbreviation
inPower - assume that values input to toString(double) will be in units of 10^inPower, relative to unit
outPower - the power for the prefix to be used; if a prefix for this power is not known, the highest valued prefix that is less than request will be used.
useAbbreviation - if true, the prefix abbreviation should be used.
Method Detail

toString

public java.lang.String toString(double val)
return a value as a string with a specified precision
Parameters:
val - the input value
Overrides:
toString in class GenericAxisPosFormatter

toString

public java.lang.String toString(double val,
                       int prec)
return a value as a string with a specified precision
Parameters:
val - the input value
prec - the number of places right of the decimal point
Overrides:
toString in class GenericAxisPosFormatter

valueOf

public double valueOf(java.lang.String s)
              throws java.lang.NumberFormatException
parse the String representation of a floating point number
Overrides:
valueOf in class GenericAxisPosFormatter

clone

public java.lang.Object clone()
Overrides:
clone in class GenericAxisPosFormatter

maxPower

public static int maxPower(java.util.Vector list,
                           int power,
                           int minpow)
return the higest power that is less than or equal to the requested power for which there is a name in the given list.
Parameters:
list - the Vector to check
power - the requested power
minpow - the minimum power in the list

setUnit

public void setUnit(java.lang.String unitName)
set the basic unit (word or abbreviation)

setAbbreviated

public void setAbbreviated(boolean useAbbreviation)
set whether abbreviations are used

setUnitPower

public void setUnitPower(int power)
assume that the values input to toString(double) will be in units of 10^power (relative to the current unit name).

fixPrefix

public void fixPrefix(int power)
when formatting values with toString(double), attempt to use the prefix associated with this power. If a prefix is not known for this power, use the prefix of the maximum power less than this power for which a prefix is known.

fixPrefix

public void fixPrefix()
when formatting values with toString(double), attempt to use the current default output prefix (set either at construction or during the last call to fixPrefix(int).

freePrefix

public void freePrefix()
when formatting values with toString(double), attempt to use the current default output prefix (set either at construction or during the last call to fixPrefix(int).

getDefPrefixPower

public int getDefPrefixPower()
return the current default output prefix power that will be used by toString(double) when isFixed() = true.

isFixed

public boolean isFixed()
return true if this formatter will use a fixed prefix

isAbbreviated

public boolean isAbbreviated()
return whether abbreviations are used

usePrefix

public void usePrefix(int power,
                      java.lang.String prefix)
use a given prefix for the specified power

prefixFor

public java.lang.String prefixFor(int power)
return the prefix that will be used for a given power, or null if one is not known

useAbbrev

public void useAbbrev(int power,
                      java.lang.String abbrev)
use a given abbreviation for the specified power

AbbrevFor

public java.lang.String AbbrevFor(int power)
return the prefix abbreviation that will be used for a given power, or null if one is not known.

initialize

protected void initialize()
loads the prefix and abbreviation lists

revmap

protected void revmap()
update the reverse maps

setMinPower

protected void setMinPower(int power)
shift the lists of prefixes and abbreviations to use a new minimum power. This will only lower the value of minpow.

scaleValue

protected double scaleValue(double val,
                            java.lang.StringBuffer unitBuf)
scale the input value and return unit appropriate for that scale
Parameters:
val - the input value
unitBuf - a buffer to append unit to
Returns:
double the scaled value

main

public static void main(java.lang.String[] args)

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD