private void adaptToStyleChange(PropertyChangeEvent event) {
    boolean bold = false;
    // bold properties need to be converted to colors for the map
    String colorPlusStyle = event.getProperty();
    String colorName =
        colorPlusStyle.substring(
            0, colorPlusStyle.length() - ColorsPreferencePage.BOLD_SUFFIX.length());
    Token token = (Token) tokenMap.get(colorName);
    LToken lToken = (LToken) tokenMap.get(colorName + MARK_SUFFIX);
    if (token == null && lToken == null) return;
    Object value = event.getNewValue();
    bold = ((Boolean) value).booleanValue();

    Object data = token.getData();
    if (data instanceof TextAttribute) {
      TextAttribute oldAttr = (TextAttribute) data;
      TextAttribute newAttr =
          new TextAttribute(
              oldAttr.getForeground(), oldAttr.getBackground(), bold ? SWT.BOLD : SWT.NORMAL);
      boolean isBold = (oldAttr.getStyle() == SWT.BOLD);
      if (isBold != bold) {
        token.setData(newAttr);
        if (lToken != null) lToken.setData(newAttr);
      }
    }
  }
 private void adaptToColorChange(PropertyChangeEvent event) {
   RGB rgb = null;
   Token token = (Token) tokenMap.get(event.getProperty());
   LToken lToken = (LToken) tokenMap.get(event.getProperty() + MARK_SUFFIX);
   if (token == null && lToken == null) {
     return;
   }
   Object value = event.getNewValue();
   if (value instanceof RGB) rgb = (RGB) value;
   else if (value instanceof String) rgb = StringConverter.asRGB((String) value);
   if (rgb != null) {
     String property = event.getProperty();
     Object data = token.getData();
     if (data instanceof TextAttribute) {
       TextAttribute oldAttr = (TextAttribute) data;
       TextAttribute newAttr =
           new TextAttribute(
               colorManager.getColor(property), oldAttr.getBackground(), oldAttr.getStyle());
       if (token != null) token.setData(newAttr);
       if (lToken != null) lToken.setData(newAttr);
     }
   }
 }
Esempio n. 3
0
  protected void updateToken(Token token, IFieldView<TextStyling> stylingPref) {
    token.setData(createTextAttribute(stylingPref));

    handleTokenModified(token);
  }