public class IlvSDMMutableStyleSheet extends IlvMutableStyleSheet
IlvSDMMutableStyleSheet styleSheet = new IlvSDMMutableStyleSheet(engine); ... engine.setStyleSheets(new String[] { styleSheet.toString() }); ... styleSheet.setDeclaration(selector, property, value); ... styleSheet.removeDeclaration(selector, property); ... styleSheet.removeRule(selector); ...In order to visit the entire contents of the style sheet, you need to iterate first over the rule selectors and then over the declared properties, for example:
IlvSDMMutableStyleSheet styleSheet = ... ... Iterator iterator1 = styleSheet.getRuleSelectors(); while (iterator1.hasNext()) { String selector = (String)iterator1.next(); Iterator iterator2 = styleSheet.getDeclaredProperties(selector); while (iterator2.hasNext()) { String property = (String)iterator2.next(); String value = styleSheet.getDeclaration(selector, property); ... } }Limitations: If
isRecreateOnPropertyChange()
returns false
, it
is not possible to change the SDM rule of the style sheet after
the style sheet was passed to the engine. The SDM rule of the style
sheet is the one with the selector "SDM"
.
If isRecreateOnPropertyChange()
returns true, this limitation does
not apply.
This limitation holds only for the SDM rule.
For example, the following code does not work:
IlvSDMMutableStyleSheet styleSheet = new IlvSDMMutableStyleSheet(engine); styleSheet.setRecreateOnPropertyChange(false); // This works because it is BEFORE installing the style sheet: styleSheet.setDeclaration("SDM", "GraphLayout", "false"); // This installs the style sheet engine.setStyleSheets(new String[] { styleSheet.toString() }); // This does not work because it is AFTER installing the style sheet: styleSheet.setDeclaration("SDM", "GraphLayout", "true"); // This works because it is not the SDM rule styleSheet.setDeclaration("GraphLayout", "enabled", "true"); ...Apart from the
isRecreateOnPropertyChange()
limitation, it is always
possible to change any other rule of the style sheet.
In practice, it is useful to install two style sheets: a static style sheet containing the SDM rule and all rules that do not change dynamically, and a mutable style sheet containing the other dynamic rules. For example:
IlvSDMMutableStyleSheet dynamicStyleSheet = new IlvSDMMutableStyleSheet(engine); engine.setStyleSheet(new URL("file:staticStyleSheet.css")); engine.setStyleSheets(1, dynamicStyleSheet.toString()); ... dynamicStyleSheet.setDeclaration(selector, property, value); ...
IlvSDMEngine.setStyleSheets(java.lang.String[])
Constructor and Description |
---|
IlvSDMMutableStyleSheet(IlvSDMEngine engine)
Creates a new mutable style sheet.
|
IlvSDMMutableStyleSheet(IlvSDMEngine engine,
boolean update,
boolean recreate)
Creates a new mutable style sheet.
|
Modifier and Type | Method and Description |
---|---|
boolean |
isRecreateOnPropertyChange()
Returns
true if graphic objects are re-created when the
contents of this style sheet change. |
boolean |
isUpdateOnPropertyChange()
Returns
true if graphic objects are updated when the
contents of this style sheet change. |
protected void |
propertyChanged()
Notifies the SDM engine that the style sheet has changed.
|
void |
setRecreateOnPropertyChange(boolean flag)
Enables or disables whether graphic objects are re-created when the
contents of this style sheet change.
|
void |
setUpdateOnPropertyChange(boolean flag)
Enables or disables whether graphic objects are updated when the
contents of this style sheet changes.
|
containsDeclaration, containsRule, getDeclaration, getDeclaredProperties, getRuleSelectors, getStylable, getUpdatedStyleSheets, isAdjusting, readStyleSheet, readStyleSheet, readStyleSheet, readStyleSheet, removeAllRules, removeDeclaration, removeRule, setAdjusting, setDeclaration, toString
public IlvSDMMutableStyleSheet(IlvSDMEngine engine)
public IlvSDMMutableStyleSheet(IlvSDMEngine engine, boolean update, boolean recreate)
engine
- The engine that should use this style sheet.update
- If true
, the graphic objects representing
the current SDM data model are updated whenever the contents
of this mutable style sheet change.
Otherwise, the graphic objects are not updated. They can be
updated later by calling IlvSDMEngine.loadData()
or
IlvSDMEngine.customizeAllObjects()
.recreate
- This parameter only has an effect if the
update
parameter is true
.
If recreate
is also true
, all the graphic
objects and the SDM renderers are re-created according to the
new style sheets whenever the contents of this mutable style
sheet change.
Otherwise, the graphic objects and the SDM renderers are not
re-created. Instead, their properties are set according to the
new style sheets.public void setUpdateOnPropertyChange(boolean flag)
true
is passed, the graphic objects representing
the current SDM data model are updated whenever the contents
of this mutable style sheet change.
Otherwise, the graphic objects are not updated. They can be
updated later by calling IlvSDMEngine.loadData()
or
IlvSDMEngine.customizeAllObjects()
.
isUpdateOnPropertyChange()
public boolean isUpdateOnPropertyChange()
true
if graphic objects are updated when the
contents of this style sheet change.
setUpdateOnPropertyChange(boolean)
public void setRecreateOnPropertyChange(boolean flag)
isUpdateOnPropertyChange()
is
true
.
If true
is passed, all the graphic objects and the SDM
renderers are re-created whenever the contents of this mutable style
sheet change.
Otherwise, the graphic objects and the SDM renderers are not
re-created. Instead, their properties are set according to the
new style sheets.
isRecreateOnPropertyChange()
public boolean isRecreateOnPropertyChange()
true
if graphic objects are re-created when the
contents of this style sheet change.
setRecreateOnPropertyChange(boolean)
protected void propertyChanged()
propertyChanged
in class IlvMutableStyleSheet
© Copyright Rogue Wave Software, Inc. 1997, 2018. All Rights Reserved.