Java Code Examples for org.eclipse.swt.custom.StyledText#redrawRange()

The following examples show how to use org.eclipse.swt.custom.StyledText#redrawRange() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextColorDrawingStrategy.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
@Override
public void draw(Annotation annotation, GC gc, StyledText textWidget, int start, int length, Color color) {
  if (length > 0) {
    if (annotation instanceof EclipseAnnotationPeer) {
      if (gc != null) {

        int end = start + length - 1;

        Rectangle bounds = textWidget.getTextBounds(start, end);

        gc.setForeground(color);

        gc.drawText(textWidget.getText(start, end), bounds.x, bounds.y, true);

      } else {
        textWidget.redrawRange(start, length, true);
      }
    }
  }
}
 
Example 2
Source File: BoxDrawingStrategy.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Draws a box around the given annotation.
 *
 * @param annotation the annotation
 * @param gc the gc
 * @param textWidget the text widget
 * @param offset the offset
 * @param length the length
 * @param color the color
 */
@Override
public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length,
        Color color) {
  if (length != 0) {
    if (gc != null) {
      Rectangle bounds = textWidget.getTextBounds(offset, offset + length - 1);

      gc.setForeground(color);

      int correctedHeight;
      
      if (bounds.height > 0) {
        correctedHeight = bounds.height -1;
      }
      else {
        correctedHeight = bounds.height;
      }
      
      int correctedWidth;
      
      if (bounds.width > 0)
        correctedWidth = bounds.width -1;
      else
        correctedWidth = bounds.width;
      
      gc.drawRectangle(bounds.x, bounds.y, correctedWidth, correctedHeight);
    } else {
      textWidget.redrawRange(offset, length, true);
    }
  }
}
 
Example 3
Source File: BracketDrawingStrategy.java    From uima-uimaj with Apache License 2.0 5 votes vote down vote up
/**
 * Draws an opening bracket to the begin and a closing bracket to the end of the given annotation.
 *
 * @param annotation the annotation
 * @param gc the gc
 * @param textWidget the text widget
 * @param offset the offset
 * @param length the length
 * @param color the color
 */
@Override
public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length,
        Color color) {
  if (length > 0) {
    if (annotation instanceof EclipseAnnotationPeer) {
      AnnotationFS annotationFS = ((EclipseAnnotationPeer) annotation).getAnnotationFS();

      if (gc != null) {
        Rectangle bounds = textWidget.getTextBounds(offset, offset + length - 1);

        gc.setForeground(color);

        boolean isDrawOpenBracket = annotationFS.getBegin() == offset;
        if (isDrawOpenBracket) {
          gc.drawLine(bounds.x, bounds.y + bounds.height - 1, bounds.x + BRACKET_WIDTH, bounds.y
                  + bounds.height - 1);

          gc.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1);

          gc.drawLine(bounds.x, bounds.y, bounds.x + BRACKET_WIDTH, bounds.y);
        }

        boolean isDrawCloseBracket = annotationFS.getEnd() == offset + length;
        if (isDrawCloseBracket) {
          gc.drawLine(bounds.x + bounds.width, bounds.y + bounds.height - 1, bounds.x
                  + bounds.width - BRACKET_WIDTH, bounds.y + bounds.height - 1);

          gc.drawLine(bounds.x + bounds.width - 1, bounds.y, bounds.x + bounds.width - 1, bounds.y
                  + bounds.height - 1);

          gc.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width - BRACKET_WIDTH,
                  bounds.y);
        }
      } else {
        textWidget.redrawRange(offset, length, true);
      }
    }
  }
}
 
Example 4
Source File: TokenDrawingStrategy.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
@Override
public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length,
        Color color) {
  if (length > 0) {
    if (annotation instanceof EclipseAnnotationPeer) {
      AnnotationFS annotationFS = ((EclipseAnnotationPeer) annotation).getAnnotationFS();
      if (gc != null) {
        Rectangle bounds = textWidget.getTextBounds(offset, offset + length - 1);

        gc.setForeground(color);

        boolean isDrawOpenBracket = annotationFS.getBegin() == offset;
        // and no space before offset
        if (isDrawOpenBracket && offset > 1 && !isWhitespace(annotationFS.getCAS().getDocumentText(), offset - 1)) {
          gc.drawLine(bounds.x, bounds.y + bounds.height - 1, bounds.x + BRACKET_WIDTH, bounds.y
                  + bounds.height - 1);

          gc.drawLine(bounds.x, bounds.y, bounds.x, bounds.y + bounds.height - 1);

          gc.drawLine(bounds.x, bounds.y, bounds.x + BRACKET_WIDTH, bounds.y);
        }

        boolean isDrawCloseBracket = annotationFS.getEnd() == offset + length;
        // and no space after offset
        if (isDrawCloseBracket && offset + length < textWidget.getText().length()
                && !isWhitespace(annotationFS.getCAS().getDocumentText(), offset + length)) {
          gc.drawLine(bounds.x + bounds.width, bounds.y + bounds.height - 1, bounds.x
                  + bounds.width - BRACKET_WIDTH, bounds.y + bounds.height - 1);

          gc.drawLine(bounds.x + bounds.width - 1, bounds.y, bounds.x + bounds.width - 1,
                  bounds.y + bounds.height - 1);

          gc.drawLine(bounds.x + bounds.width, bounds.y, bounds.x + bounds.width - BRACKET_WIDTH,
                  bounds.y);
        }
      } else {
        textWidget.redrawRange(offset, length, true);
      }
    }
  }
}