cox.jmatt.java.MathTools.markup
Class StyleInfo

java.lang.Object
  extended by cox.jmatt.java.MathTools.markup.StyleInfo
Direct Known Subclasses:
SimpleStyleImpl, StylePen

public class StyleInfo
extends java.lang.Object

This class encapsulates CSS rules and 'style=' attributes. It contains an internal Hashtable for tracking this information along with methods to add, remove, and clear it. It also has methods to format the information as a CSS-style rule or raw data for an XML attribute. For declarations whose value should be numeric, the _addNDeclaration() methods offer numeric enforcement and optional value clamping.


Constructor Summary
StyleInfo()
          Create a blank tag, waiting for declarations to be set.
StyleInfo(java.lang.String pRuleName)
          Create a named tag, if the name supplied is not null or blank.
 
Method Summary
protected  boolean _addDeclaration(java.lang.String pKey, java.lang.String pValue)
          Add a declaration to the internal data.
protected  boolean _addNDeclaration(java.lang.String pKey, java.lang.Number pValue)
          Convenience method for _addNDeclaration(pKey, pValue, null, null).
protected  boolean _addNDeclaration(java.lang.String pKey, java.lang.Number pValue, java.lang.Double pMin, java.lang.Double pMax)
          Add a possibly-clamped numeric declaration.
protected  java.util.Hashtable<java.lang.String,java.lang.String> _declarations()
          Return a copy of the current declarations.
protected  void _enableCopy()
          Use this method to enable the various copyOf() methods.
protected static java.lang.String _uniqueName()
          Use this method to generate a unique name rule for declaration groups.
 void configurate(java.util.Properties pPizza)
          This is a generic default configuration method for StyleInfo subclasses.
 void configurateGlobalPizza()
          This method simply calls configurate() on the Global Pizza.
 StyleInfo copyOf()
          Create and return a copy of this instance.
 void reset()
          Clear all inernal data.
 void setName(java.lang.String pName)
          Set the the (default) attribute name (attribute) or selector (css) text.
 java.lang.String toAttribute()
          This is the toAttribute() method with the internal name, if one is set.
 java.lang.String toAttribute(java.lang.String pName)
          Return the declarations in a format appropriate for an XML attribute.
 java.lang.String toCSS()
          Return the declarations in a format suitable for an internal or external CSS stylesheet.
 java.lang.String toRawCSS()
          List all the declarations as a String of key-value pairs.
 java.lang.String toString()
          List all the declarations as a String of key-value pairs.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StyleInfo

public StyleInfo()
Create a blank tag, waiting for declarations to be set.


StyleInfo

public StyleInfo(java.lang.String pRuleName)
Create a named tag, if the name supplied is not null or blank.

Method Detail

_uniqueName

protected static final java.lang.String _uniqueName()
Use this method to generate a unique name rule for declaration groups. It will be 'Style_' followed by a number. This is used when the methods need a rule name and none is set.


_declarations

protected final java.util.Hashtable<java.lang.String,java.lang.String> _declarations()
Return a copy of the current declarations. This is a copy; it may be empty but will never be null.


_enableCopy

protected final void _enableCopy()
Use this method to enable the various copyOf() methods. When called it stores all declarations in a temporary static variable; the next instance automatically copies the declarations set for itself, then the temporary variable is cleared.


_addDeclaration

protected final boolean _addDeclaration(java.lang.String pKey,
                                        java.lang.String pValue)
Add a declaration to the internal data. If the key is null or blank the method returns false. If the key and rule are both valid they are added. If the key is valid and the rule is null or blank, a successful removal returns true and a non-removal returns false. This method is meant to be used as follows:
addStyle('visible', 'false');.

Parameters:
pKey - The declaration property name.
pValue - The declaration value.

_addNDeclaration

protected final boolean _addNDeclaration(java.lang.String pKey,
                                         java.lang.Number pValue,
                                         java.lang.Double pMin,
                                         java.lang.Double pMax)
Add a possibly-clamped numeric declaration. The value is given as type java.lang.Number and the limits as java.lang.Double. If either limit is ignored. If not, the value is replaced by the minimum if it is less than the minimum and the maximum if it is greater than the maximum. CAUTION: This method does not check to see if the minimum supplied is in fact less than the maximum! Use with care. If the value is null it is removed. If the key is null or blank the method returns false immediately.

Parameters:
pKey - The name of the declaration property.
pValue - The (numeric) value of the declaration or null to remove it.
pMin - The minimum value, ignored if null.
pMax - The maximum value, ignored if null.

_addNDeclaration

protected final boolean _addNDeclaration(java.lang.String pKey,
                                         java.lang.Number pValue)
Convenience method for _addNDeclaration(pKey, pValue, null, null).


setName

public void setName(java.lang.String pName)
Set the the (default) attribute name (attribute) or selector (css) text. Setting null clears it.


configurate

public void configurate(java.util.Properties pPizza)
This is a generic default configuration method for StyleInfo subclasses. This implementation is empty but is provided if needed. Any subclass defining this method must document exactly what and how the information is passed (other than by the Properties object, which is given!). The theory is that subclasses can pick through the keys, select the ones relevant to themselves and self-configure accordingly.

Parameters:
pPizza - The Properties object containing configuration information.

configurateGlobalPizza

public void configurateGlobalPizza()
This method simply calls configurate() on the Global Pizza.


reset

public void reset()
Clear all inernal data.


copyOf

public StyleInfo copyOf()
Create and return a copy of this instance.


toString

public java.lang.String toString()
List all the declarations as a String of key-value pairs. Each individual declaration is terminated with a semicolon and they are space-separated. If no declarations are set the return value is a blank but non-null String.

Overrides:
toString in class java.lang.Object

toRawCSS

public java.lang.String toRawCSS()
List all the declarations as a String of key-value pairs. Each individual declaration is formatted per CSS style rules and they are space-separated. If no declarations are set the return value is null;


toAttribute

public java.lang.String toAttribute(java.lang.String pName)
Return the declarations in a format appropriate for an XML attribute. This is basically the same as toString() but with quotes on both sides. if the pName argument is not null or void it appears to the left, making the entire returned String usable as an attribute. If pName is null or blank no name or equals sign appears.

Parameters:
pName - The attribute name to be output to the left of the rules String.

toAttribute

public java.lang.String toAttribute()
This is the toAttribute() method with the internal name, if one is set.


toCSS

public java.lang.String toCSS()
Return the declarations in a format suitable for an internal or external CSS stylesheet. If the internal name is null or blank a default is assigned. The format used is selector-style with the declarations enclosed in curly braces.