|
EchoPoint 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object echopoint.stylesheet.CssStyleSheet
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 :
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.
StyleSheetIntrospector
,
StyleInfo
,
SmartStyle
,
IdKit
,
Serialized FormMethod Summary | |
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. |
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. |
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 |
Method Detail |
public void addGroup(StyleSheetGroup styleSheetGroup)
addGroup
in interface StyleSheet
styleSheetGroup
- - the stylesheet group to addpublic void addHandler(CssStyleSheetHandler handler)
public void applyTo(nextapp.echo.Component c)
StyleSheet
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.
applyTo
in interface StyleSheet
c
- - the component to apply the style sheet toStyleSheet.applyTo(nextapp.echo.Component)
public void applyTo(nextapp.echo.Component c, boolean listenForFutureChildren)
StyleSheet
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.
applyTo
in interface StyleSheet
c
- - the component to apply the style sheet tolistenForFutureChildren
- - whether to listen for future childrenStyleSheet.applyTo(nextapp.echo.Component, boolean)
public void applyTo(nextapp.echo.EchoInstance instance)
StyleSheet
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.
applyTo
in interface StyleSheet
instance
- - the EchoInstance to apply the style sheet toStyleSheet.applyTo(nextapp.echo.EchoInstance)
public void applyTo(nextapp.echo.EchoInstance instance, boolean listenForFutureChildren)
StyleSheet
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.
applyTo
in interface StyleSheet
instance
- - the EchoInstance to apply the style sheet tolistenForFutureChildren
- - whether to listen for future childrenStyleSheet.applyTo(nextapp.echo.EchoInstance, boolean)
public StyleSheetParseException[] getParseExceptions()
public boolean isExceptionParseFailure()
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.
public void loadStyleSheet(java.io.Reader styleSheetReader) throws StyleSheetParseException
loadStyleSheet
in interface StyleSheet
styleSheetReader
- - the Reader containg style sheet information
StyleSheetParseException
- - if the data cannot be parsedpublic void loadStyleSheet(java.lang.String styleSheetFileName) throws StyleSheetParseException
StyleSheetParseException
- - if the file cannot be parsedpublic void loadStyleSheet(java.net.URL styleSheetURL) throws StyleSheetParseException
StyleSheetParseException
- - if the data cannot be parsedpublic void propertyChange(java.beans.PropertyChangeEvent evt)
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.
propertyChange
in interface java.beans.PropertyChangeListener
evt
- A PropertyChangeEvent object describing the event source
and the property that has changed.public void setExceptionParseFailure(boolean newExceptionParseFailure)
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.
newExceptionParseFailure
- booleanpublic void stopListeningTo(nextapp.echo.Component c)
stopListeningTo
in interface StyleSheet
c
- - the component to stop listening for children onpublic void stopListeningTo(nextapp.echo.EchoInstance instance)
StyleSheet
stopListeningTo
in interface StyleSheet
instance
- - the EchoINstance to stop listening for children onStyleSheet.stopListeningTo(nextapp.echo.EchoInstance)
public static CssStyleSheet getEmptyInstance()
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.
public static CssStyleSheet getInstance()
The returned object implements StyleSheet and is an instance of CssStyleSheet.
public static CssStyleSheet getInstance(java.io.Reader styleSheetReader) throws StyleSheetParseException
The returned object implements StyleSheet and is an instance of CssStyleSheet.
StyleSheetParseException
public static CssStyleSheet getInstance(java.lang.String styleSheetFileName) throws StyleSheetParseException
The returned object implements StyleSheet and is an instance of CssStyleSheet.
StyleSheetParseException
public static CssStyleSheet getInstance(java.net.URL styleSheetURL) throws StyleSheetParseException
The returned object implements StyleSheet and is an instance of CssStyleSheet.
StyleSheetParseException
public boolean isParseable()
|
EchoPoint 1.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |