com.cc.framework.ui.html
Class LengthUnit

java.lang.Object
  extended byjava.lang.Number
      extended bycom.cc.framework.ui.html.LengthUnit
All Implemented Interfaces:
java.io.Serializable

public class LengthUnit
extends java.lang.Number
implements java.io.Serializable

This class encapsulates HTML length units

Version:
$Revision$
Author:
Harald Schulz
See Also:
Serialized Form

Field Summary
private static double[] CONVERSION
          The following table holds the conversion factors from 1 inch to the corresponding unit The order is: CM; MM; IN; PT; PC; PX; EM; EX
private static long serialVersionUID
          Serial Version UID
private  int type
          Size type
static int TYPE_LENGTH
          Type discriminator: Length
static int TYPE_PERCENTAGE
          Type discriminator: Percentage
private  int unit
          unit designator
private static java.lang.String[] UNIT
          Unit Strings
static int UNIT_CM
          Centimeters
static int UNIT_EM
          The height of the element's font
static int UNIT_EX
          The height of the letter "x"
static int UNIT_IN
          Inches (1 inch = 2.54 centimeters)
static int UNIT_MM
          Millimeters
static int UNIT_PC
          Picas (1 pica = 12 points)
static int UNIT_PT
          Points (1 point = 1/72 inches)
static int UNIT_PX
          Pixels
private  double value
          Floating-point number for the length or a percentage of the parent object's unit
 
Constructor Summary
  LengthUnit(double value)
          Constructs a length in pixels
  LengthUnit(double value, int unit)
          Constructor
private LengthUnit(int type, double value, int unit)
          Constructor
private LengthUnit(LengthUnit other)
          Copy Constructor
 
Method Summary
 LengthUnit convert(int targetUnit)
          Converts the length to the given unit.
private  boolean convertable(int unit)
           
 double doubleValue()
           
 float floatValue()
           
 int getType()
           
 int getUnit()
           
 int intValue()
           
 boolean isAbsoluteValue()
           
private static boolean isDigit(char ch)
          Check if the given character is a digit or a dot
 boolean isRelativeValue()
           
 long longValue()
           
 LengthUnit minus(double summand)
          adds a literal to the current length
 LengthUnit minus(LengthUnit summand)
          adds a literal to the current length
static LengthUnit parse(java.lang.String str)
          Parses a String and creates a LengthUnit object
 LengthUnit plus(double summand)
          adds a literal to the current length
 LengthUnit plus(LengthUnit summand)
          adds a literal to the current length
 java.lang.String toString()
           
 java.lang.String toString(int decimals)
           
private  java.lang.String valueStr(int decimals)
          Format the given double value with the given number of fraction digits
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
Serial Version UID

See Also:
Constant Field Values

TYPE_LENGTH

public static final int TYPE_LENGTH
Type discriminator: Length

See Also:
Constant Field Values

TYPE_PERCENTAGE

public static final int TYPE_PERCENTAGE
Type discriminator: Percentage

See Also:
Constant Field Values

UNIT_CM

public static final int UNIT_CM
Centimeters

See Also:
Constant Field Values

UNIT_MM

public static final int UNIT_MM
Millimeters

See Also:
Constant Field Values

UNIT_IN

public static final int UNIT_IN
Inches (1 inch = 2.54 centimeters)

See Also:
Constant Field Values

UNIT_PT

public static final int UNIT_PT
Points (1 point = 1/72 inches)

See Also:
Constant Field Values

UNIT_PC

public static final int UNIT_PC
Picas (1 pica = 12 points)

See Also:
Constant Field Values

UNIT_PX

public static final int UNIT_PX
Pixels

See Also:
Constant Field Values

UNIT_EM

public static final int UNIT_EM
The height of the element's font

See Also:
Constant Field Values

UNIT_EX

public static final int UNIT_EX
The height of the letter "x"

See Also:
Constant Field Values

UNIT

private static final java.lang.String[] UNIT
Unit Strings


CONVERSION

private static final double[] CONVERSION
The following table holds the conversion factors from 1 inch to the corresponding unit The order is: CM; MM; IN; PT; PC; PX; EM; EX


type

private int type
Size type


value

private double value
Floating-point number for the length or a percentage of the parent object's unit


unit

private int unit
unit designator

Constructor Detail

LengthUnit

public LengthUnit(double value)
Constructs a length in pixels

Parameters:
value - length in pixels

LengthUnit

public LengthUnit(double value,
                  int unit)
Constructor

Parameters:
value - length
unit - unit (UNIT_xx constant)

LengthUnit

private LengthUnit(int type,
                   double value,
                   int unit)
Constructor

Parameters:
type - type discriminator (TYPE_xxxx constant)
value - length or percentage
unit - the unit in witch the length is given (UNIT_xx constant)

LengthUnit

private LengthUnit(LengthUnit other)
Copy Constructor

Parameters:
other - the object to copy from
Method Detail

parse

public static LengthUnit parse(java.lang.String str)
                        throws java.lang.IllegalArgumentException
Parses a String and creates a LengthUnit object

Parameters:
str - String to parse
Returns:
LengthUnit object
Throws:
java.lang.IllegalArgumentException - When the string is no valid length string

isDigit

private static boolean isDigit(char ch)
Check if the given character is a digit or a dot

Parameters:
ch - character to check
Returns:
boolean

valueStr

private java.lang.String valueStr(int decimals)
Format the given double value with the given number of fraction digits

Parameters:
decimals - number of fraction digits
Returns:
Formatted string

convertable

private boolean convertable(int unit)

convert

public LengthUnit convert(int targetUnit)
Converts the length to the given unit.

Parameters:
targetUnit - the unit to convert to
Returns:
returns a LengthUnit object

doubleValue

public double doubleValue()
See Also:
Number.doubleValue()

floatValue

public float floatValue()
See Also:
Number.floatValue()

intValue

public int intValue()
See Also:
Number.intValue()

longValue

public long longValue()
See Also:
Number.longValue()

plus

public LengthUnit plus(double summand)
adds a literal to the current length

Parameters:
summand - the value to add
Returns:
this

plus

public LengthUnit plus(LengthUnit summand)
adds a literal to the current length

Parameters:
summand - the value to add. The value will be converted to the matching unit
Returns:
this

minus

public LengthUnit minus(double summand)
adds a literal to the current length

Parameters:
summand - the value to add
Returns:
this

minus

public LengthUnit minus(LengthUnit summand)
adds a literal to the current length

Parameters:
summand - the value to add. The value will be converted to the matching unit
Returns:
this

getType

public int getType()
Returns:
returns the type of the length unit (TYPE_xxxxx)

getUnit

public int getUnit()
Returns:
returns the metric unit of the length (UNIT_xxxxx)

isAbsoluteValue

public boolean isAbsoluteValue()
Returns:
returns true when this is an absolute value

isRelativeValue

public boolean isRelativeValue()
Returns:
returns true when this is a relative value

toString

public java.lang.String toString(int decimals)
Parameters:
decimals - internal decimal places
Returns:
String

toString

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


Copyright © 2000-2005 SCC Informationssysteme GmbH. All Rights Reserved.