Esempio n. 1
0
  /*
   * @see IPainter#paint(int)
   */
  public void paint(int reason) {
    if (fViewer == null) {
      return;
    }
    if (fViewer.getDocument() == null) {
      deactivate(false);
      return;
    }

    // initialization
    if (!fIsActive) {
      StyledText textWidget = fViewer.getTextWidget();
      textWidget.addLineBackgroundListener(this);
      textWidget.addPaintListener(this);
      fPositionManager.managePosition(fCurrentLine);
      fIsActive = true;
    }

    // This forces redraw of the line highlight
    if (updateHighlightLine()) {
      // clear last line
      // Fix the background colors for tokens that didn't have the same as line!
      if (isOpaque() && !fLastLine.isDeleted() && fViewer instanceof ITextViewerExtension2) {
        ITextViewerExtension2 ext = (ITextViewerExtension2) fViewer;
        try {
          ext.invalidateTextPresentation(fLastLine.getOffset(), fLastLine.getLength());
        } catch (Exception e) {
          IdeLog.logError(CommonEditorPlugin.getDefault(), e);
        }
      }
      drawHighlightLine(fLastLine);
      // draw new line
      drawHighlightLine(fCurrentLine);
    }
  }
 /** Extended to support the Highlighting of matching parenthesis. */
 private void addMatchingCharacterPainter() {
   ITextViewerExtension2 extension = (ITextViewerExtension2) getSourceViewer();
   DefaultCharacterPairMatcher matcher =
       new DefaultCharacterPairMatcher(new char[] {'(', ')', '{', '}', '[', ']'});
   MatchingCharacterPainter painter = new MatchingCharacterPainter(getSourceViewer(), matcher);
   painter.setColor(Display.getDefault().getSystemColor(SWT.COLOR_GRAY));
   extension.addPainter(painter);
 }
 private void repairPresentation(ITextViewer viewer) {
   if (fRememberedStyleRange != null) {
     if (viewer instanceof ITextViewerExtension2) {
       // attempts to reduce the redraw area
       ITextViewerExtension2 viewer2 = (ITextViewerExtension2) viewer;
       viewer2.invalidateTextPresentation(
           fRememberedStyleRange.start, fRememberedStyleRange.length);
     } else {
       viewer.invalidateTextPresentation();
     }
   }
 }