Package org.eclipse.jface.text

Examples of org.eclipse.jface.text.TextAttribute


      ITextRegionList regions = structuredDocumentRegion.getRegions();
      int nRegions = regions.size();
      StyleRange styleRange = null;
      for (int i = 0; i < nRegions; i++) {
        region = regions.get(i);
        TextAttribute attr = null;
        TextAttribute previousAttr = null;
        if (structuredDocumentRegion.getStartOffset(region) > partitionEndOffset)
          break;
        if (structuredDocumentRegion.getEndOffset(region) <= partitionStartOffset)
          continue;

        if (region instanceof ITextRegionCollection) {
          boolean handledCollection = (prepareTextRegion((ITextRegionCollection) region, partitionStartOffset, partitionLength, holdResults));
          handled = (!handled) ? handledCollection : handled;
        } else {

          attr = getAttributeFor(structuredDocumentRegion, region);
          if (attr != null) {
            handled = true;
            // if this region's attr is the same as previous one,
            // then just adjust the previous style range
            // instead of creating a new instance of one
            // note: to use 'equals' in this case is important,
            // since sometimes
            // different instances of attributes are associated
            // with a region, even the
            // the attribute has the same values.
            // TODO: this needs to be improved to handle readonly
            // regions correctly
            if ((styleRange != null) && (previousAttr != null) && (previousAttr.equals(attr))) {
              styleRange.length += region.getLength();
            } else {
              styleRange = createStyleRange(structuredDocumentRegion, region, attr, partitionStartOffset, partitionLength);
              holdResults.add(styleRange);
              // technically speaking, we don't need to update
View Full Code Here


        fItalic.setEnabled(true);
      fForegroundLabel.setEnabled(true);
      fBackgroundLabel.setEnabled(true);
     
    }
    TextAttribute attribute = getAttribute(namedStyle);
    Color color = attribute.getForeground();
    if (color == null) {
      color = fDefaultForeground;
    }
    fForeground.setColorValue(color.getRGB());

    color = attribute.getBackground();
    if (color == null) {
      color = fDefaultBackground;
    }
    fBackground.setColorValue(color.getRGB());

    fBold.setSelection((attribute.getStyle() & SWT.BOLD) != 0);
    if (showItalic)
      fItalic.setSelection((attribute.getStyle() & SWT.ITALIC) != 0);
  }
View Full Code Here

        ITextRegion currentRegion = regions.get(i);
        // lookup the local coloring type and apply it
        String namedStyle = (String) getContextStyleMap().get(currentRegion.getType());
        if (namedStyle == null)
          continue;
        TextAttribute attribute = getAttribute(namedStyle);
        if (attribute == null)
          continue;
        StyleRange style = new StyleRange(node.getStartOffset(currentRegion), currentRegion.getLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle());
        fText.setStyleRange(style);
      }
      node = node.getNext();
    }
  }
View Full Code Here

    button.setLayoutData(data);
    return button;
  }

  protected TextAttribute getAttribute(String namedStyle) {
    TextAttribute ta = new TextAttribute(getDefaultForeground(), getDefaultBackground(), SWT.NORMAL);

    if (namedStyle != null && getPreferenceStore() != null) {
      String prefString = getPreferenceStore().getString(namedStyle);
      String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
      if (stylePrefs != null) {
        RGB foreground = ColorHelper.toRGB(stylePrefs[0]);
        RGB background = ColorHelper.toRGB(stylePrefs[1]);

        int fontModifier = SWT.NORMAL;
        boolean bold = Boolean.valueOf(stylePrefs[2]).booleanValue();
        if (bold)
          fontModifier = fontModifier | SWT.BOLD;

        if (showItalic) {
          boolean italic = Boolean.valueOf(stylePrefs[3]).booleanValue();
          if (italic)
            fontModifier = fontModifier | SWT.ITALIC;
        }

        ta = new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, fontModifier);
      }
    }
    return ta;
  }
