public enum Unit extends Enum<Unit>
An enumeration class for defining units.
Some of the layout classes can deal with different units, e.g. with centimeters, pixels or dialog units. This class is an enumeration class which defines constants for the supported units. It also provides functionality for converting a number in their represented unit into the default unit pixel.
Usually this class will not be used directly. Instead convenience classes will be used which combine numeric values with a unit.
Enum Constant and Description |
---|
CM
The unit cm.
|
DLU
The unit dlu.
|
INCH
The unit inch.
|
PIXEL
The unit pixel.
|
Modifier and Type | Method and Description |
---|---|
static Unit |
fromString(String name)
Returns the
Unit constant for the unit with the given short name. |
String |
getUnitName()
Returns the short unit name.
|
abstract int |
toPixel(double value,
UnitSizeHandler handler,
Object comp,
boolean y)
Converts the specified value from this unit into pixels.
|
static Unit |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static Unit[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final Unit PIXEL
public static final Unit INCH
public static final Unit CM
public static final Unit DLU
public static Unit[] values()
for (Unit c : Unit.values()) System.out.println(c);
public static Unit valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic String getUnitName()
fromString(String)
method for
obtaining the corresponding enumeration literal.public abstract int toPixel(double value, UnitSizeHandler handler, Object comp, boolean y)
value
- the value to be convertedhandler
- the size handler implementation; this is needed by complex
unit classescomp
- the affected component; can be used by derived classes to
obtain needed informationy
- a flag whether the value is to be converted for the X or the Y
direction; some units may make a distinctionpublic static Unit fromString(String name)
Unit
constant for the unit with the given short name.
This method works like the default valueOf()
method available for
each enumeration class. However, it operates on the short unit names as
returned by getUnitName()
. It is case insensitive and throws an
exception if the name cannot be resolved.name
- the short name of the unitUnit
constant with this short nameIllegalArgumentException
- if the name cannot be resolvedCopyright © 2016 The JGUIraffe Team. All rights reserved.