Class StyleSheet
java.lang.Object
org.graphstream.ui.graphicGraph.stylesheet.StyleSheet
public class StyleSheet extends Object
Implementation of the style sheets that can be stored in the graphic graph.
- Author:
- Antoine Dutot
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classStyleSheet.NameSpaceA name space is a tuple (default rule, id rule set, class rule set). -
Field Summary
Fields Modifier and Type Field Description RuledefaultRuleThe top-level default rule.StyleSheet.NameSpaceedgeRulesThe default, id and class rules for edges.StyleSheet.NameSpacegraphRulesThe default, id and class rules for graphs.ArrayList<StyleSheetListener>listenersSet of listeners.StyleSheet.NameSpacenodeRulesThe default, id and class rules for nodes.StyleSheet.NameSpacespriteRulesThe default, id and class rules for sprites. -
Constructor Summary
Constructors Constructor Description StyleSheet()New style sheet initialised to defaults. -
Method Summary
Modifier and Type Method Description voidaddListener(StyleSheetListener listener)Add a listener for style events.voidaddRule(Rule newRule)Add a new rule with its style.voidclear()Clear all specific rules and initialise the default rules.RulegetDefaultEdgeRule()The default rule for edges.StylegetDefaultEdgeStyle()The default style for edges.RulegetDefaultGraphRule()The default rule for graphs.StylegetDefaultGraphStyle()The default style for graphs.RulegetDefaultNodeRule()The default rule for nodes.StylegetDefaultNodeStyle()The default style for nodes.RulegetDefaultSpriteRule()The default rule for sprites.StylegetDefaultSpriteStyle()The default style for sprites.StyleSheet.NameSpacegetEdgeStyleNameSpace()All the rules (default, specific and class) that apply to edges.StyleSheet.NameSpacegetGraphStyleNameSpace()All the rules (default, specific and class) that apply to graphs.StyleSheet.NameSpacegetNodeStyleNameSpace()All the rules (default, specific and class) that apply to nodes.ArrayList<Rule>getRulesFor(Element element)Get the rules that match a given element.StyleSheet.NameSpacegetSpriteStyleNameSpace()All the rules (default, specific and class) that apply to sprites.StringgetStyleGroupIdFor(Element element, ArrayList<Rule> rules)Compute the name of the style group and element will pertain to knowing its styling rules.voidload(String styleSheetValue)Load a style sheet from an attribute value, the value can either be the contents of the whole style sheet, or begin by "url".voidparseFromFile(String fileName)Parse a style sheet from a file.voidparseFromString(String styleSheet)Parse a style sheet from a string.voidparseFromURL(String url)Parse a style sheet from an URL.voidparseStyleFromString(Selector select, String styleString)Parse only one style, create a rule with the given selector, and add this rule.voidremoveListener(StyleSheetListener listener)Remove a previously registered listener.StringtoString()
-
Field Details
-
defaultRule
The top-level default rule. -
graphRules
The default, id and class rules for graphs. -
nodeRules
The default, id and class rules for nodes. -
edgeRules
The default, id and class rules for edges. -
spriteRules
The default, id and class rules for sprites. -
listeners
Set of listeners.
-
-
Constructor Details
-
StyleSheet
public StyleSheet()New style sheet initialised to defaults.
-
-
Method Details
-
getDefaultGraphRule
The default rule for graphs.- Returns:
- A rule.
-
getDefaultNodeRule
The default rule for nodes.- Returns:
- A rule.
-
getDefaultEdgeRule
The default rule for edges.- Returns:
- A rule.
-
getDefaultSpriteRule
The default rule for sprites.- Returns:
- A rule.
-
getDefaultGraphStyle
The default style for graphs.- Returns:
- A style.
-
getDefaultNodeStyle
The default style for nodes.- Returns:
- A style.
-
getDefaultEdgeStyle
The default style for edges.- Returns:
- A style.
-
getDefaultSpriteStyle
The default style for sprites.- Returns:
- A style.
-
getGraphStyleNameSpace
All the rules (default, specific and class) that apply to graphs.- Returns:
- The set of rules for graphs.
-
getNodeStyleNameSpace
All the rules (default, specific and class) that apply to nodes.- Returns:
- The set of rules for nodes.
-
getEdgeStyleNameSpace
All the rules (default, specific and class) that apply to edges.- Returns:
- The set of rules for edges.
-
getSpriteStyleNameSpace
All the rules (default, specific and class) that apply to sprites.- Returns:
- The set of rules for sprites.
-
getRulesFor
Get the rules that match a given element. First a rule for the identifier of the element is looked for. It is looked for in its name space (nodes for Node element, etc.) If it is not found, the default rule for this kind of element is used. This rule is pushed at start of the returned array of rules. After a rule for the element is found, then the various classes the element pertains to are looked at and each class rule found is added in order in the returned array.- Parameters:
element- The element a rules are searched for.- Returns:
- A set of rules matching the element, with the main rule at index 0.
-
getStyleGroupIdFor
Compute the name of the style group and element will pertain to knowing its styling rules.- Parameters:
element- The element.rules- The styling rules.- Returns:
- The unique identifier of the style group for the element.
- See Also:
getRulesFor(Element)
-
addListener
Add a listener for style events. You never receive events for default rules and styles. You receive events only for the rules and styles that are added after this listener is registered.- Parameters:
listener- The new listener.
-
removeListener
Remove a previously registered listener.- Parameters:
listener- The listener to remove.
-
clear
public void clear()Clear all specific rules and initialise the default rules. The listeners are not changed. -
parseFromFile
Parse a style sheet from a file. The style sheet will complete the previously parsed style sheets.- Parameters:
fileName- Name of the file containing the style sheet.- Throws:
IOException- For any kind of I/O error or parse error.
-
parseFromURL
Parse a style sheet from an URL. The style sheet will complete the previously parsed style sheets. First, this method will search the URL as SystemRessource, then as a file and if there is no match, just try to create an URL object giving the URL as constructor's parameter.- Parameters:
url- Name of the file containing the style sheet.- Throws:
IOException- For any kind of I/O error or parse error.
-
parseFromString
Parse a style sheet from a string. The style sheet will complete the previously parsed style sheets.- Parameters:
styleSheet- The string containing the whole style sheet.- Throws:
IOException- For any kind of I/O error or parse error.
-
parseStyleFromString
Parse only one style, create a rule with the given selector, and add this rule.- Parameters:
select- The elements for which this style must apply.styleString- The style string to parse.- Throws:
IOException
-
load
Load a style sheet from an attribute value, the value can either be the contents of the whole style sheet, or begin by "url". If it starts with "url", it must then contain between parenthesis the string of the URL to load. For example:url('file:///some/path/on/the/file/system')Orurl('http://some/web/url')The loaded style sheet will be merged with the styles already present in the style sheet.- Parameters:
styleSheetValue- The style sheet name of content.- Throws:
IOException- If the loading or parsing of the style sheet failed.
-
addRule
Add a new rule with its style. If the rule selector is just GRAPH, NODE, EDGE or SPRITE, the default corresponding rules make a copy (or augmentation) of its style. Else if an id or class is specified the rules are added (or changed/augmented if the id or class was already set) and their parent is set to the default graph, node, edge or sprite rules. If this is an event rule (or meta-class rule), its sibling rule (the same rule without the meta-class) is searched and created if not found and the event rule is added as an alternative to it.- Parameters:
newRule- The new rule.
-
toString
-