Exemplo n.º 1
0
  /**
   * 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.
   *
   * @param newRule The new rule.
   */
  public void addRule(Rule newRule) {
    Rule oldRule = null;

    switch (newRule.selector.getType()) {
      case ANY:
        throw new RuntimeException(
            "The ANY selector should never be used, it is created automatically.");
      case GRAPH:
        oldRule = graphRules.addRule(newRule);
        break;
      case NODE:
        oldRule = nodeRules.addRule(newRule);
        break;
      case EDGE:
        oldRule = edgeRules.addRule(newRule);
        break;
      case SPRITE:
        oldRule = spriteRules.addRule(newRule);
        break;
      default:
        throw new RuntimeException("Ho ho ho ?");
    }

    for (StyleSheetListener listener : listeners) listener.styleAdded(oldRule, newRule);
  }
Exemplo n.º 2
0
  /** Clear all specific rules and initialise the default rules. The listeners are not changed. */
  public void clear() {
    graphRules.clear();
    nodeRules.clear();
    edgeRules.clear();
    spriteRules.clear();
    initRules();

    for (StyleSheetListener listener : listeners) listener.styleSheetCleared();
  }
Exemplo n.º 3
0
  /**
   * Create the default rules. This method is the place to set defaults for specific element types.
   * This is here that the edge width is reset to one, since the default width is larger. The
   * default z index that is different for every class of element is also set here.
   */
  protected void initRules() {
    defaultRule = new Rule(new Selector(Selector.Type.ANY), null);

    defaultRule.getStyle().setDefaults();

    graphRules.defaultRule = new Rule(new Selector(Selector.Type.GRAPH), defaultRule);
    nodeRules.defaultRule = new Rule(new Selector(Selector.Type.NODE), defaultRule);
    edgeRules.defaultRule = new Rule(new Selector(Selector.Type.EDGE), defaultRule);
    spriteRules.defaultRule = new Rule(new Selector(Selector.Type.SPRITE), defaultRule);

    graphRules.defaultRule.getStyle().setValue("padding", new Values(Style.Units.PX, 30));
    edgeRules.defaultRule.getStyle().setValue("shape", StyleConstants.Shape.LINE);
    edgeRules.defaultRule.getStyle().setValue("size", new Values(Style.Units.PX, 1));
    edgeRules.defaultRule.getStyle().setValue("z-index", new Integer(1));
    nodeRules.defaultRule.getStyle().setValue("z-index", new Integer(2));
    spriteRules.defaultRule.getStyle().setValue("z-index", new Integer(3));

    Colors colors = new Colors();
    colors.add(Color.WHITE);

    graphRules.defaultRule.getStyle().setValue("fill-color", colors);
    graphRules.defaultRule.getStyle().setValue("stroke-mode", StrokeMode.NONE);

    for (StyleSheetListener listener : listeners) {
      listener.styleAdded(defaultRule, defaultRule);
      listener.styleAdded(graphRules.defaultRule, graphRules.defaultRule);
      listener.styleAdded(nodeRules.defaultRule, nodeRules.defaultRule);
      listener.styleAdded(edgeRules.defaultRule, edgeRules.defaultRule);
      listener.styleAdded(spriteRules.defaultRule, spriteRules.defaultRule);
    }

    // for( StyleSheetListener listener: listeners )
    // listener.styleAdded( defaultRule, defaultRule );
    // for( StyleSheetListener listener: listeners )
    // listener.styleAdded( graphRules.defaultRule, graphRules.defaultRule
    // );
    // for( StyleSheetListener listener: listeners )
    // listener.styleAdded( nodeRules.defaultRule, nodeRules.defaultRule );
    // for( StyleSheetListener listener: listeners )
    // listener.styleAdded( edgeRules.defaultRule, edgeRules.defaultRule );
    // for( StyleSheetListener listener: listeners )
    // listener.styleAdded( spriteRules.defaultRule, spriteRules.defaultRule
    // );
  }