Exemplo n.º 1
0
 /**
  * Creates a new painter for the given text viewer.
  *
  * @param textViewer the text viewer the painter should be attached to
  */
 public WhitespaceCharacterPainter(ITextViewer textViewer) {
   super();
   fTextViewer = textViewer;
   fTextWidget = textViewer.getTextWidget();
   GC gc = new GC(fTextWidget);
   gc.setAdvanced(true);
   fIsAdvancedGraphicsPresent = gc.getAdvanced();
   gc.dispose();
 }
  void paint(PaintEvent e) {
    GC gc = e.gc;
    Point size = comp.getSize();
    if (curveColor == null) curveColor = e.display.getSystemColor(SWT.COLOR_BLACK);
    int h = size.y;
    int[] simpleCurve = new int[] {0, h - 1, 1, h - 1, 2, h - 2, 2, 1, 3, 0};
    // draw border
    gc.setForeground(curveColor);
    gc.setAdvanced(true);
    if (gc.getAdvanced()) {
      gc.setAntialias(SWT.ON);
    }
    gc.drawPolyline(simpleCurve);

    Rectangle bounds = ((Control) e.widget).getBounds();
    bounds.x = bounds.y = 0;
    Region r = new Region();
    r.add(bounds);
    int[] simpleCurveClose = new int[simpleCurve.length + 4];
    System.arraycopy(simpleCurve, 0, simpleCurveClose, 0, simpleCurve.length);
    int index = simpleCurve.length;
    simpleCurveClose[index++] = bounds.width;
    simpleCurveClose[index++] = 0;
    simpleCurveClose[index++] = bounds.width;
    simpleCurveClose[index++] = bounds.height;
    r.subtract(simpleCurveClose);
    Region clipping = new Region();
    gc.getClipping(clipping);
    r.intersect(clipping);
    gc.setClipping(r);
    Image b = toolParent.getBackgroundImage();
    if (b != null && !b.isDisposed()) gc.drawImage(b, 0, 0);

    r.dispose();
    clipping.dispose();
    // // gc.fillRectangle(bounds);
    // Rectangle mappedBounds = e.display.map(comp, comp.getParent(),
    // bounds);
    // ((Composite) toolParent).drawBackground(gc, bounds.x, bounds.y,
    // bounds.width,
    // bounds.height, mappedBounds.x, mappedBounds.y);

  }