/**
  * 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();
 }
Beispiel #2
0
    public void paintControl(PaintEvent e) {
      if (!resizing) {
        GC gc = e.gc;
        gc.setAdvanced(true);
        gc.setAntialias(SWT.ON);

        for (Channel channel : channelArray) {
          channel.paint(e.gc);
        }
      }
    }
  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);

  }
  private static Image takeScreenshot(final Display display, final Shell parent) {
    /* Take the screen shot */
    GC gc = new GC(parent);
    Image image = new Image(display, parent.getClientArea());
    gc.copyArea(image, 0, 0);
    GC gcImage = new GC(image);
    gcImage.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gcImage.setAdvanced(true);
    Region region = parent.getRegion();

    data = image.getImageData();
    if (region != null) {
      int height = image.getBounds().height;
      int width = image.getBounds().width;
      byte[] alphaData = new byte[height * width];
      int currentPosition = 0;
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          if (!region.contains(j, i)) {
            gcImage.drawPoint(j, i);
            alphaData[currentPosition] = 0;
          } else {
            alphaData[currentPosition] = (byte) 255;
          }
          currentPosition++;
        }
      }
      data.alphaData = alphaData;
    }

    image.dispose();
    gcImage.dispose();
    gc.dispose();

    return new Image(display, data);
  }
  protected void paintControl(PaintEvent e) {

    long start = System.currentTimeMillis();

    for (int c = 0; c < chan.length; c++) {

      // if (chan[c].tailSize <= 0) {
      // chan[c].stack.popNegate(0);
      // continue;
      // }

      // Go calculate the line
      Object[] result = calculate(c);
      int[] l1 = (int[]) result[0];
      int[] l2 = (int[]) result[1];

      PositionPolyLine(l1);
      PositionPolyLine(l2);
      // System.out.print(System.currentTimeMillis() - start + "-");

      // Draw it
      GC gc = e.gc;
      gc.setForeground(getForeground(c));
      gc.setAdvanced(true);
      gc.setAntialias(SWT.ON);
      gc.setLineWidth(getLineWidth(c));

      // Fade tail
      if (isFade(c)) {
        gc.setAlpha(0);
        double fade = 0;
        double fadeOutStep = (double) 125 / (double) ((getTailSize(c) * (getTailFade(c)) / 100));
        for (int i = 0; i < l1.length - 4; ) {
          fade += (fadeOutStep / 2);
          setAlpha(gc, fade);

          gc.drawLine(l1[i], l1[i + 1], l1[i + 2], l1[i + 3]);
          i += 2;
        }

        for (int i = 0; i < l2.length - 4; ) {
          fade += (fadeOutStep / 2);
          setAlpha(gc, fade);
          gc.drawLine(l2[i], l2[i + 1], l2[i + 2], l2[i + 3]);
          i += 2;
        }

      } else {
        long time = System.nanoTime();
        gc.drawPolyline(l1);
        gc.drawPolyline(l2);
        // System.out.println(System.nanoTime() - time + " nanoseconds");
      }

      // Connects the head with the tail
      if (isConnect(c)
          && !isFade(c)
          && chan[c].originalTailSize == TAILSIZE_MAX
          && l1.length > 0
          && l2.length > 0) {
        gc.drawLine(l2[l2.length - 2], l2[l2.length - 1], l1[0], l1[1]);
      }
    }

    // System.out.println(System.currentTimeMillis() - start + " milliseconds for all channels");

  }
 protected void highlightDifferences(GC gc) {
   // if the differencer is null then we are currently
   // in the middle of a content update, skip this paint
   // request
   if (mergeViewer.getDifferencer() == null) {
     return;
   }
   gc.setAdvanced(true);
   gc.setAntialias(SWT.ON);
   Tree tree = getTree();
   List<TreeDifference> differences = mergeViewer.getDifferencer().getLeftDifferences();
   if (mergeViewer.getLeftViewer() != this && mergeViewer.getAncestorTree() != this) {
     differences = mergeViewer.getDifferencer().getRightDifferences();
   }
   for (TreeDifference difference : differences) {
     if (differenceIsGraphical(difference)) {
       // we do not include graphical differences
       // at this time
       continue;
     }
     gc.setForeground(
         getMergeViewer()
             .getColor(
                 PlatformUI.getWorkbench().getDisplay(),
                 getMergeViewer().getStrokeColor(difference)));
     TreeItem item = getItemForDifference(difference);
     if (item == null || item.isDisposed()) {
       continue;
     }
     Rectangle highlightBounds =
         buildHighlightRectangle(
             item, difference.getIncludeChildren() && item.getExpanded(), gc, false, true);
     Rectangle itemBounds = buildHighlightRectangle(item, false, gc, false, true);
     boolean itemMatchesDifference = difference.getElement().equals(item.getData());
     if (!itemMatchesDifference && !(item.getData() instanceof EmptyElement)) {
       gc.setLineDash(new int[] {3});
       gc.setLineStyle(SWT.LINE_CUSTOM);
     } else {
       gc.setLineStyle(SWT.LINE_SOLID);
     }
     gc.drawRoundRectangle(
         highlightBounds.x,
         highlightBounds.y,
         highlightBounds.width,
         highlightBounds.height,
         5,
         5);
     if (mergeViewer.getLeftViewer() == this) {
       gc.drawLine(
           highlightBounds.x + highlightBounds.width,
           highlightBounds.y + (itemBounds.height / 2),
           tree.getClientArea().x + tree.getClientArea().width,
           highlightBounds.y + (itemBounds.height / 2));
     } else {
       gc.drawLine(
           highlightBounds.x,
           highlightBounds.y + (itemBounds.height / 2),
           tree.getClientArea().x,
           highlightBounds.y + (itemBounds.height / 2));
     }
     gc.setLineStyle(SWT.LINE_SOLID);
   }
 }
  public static /* synchronized */ Image resize(
      final Display display,
      final Image srcImage,
      final int newWidth,
      final int newHeight,
      final int antialias,
      final int interpolation,
      final Rotation exifRotation) {

    if (srcImage == null) {
      return null;
    }

    final Rectangle originalImageBounds = srcImage.getBounds();
    final int originalWidth = originalImageBounds.width;
    final int originalHeight = originalImageBounds.height;

    final int srcWidth = originalWidth;
    final int srcHeight = originalHeight;
    final int destWidth = newWidth;
    final int destHeight = newHeight;

    int imgWidth = newWidth;
    int imgHeight = newHeight;

    // OSX is rotating the image automatically
    boolean isNoAutoRotate = UI.IS_OSX == false;

    isNoAutoRotate |= _isRotateImageAutomatically == false;

    if (isNoAutoRotate) {

      if (exifRotation == Rotation.CW_90 || exifRotation == Rotation.CW_270) {
        // swap width/height
        imgWidth = newHeight;
        imgHeight = newWidth;
      }
    }

    final Image scaledImage = new Image(display, imgWidth, imgHeight);
    final GC gc = new GC(scaledImage);
    Transform transformation = null;
    try {
      gc.setAdvanced(true);

      gc.setAntialias(antialias);
      gc.setInterpolation(interpolation);
      //			gc.setAntialias(SWT.ON);
      //			gc.setInterpolation(SWT.LOW);

      int destX = 0;
      int destY = 0;

      if (exifRotation != null && isNoAutoRotate) {

        final int imgWidth2 = imgWidth / 2;
        final int imgHeight2 = imgHeight / 2;

        transformation = new Transform(display);
        transformation.translate(imgWidth2, imgHeight2);

        if (exifRotation == Rotation.CW_90) {

          transformation.rotate(90);

          destX = -imgHeight2;
          destY = -imgWidth2;

        } else if (exifRotation == Rotation.CW_180) {

          // this case is not yet tested

          transformation.rotate(180);

          destX = -imgWidth2;
          destY = -imgHeight2;

        } else if (exifRotation == Rotation.CW_270) {

          transformation.rotate(270);

          destX = -imgHeight2;
          destY = -imgWidth2;
        }

        gc.setTransform(transformation);
      }

      gc.drawImage(
          srcImage, //
          0,
          0,
          srcWidth,
          srcHeight,
          //
          destX,
          destY,
          destWidth,
          destHeight);
    } finally {

      // ensure resources are disposed when an error occures

      gc.dispose();

      if (transformation != null) {
        transformation.dispose();
      }
    }

    return scaledImage;
  }