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

The following examples show how to use org.eclipse.swt.graphics.Image#dispose() . These examples are extracted from open source projects. 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
@Override
public void run() {
	if (composite == null)
		return;

	log.trace("Take image snapshot");
	Point size = composite.getSize();
	Image image = new Image(composite.getDisplay(), size.x, size.y);
	GC gc = new GC(composite);
	gc.copyArea(image, 0, 0);

	try {
		writeToFile(image);
	} catch (Exception e) {
		log.error("Failed to save export image", e);
	} finally {
		gc.dispose();
		image.dispose();
	}
}
 
Example 2
@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 3
@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 4
/**
 * Disposes all images managed by this registry.
 */	
public void dispose() {
	for (Image image : fRegistry.values()) {
		image.dispose();
	}
	fRegistry.clear();
}
 
Example 5
private void repaint(Event event) {
	GC gc = event.gc;
	if (mCreated && mEnableDoubleBuffering) {
		try {
			Image buffer = new Image(Display.getDefault(), super.getBounds());
			GC gc2 = new GC(buffer);
			drawOntoGC(gc2);

			// transfer the image buffer onto this canvas
			// just drawImage(buffer, w, h) didn't work, so we do the whole
			// source transfer call
			Rectangle b = getBounds();
			gc.drawImage(buffer, 0, 0, b.width, b.height, 0, 0, b.width, b.height);

			// dispose the buffer, very important or we'll run out of
			// address space for buffered images
			buffer.dispose();
			gc2.dispose();
		} catch (IllegalArgumentException iea) {
			// seems to come here for some reason when we switch phases
			// while the gantt chart is being viewed, I'm not sure why
			// but no time to figure it out for the demo.. so instead of
			// buffering, just draw it onto the GC
			drawOntoGC(gc);
		}
	} else {
		drawOntoGC(gc);
		mCreated = true;

	}
}
 
Example 6
Source Project: hop   File: ImageUtil.java    License: Apache License 2.0 5 votes vote down vote up
public static Image makeImageTransparent( Display display, Image tempImage, RGB transparentColor ) {
  ImageData imageData = tempImage.getImageData();
  int pixelIndex = imageData.palette.getPixel( transparentColor );
  imageData.transparentPixel = pixelIndex;
  Image image = new Image( display, imageData );
  tempImage.dispose();
  return image;
}
 
Example 7
Source Project: birt   File: SampleReportCanvas.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void setSampleImage( Image sampleImage )
{
	Image oldImage = this.sampleImage;
	this.sampleImage = sampleImage;
	if ( oldImage != null && oldImage != sampleImage )
	{
		oldImage.dispose( );
	}
}
 
