示例#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);
    }
  }
 private void createHighlighting(Class<SourceViewer> sourceViewerClazz)
     throws IllegalArgumentException, IllegalAccessException, SecurityException,
         NoSuchFieldException {
   // TODO this could use some performance tweaks
   final StyledText styledText = sourceViewer.getTextWidget();
   styledText.addLineBackgroundListener(new ColoringLineBackgroundListener(styledText));
 }
示例#3
0
  /**
   * Installs this highlighter into the specified StyledText object. Client can manually call
   * detach() method, then wants to destroy this object.
   */
  public void attach(StyledText parent) {
    detach();

    text = parent;
    text.addDisposeListener(ml);
    text.addLineStyleListener(ml);
    text.addLineBackgroundListener(ml);
    text.addPaintListener(ml);
    text.addVerifyListener(ml);
    text.addExtendedModifyListener(ml);
    text.addControlListener(ml);
    text.addKeyListener(ml);
    text.addTraverseListener(ml);
    text.addMouseListener(ml);
    text.addSelectionListener(ml);
    text.getContent().addTextChangeListener(ml);
    ScrollBar sb = text.getVerticalBar();
    if (sb != null) sb.addSelectionListener(ml);
    updateViewport();

    new Thread() {
      public void run() {
        // setPriority(Thread.NORM_PRIORITY-1);
        while (true) {
          try {
            sleep(300);
          } catch (InterruptedException e) {
          }
          if (baseEditor == null || text == null) break;
          if (backParserDelay) {
            backParserDelay = false;
            try {
              sleep(1500);
            } catch (InterruptedException e) {
            }
            continue;
          }
          ;
          Display.getDefault()
              .syncExec(
                  new Runnable() {
                    public void run() {
                      if (baseEditor == null || text == null) return;
                      if (text.isDisposed()) return;
                      // System.out.println(System.currentTimeMillis());
                      baseEditor.idleJob(80);
                      // redrawFrom(text.getLineAtOffset(text.getCaretOffset()));
                    }
                  });
        }
        ;
      };
    }.start();
  }