View Full Code Here

      fItalic.setSelection(false);
      fStrike.setSelection(false);
      fUnderline.setSelection(false);
    }
    else {
      TextAttribute attribute = getAttributeFor(namedStyle);
      fClearStyle.setEnabled(true);
      boolean enableBackgroundOnly = IStyleConstantsJSP.JSP_CONTENT.equals(namedStyle);
      fBold.setEnabled(!enableBackgroundOnly);
      fItalic.setEnabled(!enableBackgroundOnly);
      fStrike.setEnabled(!enableBackgroundOnly);
      fUnderline.setEnabled(!enableBackgroundOnly);
      fForegroundLabel.setEnabled(!enableBackgroundOnly);
      fForegroundColorEditor.setEnabled(!enableBackgroundOnly);
      fBackgroundLabel.setEnabled(true);
      fBackgroundColorEditor.setEnabled(true);
      fBold.setSelection((attribute.getStyle() & SWT.BOLD) != 0);
      fItalic.setSelection((attribute.getStyle() & SWT.ITALIC) != 0);
      fStrike.setSelection((attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0);
      fUnderline.setSelection((attribute.getStyle() & TextAttribute.UNDERLINE) != 0);
      if (attribute.getForeground() != null) {
        foreground = attribute.getForeground();
      }
      if (attribute.getBackground() != null) {
        background = attribute.getBackground();
      }
    }

    fForegroundColorEditor.setColorValue(foreground.getRGB());
    fBackgroundColorEditor.setColorValue(background.getRGB());
View Full Code Here

        ITextRegion currentRegion = regions.get(i);
        // lookup the local coloring type and apply it
        String namedStyle = (String) fContextToStyleMap.get(currentRegion.getType());
        if (namedStyle == null)
          continue;
        TextAttribute attribute = getAttributeFor(namedStyle);
        if (attribute == null)
          continue;
        StyleRange style = new StyleRange(documentRegion.getStartOffset(currentRegion), currentRegion.getTextLength(), attribute.getForeground(), attribute.getBackground(), attribute.getStyle());
        style.strikeout = (attribute.getStyle() & TextAttribute.STRIKETHROUGH) != 0;
        style.underline = (attribute.getStyle() & TextAttribute.UNDERLINE) != 0;
        fText.setStyleRange(style);
      }
      documentRegion = documentRegion.getNext();
    }
  }
View Full Code Here

  protected IPreferenceStore doGetPreferenceStore() {
    return JSPUIPlugin.getDefault().getPreferenceStore();
  }

  private TextAttribute getAttributeFor(String namedStyle) {
    TextAttribute ta = new TextAttribute(fDefaultForeground, fDefaultBackground, SWT.NORMAL);

    if (namedStyle != null && fOverlayStore != null) {
      // note: "namedStyle" *is* the preference key
      String prefString = getOverlayStore().getString(namedStyle);
      String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString);
      if (stylePrefs != null) {
        RGB foreground = ColorHelper.toRGB(stylePrefs[0]);
        RGB background = ColorHelper.toRGB(stylePrefs[1]);

        int fontModifier = SWT.NORMAL;

        if (stylePrefs.length > 2) {
          boolean on = Boolean.valueOf(stylePrefs[2]).booleanValue();
          if (on)
            fontModifier = fontModifier | SWT.BOLD;
        }
        if (stylePrefs.length > 3) {
          boolean on = Boolean.valueOf(stylePrefs[3]).booleanValue();
          if (on)
            fontModifier = fontModifier | SWT.ITALIC;
        }
        if (stylePrefs.length > 4) {
          boolean on = Boolean.valueOf(stylePrefs[4]).booleanValue();
          if (on)
            fontModifier = fontModifier | TextAttribute.STRIKETHROUGH;
        }
        if (stylePrefs.length > 5) {
          boolean on = Boolean.valueOf(stylePrefs[5]).booleanValue();
          if (on)
            fontModifier = fontModifier | TextAttribute.UNDERLINE;
        }

        ta = new TextAttribute((foreground != null) ? EditorUtility.getColor(foreground) : null, (background != null) ? EditorUtility.getColor(background) : null, fontModifier);
      }
    }
    return ta;
  }
View Full Code Here

    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;
    }
View Full Code Here

  protected TextAttribute getAttributeFor(ITextRegion region) {
    /**
     * a method to centralize all the "sytle rules" for regions
     */
    TextAttribute result = null;
    // not sure why this is coming through null, but just to catch it
    if (region == null) {
      result = (TextAttribute) getTextAttributes().get(IStyleConstantsXML.CDATA_TEXT);
    }
    else {
View Full Code Here

   * @param colorKey
   */
  private void addJavaTextAttribute(String colorKey) {
    IPreferenceStore store = getJavaColorPreferences();
    if (store != null && colorKey != null) {
      TextAttribute ta = null;
      if (colorKey == IStyleConstantsJSPEL.EL_KEYWORD) {
        // keyword
        RGB foreground = PreferenceConverter.getColor(store, PreferenceConstants.EDITOR_JAVA_KEYWORD_COLOR);
        boolean bold = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_BOLD);
        boolean italics = store.getBoolean(PreferenceConstants.EDITOR_JAVA_KEYWORD_ITALIC);
View Full Code Here

TOP

Related Classes of org.eclipse.jface.text.TextAttribute

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.