private String formatRGB(RGB rgb) {
    if (rgb == null) {
      return NONE_CHOICE;
    }

    String value = ColorUtil.getPredefinedColor(DEUtil.getRGBInt(rgb));
    if (value != null && combo != null) {
      String items[] = combo.getItems();
      for (int i = 0; i < items.length; i++) {
        if (items[i].equalsIgnoreCase(value)) {
          return items[i];
        }
      }
    }

    return ColorUtil.format(
        ColorUtil.formRGB(rgb.red, rgb.green, rgb.blue), ColorUtil.CSS_ABSOLUTE_FORMAT);
  }
  public void setColorValue(String value) {
    predefinedColor = null;
    if (choiceSet != null) {
      IChoice choice = choiceSet.findChoice(value);
      if (choice != null) {
        predefinedColor = choice.getDisplayName();
      }
    }

    int[] rgbValues = ColorUtil.getRGBs(value);
    if (rgbValues == null) {
      setRGB(null);
    } else {
      setRGB(new RGB(rgbValues[0], rgbValues[1], rgbValues[2]));
    }
  }
  /**
   * Parses the input string to a GRB object.
   *
   * @param string The input string.
   * @return The RGB object represented the string.
   */
  protected RGB parseString(String string) {
    int colors[] = ColorUtil.getRGBs(string);
    if (colors != null) return new RGB(colors[0], colors[1], colors[2]);

    StringTokenizer st = new StringTokenizer(string, " ,()"); // $NON-NLS-1$
    if (!st.hasMoreTokens()) return null;
    int[] rgb = new int[] {0, 0, 0};
    int index = 0;
    while (st.hasMoreTokens()) {
      try {
        rgb[index] = Integer.decode(st.nextToken()).intValue();
        if (rgb[index] < 0 || rgb[index] > 255) return null;
        index++;
      } catch (Exception e) {
        return null;
      }
    }
    return new RGB(rgb[0], rgb[1], rgb[2]);
  }
Ejemplo n.º 4
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.birt.report.model.api.extension.IStyleDeclaration#getProperty(java.lang.String)
   */
  public Object getProperty(String name) {
    if (name != null) {
      if (name.equals(Style.NAME_PROP)) {
        return styleName;
      }
      if (name.indexOf("color") != -1 || name.indexOf("Color") != -1) // $NON-NLS-1$ //$NON-NLS-2$
      {
        return new Integer(ColorUtil.formRGB(0xcc, 0xcc, 0xcc));
      }

      if (name.startsWith("border") && name.endsWith("Style")) // $NON-NLS-1$ //$NON-NLS-2$
      {
        return DesignChoiceConstants.LINE_STYLE_SOLID;
      }

      if (name.startsWith("border") && name.endsWith("Width")) // $NON-NLS-1$ //$NON-NLS-2$
      {
        return "1pt"; //$NON-NLS-1$
      }

      if (name.startsWith("margin") || name.startsWith("padding")) // $NON-NLS-1$ //$NON-NLS-2$
      {
        return "10pt"; //$NON-NLS-1$
      }

      if (FONT_FAMILY_PROP.equals(name)) {
        return "Tahoma"; //$NON-NLS-1$
      }

      if (FONT_SIZE_PROP.equals(name)) {
        return "12pt"; //$NON-NLS-1$
      }

      if (FONT_STYLE_PROP.equals(name)) {
        return DesignChoiceConstants.FONT_STYLE_ITALIC;
      }

      if (FONT_WEIGHT_PROP.equals(name)) {
        return DesignChoiceConstants.FONT_WEIGHT_BOLD;
      }

      if (TEXT_LINE_THROUGH_PROP.equals(name)) {
        return DesignChoiceConstants.TEXT_LINE_THROUGH_LINE_THROUGH;
      }

      if (TEXT_UNDERLINE_PROP.equals(name)) {
        return DesignChoiceConstants.TEXT_UNDERLINE_UNDERLINE;
      }

      if (TEXT_OVERLINE_PROP.equals(name)) {
        return DesignChoiceConstants.TEXT_OVERLINE_OVERLINE;
      }

      if (TEXT_ALIGN_PROP.equals(name)) {
        return DesignChoiceConstants.TEXT_ALIGN_CENTER;
      }

      if (VERTICAL_ALIGN_PROP.equals(name)) {
        return DesignChoiceConstants.VERTICAL_ALIGN_MIDDLE;
      }

      if (PAGE_BREAK_BEFORE_PROP.equals(name)) {
        return DesignChoiceConstants.PAGE_BREAK_BEFORE_ALWAYS;
      }

      if (PAGE_BREAK_AFTER_PROP.equals(name)) {
        return DesignChoiceConstants.PAGE_BREAK_AFTER_ALWAYS;
      }

      if (PAGE_BREAK_INSIDE_PROP.equals(name)) {
        return DesignChoiceConstants.PAGE_BREAK_INSIDE_AVOID;
      }
    }

    return null;
  }