コード例 #1
0
  private void adaptToTextForegroundChange(Highlighting highlighting, PropertyChangeEvent event) {
    RGB rgb = null;

    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();
      Color color = fColorManager.getColor(property);

      if ((color == null || !rgb.equals(color.getRGB()))
          && fColorManager instanceof IColorManagerExtension) {
        IColorManagerExtension ext = (IColorManagerExtension) fColorManager;
        ext.unbindColor(property);
        ext.bindColor(property, rgb);
        color = fColorManager.getColor(property);
      }

      TextAttribute oldAttr = highlighting.getTextAttribute();
      highlighting.setTextAttribute(
          new TextAttribute(color, oldAttr.getBackground(), oldAttr.getStyle()));
    }
  }
コード例 #2
0
 private void adaptToEnablementChange(Highlighting highlighting, PropertyChangeEvent event) {
   Object value = event.getNewValue();
   boolean eventValue;
   if (value instanceof Boolean) eventValue = ((Boolean) value).booleanValue();
   else if (IPreferenceStore.TRUE.equals(value)) eventValue = true;
   else eventValue = false;
   highlighting.setEnabled(eventValue);
 }
コード例 #3
0
  private void adaptToTextStyleChange(
      Highlighting highlighting, PropertyChangeEvent event, int styleAttribute) {
    boolean eventValue = false;
    Object value = event.getNewValue();
    if (value instanceof Boolean) eventValue = ((Boolean) value).booleanValue();
    else if (IPreferenceStore.TRUE.equals(value)) eventValue = true;

    TextAttribute oldAttr = highlighting.getTextAttribute();
    boolean activeValue = (oldAttr.getStyle() & styleAttribute) == styleAttribute;

    if (activeValue != eventValue)
      highlighting.setTextAttribute(
          new TextAttribute(
              oldAttr.getForeground(),
              oldAttr.getBackground(),
              eventValue
                  ? oldAttr.getStyle() | styleAttribute
                  : oldAttr.getStyle() & ~styleAttribute));
  }
コード例 #4
0
  /**
   * Computes the hard-coded positions from the hard-coded ranges
   *
   * @return the hard-coded positions
   */
  private HighlightedPosition[] createHardcodedPositions() {
    List<HighlightedPosition> positions = new ArrayList<HighlightedPosition>();
    for (int i = 0; i < fHardcodedRanges.length; i++) {
      HighlightedRange range = null;
      Highlighting hl = null;
      for (int j = 0; j < fHardcodedRanges[i].length; j++) {
        hl = getHighlighting(fHardcodedRanges[i][j].getKey());
        if (hl.isEnabled()) {
          range = fHardcodedRanges[i][j];
          break;
        }
      }

      if (range != null)
        positions.add(
            fPresenter.createHighlightedPosition(range.getOffset(), range.getLength(), hl));
    }
    return positions.toArray(new HighlightedPosition[positions.size()]);
  }
コード例 #5
0
    /** @return Returns a corresponding style range. */
    public StyleRange createStyleRange() {
      int len = 0;
      if (fStyle.isEnabled()) len = getLength();

      TextAttribute textAttribute = fStyle.getTextAttribute();
      int style = textAttribute.getStyle();
      int fontStyle = style & (SWT.ITALIC | SWT.BOLD | SWT.NORMAL);
      StyleRange styleRange =
          new StyleRange(
              getOffset(),
              len,
              textAttribute.getForeground(),
              textAttribute.getBackground(),
              fontStyle);
      styleRange.strikeout = (style & TextAttribute.STRIKETHROUGH) != 0;
      styleRange.underline = (style & TextAttribute.UNDERLINE) != 0;

      return styleRange;
    }