com.lightdev.app.shtm
Class CombinedAttribute

java.lang.Object
  extended by com.lightdev.app.shtm.CombinedAttribute

public class CombinedAttribute
extends java.lang.Object

A class to represent an attribute combining several other attributes.

The CSS 1.0 specification defines 'shorthand properties' which can hold more than one value separated by blanks. Depending on the number of values inside the property the values are applied following a fixed ratio.

Following is an excerpt of the spec for CSS property border-width

 There can be from one to four values, with the following interpretation:
     one value: all four border widths are set to that value
     two values: top and bottom border widths are set to the
                    first value, right and left are set to the second
     three values: top is set to the first, right and left are set to
                    the second, bottom is set to the third
     four values: top, right, bottom and left, respectively
 

In SimplyHTML this spec is used on properties margin, padding, border-width and border-color


Field Summary
static int ATTR_BOTTOM
          index of bottom value
static int ATTR_LEFT
          index of left value
static int ATTR_RIGHT
          index of right value
static int ATTR_TOP
          index of top value
 
Constructor Summary
CombinedAttribute(java.lang.Object key, javax.swing.text.AttributeSet a, boolean includeParents)
          construct a CombinedAttribute for a certain attribute out of a given set of attributes
 
Method Summary
 java.lang.String getAttribute()
          get all values of this CombinedAttribute as one attribute.
 java.lang.String getAttribute(int side)
          get one attribute of this CombinedAttribute
 java.lang.Object getAttributeKey()
          get the attribute key this CombinedAttribute represents
 int getOppositeSide(int side)
          get the side opposite of a given side
 boolean isEmpty()
          determine whether or not the set of attributes this CombinedAttribute was created from contained any of the attributes in this CombinedAttribute
 void setAttribute(int side, java.lang.String value)
          set one attribute of this CombinedAttribute
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATTR_TOP

public static final int ATTR_TOP
index of top value

See Also:
Constant Field Values

ATTR_RIGHT

public static final int ATTR_RIGHT
index of right value

See Also:
Constant Field Values

ATTR_BOTTOM

public static final int ATTR_BOTTOM
index of bottom value

See Also:
Constant Field Values

ATTR_LEFT

public static final int ATTR_LEFT
index of left value

See Also:
Constant Field Values
Constructor Detail

CombinedAttribute

public CombinedAttribute(java.lang.Object key,
                         javax.swing.text.AttributeSet a,
                         boolean includeParents)
construct a CombinedAttribute for a certain attribute out of a given set of attributes

Parameters:
key - the attribute key to get single attribute values from
a - the set of attributes to get the attribute of type 'key'
Method Detail

isEmpty

public boolean isEmpty()
determine whether or not the set of attributes this CombinedAttribute was created from contained any of the attributes in this CombinedAttribute

Can be used for instance to determine whether or not this CombinedAttribute should be written

Returns:
true, if this CombinedAttribute contains default values only, false if not

getOppositeSide

public int getOppositeSide(int side)
get the side opposite of a given side

Parameters:
side - the side to get the opposite of
Returns:
the opposite side of the given side

setAttribute

public void setAttribute(int side,
                         java.lang.String value)
set one attribute of this CombinedAttribute

Parameters:
side - the side to set the attribute for, one of ATTR_TOP, ATTR_RIGHT, ATTR_BOTTOM, ATTR_LEFT
value - the attribute value to set

getAttribute

public java.lang.String getAttribute(int side)
get one attribute of this CombinedAttribute

Parameters:
side - the side to get the attribute for, one of ATTR_TOP, ATTR_RIGHT, ATTR_BOTTOM, ATTR_LEFT
Returns:
the attribute value for the specified side or null, if the attribute key provided in the constructor was not found

getAttributeKey

public java.lang.Object getAttributeKey()
get the attribute key this CombinedAttribute represents

Returns:
the attribute key

getAttribute

public java.lang.String getAttribute()
get all values of this CombinedAttribute as one attribute.

Returns:
a String having all values delimited by blanks in the order top right, bottom, left or null if no attributes were found