Package com.privatejgoodies.forms.layout

# Class ConstantSize

java.lang.Object
com.privatejgoodies.forms.layout.ConstantSize

All Implemented Interfaces:
  `Size`, `Serializable`

public final class ConstantSize extends Object implements Size, Serializable
An implementation of the `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);

Version:
  $Revision: 1.21 $
Author:
  Karsten Lentzsch
See Also:
  - `Size`
  - `Sizes`
  - Serialized Form

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static final class`
`ConstantSize.Unit`
An ordinal-based serializable typesafe enumeration for units as used in instances of `ConstantSize`.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final ConstantSize.Unit`
`CENTIMETER`
`static final ConstantSize.Unit`
`CM`
`static final ConstantSize.Unit`
`DIALOG_UNITS_X`
`static final ConstantSize.Unit`
`DIALOG_UNITS_Y`
`static final ConstantSize.Unit`
`DLUX`
`static final ConstantSize.Unit`
`DLUY`
`static final ConstantSize.Unit`
`IN`
`static final ConstantSize.Unit`
`INCH`
`static final ConstantSize.Unit`
`MILLIMETER`
`static final ConstantSize.Unit`
`MM`
`static final ConstantSize.Unit`
`PIXEL`
`static final ConstantSize.Unit`
`POINT`
`static final ConstantSize.Unit`
`PT`
`static final ConstantSize.Unit`
`PX`

## Constructor Summary

Constructors
Constructor
Description
`ConstantSize(double value, ConstantSize.Unit unit)`
Constructs a ConstantSize for the given size and unit.
`ConstantSize(int value, ConstantSize.Unit unit)`
Constructs a ConstantSize for the given size and unit.

## Method Summary

Modifier and Type
Method
Description
`boolean`
`compressible()`
Describes if this Size can be compressed, if container space gets scarce.
`String`
`encode()`
Returns a parseable string representation of this constant size.
`boolean`
`equals(Object o)`
Indicates whether some other ConstantSize is "equal to" this one.
`int`
`getPixelSize(Component component)`
Converts the size if necessary and returns the value in pixels.
`ConstantSize.Unit`
`getUnit()`
Returns this size's unit.
`double`
`getValue()`
Returns this size's value.
`int`
`hashCode()`
Returns a hash code value for the object.
`int`
`maximumSize(Container container, List components, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure)`
Returns this size as pixel size.
`String`
`toString()`
Returns a string representation of this size object.

### Methods inherited from class java.lang.Object

`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

## Field Details

### PIXEL

public static final ConstantSize.Unit PIXEL

### POINT

public static final ConstantSize.Unit POINT

### DIALOG_UNITS_X

public static final ConstantSize.Unit DIALOG_UNITS_X

### DIALOG_UNITS_Y

public static final ConstantSize.Unit DIALOG_UNITS_Y

### MILLIMETER

public static final ConstantSize.Unit MILLIMETER

### CENTIMETER

public static final ConstantSize.Unit CENTIMETER

### INCH

public static final ConstantSize.Unit INCH

### PX

public static final ConstantSize.Unit PX

### PT

public static final ConstantSize.Unit PT

### DLUX

public static final ConstantSize.Unit DLUX

### DLUY

public static final ConstantSize.Unit DLUY

### MM

public static final ConstantSize.Unit MM

### CM

public static final ConstantSize.Unit CM

### IN

public static final ConstantSize.Unit IN

## Constructor Details

### ConstantSize

public ConstantSize(int value, ConstantSize.Unit unit)
Constructs a ConstantSize for the given size and unit.

Parameters:
  `value` - the size value interpreted in the given units
  `unit` - the size's unit
Since:
  1.1

### ConstantSize

public ConstantSize(double value, ConstantSize.Unit unit)
Constructs a ConstantSize for the given size and unit.

Parameters:
  `value` - the size value interpreted in the given units
  `unit` - the size's unit
Since:
  1.1

## Method Details

### getValue

public double getValue()
Returns this size's value.

Returns:
  the size value
Since:
  1.1

### getUnit

public ConstantSize.Unit getUnit()
Returns this size's unit.

Returns:
  the size unit
Since:
  1.1

### getPixelSize

public int getPixelSize(Component component)
Converts the size if necessary and returns the value in pixels.

Parameters:
  `component` - the associated component
Returns:
  the size in pixels

### maximumSize

public int maximumSize(Container container, List components, FormLayout.Measure minMeasure, FormLayout.Measure prefMeasure, FormLayout.Measure defaultMeasure)
Returns this size as pixel size. Neither requires the component list nor the specified measures.

Invoked by `FormSpec` to determine the size of a column or row.

Specified by:
  `maximumSize` in interface `Size`
Parameters:
  `container` - the layout container
  `components` - the list of components used to compute the size
  `minMeasure` - the measure that determines the minimum sizes
  `prefMeasure` - the measure that determines the preferred sizes
  `defaultMeasure` - the measure that determines the default sizes
Returns:
  the computed maximum size in pixel

### compressible

public boolean compressible()
Describes if this Size can be compressed, if container space gets scarce. Used by the FormLayout size computations in `#compressedSizes` to check whether a column or row can be compressed or not.

ConstantSizes are incompressible.

Specified by:
  `compressible` in interface `Size`
Returns:
  `false`
Since:
  1.1

### equals

public boolean equals(Object o)
Indicates whether some other ConstantSize is "equal to" this one.

Overrides:
  `equals` in class `Object`
Parameters:
  `o` - the Object with which to compare
Returns:
  `true` if this object is the same as the obj argument; `false` otherwise.
See Also:
  - `Object.hashCode()`
  - `Hashtable`

### hashCode

public int hashCode()
Returns a hash code value for the object. This method is supported for the benefit of hashtables such as those provided by `java.util.Hashtable`.

Overrides:
  `hashCode` in class `Object`
Returns:
  a hash code value for this object.
See Also:
  - `Object.equals(java.lang.Object)`
  - `Hashtable`

### toString

public String toString()
Returns a string representation of this size object. Note: This string representation may change at any time. It is intended for debugging purposes. For parsing, use `encode()` instead.

Overrides:
  `toString` in class `Object`
Returns:
  a string representation of the constant size

### encode

public String encode()
Returns a parseable string representation of this constant size.

Specified by:
  `encode` in interface `Size`
Returns:
  a String that can be parsed by the Forms parser
Since:
  1.2