Example 8
Source Project: logbook   File: CaptureDialog.java    License: MIT License 5 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent paramSelectionEvent) {
    try {
        Display display = Display.getDefault();
        // ダイアログを非表示にする
        CaptureDialog.this.shell.setVisible(false);
        // 消えるまで待つ
        Thread.sleep(WAIT);
        // ディスプレイに対してGraphics Contextを取得する(フルスクリーンキャプチャ)
        GC gc = new GC(display);
        Image image = new Image(display, display.getBounds());
        gc.copyArea(image, 0, 0);
        gc.dispose();

        try {
            // 範囲を取得する
            Rectangle rectangle = new FullScreenDialog(CaptureDialog.this.shell, image,
                    CaptureDialog.this.shell.getMonitor())
                            .open();

            if ((rectangle != null) && (rectangle.width > 1) && (rectangle.height > 1)) {
                CaptureDialog.this.rectangle = rectangle;
                CaptureDialog.this.text.setText("(" + rectangle.x + "," + rectangle.y + ")-("
                        + (rectangle.x + rectangle.width) + "," + (rectangle.y + rectangle.height) + ")");
                CaptureDialog.this.capture.setEnabled(true);
            }
        } finally {
            image.dispose();
        }
        CaptureDialog.this.shell.setVisible(true);
        CaptureDialog.this.shell.setActive();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 9
/**
 * Disposes the cached images and clears the cache.
 */
public static void clearCachedImages() {

  for (Image image : CACHED_IMAGES.values()) {
    image.dispose();
  }

  CACHED_IMAGES.clear();
}
 
Example 10
/**
 * Disposes of all images in the cache.
 */
public void disposeAll() {
	for (Iterator it = cache.values().iterator(); it.hasNext();) {
		Image image = (Image) it.next();
		image.dispose();
	}
	cache.clear();
}
 
Example 11
public void dispose() {
	Iterator iter = images.iterator();
	while(iter.hasNext()) {
		Image image = (Image)iter.next();
		image.dispose();
	}
	super.dispose();
}
 
Example 12
/**
 * Dispose of resources.
 */
public void dispose() {
	for (int i=0; i<imageNames.length; i++) {
		String imageName = imageNames[i];
		Image image = (Image) images.get(imageName);
		image.dispose();
		images.remove(imageName);
	}
}
 
Example 13
Source Project: nebula   File: CTree.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void paintBody(Event e) {
	if(!addedItems.isEmpty()) addItems();
	if(!removedItems.isEmpty()) removeItems();
	
	int top = ((vBar == null || vBar.isDisposed()) ? -1 : vBar.getSelection());
	int height = getClientArea().height;
	if(updatePaintedList || topOld != top || heightOld != height) {
		updatePaintedList = false;
		topOld = top;
		heightOld = height;
		updatePaintedItems();
	}

	Rectangle ebounds = e.getBounds();
	Image image = new Image(e.display, ebounds);
	GC gc = new GC(image);

	paintBackground(gc, ebounds);
	if(paintGridAsBackground) paintGridLines(gc, ebounds);
	paintItemBackgrounds(gc, ebounds);
	paintSelectionIndicators(gc, ebounds);
	paintColumns(gc, ebounds);
	paintItems(gc, ebounds);
	if(!paintGridAsBackground) paintGridLines(gc, ebounds);
	paintViewport(gc, ebounds);
	paintFocus(gc, ebounds);

	e.gc.drawImage(image, ebounds.x, ebounds.y);
	gc.dispose();
	image.dispose();
}
 
Example 14
/**
 * Dispose all of the cached images.
 */
public static void disposeImages() {
	SWTResourceManager.disposeImages();
	// dispose ImageDescriptor images
	{
		for (Iterator<Image> I = m_descriptorImageMap.values().iterator(); I.hasNext();) {
			I.next().dispose();
		}
		m_descriptorImageMap.clear();
	}
	// dispose decorated images
	for (int i = 0; i < m_decoratedImageMap.length; i++) {
		Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
		if (cornerDecoratedImageMap != null) {
			for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) {
				for (Image image : decoratedMap.values()) {
					image.dispose();
				}
				decoratedMap.clear();
			}
			cornerDecoratedImageMap.clear();
		}
	}
	// dispose plugin images
	{
		for (Iterator<Image> I = m_URLImageMap.values().iterator(); I.hasNext();) {
			I.next().dispose();
		}
		m_URLImageMap.clear();
	}
}
 
Example 15
Source Project: birt   File: RotatedTextImageUI.java    License: Eclipse Public License 1.0 5 votes vote down vote up
public void disposeImage( ExtendedItemHandle handle, Image image )
{
	if ( image != null && !image.isDisposed( ) )
	{
		image.dispose( );
	}

}
 
Example 16
private Image makeShot(Control control, boolean type) {
    /* Hopefully no platform uses exactly this color because we'll make
       it transparent in the image.*/
    Color greenScreen = new Color(control.getDisplay(), 222, 223, 224);

    shell = new Shell(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
            SWT.NO_TRIM | SWT.NO_BACKGROUND);

    // otherwise we have a default gray color
    shell.setBackground(greenScreen);

    Button button = new Button(shell, SWT.CHECK | SWT.NO_BACKGROUND);
    button.setBackground(greenScreen);
    button.setSelection(type);

    // otherwise an image is located in a corner
    button.setLocation(1, 1);
    Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);

    // otherwise an image is stretched by width
    bsize.x = Math.max(bsize.x - 1, bsize.y - 1);
    bsize.y = Math.max(bsize.x - 1, bsize.y - 1);
    button.setSize(bsize);

    GC gc = new GC(shell);
    Point shellSize = new Point(32, 32);
    shell.setSize(shellSize);
    shell.open();

    Image image = new Image(control.getDisplay(), bsize.x, bsize.y);
    gc.copyArea(image, 0, 0);
    gc.dispose();
    shell.close();

    ImageData imageData = image.getImageData();
    imageData.transparentPixel = imageData.palette.getPixel(greenScreen
            .getRGB());

    Image img = new Image(control.getDisplay(), imageData);
    image.dispose();

    return img;
}
 
Example 17
@Override
protected void paintFigure(Graphics graphics) {
	double stroke = getPreferredSize().width *(strokeWidth > 0 ? strokeWidth : 2.0)/ getClientArea().getSize().width ;

	Document document = getDocument();
	if(document!= null && foregroundColor != null && backgroundColor != null){

		if(!foundBgElement) {

			border = document.getElementById("BORDER");
			Element svgid_1_ = document.getElementById("SVGID_1_");
			NodeList stop = svgid_1_.getElementsByTagName("stop");
			bgStyleNode = stop.item(0).getAttributes().getNamedItem("style");
			foundBgElement  = true;
		}

		if(border != null){
			border.setAttribute("stroke", foregroundColor) ;
			if(stroke > 0){
				border.setAttribute("stroke-width", String.valueOf(stroke)) ;
			}
		}

		if(bgStyleNode != null){
			bgStyleNode.setNodeValue("stop-color:"+backgroundColor) ;
		}
	}

	if(document != null) {
		Image image = null;

		try {
			Rectangle r = this.getClientArea();
			this.transcoder.setCanvasSize(this.specifyCanvasWidth?r.width:-1, this.specifyCanvasHeight?r.height:-1);
			this.updateRenderingHints(graphics);
			BufferedImage awtImage = this.transcoder.getBufferedImage();
			if(awtImage != null) {
				image = toSWT(Display.getCurrent(), awtImage);
				graphics.drawImage(image, r.x, r.y);
			}
		} finally {
			if(image != null) {
				image.dispose();
			}

			document = null;
		}

	}
}
 
