net.xoetrope.xui.style
Class XStyleManager

java.lang.Object
  extended by net.xoetrope.xui.style.XStyleManager

public class XStyleManager
extends java.lang.Object

    

Class for managing XStyles. XStyles are created externally and added to the hashtable. Also handles the retrieval of styles.

Copyright (c) Xoetrope Ltd., 1998-2004
$Revision: 2.7 $


Field Summary
protected static XStyle baseStyle
          The base style from which all others will be inherited
protected  XProject currentProject
          The XProject for which this instance of the XStyleManager is working
protected  java.util.Hashtable fontCache
          Fonts found when creating styles
protected  java.util.Hashtable mergedStyles
          Used to merge child styles with their parents
protected  java.util.Hashtable styles
          Hashtable of project styles
 
Constructor Summary
XStyleManager()
          Construct a new style manager.
XStyleManager(int styleCount)
          Construct a new style manager with an initial size.
 
Method Summary
 void addStyle(java.lang.String name, XStyle newStyle)
          Add a new XStyle to the hashtable with a unique name
 java.awt.Font getFont(java.lang.String style)
          Get the font for a given style.
 java.awt.Font getFont(XStyle style)
          Get the font for a given style.
static XStyleManager getInstance()
          Deprecated. since 1.03
 XStyle getStyle(java.lang.String name)
          Retrieve a named XStyle from the hashtable.
 XStyle getStyle(java.lang.String name, boolean create)
          Retrieve a named XStyle from the hashtable.
protected  int getStyleIndex(java.lang.String name)
          Gets a integer constant corresponding to a style name
 XStyle getStyleParent(java.lang.String name)
          Get the parent of the named style
 java.util.Hashtable getStyles()
          Get the table of styles
 void load(java.lang.String file)
          Load the styles from the specified file
 void loadXStyle(XmlElement element, java.lang.String path)
          Load a style from the XML element and save it to the specified path in the style hierarchy
 void reset()
          reset the styles in case a new stylesheet is to be loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

styles

protected java.util.Hashtable styles
Hashtable of project styles


mergedStyles

protected java.util.Hashtable mergedStyles
Used to merge child styles with their parents


fontCache

protected java.util.Hashtable fontCache
Fonts found when creating styles


baseStyle

protected static XStyle baseStyle
The base style from which all others will be inherited


currentProject

protected XProject currentProject
The XProject for which this instance of the XStyleManager is working

Constructor Detail

XStyleManager

public XStyleManager()
Construct a new style manager.


XStyleManager

public XStyleManager(int styleCount)
Construct a new style manager with an initial size.

Parameters:
styleCount - The number of initial styles in the styles Hashtable
Method Detail

addStyle

public void addStyle(java.lang.String name,
                     XStyle newStyle)
Add a new XStyle to the hashtable with a unique name

Parameters:
name - The name of the style
newStyle - The XStyle to be associated with the passed name

getStyle

public XStyle getStyle(java.lang.String name,
                       boolean create)
Retrieve a named XStyle from the hashtable. loop thru the "/" character and merge each one found with a new XStyle.

Parameters:
name - The name of the style.
create - booean to indicate whether the style should be created.
Returns:
The referenced XStyle

getStyle

public XStyle getStyle(java.lang.String name)
Retrieve a named XStyle from the hashtable. loop thru the "/" character and merge each one found with a new XStyle.

Parameters:
name - The name of the style.
Returns:
The referenced XStyle

getFont

public java.awt.Font getFont(java.lang.String style)
Get the font for a given style. Use the bold and italic attributes and do a bitwise or using the Font values to set the style.

Parameters:
style - the name of the style
Returns:
The constructed Font Object for the named XStyle

getFont

public java.awt.Font getFont(XStyle style)
Get the font for a given style. Use the bold and italic attributes and do a bitwise or using the Font values to set the style.

Parameters:
style - the style
Returns:
The constructed Font Object for the passed XStyle

getInstance

public static XStyleManager getInstance()
Deprecated. since 1.03

Create the singleton instance


load

public void load(java.lang.String file)
Load the styles from the specified file

Parameters:
file - the file name of the file to load

loadXStyle

public void loadXStyle(XmlElement element,
                       java.lang.String path)
Load a style from the XML element and save it to the specified path in the style hierarchy

Parameters:
element - the source element
path - the save path

getStyleIndex

protected int getStyleIndex(java.lang.String name)
Gets a integer constant corresponding to a style name

Parameters:
name - the style name e.g. "font_face"
Returns:
the style constant e.g. XStyle.FONT_FACE

getStyles

public java.util.Hashtable getStyles()
Get the table of styles

Returns:
the stytle table

getStyleParent

public XStyle getStyleParent(java.lang.String name)
Get the parent of the named style

Parameters:
name - the style name
Returns:
the parent style

reset

public void reset()
reset the styles in case a new stylesheet is to be loaded.