コード例 #1
0
  private Style createStyle(Style baseStyle, Style extendStyle) {
    if (baseStyle != null && extendStyle != null) {
      if (baseStyle.name.equals(extendStyle.name)) {
        return baseStyle;
      }
    }

    // #debug sl.debug.style
    System.out.println("extending style " + baseStyle.name + " with style " + extendStyle.name);

    Style result = new Style(baseStyle);

    result.name = baseStyle.name + "." + extendStyle.name;

    if (extendStyle.layout != Item.LAYOUT_DEFAULT) {
      result.layout = extendStyle.layout;
    }

    if (extendStyle.border != null) {
      result.border = extendStyle.border;
    }

    if (extendStyle.background != null) {
      result.background = extendStyle.background;
    }

    Style baseFocusedStyle = (Style) baseStyle.getObjectProperty("focused-style");
    short[] keys = extendStyle.getRawAttributeKeys();

    if (keys != null) {
      for (int i = 0; i < keys.length; i++) {
        short key = keys[i];
        Object value = extendStyle.getObjectProperty(key);

        if (key == FOCUSED_STYLE_KEY && baseFocusedStyle != null && value != null) {
          Style extendFocusedStyle = (Style) value;
          Style resultFocusedStyle = createStyle(baseFocusedStyle, extendFocusedStyle);
          result.addAttribute(key, resultFocusedStyle);
        } else {
          if (value != null) {
            result.addAttribute(key, value);
          }
        }
      }
    }

    return result;
  }
コード例 #2
0
  private Style createTextStyle(Style baseStyle, Style extendStyle) {
    if (baseStyle != null && extendStyle != null) {
      if (baseStyle.name.equals(extendStyle.name)) {
        return baseStyle;
      }
    }

    // #mdebug sl.debug.style
    if (baseStyle != null) {
      System.out.println("creating text style : " + baseStyle.name + " / " + extendStyle.name);
    } else {
      System.out.println("creating text style from " + extendStyle.name);
    }
    // #enddebug

    Style resultStyle = new Style(defaultTextStyle);

    // get the attributes to extend the style
    /*String x = extendStyle.getProperty("float");
    String y = extendStyle.getProperty("display");*/
    Color extendFontColor = extendStyle.getColorProperty("font-color");
    Integer extendFontStyle = extendStyle.getIntProperty("font-style");
    Integer extendFontSize = extendStyle.getIntProperty("font-size");
    Style extendFocusedStyle = getFocusedStyle(extendStyle);

    /*
    extendFontSize = extendStyle.getIntProperty("margin-left");
    extendFontSize = extendStyle.getIntProperty("margin-right");
    extendFontSize = extendStyle.getIntProperty("margin-top");
    extendFontSize = extendStyle.getIntProperty("margin-bottom");

    extendFontSize = extendStyle.getIntProperty("padding-left");
    extendFontSize = extendStyle.getIntProperty("padding-right");
    extendFontSize = extendStyle.getIntProperty("padding-top");
    extendFontSize = extendStyle.getIntProperty("padding-bottom"); */

    // if a base style is given ...
    if (baseStyle == null) {
      resultStyle.name = extendStyle.name;
      resultStyle.addAttribute("font-color", extendFontColor);
      resultStyle.addAttribute("font-style", extendFontStyle);
      resultStyle.addAttribute("font-size", extendFontSize);
      resultStyle.addAttribute("focused-style", extendFocusedStyle);
    } else {
      // get default size and color from text style
      Integer defaultFontSize = resultStyle.getIntProperty("font-size");
      Color defaultFontColor = resultStyle.getColorProperty("font-color");

      // get font attributes from the base style
      Color baseFontColor = baseStyle.getColorProperty("font-color");
      Integer baseFontStyle = baseStyle.getIntProperty("font-style");
      Integer baseFontSize = baseStyle.getIntProperty("font-size");

      Color resultTextColor = (Color) extendValue(baseFontColor, extendFontColor, defaultFontColor);
      Integer resultTextStyle = extendFlag(baseFontStyle, extendFontStyle);
      Integer resultTextSize = (Integer) extendValue(baseFontSize, extendFontSize, defaultFontSize);

      Style baseFocusedStyle = getFocusedStyle(baseStyle);

      // add the resulting attributes to the text style
      resultStyle.name = baseStyle.name + "." + extendStyle.name;
      resultStyle.addAttribute("font-color", resultTextColor);
      resultStyle.addAttribute("font-style", resultTextStyle);
      resultStyle.addAttribute("font-size", resultTextSize);

      // extend the focused style
      if (extendFocusedStyle != null) {
        Style resultFocusedStyle = createTextStyle(baseFocusedStyle, extendFocusedStyle);
        resultStyle.addAttribute("focused-style", resultFocusedStyle);
      }
    }
    return resultStyle;
  }