Beispiel #1
0
  /**
   * @param source
   * @param target
   */
  public static void copyAttributes(Element source, Element target) {
    for (String key : source.getAttributeKeySet()) {
      Object value = source.getAttribute(key);
      value = checkedArrayOrCollectionCopy(value);

      target.setAttribute(key, value);
    }
  }
Beispiel #2
0
 protected void removeElementFromReverseSearch(Element element) {
   if (element instanceof Node) {
     byNodeIdGroups.remove(element.getId());
   } else if (element instanceof Edge) {
     byEdgeIdGroups.remove(element.getId());
   } else if (element instanceof GraphicSprite) {
     bySpriteIdGroups.remove(element.getId());
   } else if (element instanceof Graph) {
     byGraphIdGroups.remove(element.getId());
   } else {
     throw new RuntimeException("What ?");
   }
 }
Beispiel #3
0
 protected void addElementToReverseSearch(Element element, String groupId) {
   if (element instanceof Node) {
     byNodeIdGroups.put(element.getId(), groupId);
   } else if (element instanceof Edge) {
     byEdgeIdGroups.put(element.getId(), groupId);
   } else if (element instanceof GraphicSprite) {
     bySpriteIdGroups.put(element.getId(), groupId);
   } else if (element instanceof Graph) {
     byGraphIdGroups.put(element.getId(), groupId);
   } else {
     throw new RuntimeException("What ?");
   }
 }
Beispiel #4
0
 /**
  * Retrieve the group identifier of an element knowing the element identifier.
  *
  * @param element The element to search for.
  * @return Identifier of the group containing the element.
  */
 public String getElementGroup(Element element) {
   if (element instanceof Node) {
     return byNodeIdGroups.get(element.getId());
   } else if (element instanceof Edge) {
     return byEdgeIdGroups.get(element.getId());
   } else if (element instanceof GraphicSprite) {
     return bySpriteIdGroups.get(element.getId());
   } else if (element instanceof Graph) {
     return byGraphIdGroups.get(element.getId());
   } else {
     throw new RuntimeException("What ?");
   }
 }
Beispiel #5
0
    /**
     * Search if the given element has classes attributes and fill the given array with the set of
     * rules that match these classes.
     *
     * @param element The element for which classes must be found.
     * @param rules The rule array to fill.
     */
    protected void getClassRules(Element element, ArrayList<Rule> rules) {
      Object o = element.getAttribute("ui.class");

      if (o != null) {
        if (o instanceof Object[]) {
          for (Object s : (Object[]) o) {
            if (s instanceof CharSequence) {
              Rule rule = byClass.get((CharSequence) s);

              if (rule != null) rules.add(rule);
            }
          }
        } else if (o instanceof CharSequence) {
          String classList = ((CharSequence) o).toString().trim();
          String[] classes = classList.split("\\s*,\\s*");

          for (String c : classes) {
            Rule rule = byClass.get(c);

            if (rule != null) rules.add(rule);
          }
        } else {
          throw new RuntimeException("Oups ! class attribute is of type " + o.getClass().getName());
        }
      }
    }
Beispiel #6
0
    /**
     * Get the rules that match a given element. The rules are returned in a given order. The array
     * always contain the "main" rule that matches the element. This rule is either a default rule
     * for the kind of element given or the rule that matches its identifier if there is one. Then
     * class rules the element has can be appended to this array in order.
     *
     * @return an array of rules that match the element, with the main rule at index 0.
     */
    protected ArrayList<Rule> getRulesFor(Element element) {
      Rule rule = byId.get(element.getId());
      ArrayList<Rule> rules = new ArrayList<Rule>();

      if (rule != null) rules.add(rule);
      else rules.add(defaultRule);

      getClassRules(element, rules);

      if (rules.isEmpty()) rules.add(defaultRule);

      return rules;
    }
Beispiel #7
0
    public boolean isAvailable(Element e) {
      if (e instanceof Edge) return e.getId().matches(edgePattern);

      return e.getId().matches(nodePattern);
    }