public void lineGetBackground(LineBackgroundEvent event) {
   int lineNr = styledText.getLineAtOffset(event.lineOffset) + 1;
   Iterator<CommentAnnotation> it = annotationModel.getAnnotationIterator();
   while (it.hasNext()) {
     CommentAnnotation annotation = it.next();
     int startLine;
     int endLine;
     ITopic comment = annotation.getTopic();
     // TODO This code assumes that we have one comment per annotation. That won't work for r4E.
     if (comment.getLocations().size() == 1) {
       ILocation location = comment.getLocations().get(0);
       if (location instanceof ILineLocation) {
         ILineLocation lineLocation = (ILineLocation) location;
         startLine = lineLocation.getRangeMin();
         endLine = lineLocation.getRangeMax();
         if (lineNr >= startLine && lineNr <= endLine) {
           AnnotationPreference pref =
               new AnnotationPreferenceLookup().getAnnotationPreference(annotation);
           if (pref.getHighlightPreferenceValue()) {
             event.lineBackground = colorCommented;
           }
         }
       }
     }
   }
 }
Esempio n. 2
0
  public void lineGetBackground(LineBackgroundEvent event) {
    if (fViewer == null) {
      return;
    }
    final StyledText textWidget = fViewer.getTextWidget();
    if (textWidget == null) {
      return;
    }

    try {
      final int offset = event.lineOffset;
      IDocument document = fViewer.getDocument();
      int line = document.getLineOfOffset(offset);
      final IRegion lineRegion = document.getLineInformation(line);

      // Handle fully opaque line highlight here. A modified approach from CursorLinePainter.
      if (fEnabled && isOpaque() && isCurrentLine(line)) {
        // draw current line
        drawCurrentLine(event, lineRegion);
        return;
      }

      // Not drawing an opaque line highlight, so we need to do our normal line coloring here.
      // This extends the bg color out for a given line based on it's end scope.
      String endOfLineScope =
          getScopeManager().getScopeAtOffset(document, lineRegion.getLength() + offset);
      String commonPrefix = getScope(document, line, endOfLineScope);
      TextAttribute at = getCurrentTheme().getTextAttribute(commonPrefix);

      // if we have no color we need to extend to end of line, but this used to be the highlight
      // line, force the
      // theme bg color
      if (at.getBackground() == null && isOpaque() && fLastLine.includes(offset)) {
        event.lineBackground = getColorManager().getColor(getCurrentTheme().getBackground());
      } else {
        event.lineBackground = at.getBackground();
      }
    } catch (BadLocationException e) {
      IdeLog.logError(CommonEditorPlugin.getDefault(), e);
    }
  }
Esempio n. 3
0
  private void drawCurrentLine(LineBackgroundEvent event, final IRegion lineRegion) {
    final StyledText textWidget = fViewer.getTextWidget();
    final int offset = event.lineOffset;
    final RGBa lineHighlight = getCurrentTheme().getLineHighlight();
    event.lineBackground = getColorManager().getColor(lineHighlight.toRGB());

    // In this case, we should be overriding the bg of the style ranges for the line too!
    if (textWidget.isDisposed()) {
      return;
    }
    // FIXME Only change bg colors of visible ranges!
    int replaceLength = 160;
    if (lineRegion != null) {
      replaceLength = Math.min(replaceLength, lineRegion.getLength());
    }

    // be safe about offsets
    int charCount = textWidget.getCharCount();
    if (offset + replaceLength > charCount) {
      replaceLength = charCount - offset;
      if (replaceLength < 0) {
        // Just playing safe here
        replaceLength = 0;
      }
    }
    final StyleRange[] ranges = textWidget.getStyleRanges(offset, replaceLength, true);
    if (ranges == null || ranges.length == 0) {
      return;
    }
    Color background = textWidget.getBackground();
    final int[] positions = new int[ranges.length << 1];
    int x = 0;
    boolean apply = false;
    for (StyleRange range : ranges) {
      if (range.background != null) {
        if (!range.background.equals(background)) {
          positions[x] = range.start;
          positions[x + 1] = range.length;
          x += 2;
          continue;
        }
        apply = true;
      }
      range.background = null;
      positions[x] = range.start;
      positions[x + 1] = range.length;
      x += 2;
    }

    if (apply) {
      textWidget.setStyleRanges(offset, replaceLength, positions, ranges);
    }
  }
Esempio n. 4
0
    public void lineGetBackground(LineBackgroundEvent e) {
      int lno = text.getLineAtOffset(e.lineOffset);
      int caret = text.getCaretOffset();
      int length = e.lineText.length();

      if (horzCrossColor != null
          && horzCross
          && lineHighlighting
          && e.lineOffset <= caret
          && caret <= e.lineOffset + length) {
        e.lineBackground =
            cm.getColor(
                ((StyledRegion) horzCrossColor).bback, ((StyledRegion) horzCrossColor).back);
        return;
      }
      if (!fullBackground) return;
      LineRegion[] lr = baseEditor.getLineRegions(lno);
      for (int idx = 0; idx < lr.length; idx++) {
        StyledRegion rdef = (StyledRegion) lr[idx].rdef;
        if (lr[idx].end == -1 && rdef != null)
          e.lineBackground = cm.getColor(rdef.bback, rdef.back);
      }
    }