org.wings
Class SDimension

java.lang.Object
  extended by org.wings.SDimension
All Implemented Interfaces:
Serializable

public class SDimension
extends Object
implements Serializable

Holds preferred component sizes (dimensions).

Web browsers support different notations for sizes. Absolute pixel values, realtive percentages (of the available viewport) and special CSS values as 'inherit' and 'auto' (Default). This class if capable of handling all these cases.

See Also:
Serialized Form

Field Summary
static String AUTO
          String constant for CSS dimension 'auto'.
static int AUTO_INT
          Integer constant for CSS dimension 'auto'.
static SDimension AUTOAREA
          Immutable SDimension constants for a component taking up normal space
static SDimension FULLAREA
          Immutable SDimension constants for a component taking up the full available area.
static SDimension FULLHEIGHT
          Immutable SDimension constants for a component taking up the full available height.
static SDimension FULLWIDTH
          Immutable SDimension constants for a component taking up the full available width.
static String INHERIT
          String for CSS dimension 'inherit'.
static int INHERIT_INT
          Integer constant for CSS dimension 'inherit'.
 
Constructor Summary
SDimension()
           
SDimension(Integer width, Integer height)
          Construct a new dimension with absolute values.
SDimension(int width, int height)
          Construct a new dimension with absolute values.
SDimension(String width, String height)
           
 
Method Summary
 boolean equals(Object o)
           
protected  int extractNumericValue(String value)
          Extract number from string.
 String getHeight()
           
 int getHeightInt()
          Get just the height as number without trailing unit.
 String getHeightUnit()
           
protected  int getIntValue(String sizeString)
          Extract number from string.
 String getWidth()
           
 int getWidthInt()
          Get just the width as number without trailing unit.
 String getWidthUnit()
           
 int hashCode()
           
 void setHeight(int height)
          Set height in pixel.
 void setHeight(String height)
          Sets the preferred height via an string.
 void setSize(int width, int height)
          Set the size of this Dimension object to the specified width and height and append "px" to both values.
 void setWidth(int width)
          Set width in pixel.
 void setWidth(String width)
          Sets the preferred width via an string.
 String toString()
           
protected  String toString(int size, String unit)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

AUTO

public static final String AUTO
String constant for CSS dimension 'auto'. This is the default width used by wings as well as by CSS capable browsers.

See Also:
Constant Field Values

INHERIT

public static final String INHERIT
String for CSS dimension 'inherit'. With this value the preferred size is inherited by the surrounding element.

See Also:
Constant Field Values

AUTO_INT

public static final int AUTO_INT
Integer constant for CSS dimension 'auto'. This is the default width used by wings as well as by CSS capable browsers.

See Also:
Constant Field Values

INHERIT_INT

public static final int INHERIT_INT
Integer constant for CSS dimension 'inherit'. With this value the preferred size is inherited by the surrounding element.

See Also:
Constant Field Values

FULLWIDTH

public static final SDimension FULLWIDTH
Immutable SDimension constants for a component taking up the full available width.


FULLHEIGHT

public static final SDimension FULLHEIGHT
Immutable SDimension constants for a component taking up the full available height.


FULLAREA

public static final SDimension FULLAREA
Immutable SDimension constants for a component taking up the full available area.


AUTOAREA

public static final SDimension AUTOAREA
Immutable SDimension constants for a component taking up normal space

Constructor Detail

SDimension

public SDimension()

SDimension

public SDimension(String width,
                  String height)

SDimension

public SDimension(int width,
                  int height)
Construct a new dimension with absolute values. The value is interpreted as absolute pixel values.

Parameters:
width - the preferred width in pixel. Use -1 for AUTO.
height - the preferred height in pixel. Use -1 for AUTO.
See Also:
setSize(int,int)

SDimension

public SDimension(Integer width,
                  Integer height)
Construct a new dimension with absolute values. The value is interpreted as absolute pixel values.

Parameters:
width - the preferred width in pixel. You may pass null.
height - the preferred height in pixel. You may pass null.
See Also:
setSize(int,int)
Method Detail

setWidth

public void setWidth(String width)
Sets the preferred width via an string. Expects an dimension/unit compount i.e. "120px" or "80%" but will assume px by default.

Parameters:
width - A preferred witdth.

setHeight

public void setHeight(String height)
Sets the preferred height via an string. Expects an dimension/unit compount i.e. "120px" or "80%" but will assume px by default.

Parameters:
height - A preferred height.

setWidth

public void setWidth(int width)
Set width in pixel. This appends "px" to the integer value.

Parameters:
width - if -1 set widthInt to null

setHeight

public void setHeight(int height)
Set height in pixel. This appends "px" to the integer value.

Parameters:
height - if -1 set heightInt to null

getWidth

public String getWidth()
Returns:
The preferred width i.e. like 120px or 80% or auto

getHeight

public String getHeight()
Returns:
The preferred height i.e. like 120px or 80% or auto

getWidthInt

public int getWidthInt()
Get just the width as number without trailing unit.


getHeightInt

public int getHeightInt()
Get just the height as number without trailing unit.


getWidthUnit

public String getWidthUnit()
Returns:
The unit of the current width. Returns null for AUTO and INHERIT. Otherwise always returns a non-null value!

getHeightUnit

public String getHeightUnit()
Returns:
The unit of the current height. Returns null for AUTO and INHERIT. Otherwise always returns a non-null value!

setSize

public void setSize(int width,
                    int height)
Set the size of this Dimension object to the specified width and height and append "px" to both values.

See Also:
setHeight(int), setWidth(int)

toString

public String toString()
Overrides:
toString in class Object

getIntValue

protected int getIntValue(String sizeString)
Extract number from string.

Returns:
extracted integer. f.e.: "120px" becomes 120

toString

protected String toString(int size,
                          String unit)

extractNumericValue

protected int extractNumericValue(String value)
Extract number from string.

Returns:
extracted integer. f.e.: "120px" becomes 120 or AUTO_INT if null

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


wingS Swings ;-)