Package net.sf.jguiraffe.gui.layout
Enum Unit
- java.lang.Object
-
- java.lang.Enum<Unit>
-
- net.sf.jguiraffe.gui.layout.Unit
-
- All Implemented Interfaces:
Serializable
,Comparable<Unit>
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.
- Version:
- $Id: Unit.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static Unit
fromString(String name)
Returns theUnit
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.
-
-
-
Enum Constant Detail
-
PIXEL
public static final Unit PIXEL
The unit pixel. Pixels are the default unit. They do not require any special conversion logic.
-
INCH
public static final Unit INCH
The unit inch. Inches can be converted to pixels based on the current screen resolution, which is defined in pixels per inch.
-
CM
public static final Unit CM
The unit cm. Centimeters work similar to inches. The conversion to pixels is also based on the current screen resolution. However, a different conversion factor is used.
-
DLU
public static final Unit DLU
The unit dlu. A "dialog unit" is a unit whose exact size depends on the font of the container it is used in. A horizontal dialog unit equals the fourth part of the container's font's average character width; a vertical dialog unit equals the eighth part of the character height. So to transform a value in this unit to pixels always the corresponding container component must be known.
-
-
Method Detail
-
values
public static Unit[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Unit c : Unit.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Unit valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
getUnitName
public String getUnitName()
Returns the short unit name. This is something like "cm" or "in". This name can be passed to thefromString(String)
method for obtaining the corresponding enumeration literal.- Returns:
- the short unit name
-
toPixel
public abstract int toPixel(double value, UnitSizeHandler handler, Object comp, boolean y)
Converts the specified value from this unit into pixels. This can be used for calculating values in the default unit pixels.- Parameters:
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 distinction- Returns:
- the value in pixels
-
fromString
public static Unit fromString(String name)
Returns theUnit
constant for the unit with the given short name. This method works like the defaultvalueOf()
method available for each enumeration class. However, it operates on the short unit names as returned bygetUnitName()
. It is case insensitive and throws an exception if the name cannot be resolved.- Parameters:
name
- the short name of the unit- Returns:
- the
Unit
constant with this short name - Throws:
IllegalArgumentException
- if the name cannot be resolved
-
-