Package org.apache.pivot.wtk
Class Dimensions
- java.lang.Object
-
- org.apache.pivot.wtk.Dimensions
-
- All Implemented Interfaces:
java.io.Serializable
public final class Dimensions extends java.lang.Object implements java.io.SerializableClass representing the dimensions of an object.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description intheightThe height value of the dimension.static java.lang.StringHEIGHT_KEYThe map key to retrieve the height value.intwidthThe width value of the dimension.static java.lang.StringWIDTH_KEYThe map key to retrieve the width value.static DimensionsZEROAn empty (zero size) dimension value.
-
Constructor Summary
Constructors Constructor Description Dimensions(int size)Construct a "square" dimensions that has the same width as height.Dimensions(int widthValue, int heightValue)Construct a dimension with the given values.Dimensions(Dictionary<java.lang.String,?> dimensions)Construct new dimensions from the given dictionary.Dimensions(Sequence<?> dimensions)Construct new dimensions from the given sequence ofNumbervalues.Dimensions(Dimensions dimensions)Construct new dimensions from the given dimensions.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Dimensionsdecode(java.lang.String value)Convert a string dimensions value to the object.booleanequals(java.lang.Object object)Dimensionsexpand(int delta)Expand this dimensions by the given amount (positive or negative) in both width and height directions.Dimensionsexpand(int widthDelta, int heightDelta)Expand this dimensions by the given amounts (positive or negative) separately in the width and height directions.Dimensionsexpand(Insets insets)Expand this dimensions by the givenInsetsamounts in the width and height directions.inthashCode()java.lang.StringtoString()
-
-
-
Field Detail
-
width
public final int width
The width value of the dimension.
-
height
public final int height
The height value of the dimension.
-
WIDTH_KEY
public static final java.lang.String WIDTH_KEY
The map key to retrieve the width value.- See Also:
- Constant Field Values
-
HEIGHT_KEY
public static final java.lang.String HEIGHT_KEY
The map key to retrieve the height value.- See Also:
- Constant Field Values
-
ZERO
public static final Dimensions ZERO
An empty (zero size) dimension value.
-
-
Constructor Detail
-
Dimensions
public Dimensions(int size)
Construct a "square" dimensions that has the same width as height.- Parameters:
size- The width and height of this dimension.
-
Dimensions
public Dimensions(int widthValue, int heightValue)Construct a dimension with the given values.- Parameters:
widthValue- The width of the new dimension.heightValue- The height of the new dimension.
-
Dimensions
public Dimensions(Dimensions dimensions)
Construct new dimensions from the given dimensions.- Parameters:
dimensions- The existing dimensions to copy.- Throws:
java.lang.IllegalArgumentException- if the given dimensions isnull.
-
Dimensions
public Dimensions(Dictionary<java.lang.String,?> dimensions)
Construct new dimensions from the given dictionary.- Parameters:
dimensions- The dictionary to lookup the new values from.- Throws:
java.lang.IllegalArgumentException- if the dictionary value isnull.- See Also:
WIDTH_KEY,HEIGHT_KEY
-
Dimensions
public Dimensions(Sequence<?> dimensions)
Construct new dimensions from the given sequence ofNumbervalues.- Parameters:
dimensions- The sequence of dimension values in [width, height] order.- Throws:
java.lang.IllegalArgumentException- if the sequence value isnull.
-
-
Method Detail
-
expand
public Dimensions expand(int delta)
Expand this dimensions by the given amount (positive or negative) in both width and height directions.- Parameters:
delta- The amount to add to/subtract from both the width and height.- Returns:
- The new dimensions with the changed values.
-
expand
public Dimensions expand(int widthDelta, int heightDelta)
Expand this dimensions by the given amounts (positive or negative) separately in the width and height directions.- Parameters:
widthDelta- The amount to add to/subtract from the width.heightDelta- The amount to add to/subtract from the height.- Returns:
- The new dimensions with the changed values.
-
expand
public Dimensions expand(Insets insets)
Expand this dimensions by the givenInsetsamounts in the width and height directions.- Parameters:
insets- The padding amounts (width and height) to expand by.- Returns:
- The new dimensions with the changed values.
-
equals
public boolean equals(java.lang.Object object)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
decode
public static Dimensions decode(java.lang.String value)
Convert a string dimensions value to the object.The string can be in a variety of forms:
- A JSON map like this:
{ width:nnn, height:nnn } - A JSON array list this:
[ width, height ]
- A string formatted as:
"widthXheight"
(where the X is case-insensitive) - A simple comma-separated string with two numeric values:
"width, height"
- Parameters:
value- The input string in one of these formats.- Returns:
- The parsed dimensions value if possible.
- Throws:
java.lang.IllegalArgumentException- if the input value is null, empty, or cannot be parsed in one of these forms.- See Also:
Dimensions(Dictionary),Dimensions(Sequence),Dimensions(int, int)
- A JSON map like this:
-
-