de.lessvoid.nifty.tools
Class SizeValue

java.lang.Object
  extended by de.lessvoid.nifty.tools.SizeValue

public class SizeValue
extends Object

The SizeValue class stores and manages size value strings. Such strings are used to store size representations. See the constants for all supported special kind of values.

Author:
void

Field Summary
static String HEIGHT_SUFFIX
          Add a HEIGHT_SUFFIX to some size value to indicate that this value will be calculated in respect to the Height of an element.
static float MAX_PERCENT
          Max percent constant.
static String PERCENT
          Add a PERCENT to some size value to indicate a percent value.
static String PIXEL
          Add a PIXEL to some size value to indicate a pixel value.
static String WIDTH_SUFFIX
          Add a WIDTH_SUFFIX to some size value to indicate that this value will be calculated in respect to the Width of an element.
static String WILDCARD
          The WILDCARD value will not really be handled by the SizeValue class.
 
Constructor Summary
SizeValue(String valueParam)
          Create a new instance using the given value.
 
Method Summary
 boolean equals(Object obj)
           
 float getValue(float range)
          Get the value as float.
 int getValueAsInt(float range)
          Get the value as int.
 int hashCode()
           
 boolean hasHeightSuffix()
           
 boolean hasWidthSuffix()
           
 boolean hasWildcard()
           
 boolean isPercentOrPixel()
          Checks if the value contains either PERCENT or PIXEL.
 boolean isPixel()
          Checks if this value describes a pixel value.
static SizeValue percent(int percentage)
          static helper to create a percentage based SizeValue.
static SizeValue px(int pixelValue)
          static helper to create a pixel based SizeValue.
 String toString()
          toString.
static SizeValue wildcard()
          static helper to create a wildcard based SizeValue.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PIXEL

public static final String PIXEL
Add a PIXEL to some size value to indicate a pixel value. Example: "100px" or "640px"

See Also:
Constant Field Values

PERCENT

public static final String PERCENT
Add a PERCENT to some size value to indicate a percent value. Example: "100%" or "50%"

See Also:
Constant Field Values

WIDTH_SUFFIX

public static final String WIDTH_SUFFIX
Add a WIDTH_SUFFIX to some size value to indicate that this value will be calculated in respect to the Width of an element. This is only appropriate to a height attribute and this class can only detect it's present. Handling must be performed outside of this class.

See Also:
Constant Field Values

HEIGHT_SUFFIX

public static final String HEIGHT_SUFFIX
Add a HEIGHT_SUFFIX to some size value to indicate that this value will be calculated in respect to the Height of an element. This is only appropriate to a width attribute and this class can only detect it's present. Handling must be performed outside of this class.

See Also:
Constant Field Values

WILDCARD

public static final String WILDCARD
The WILDCARD value will not really be handled by the SizeValue class. Its used to use the maximum available space by some layout managers.

See Also:
Constant Field Values

MAX_PERCENT

public static final float MAX_PERCENT
Max percent constant.

See Also:
Constant Field Values
Constructor Detail

SizeValue

public SizeValue(String valueParam)
Create a new instance using the given value.

Parameters:
valueParam - the String value
Method Detail

px

public static SizeValue px(int pixelValue)
static helper to create a pixel based SizeValue.

Parameters:
pixelValue - pixel value
Returns:
SizeValue

percent

public static SizeValue percent(int percentage)
static helper to create a percentage based SizeValue.

Parameters:
percentage - percentage value
Returns:
SizeValue

wildcard

public static SizeValue wildcard()
static helper to create a wildcard based SizeValue.

Returns:
SizeValue

isPercentOrPixel

public boolean isPercentOrPixel()
Checks if the value contains either PERCENT or PIXEL.

Returns:
true when either PERCENT or PIXEL is given.

getValue

public float getValue(float range)
Get the value as float.

Parameters:
range - the size that percent values are calculated from.
Returns:
the result value as float

getValueAsInt

public int getValueAsInt(float range)
Get the value as int.

Parameters:
range - range the size that percent values are calculated from.
Returns:
the result value as int

isPixel

public boolean isPixel()
Checks if this value describes a pixel value.

Returns:
true if the given string value ends with PIXEL and false otherwise

toString

public String toString()
toString.

Overrides:
toString in class Object
Returns:
value

hasWidthSuffix

public boolean hasWidthSuffix()

hasHeightSuffix

public boolean hasHeightSuffix()

hasWildcard

public boolean hasWildcard()

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

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


Copyright © 2012. All Rights Reserved.