Java Code Examples for org.eclipse.swt.graphics.Image#getDevice()

The following examples show how to use org.eclipse.swt.graphics.Image#getDevice() . 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: CrossFadeEffect.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Cross fade from image1 to image2 on obj.
 * 
 * @param obj
 * @param image1
 * @param image2
 * @param lengthMilli
 * @param movement
 * @param onStop
 * @param onCancel
 */
public CrossFadeEffect(IImageObject obj, Image image1, Image image2,
		long lengthMilli, IMovement movement, Runnable onStop,
		Runnable onCancel) {
	super(lengthMilli, movement, onStop, onCancel);
	this.obj = obj;
	this.image1 = image1;
	this.image2 = image2;

	if (!image1.getBounds().equals(image2.getBounds())) {
		throw new IllegalArgumentException(
				"Both image must have the same dimensions");
	}

	easingFunction.init(0, 1, (int) lengthMilli);

	buffer = new Image(image1.getDevice(), image1.getBounds().width,
			image1.getBounds().height);
	gc = new GC(buffer);
}
 
Example 2
Source File: SWTGraphicUtil.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Returns a new scaled image.
 *
 * @param source the image to be scaled
 * @param newWidth new width of the image
 * @param newHeight new height of the image
 * @return a scaled image of the source
 */
public static Image resize(final Image source, final int newWidth, final int newHeight) {
	if (source == null) {
		return null;
	}

	if (source.isDisposed()) {
		SWT.error(SWT.ERROR_WIDGET_DISPOSED);
	}

	final Image scaledImage = new Image(source.getDevice(), newWidth, newHeight);
	final GC gc = new GC(scaledImage);
	gc.setAntialias(SWT.ON);
	gc.setInterpolation(SWT.HIGH);
	gc.drawImage(source, 0, 0, source.getBounds().width, source.getBounds().height, 0, 0, newWidth, newHeight);
	gc.dispose();

	return scaledImage;
}
 
Example 3
Source File: FullTraceHistogram.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void paintControl(PaintEvent event) {
    super.paintControl(event);

    Image image = Objects.requireNonNull((Image) fCanvas.getData(IMAGE_KEY));

    Image rangeRectangleImage = new Image(image.getDevice(), image, SWT.IMAGE_COPY);
    GC rangeWindowGC = new GC(rangeRectangleImage);

    if ((fScaledData != null) && (fRangeDuration != 0 || fDragState == DRAG_ZOOM)) {
        drawTimeRangeWindow(rangeWindowGC, fRangeStartTime, fRangeDuration);
    }

    // Draws the buffer image onto the canvas.
    event.gc.drawImage(rangeRectangleImage, 0, 0);

    rangeWindowGC.dispose();
    rangeRectangleImage.dispose();
}
 
Example 4
Source File: TimeRangeHistogram.java    From tracecompass with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void paintControl(PaintEvent event) {
    super.paintControl(event);

    if (fDragState == DRAG_ZOOM) {
        Image image = Objects.requireNonNull((Image) fCanvas.getData(IMAGE_KEY));

        Image rangeRectangleImage = new Image(image.getDevice(), image, SWT.IMAGE_COPY);
        GC rangeWindowGC = new GC(rangeRectangleImage);

        drawTimeRangeWindow(rangeWindowGC, fRangeStartTime, fRangeDuration);

        // Draws the buffer image onto the canvas.
        event.gc.drawImage(rangeRectangleImage, 0, 0);

        rangeWindowGC.dispose();
        rangeRectangleImage.dispose();
    }
}
 
Example 5
Source File: TagCloud.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private ImageData createImageData(final Word word, Font font, Point stringExtent, final double sin,
		final double cos, int x, int y, Color color) {
	Image img = new Image(null, x, y);
	word.width = x;
	word.height = y;
	word.stringExtent = stringExtent;
	GC g = new GC(img);
	g.setAntialias(antialias);
	g.setForeground(color);
	Transform t = new Transform(img.getDevice());
	if (word.angle < 0) {
		t.translate(0, img.getBounds().height - (int) (cos * stringExtent.y));
	} else {
		t.translate((int) (sin * stringExtent.y), 0);
	}
	t.rotate(word.angle);
	g.setTransform(t);
	g.setFont(font);
	// Why is drawString so slow? between 30 and 90 percent of the whole
	// draw time...
	g.drawString(word.string, 0, 0, false);
	int max = Math.max(x, y);
	int tmp = maxSize;
	while (max < tmp) {
		tmp = tmp / 2;
	}
	tmp = tmp * 2;
	SmallRect root = new SmallRect(0, 0, tmp, tmp);
	word.tree = new RectTree(root, accuracy);
	final ImageData id = img.getImageData();
	g.dispose();
	img.dispose();
	return id;
}
 
Example 6
Source File: InteractiveDecorator.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * TODO: move to UtilityClass
 * 
 * This method disposes the input image and returns a new Image.
 * 
 * @param image
 * @param width
 * @param height
 * @return
 */
protected Image resize(Image image, int width, int height) {
	Image scaled = new Image(image.getDevice(), width, height);
	GC gc = new GC(scaled);
	gc.setAntialias(SWT.ON);
	gc.setInterpolation(SWT.HIGH);
	gc.drawImage(image, 0, 0, image.getBounds().width,
			image.getBounds().height, 0, 0, width, height);
	gc.dispose();
	image.dispose();
	return scaled;
}
 
Example 7
Source File: SharedProjectFileDecorator.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
/** Returns null, if the image is not a RGB image with 8 Bit per color value */
private static Image tintImage(Image image, Color color) {
  ImageData data = image.getImageData();
  int red = color.getRed();
  int green = color.getGreen();
  int blue = color.getBlue();

  if (data.depth < 24 || !data.palette.isDirect) return null;

  int rs = data.palette.redShift;
  int gs = data.palette.greenShift;
  int bs = data.palette.blueShift;
  int rm = data.palette.redMask;
  int gm = data.palette.greenMask;
  int bm = data.palette.blueMask;

  if (rs < 0) rs = ~rs + 1;

  if (gs < 0) gs = ~gs + 1;

  if (bs < 0) bs = ~bs + 1;

  for (int x = 0; x < data.width; x++) {
    for (int y = 0; y < data.height; y++) {
      int p = data.getPixel(x, y);
      int r = (p & rm) >>> rs;
      int g = (p & gm) >>> gs;
      int b = (p & bm) >>> bs;
      r = (r * red) / 255;
      g = (g * green) / 255;
      b = (b * blue) / 255;
      data.setPixel(x, y, (r << rs) | (g << gs) | (b << bs));
    }
  }

  return new Image(image.getDevice(), data);
}