public final class ConstantSize extends java.lang.Object implements Size, java.io.Serializable
Size
interface that represents constant
sizes described by a value and unit, for example:
10 pixel, 15 point or 4 dialog units.
You can get instances of ConstantSize
using
the factory methods and constants in the Sizes
class.
Logical constant sizes that vary with the current layout style
are delivered by the LayoutStyle
class.This class supports different size units:
Unit | Abbreviation | Size |
Millimeter | mm | 0.1 cm |
Centimeter | cm | 10.0 mm |
Inch | in | 25.4 mm |
DTP Point | pt | 1/72 in |
Pixel | px | 1/(resolution in dpi) in |
Dialog Unit | dlu | honors l&f, resolution, and dialog font size |
Examples:
Sizes.ZERO; Sizes.DLUX9; Sizes.dluX(42); Sizes.pixel(99);
Size
,
Sizes
,
Serialized FormModifier and Type | Class and Description |
---|---|
static class |
ConstantSize.Unit
An ordinal-based serializable typesafe enumeration for units
as used in instances of
ConstantSize . |
Modifier and Type | Field and Description |
---|---|
static ConstantSize.Unit |
CENTIMETER |
static ConstantSize.Unit |
CM |
static ConstantSize.Unit |
DIALOG_UNITS_X |
static ConstantSize.Unit |
DIALOG_UNITS_Y |
static ConstantSize.Unit |
DLUX |
static ConstantSize.Unit |
DLUY |
static ConstantSize.Unit |
IN |
static ConstantSize.Unit |
INCH |
static ConstantSize.Unit |
MILLIMETER |
static ConstantSize.Unit |
MM |
static ConstantSize.Unit |
PIXEL |
static ConstantSize.Unit |
POINT |
Constructor and Description |
---|
ConstantSize(double value,
ConstantSize.Unit unit)
Constructs an instance of
ConstantSize from the given
encoded size and unit description. |
ConstantSize(int value,
ConstantSize.Unit unit)
Constructs an instance of
ConstantSize from the given
encoded size and unit description. |
Modifier and Type | Method and Description |
---|---|
(package private) static ConstantSize |
dluX(int value)
Returns an instance of
Size for the specified value
in horizontal dialog units. |
(package private) static ConstantSize |
dluY(int value)
Returns an instance of
Size for the specified value
in vertical dialog units. |
boolean |
equals(java.lang.Object o)
Indicates whether some other ConstantSize is "equal to" this one.
|
int |
getPixelSize(java.awt.Component component)
Converts the size if necessary and returns the value in pixels.
|
int |
hashCode()
Returns a hash code value for the object.
|
int |
maximumSize(java.awt.Container container,
java.util.List components,
FormLayout.Measure minMeasure,
FormLayout.Measure prefMeasure,
FormLayout.Measure defaultMeasure)
Returns this size as pixel size.
|
(package private) static java.lang.String[] |
splitValueAndUnit(java.lang.String encodedValueAndUnit)
Splits a string that encodes size with unit into the size and unit
substrings.
|
java.lang.String |
toString()
Returns a string representation of this size object.
|
(package private) static ConstantSize |
valueOf(java.lang.String encodedValueAndUnit,
boolean horizontal)
Constructs an instance of
ConstantSize from the given
encoded size and unit description. |
public static final ConstantSize.Unit PIXEL
public static final ConstantSize.Unit POINT
public static final ConstantSize.Unit DIALOG_UNITS_X
public static final ConstantSize.Unit DLUX
public static final ConstantSize.Unit DIALOG_UNITS_Y
public static final ConstantSize.Unit DLUY
public static final ConstantSize.Unit MILLIMETER
public static final ConstantSize.Unit MM
public static final ConstantSize.Unit CENTIMETER
public static final ConstantSize.Unit CM
public static final ConstantSize.Unit INCH
public static final ConstantSize.Unit IN
ConstantSize(int value, ConstantSize.Unit unit)
ConstantSize
from the given
encoded size and unit description.value
- the size value interpreted in the given unitsunit
- the size's unitConstantSize(double value, ConstantSize.Unit unit)
ConstantSize
from the given
encoded size and unit description.value
- the size value interpreted in the given unitsunit
- the size's unitstatic ConstantSize valueOf(java.lang.String encodedValueAndUnit, boolean horizontal)
ConstantSize
from the given
encoded size and unit description.encodedValueAndUnit
- the size's value and unit as stringhorizontal
- true for horizontal, false for verticaljava.lang.IllegalArgumentException
- if the unit requires integer
but the value is not an integerstatic ConstantSize dluX(int value)
Size
for the specified value
in horizontal dialog units.value
- size value in horizontal dialog unitsstatic ConstantSize dluY(int value)
Size
for the specified value
in vertical dialog units.value
- size value in vertical dialog unitspublic int getPixelSize(java.awt.Component component)
component
- the associated componentpublic int maximumSize(java.awt.Container container, java.util.List components, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure)
Invoked by FormSpec
to determine
the size of a column or row.
maximumSize
in interface Size
container
- the layout containercomponents
- the list of components used to compute the sizeminMeasure
- the measure that determines the minimum sizesprefMeasure
- the measure that determines the preferred sizesdefaultMeasure
- the measure that determines the default sizespublic boolean equals(java.lang.Object o)
equals
in class java.lang.Object
o
- the Object with which to comparetrue
if this object is the same as the obj
argument; false
otherwise.Object.hashCode()
,
Hashtable
public int hashCode()
java.util.Hashtable
.hashCode
in class java.lang.Object
Object.equals(java.lang.Object)
,
Hashtable
public java.lang.String toString()
toString
in class java.lang.Object
static java.lang.String[] splitValueAndUnit(java.lang.String encodedValueAndUnit)
encodedValueAndUnit
- a strings that represents a size with unit