public class GUnit extends Object implements Cloneable
Dialog units use font metrics as: 1/4 maximum character width, 1/8 maximum character height (+ external & internal leadings). This is a heritage from the Windows.
Two different unit types exist: integer values and decimal values. The type "px" only supports integer values. Integer values can range from -536870911 (-0x1FFFFFFF) to 536870911 (0x1FFFFFFF). Decimal values can be from -536870911.ddddddd (-0x1FFFFFFF.ddddddd) to 536870911.ddddddd (0x1FFFFFFF.ddddddd) where "ddddddd" is the decimal part with a maximum of 7 digits. A unit can be a combination of several other units, e.g. "90%-10px+1pt". This type is called FORMULA.
Modifier and Type | Field and Description |
---|---|
static GUnit |
NONE
An empty "NONE" unit, i.e.
|
static int |
UT_DLG
The unit type "dialog" or "dlg" for short.
|
static int |
UT_EM
The unit type size of the current font or "em" for short.
|
static int |
UT_EX
The unit type size of the "x" character of current font or "ex" for short.
|
static int |
UT_FORMULA
The unit type for complex values with a formula.
|
static int |
UT_PC
The unit type size for percentage of parent or "%" for short.
|
static int |
UT_PCH
The unit type size for percentage of parent height or "%h" for short.
|
static int |
UT_PCMAX
The unit type size for maximum size of percentage of parent width and height or "%max" for short.
|
static int |
UT_PCMIN
The unit type size for minimum size of percentage of parent width and height or "%min" for short.
|
static int |
UT_PCW
The unit type size for percentage of parent width or "%w" for short.
|
static int |
UT_PT
The unit type in points, i.e.
|
static int |
UT_PX
The unit type "pixels" or "px" for short.
|
static int |
UT_VALUE
The unit type size special value string, set as the formula.
|
static int |
UT_VH
The unit type size for percentage of viewport height or "vh" for short.
|
static int |
UT_VMAX
The unit type size for maximum size of percentage of viewport width and height or "vmax" for short.
|
static int |
UT_VMIN
The unit type size for minimum size of percentage of viewport width and height or "vmin" for short.
|
static int |
UT_VW
The unit type size for percentage of viewport width or "vw" for short.
|
Constructor and Description |
---|
GUnit()
Creates a unit object to 0 (zero) in pixels.
|
GUnit(double value,
int unit)
Creates a unit object with the specified value in pixels.
|
GUnit(int value)
Creates a unit object with the specified value in pixels.
|
GUnit(Transaction trans)
Creates a unit object from a transaction.
|
Modifier and Type | Method and Description |
---|---|
void |
append(Transaction trans)
Appends the unit object to a transaction.
|
static GUnit |
createCSSGUnit(String value,
String... specialValues)
Creates a GUnit object from a String.
|
static GUnit |
createGUnit(String expr0,
String... specialValues)
Creates a GUnit object from a String.
|
boolean |
equals(GUnit unit)
Checks if two unit objects are equal.
|
boolean |
equals(Object o)
Checks if two unit objects are equal.
|
String |
getCSSValue()
Gets the unit as a CSS value.
|
double |
getPixelValue(UIComp comp,
boolean isHorz)
Calculates the unit into a pixel value using the font information.
|
static ScriptEngine |
getScriptEngine()
Returns the script engine manager.
|
String |
getString()
Gets the String representation of the bounds as "value type".
|
int |
getType()
Gets the type of the unit (0-6):
one of the values UT_PX (pixel), UT_DLG (dialog), UT_EM ("em"), UT_EX ("ex"), UT_PT (point), UT_PC (percent),
UT_FORMULA (formula) or UT_VALUE (special value).
|
double |
getValue()
Returns the double value for the unit.
|
boolean |
isContainerDependent()
Returns if this value is dependent on the container size, i.e.
|
boolean |
isLocked()
Checks if the unit is "locked" from user change in the GUI design editor.
|
boolean |
isPureCSS()
Checks if this is a valid CSS pure unit, e.g.
|
boolean |
isZero()
Checks if the unit is zero.
|
protected String |
paramString()
Returns the parameter string representing the state of this event.
|
void |
setLocked(boolean on)
Sets the lock state of the unit.
|
String |
toString()
Returns a string representation of this class instance.
|
String |
validate()
Validates an expression formula.
|
static void |
validateCSSGUnit(GUnit unit,
String... specialValues)
Validates a GUnit object.
|
public static final GUnit NONE
public static final int UT_PX
public static final int UT_PT
public static final int UT_EM
public static final int UT_EX
public static final int UT_DLG
public static final int UT_PC
public static final int UT_PCW
public static final int UT_PCH
public static final int UT_PCMIN
public static final int UT_PCMAX
public static final int UT_VW
public static final int UT_VH
public static final int UT_VMIN
public static final int UT_VMAX
public static final int UT_FORMULA
public static final int UT_VALUE
public GUnit()
public GUnit(int value)
value
- The value.IllegalArgumentException
- if the value is not in range of -0x1FFFFFFF to 0x1FFFFFFF.public GUnit(double value, int unit)
value
- The value.unit
- The unit UT_* (excluding UT_FORMULA and UT_VALUE).IllegalArgumentException
- For invalid value range.public GUnit(Transaction trans)
trans
- The transaction.public static ScriptEngine getScriptEngine() throws GUnitException
GUnitException
- If engine cannot be instantiated.public static GUnit createGUnit(String expr0, String... specialValues) throws GUnitException
- [+|-] nnn [unit] - [+|-] nnn[.ddd] [unit] - formula consisting of characters "()+-/* 0123456789." and the unit characters
expr0
- The expression string.specialValues
- Accepted special values.GUnitException
- The error message.public static GUnit createCSSGUnit(String value, String... specialValues) throws GUnitException
- [+|-] nnn [unit] - [+|-] nnn[.ddd] [unit]
Formulas are not supported. The following units are supported:
value
- The value string.specialValues
- Accepted special values.GUnitException
- The error message.public static void validateCSSGUnit(GUnit unit, String... specialValues) throws GUnitException
Formulas are not supported. The following units are supported:
unit
- The unit as CSS value.specialValues
- Accepted special values.GUnitException
- The error message.public int getType()
public boolean isLocked()
public void setLocked(boolean on)
public String getString()
value type
.public boolean isZero()
public boolean equals(Object o)
public boolean equals(GUnit unit)
unit
- another size object. If null, the sizes are not equal.protected String paramString()
public double getValue()
public String toString()
public String getCSSValue()
public void append(Transaction trans)
trans
- The transaction.public String validate() throws GUnitException
GUnitException
- For validation errors.public double getPixelValue(UIComp comp, boolean isHorz)
comp
- The component.isHorz
- Flag indicating this is a horizontal value (significant only for % or DLG).IllegalStateException
- If this is called outside of the Designer.public boolean isPureCSS()
public boolean isContainerDependent()
iizi® is a registered trademark of Mindus SARL. © Copyright Mindus SARL, 2020. All rights reserved.