de.infinityloop.util
Class UnitConverter

java.lang.Object
  extended by de.infinityloop.util.UnitConverter

public class UnitConverter
extends java.lang.Object

Unit converter class Converts between several units like cm, mm, twips, pt, inches etc.


Field Summary
static int kUnit_cm
           
static int kUnit_Default
           
static int kUnit_emu
           
static int kUnit_hp
           
static int kUnit_in
           
static int kUnit_m
           
static int kUnit_mm
           
static int kUnit_pc
           
static int kUnit_pt
           
static int kUnit_px
           
static int kUnit_tw
           
 
Constructor Summary
UnitConverter()
           
 
Method Summary
static double convert(double src, int srcUnit, int destUnit)
          Converts a value from one unit to another.
static double convert(java.lang.String srcString, int destUnit)
          Converts a value from one unit to another.
static java.lang.String convertString(double src, int srcUnit, int destUnit, int prec)
          Converts a value from one unit to another.
static double getDPI()
          Returns the currently set global DPI value used for calculating conversions
static int getUnit(java.lang.String srcString)
          Determines which unit a value passed as String is in.
static int getUnitId(java.lang.String u, int def)
          converts an ASCII unit name string to its respective unit id
static java.lang.String precisionString(double d, int prec)
          Convert the passed floating point value to a string representation with the specified number of decimals.
static void setDPI(double dpi)
           
static void setPrecision(int decs)
          Sets the precision to be used for all following conversions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kUnit_cm

public static final int kUnit_cm
See Also:
Constant Field Values

kUnit_mm

public static final int kUnit_mm
See Also:
Constant Field Values

kUnit_m

public static final int kUnit_m
See Also:
Constant Field Values

kUnit_in

public static final int kUnit_in
See Also:
Constant Field Values

kUnit_tw

public static final int kUnit_tw
See Also:
Constant Field Values

kUnit_pt

public static final int kUnit_pt
See Also:
Constant Field Values

kUnit_pc

public static final int kUnit_pc
See Also:
Constant Field Values

kUnit_px

public static final int kUnit_px
See Also:
Constant Field Values

kUnit_hp

public static final int kUnit_hp
See Also:
Constant Field Values

kUnit_emu

public static final int kUnit_emu
See Also:
Constant Field Values

kUnit_Default

public static final int kUnit_Default
See Also:
Constant Field Values
Constructor Detail

UnitConverter

public UnitConverter()
Method Detail

setDPI

public static void setDPI(double dpi)
Parameters:
dpi - sets the DPI value to use in subsequent calculations

getDPI

public static double getDPI()
Returns the currently set global DPI value used for calculating conversions


setPrecision

public static void setPrecision(int decs)
Sets the precision to be used for all following conversions.

Parameters:
decs - the number of decimals

convert

public static double convert(double src,
                             int srcUnit,
                             int destUnit)
Converts a value from one unit to another.

Parameters:
src - source value
srcUnit - source unit
destUnit - destination unit
Returns:
the converted value in the new unit

getUnit

public static int getUnit(java.lang.String srcString)
Determines which unit a value passed as String is in.

Parameters:
srcString - source value
Returns:
the unit constant or kUnit_Default if it could not be determined.

convert

public static double convert(java.lang.String srcString,
                             int destUnit)
Converts a value from one unit to another. The source unit is analyzed from the source string.

Parameters:
srcString - the source value string
destUnit - the unit to convert to
Returns:
the converted value in the new unit

convertString

public static java.lang.String convertString(double src,
                                             int srcUnit,
                                             int destUnit,
                                             int prec)
Converts a value from one unit to another.

Parameters:
src - the source value
srcUnit - the unit the source value is in
destUnit - the unit to convert to
prec - the precision the resulting string should have
Returns:
the converted value in the new unit as String

getUnitId

public static int getUnitId(java.lang.String u,
                            int def)
converts an ASCII unit name string to its respective unit id


precisionString

public static java.lang.String precisionString(double d,
                                               int prec)
Convert the passed floating point value to a string representation with the specified number of decimals.

Parameters:
d - the value to convert to a string
prec - the decimal precision (number of decimals)
Returns:
string representation of input value