public class Size
extends java.lang.Object
Class that represents a size that is based on a width and height of type Length
.
Constructs from standard paper sizes, generates a string representation, and provides conversions to portrait and landscape mode.
Modifier and Type | Class | Description |
---|---|---|
static class |
Size.PaperSizes |
Constructor | Description |
---|---|
Size(double width,
double height,
Length.Units unit) |
Construct
Size object from width, height and a common unit. |
Size(Length width,
Length height) |
Construct
Size object from width and height. |
Size(Size.PaperSizes paperSize) |
Construct a
Size object from standard paper sizes defined in enum Size.PaperSizes . |
Modifier and Type | Method | Description |
---|---|---|
boolean |
equals(java.lang.Object obj) |
|
double |
getAspectRatio() |
Calculate ratio between height and width.
|
Length |
getHeight() |
Gets the height (vertical size) as
Length object. |
Length |
getWidth() |
Gets the width (horizontal size) as
Length object. |
int |
hashCode() |
|
static Size |
parse(java.lang.String value) |
Create a
Size object from a string representation. |
Size |
toLandscape() |
Switches width and height if the absolute value of height is greater than the the absolute value of width.
|
Size |
toPortrait() |
Switches width and height if the absolute value of the width is greater than the absolute value of the height.
|
java.lang.String |
toString() |
Creates a string representation as width-height-pair with associated suitable metric units, "m", "cm" or "mm".
|
java.lang.String |
toString(Length.Units unit) |
Creates a string representation as width-height-pair with the specified unit.
|
public Size(double width, double height, Length.Units unit)
Size
object from width, height and a common unit.width
- as numerical valueheight
- as numerical valueunit
- the unitpublic Size(Size.PaperSizes paperSize)
Size
object from standard paper sizes defined in enum Size.PaperSizes
.paperSize
- enumeration item e.g. Size.PaperSizes.A4
, or Size.PaperSizes.LETTER
.public static Size parse(java.lang.String value)
Create a Size
object from a string representation.
Allowed are value-unit pairs of the form "<width_value><width_unit> <height_value><height_unit>" or the name of a standard paper size.
Examples: "12.3cm 23.9mm" or "A4"
value
- the string valuepublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(Length.Units unit)
public Size toPortrait()
public Size toLandscape()
public double getAspectRatio()
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object