Example 18
protected void drawCompositeImage(int width, int height) {
  Display display = fParentComposite.getDisplay();

  Image image = new Image(display, ARROW_SIZE, ARROW_SIZE * 2);

  GC gc = new GC(image);

  Color triangle = createColor(SWT.COLOR_LIST_FOREGROUND,
      SWT.COLOR_LIST_BACKGROUND, 20, display);
  Color aliasing = createColor(SWT.COLOR_LIST_FOREGROUND,
      SWT.COLOR_LIST_BACKGROUND, 30, display);
  gc.setBackground(triangle);

  if (fLTR) {
    gc.fillPolygon(new int[] {
        mirror(0), 0, mirror(ARROW_SIZE), ARROW_SIZE, mirror(0),
        ARROW_SIZE * 2});
  } else {
    gc.fillPolygon(new int[] {
        ARROW_SIZE, 0, 0, ARROW_SIZE, ARROW_SIZE, ARROW_SIZE * 2});
  }

  gc.setForeground(aliasing);
  gc.drawLine(mirror(0), 1, mirror(ARROW_SIZE - 1), ARROW_SIZE);
  gc.drawLine(mirror(ARROW_SIZE - 1), ARROW_SIZE, mirror(0),
      ARROW_SIZE * 2 - 1);

  gc.dispose();
  triangle.dispose();
  aliasing.dispose();

  ImageData imageData = image.getImageData();
  for (int y = 1; y < ARROW_SIZE; y++) {
    for (int x = 0; x < y; x++) {
      imageData.setAlpha(mirror(x), y, 255);
    }
  }
  for (int y = 0; y < ARROW_SIZE; y++) {
    for (int x = 0; x <= y; x++) {
      imageData.setAlpha(mirror(x), ARROW_SIZE * 2 - y - 1, 255);
    }
  }

  int offset = fLTR ? 0 : -1;
  drawImage(imageData, (width / 2) - (ARROW_SIZE / 2) + offset,
      (height / 2) - ARROW_SIZE - 1);

  image.dispose();
}
 
Example 19
public static void main(String[] args) {
	Display display = new Display();
	Image itemImage = new Image(display, Program
			.findProgram("jpg").getImageData()); //$NON-NLS-1$

	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	Gallery gallery = new Gallery(shell, SWT.V_SCROLL | SWT.MULTI);

	// Renderers
	DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
	gr.setMinMargin(2);
	gr.setItemHeight(56);
	gr.setItemWidth(72);
	gr.setAutoMargin(true);
	gallery.setGroupRenderer(gr);

	DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
	gallery.setItemRenderer(ir);

	for (int g = 0; g < 2; g++) {
		GalleryItem group = new GalleryItem(gallery, SWT.NONE);
		group.setText("Group " + g); //$NON-NLS-1$
		group.setExpanded(true);

		for (int i = 0; i < 50; i++) {
			GalleryItem item = new GalleryItem(group, SWT.NONE, 0);
			if (itemImage != null) {
				item.setImage(itemImage);
			}
			item.setText("Item " + i); //$NON-NLS-1$
		}
	}

	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}

	if (itemImage != null)
		itemImage.dispose();

	display.dispose();
}
 
Example 20
public static void main(String[] args) {
	Display display = new Display();
	Image itemImage = new Image(display, Program.findProgram("jpg") //$NON-NLS-1$
			.getImageData());

	Shell shell = new Shell(display);
	shell.setLayout(new FillLayout());
	Gallery gallery = new Gallery(shell, SWT.H_SCROLL | SWT.MULTI);

	// Renderers
	DefaultGalleryGroupRenderer gr = new DefaultGalleryGroupRenderer();
	gr.setMinMargin(2);
	gr.setItemHeight(56);
	gr.setItemWidth(72);
	gr.setAutoMargin(true);

	gallery.setGroupRenderer(gr);

	DefaultGalleryItemRenderer ir = new DefaultGalleryItemRenderer();
	gallery.setItemRenderer(ir);

	for (int g = 0; g < 3; g++) {
		GalleryItem group = new GalleryItem(gallery, SWT.NONE);
		group.setText("Group " + g); //$NON-NLS-1$
		group.setExpanded(true);
		group.setImage(itemImage);

		if (g > 0)
			group.setText(1, "descr1"); //$NON-NLS-1$

		if (g > 1)
			group.setText(2, "descr2"); //$NON-NLS-1$

		for (int i = 0; i < 50; i++) {
			GalleryItem item = new GalleryItem(group, SWT.NONE);
			if (itemImage != null) {
				item.setImage(itemImage);
			}
			item.setText("Item " + i); //$NON-NLS-1$
		}
	}

	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}

	if (itemImage != null)
		itemImage.dispose();
	display.dispose();
}