Ejemplo n.º 1
0
 void pairDraw(GC gc, StyledRegion sr, int start, int end) {
   if (start > text.getCharCount() || end > text.getCharCount()) return;
   if (gc != null) {
     Point left = text.getLocationAtOffset(start);
     Point right = text.getLocationAtOffset(end);
     if (sr != null) {
       if (highlightStyle == HLS_XOR) {
         int resultColor = sr.fore ^ cm.getColor(text.getBackground());
         if (text.getLineAtOffset(text.getCaretOffset()) == text.getLineAtOffset(start)
             && horzCross
             && horzCrossColor != null
             && ((StyledRegion) horzCrossColor).bback)
           resultColor = sr.fore ^ ((StyledRegion) horzCrossColor).back;
         Color color = cm.getColor(sr.bfore, resultColor);
         gc.setBackground(color);
         gc.setXORMode(true);
         gc.fillRectangle(left.x, left.y, right.x - left.x, gc.getFontMetrics().getHeight());
       } else if (highlightStyle == HLS_OUTLINE) {
         Color color = cm.getColor(sr.bfore, sr.fore);
         gc.setForeground(color);
         gc.drawRectangle(
             left.x, left.y, right.x - left.x - 1, gc.getFontMetrics().getHeight() - 1);
       } else if (highlightStyle == HLS_OUTLINE2) {
         Color color = cm.getColor(sr.bfore, sr.fore);
         gc.setForeground(color);
         gc.setLineWidth(2);
         gc.drawRectangle(
             left.x + 1, left.y + 1, right.x - left.x - 2, gc.getFontMetrics().getHeight() - 2);
       }
     }
   } else {
     text.redrawRange(start, end - start, true);
   }
 }
  private final void draw(final GC gc, final int offset, final int length) {
    if (gc != null) {
      Point left = mTextWidget.getLocationAtOffset(offset);
      Point right = mTextWidget.getLocationAtOffset(offset + length);
      Color color = mMismatch ? mMismatchColor : mColor;

      if (mBox) {
        gc.setForeground(color);
        int x = left.x;
        int y = left.y;
        int w = right.x - left.x - 1;
        int h = gc.getFontMetrics().getHeight();
        gc.drawRectangle(x, y, w, h);
      } else {
        gc.setForeground(mDefaultColor);
        gc.setBackground(color);
        gc.drawString(mTextWidget.getTextRange(offset, 1), left.x, left.y, false);
      }
    } else {
      mTextWidget.redrawRange(offset, length, true);
    }
  }