|
|||||||||
| Home >> All >> echopoint >> [ stylesheet overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
echopoint.stylesheet
Class CssStyleSheet

java.lang.Objectechopoint.stylesheet.CssStyleSheet
- All Implemented Interfaces:
- java.util.EventListener, java.beans.PropertyChangeListener, java.io.Serializable, StyleSheet
- public class CssStyleSheet
- extends java.lang.Object
- implements StyleSheet, java.beans.PropertyChangeListener, java.io.Serializable
- extends java.lang.Object
The CssStyleSheet class implements a StyleSheet for
Echo derived Components.
A StyleSheet is a collection of style attributes that can be applied to a Component and any of its children. A StyleSheet object can listen for when child Components are added, and apply the StyleSheet to those child components
CssStyleSheet style data can be loaded from external files or other reader data sources. The format of the CssStyleSheet data is based on w3c Cascading Style Sheets, and has been made to look 'CSS like'. (although pure CSS files cannot be used.)
A CssStyleSheet file contain style instructions for a Component class. Lower level class names can be used. For example the 'font" attribute may be set for the class nextapp.echo.Component to Verdana. This means that all derived Components will have the Verdana font style applied to them unless they have an entry for a more specific class.
A map of all styles and classes is kept and when a given component is to have a CssStyleSheet applied to it, the application is done from least specific Class to most specific Class.
For example if a CssStyleSheet is applied to a PasswordField object, then a style will be searched first for the Component class, then the TextComponent class, the TextField class and then finally the PasswordField class.
This application of styles allows "cascading" style values to be applied to a given Component object. The more specific StyleSheet entries will overrride any previous entries.
CssStyleSheet data has a 'CSS like' format of :
className1 [,classNameN] {
attributeName1 : attributeValue2;
...
[attributeNameN : attributeValueN;]
}
Multiple class names can be specified for the one entry. The class names are case senstive however the style attribute names and values are not. Quotes can be used at any time within the entries.
For example :
// comments allowed
echopoint.DatePicker {
foreground : #FF00CC;
background : color(AA,99,CC);
rolloverEnabled : true;
font : 'sans serif',bold,12;
calendarFont : font(verdana,italic,16)
}
C and C++ style comments (slash slash or slash asterisk) can be used anywhere within the CssStyleSheet data
The className can be in three forms :
- className
- className!groupName
- className#id
Using groupName allows you to "logically" group a number of components under the one name. You do this by setting using an attributed identifier of "stylegroup=xxx", where xxx equals groupName.
Using id, will cause the styles to be applied to Components of a certain class that have the specified identifier or an attributed identifier of "style=xxx", where xxx equals id.
For more information on attributed identifiers, see echopoint.util.IdKit
For example :
echopoint.PushButton {
foreground : #FF00CC;
background : color(AA,99,CC);
}
echopoint.PushButton!large {
font : 'sans serif',bold,24;
}
echopoint.PushButton!small {
font : 'verdana',plain,8;
}
echopoint.PushButton#pbId {
font : 'serif',bold,12;
}
The ordering of application of styles is : className, className and groupName, className and finally id.
Use the CssStyleSheet.getInstance() to create new StyleSheet objects. This method will return a CssStyleSheet with handlers for both Echo and EchoPoint components.
The CssStyleSheet.getEmptyInstance() method returns a CssStyleSheet object with no CssStyleSheetHandlers within it. You would rarely use this method however.
If a Component class has a StyleInfo support class associated with it then the CssStyleSheet will invoke it to find out the class for values of a given style attribute name. This ensures that Style objects are created safely, with little chance of a ClassCastException when applied. This also allows case insensitive CCS attribute names to be turned into case sensitive Style attribute names.
Internally a SmartStyle object is built with all of the information in the style sheet. This is then applied to the Component via the Component.applyStyle() method. If any of the style attributes are not set during the applyStyle() method, then relection is used to find "setter" methods in the Component and this is used to set values.
NOTE : that this StyleInfo is optional, and if not found then the CssStyleSheet will make an intelligent guess about what class of object is required for a given attribute name.
| Nested Class Summary | |
private class |
CssStyleSheet.StyleEntry
|
| Field Summary | |
private java.util.ArrayList |
exceptionList
|
private boolean |
failOnInvalidAttributes
|
private java.util.ArrayList |
groupList
|
private java.util.ArrayList |
handlerList
|
private boolean |
hasParsingOccurred
|
private java.util.ArrayList |
idList
|
private boolean |
parseable
|
private java.util.HashMap |
styleMap
|
private java.util.ArrayList |
styleSheetGroupList
|
| Constructor Summary | |
private |
CssStyleSheet()
CssStyleSheet constructor |
| Method Summary | |
private void |
_applyStyle(nextapp.echo.Component c,
CssStyleSheet.StyleEntry entry)
Tries to apply a style to a component. |
private void |
_applyStyleSheetRecursively(nextapp.echo.Component c)
Recursively applies the StyleSheet to a Component and its chidren |
private void |
_applyStyleSheetToComponent(nextapp.echo.Component c)
Deprecated. StyleSheetGroup has been deprecated and will be removed in the next version of EchoPoint. Use the new attributed identifier on the Component from now on, eg component.setIdentifier("stylegroup=xxx;"); |
private java.lang.Class |
_findClassFromName(java.lang.String className)
This method finds the Class object for a given name. |
private StyleSheetGroup |
_findStyleSheetGroup(java.lang.String name)
Deprecated. StyleSheetGroup has been deprecated and will be removed in the next version of EchoPoint. Use the new attributed identifier on the Component from now on, eg component.setIdentifier("stylegroup=xxx;"); |
private boolean |
_isObjValue(java.lang.String attrValue)
Returns true if a value is in the form obj(...) |
private boolean |
_isQuotedValue(java.lang.String attrValue)
|
private boolean |
_magicSetStyleAttribute(nextapp.echo.Style style,
java.lang.Class componentClass,
StyleAttrDescriptor descriptor,
java.lang.String attrName,
java.lang.String attrValue)
This will try and set a value into a Style if it really is of the given type valueClass! It returns false if the value cannot be set. |
private StyleAttrDescriptor |
_magicStyleFindDescriptor(StyleInfo styleInfo,
java.lang.String attrName)
Checks that the StyleInfo knows about the attr name. |
private boolean |
_magicStyleInfoSupport(CssStyleSheetParser.AttrEntry attrEntry,
java.lang.Class componentClass,
nextapp.echo.Style style)
Check with the component class whether it supports the magic StyleInfo If yes it determines if the attrName is okay and the value can be set into a Style for the component class. |
private void |
_processStyleAttribute(CssStyleSheetParser.AttrEntry attrEntry,
java.lang.Class[] classes,
java.lang.Class componentClass,
nextapp.echo.Style style)
Processes a style attribute and make sure it can be set okay |
private void |
_processStyleSheet(java.io.Reader styleSheetReader)
processes style sheet data |
private StyleSheetParseException |
_throwTPE(int lineNo,
java.lang.String message)
internal function to throw a formatted StyleSheetParseException |
void |
addGroup(StyleSheetGroup styleSheetGroup)
Deprecated. StyleSheetGroup has been deprecated and will be removed in the next version of EchoPoint. Use the new attributed identifier on the Component from now on, eg component.setIdentifier("stylegroup=xxx;"); |
void |
addHandler(CssStyleSheetHandler handler)
Adds a CssStyleSheetHandler to the CssStyleSheet. |
void |
applyTo(nextapp.echo.Component c)
This method applies the StyleSheet to the given Component c and all of its children. |
void |
applyTo(nextapp.echo.Component c,
boolean listenForFutureChildren)
This method applies the StyleSheet to the given Component c and all of its children. |
void |
applyTo(nextapp.echo.EchoInstance instance)
This method applies the StyleSheet to the Windows of the given EchoInstance and all of their children. |
void |
applyTo(nextapp.echo.EchoInstance instance,
boolean listenForFutureChildren)
This method applies the StyleSheet to the Windows of the given EchoInstance and all of their children. |
private java.lang.Class[] |
getClassesLeastSpecific(java.lang.Class clazz)
Returns all the derived classes of clazz, including clazz, in least specific order (ie clazz is last). |
private java.lang.Class[] |
getClassesMostSpecific(java.lang.Class clazz)
Returns all the derived classes of clazz, including clazz, in most specific order first (ie clazz is first) |
static CssStyleSheet |
getEmptyInstance()
Returns an empty StyleSheet with no StyleSheetHandlers within it. |
static CssStyleSheet |
getInstance()
Returns a StyleSheet object. |
static CssStyleSheet |
getInstance(java.io.Reader styleSheetReader)
Returns a StyleSheet object by parsing the given Reader style sheet data. |
static CssStyleSheet |
getInstance(java.lang.String styleSheetFileName)
Returns a StyleSheet object by parsing the given style sheet file name. |
static CssStyleSheet |
getInstance(java.net.URL styleSheetURL)
Returns a StyleSheet object by parsing the given URL style sheet data. |
StyleSheetParseException[] |
getParseExceptions()
This method returns an array of StyleSheetParseExceptions that have occurred during parsing. |
boolean |
isExceptionParseFailure()
This returns true if the CssStyleSheet will throw an StyleSheetParseException if it encounters an invalid or unknown attribute. |
boolean |
isParseable()
Returns true if the current CssStyleSheet can be parsed. |
void |
loadStyleSheet(java.io.Reader styleSheetReader)
Loads the CssStyleSheet data contained in the Reader. |
void |
loadStyleSheet(java.lang.String styleSheetFileName)
Loads the CssStyleSheet data contained in the file named "fileName". |
void |
loadStyleSheet(java.net.URL styleSheetURL)
Loads the CssStyleSheet data contained in the URL. |
void |
propertyChange(java.beans.PropertyChangeEvent evt)
This method gets called when a bound property is changed. |
void |
setExceptionParseFailure(boolean newExceptionParseFailure)
This controls whether the CssStyleSheet will throw a StyleSheetParseException if it encounters an invalid or unknown attribute. |
private void |
startListeningTo(nextapp.echo.Component c)
Listens to a Component and all its children |
private void |
startListeningTo(nextapp.echo.EchoInstance instance)
Listens to a Component and all its children |
void |
stopListeningTo(nextapp.echo.Component c)
This stops the CssStyleSheet from listening for CHILDREN_PROPERTY_CHANGED events on the given Component c. |
void |
stopListeningTo(nextapp.echo.EchoInstance instance)
This stops the StyleSheet from listening for EchoInstance.WINDOWS_CHANGED_PROPERTY and Component.CHILDREN_PROPERTY_CHANGED events on the given EchoInstance. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
exceptionList
private java.util.ArrayList exceptionList
failOnInvalidAttributes
private boolean failOnInvalidAttributes
groupList
private java.util.ArrayList groupList
handlerList
private java.util.ArrayList handlerList
hasParsingOccurred
private boolean hasParsingOccurred
idList
private java.util.ArrayList idList
styleMap
private java.util.HashMap styleMap
styleSheetGroupList
private java.util.ArrayList styleSheetGroupList
parseable
private boolean parseable
| Constructor Detail |
CssStyleSheet
private CssStyleSheet()
- CssStyleSheet constructor
| Method Detail |
_applyStyle
private void _applyStyle(nextapp.echo.Component c, CssStyleSheet.StyleEntry entry)
- Tries to apply a style to a component.
SmartStyles are used so that attributes that have not been accessed can still be applied via reflection
It catches any exceptions and rethrows them as StyleSheetInvalidValueException's
_applyStyleSheetRecursively
private void _applyStyleSheetRecursively(nextapp.echo.Component c)
- Recursively applies the StyleSheet to a Component and its chidren
_applyStyleSheetToComponent
private void _applyStyleSheetToComponent(nextapp.echo.Component c)
- Deprecated. StyleSheetGroup has been deprecated and will be removed in the next version
of EchoPoint. Use the new attributed identifier on the Component from now on,
eg component.setIdentifier("stylegroup=xxx;");
- This applyes a style to an Component. It can be via class and/or via StyleSheetGroup and/or via component identifier (if present).
The style application is done in least specific class order. e.g. Component/AbstractButton/Button/PushButton
If any Exceptions are encountered during Style application, such as ClassCastExceptions, then they are caught and rethrown as StyleSheetInvalidValueExceptions
- This applyes a style to an Component. It can be via class and/or via StyleSheetGroup and/or via component identifier (if present).
_findClassFromName
private java.lang.Class _findClassFromName(java.lang.String className) throws java.lang.ClassNotFoundException
- This method finds the Class object for a given name. It also does some simple subsitution
to find inner classe names which must be loaded with the xx.yyy$InnerName syntax.
_findStyleSheetGroup
private StyleSheetGroup _findStyleSheetGroup(java.lang.String name)
- Deprecated. StyleSheetGroup has been deprecated and will be removed in the next version
of EchoPoint. Use the new attributed identifier on the Component from now on,
eg component.setIdentifier("stylegroup=xxx;");
_magicSetStyleAttribute
private boolean _magicSetStyleAttribute(nextapp.echo.Style style, java.lang.Class componentClass, StyleAttrDescriptor descriptor, java.lang.String attrName, java.lang.String attrValue)
- This will try and set a value into a Style if it really is of the given type
valueClass! It returns false if the value cannot be set.
_magicStyleFindDescriptor
private StyleAttrDescriptor _magicStyleFindDescriptor(StyleInfo styleInfo, java.lang.String attrName)
- Checks that the StyleInfo knows about the attr name.
_magicStyleInfoSupport
private boolean _magicStyleInfoSupport(CssStyleSheetParser.AttrEntry attrEntry, java.lang.Class componentClass, nextapp.echo.Style style) throws StyleSheetParseException
- Check with the component class whether it supports the magic StyleInfo
If yes it determines if the attrName is okay and the value
can be set into a Style for the component class. If not it returns false.
_processStyleAttribute
private void _processStyleAttribute(CssStyleSheetParser.AttrEntry attrEntry, java.lang.Class[] classes, java.lang.Class componentClass, nextapp.echo.Style style) throws StyleSheetParseException
- Processes a style attribute and make sure it can be set okay
_processStyleSheet
private void _processStyleSheet(java.io.Reader styleSheetReader) throws StyleSheetParseException
- processes style sheet data
_throwTPE
private StyleSheetParseException _throwTPE(int lineNo, java.lang.String message) throws StyleSheetParseException
- internal function to throw a formatted StyleSheetParseException
_isObjValue
private boolean _isObjValue(java.lang.String attrValue)
- Returns true if a value is in the form obj(...)
_isQuotedValue
private boolean _isQuotedValue(java.lang.String attrValue)
addGroup
public void addGroup(StyleSheetGroup styleSheetGroup)
- Deprecated. StyleSheetGroup has been deprecated and will be removed in the next version
of EchoPoint. Use the new attributed identifier on the Component from now on,
eg component.setIdentifier("stylegroup=xxx;");
- Adds a StyleSheetGroup to the StyleSheet.
- Specified by:
addGroupin interfaceStyleSheet
- Adds a StyleSheetGroup to the StyleSheet.
addHandler
public void addHandler(CssStyleSheetHandler handler)
- Adds a CssStyleSheetHandler to the CssStyleSheet. Ths allows extension of the
known style attribute names and values.
applyTo
public void applyTo(nextapp.echo.Component c)
- Description copied from interface:
StyleSheet - This method applies the StyleSheet to the given Component c and
all of its children.
This method can throw a StyleSheetInvalidValueException if a value of the wrong type is stored in a Style object. The StyleSheet is expected to catch the ClassCastException that might be thrown and then rethrow it as a StyleSheetInvalidValueException.
- Specified by:
applyToin interfaceStyleSheet
applyTo
public void applyTo(nextapp.echo.Component c, boolean listenForFutureChildren)
- Description copied from interface:
StyleSheet - This method applies the StyleSheet to the given Component c and
all of its children.
If listenForFutureChildren is true, then the StyleSheet is expected to listen for Component.CHILDREN_CHANGED_PROPERTY property change events and apply the StyleSheet to any new children.
The can be done by called the Component.addPropertyChangeListener
This method can throw a StyleSheetInvalidValueException if a value of the wrong type is stored in a Style object. The StyleSheet is expected to catch the ClassCastException that might be thrown and then rethrow it as a StyleSheetInvalidValueException.
- Specified by:
applyToin interfaceStyleSheet
applyTo
public void applyTo(nextapp.echo.EchoInstance instance)
- Description copied from interface:
StyleSheet - This method applies the StyleSheet to the Windows of the given EchoInstance
and all of their children.
Be aware when using this function in EchoInstance.init(). Add that stage there are no Windows in the EchoInstance and it does not fire any events once it has finished, and hence the StyleSheet will not be applied. You can get around this issue by applying the StyleSheet to the Window object you must return in EchoInstance.init() as well as the EchoInstance itself. The code might look like this :
public nextapp.echo.Window init() { Window window = new Window(); ... ... try { styleSheet.applyTo(this,true); styleSheet.applyTo(window); } catch (StyleSheetParseException e) { .... } return window; }This method can throw a StyleSheetInvalidValueException if a value of the wrong type is stored in a Style object. The StyleSheet is expected to catch the ClassCastException that might be thrown and then rethrow it as a StyleSheetInvalidValueException.
- Specified by:
applyToin interfaceStyleSheet
applyTo
public void applyTo(nextapp.echo.EchoInstance instance, boolean listenForFutureChildren)
- Description copied from interface:
StyleSheet - This method applies the StyleSheet to the Windows of the given EchoInstance
and all of their children.
If listenForFutureChildren is true, then the StyleSheet is expected to listen for EchoInstance.WINDOWS_CHANGED_PROPERTY and Component.CHILDREN_CHANGED_PROPERTY property change events and apply the StyleSheet to any new children.
Be aware when using this function in EchoInstance.init(). Add that stage there are no Windows in the EchoInstance and it does not fire any events once it has finished, and hence the StyleSheet will not be applied. You can get around this issue by applying the StyleSheet to the Window object you must return in EchoInstance.init() as well as the EchoInstance itself. The code might look like this :
public nextapp.echo.Window init() { Window window = new Window(); ... ... try { styleSheet.applyTo(this,true); styleSheet.applyTo(window); } catch (StyleSheetParseException e) { .... } return window; }This method can throw a StyleSheetInvalidValueException if a value of the wrong type is stored in a Style object. The StyleSheet is expected to catch the ClassCastException that might be thrown and then rethrow it as a StyleSheetInvalidValueException.
- Specified by:
applyToin interfaceStyleSheet
getClassesLeastSpecific
private java.lang.Class[] getClassesLeastSpecific(java.lang.Class clazz)
- Returns all the derived classes of clazz, including clazz, in least
specific order (ie clazz is last).
getClassesMostSpecific
private java.lang.Class[] getClassesMostSpecific(java.lang.Class clazz)
- Returns all the derived classes of clazz, including clazz, in most specific
order first (ie clazz is first)
getParseExceptions
public StyleSheetParseException[] getParseExceptions()
- This method returns an array of StyleSheetParseExceptions that have occurred
during parsing. Note that this will only have more than 1 entries if
setExceptionParseFailure is set to true.
isExceptionParseFailure
public boolean isExceptionParseFailure()
- This returns true if the CssStyleSheet will throw an StyleSheetParseException if it
encounters an invalid or unknown attribute. The default is true.
Note : this only covers the setting of style attributes values, not the general parsing of the style sheet data. A general parse problem will always throw a StyleSheetParseException.
loadStyleSheet
public void loadStyleSheet(java.io.Reader styleSheetReader) throws StyleSheetParseException
- Loads the CssStyleSheet data contained in the Reader.
- Specified by:
loadStyleSheetin interfaceStyleSheet
loadStyleSheet
public void loadStyleSheet(java.lang.String styleSheetFileName) throws StyleSheetParseException
- Loads the CssStyleSheet data contained in the file named "fileName".
loadStyleSheet
public void loadStyleSheet(java.net.URL styleSheetURL) throws StyleSheetParseException
- Loads the CssStyleSheet data contained in the URL.
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent evt)
- This method gets called when a bound property is changed.
The CssStyleSheet class will listen for Component.CHILDREN_CHANGED_PROPERTY and EchoInstance.WINDOWS_CHANGED_PROPERTY events and will then apply any applicable Styles to the new Component and its children, or conversely, stop listening if the child is being removed.
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
setExceptionParseFailure
public void setExceptionParseFailure(boolean newExceptionParseFailure)
- This controls whether the CssStyleSheet will throw a StyleSheetParseException if it
encounters an invalid or unknown attribute.
Note : this only covers the setting of style attributes values, not the general parsing of the style sheet data. A general parse problem will always throw a StyleSheetParseException.
startListeningTo
private void startListeningTo(nextapp.echo.Component c)
- Listens to a Component and all its children
startListeningTo
private void startListeningTo(nextapp.echo.EchoInstance instance)
- Listens to a Component and all its children
stopListeningTo
public void stopListeningTo(nextapp.echo.Component c)
- This stops the CssStyleSheet from listening for CHILDREN_PROPERTY_CHANGED events
on the given Component c.
- Specified by:
stopListeningToin interfaceStyleSheet
stopListeningTo
public void stopListeningTo(nextapp.echo.EchoInstance instance)
- Description copied from interface:
StyleSheet - This stops the StyleSheet from listening for EchoInstance.WINDOWS_CHANGED_PROPERTY
and Component.CHILDREN_PROPERTY_CHANGED events on the given EchoInstance.
- Specified by:
stopListeningToin interfaceStyleSheet
getEmptyInstance
public static CssStyleSheet getEmptyInstance()
- Returns an empty StyleSheet with no StyleSheetHandlers within it.
The returned object implements StyleSheet and is an instance of CssStyleSheet.
Using this form allows the developer to change the StyleSheetHandlers used and/or the order in which they are applied.
getInstance
public static CssStyleSheet getInstance()
- Returns a StyleSheet object.
The returned object implements StyleSheet and is an instance of CssStyleSheet.
getInstance
public static CssStyleSheet getInstance(java.io.Reader styleSheetReader) throws StyleSheetParseException
- Returns a StyleSheet object by parsing the given Reader style sheet data.
The returned object implements StyleSheet and is an instance of CssStyleSheet.
getInstance
public static CssStyleSheet getInstance(java.lang.String styleSheetFileName) throws StyleSheetParseException
- Returns a StyleSheet object by parsing the given style sheet file name.
The returned object implements StyleSheet and is an instance of CssStyleSheet.
getInstance
public static CssStyleSheet getInstance(java.net.URL styleSheetURL) throws StyleSheetParseException
- Returns a StyleSheet object by parsing the given URL style sheet data.
The returned object implements StyleSheet and is an instance of CssStyleSheet.
isParseable
public boolean isParseable()
- Returns true if the current CssStyleSheet can be parsed. This
does not mean that it is perfectly valid, since the application
of the generated Style objects may still pose problems. But it
does mean that the CssStyleSheet has validated style attribute
name and values as best it can.
|
|||||||||
| Home >> All >> echopoint >> [ stylesheet overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
echopoint.stylesheet.CssStyleSheet