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
  • Field Details

  • Constructor Details

    • StyleSheet

      public StyleSheet()
      New style sheet initialised to defaults.
  • Method Details

    • getDefaultGraphRule

      public Rule getDefaultGraphRule()
      The default rule for graphs.
      Returns:
      A rule.
    • getDefaultNodeRule

      public Rule getDefaultNodeRule()
      The default rule for nodes.
      Returns:
      A rule.
    • getDefaultEdgeRule

      public Rule getDefaultEdgeRule()
      The default rule for edges.
      Returns:
      A rule.
    • getDefaultSpriteRule

      public Rule getDefaultSpriteRule()
      The default rule for sprites.
      Returns:
      A rule.
    • getDefaultGraphStyle

      public Style getDefaultGraphStyle()
      The default style for graphs.
      Returns:
      A style.
    • getDefaultNodeStyle

      public Style getDefaultNodeStyle()
      The default style for nodes.
      Returns:
      A style.
    • getDefaultEdgeStyle

      public Style getDefaultEdgeStyle()
      The default style for edges.
      Returns:
      A style.
    • getDefaultSpriteStyle

      public Style getDefaultSpriteStyle()
      The default style for sprites.
      Returns:
      A style.
    • getGraphStyleNameSpace

      public StyleSheet.NameSpace getGraphStyleNameSpace()
      All the rules (default, specific and class) that apply to graphs.
      Returns:
      The set of rules for graphs.
    • getNodeStyleNameSpace

      public StyleSheet.NameSpace getNodeStyleNameSpace()
      All the rules (default, specific and class) that apply to nodes.
      Returns:
      The set of rules for nodes.
    • getEdgeStyleNameSpace

      public StyleSheet.NameSpace getEdgeStyleNameSpace()
      All the rules (default, specific and class) that apply to edges.
      Returns:
      The set of rules for edges.
    • getSpriteStyleNameSpace

      public StyleSheet.NameSpace getSpriteStyleNameSpace()
      All the rules (default, specific and class) that apply to sprites.
      Returns:
      The set of rules for sprites.
    • getRulesFor

      public ArrayList<Rule> getRulesFor​(Element element)
      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

      public String getStyleGroupIdFor​(Element element, ArrayList<Rule> rules)
      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

      public void addListener​(StyleSheetListener listener)
      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

      public void removeListener​(StyleSheetListener listener)
      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

      public void parseFromFile​(String fileName) throws IOException
      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

      public void parseFromURL​(String url) throws IOException
      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

      public void parseFromString​(String styleSheet) throws IOException
      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

      public void parseStyleFromString​(Selector select, String styleString) throws IOException
      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

      public void load​(String styleSheetValue) throws IOException
      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')
       
      Or
                      url('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

      public void addRule​(Rule newRule)
      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

      public String toString()
      Overrides:
      toString in class Object