Java Code Examples for org.eclipse.swt.graphics.GC#copyArea()

The following examples show how to use org.eclipse.swt.graphics.GC#copyArea() . 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: VButtonImageBak.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
public void handleEvent(Event e) {
	GC gc = new GC(b);
	Image image = new Image(b.getDisplay(), e.width, e.height);
	gc.copyArea(image, 0, 0);
	ImageData data = image.getImageData();
	gc.dispose();
	image.dispose();
	images.put(key, data);
	keys.put(data, key);
	if(requests.containsKey(key)) {
		for(Iterator<VButton> iter = requests.get(key).iterator(); iter.hasNext();) {
			iter.next().redraw();
			iter.remove();
		}
		requests.remove(key);
	}
	Display.getDefault().asyncExec(new Runnable() {
		public void run() {
			if(!b.isDisposed() && b == b.getDisplay().getFocusControl()) {
				b.getParent().forceFocus();
			}
			b.dispose();
		}
	});
}
 
Example 2
Source File: TransitionTest1.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
private void setCompImage(Composite comp) {
    int index = -1;
    if (comp == comp1) {
        index = 0;
    } else if (comp == comp2) {
        index = 1;
    } else if (comp == comp3) {
        index = 2;
    }
    if (index > -1) {
        tf.setSelection(index);
        
        comp.redraw();
        comp.getDisplay().update();
        comp.getDisplay().readAndDispatch();
        
        Image image = new Image(comp.getDisplay(),
                comp.getBounds().width, comp.getBounds().height);
        GC gc = new GC(comp);
        gc.copyArea(image, 0, 0);
        gc.dispose();
        
        compImage[index] = image;
    }
}
 
Example 3
Source File: ImageWriter.java    From logbook with MIT License 6 votes vote down vote up
/**
 * 指定されたcontrolを画像イメージとして書き込みます。
 *
 * @param control
 *            画像イメージとして書き込むControl
 * @throws IOException
 */
public void write(Control control) throws IOException {
    Point size = control.getSize();
    GC gc = new GC(control);
    try {
        Image image = new Image(Display.getDefault(), size.x, size.y);
        try {
            gc.copyArea(image, 0, 0);
            this.write(image);
        } finally {
            image.dispose();
        }
    } finally {
        gc.dispose();
    }
}
 
Example 4
Source File: ImageExportAction.java    From olca-app with Mozilla Public License 2.0 6 votes vote down vote up
@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 5
Source File: BlurredPanel.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
private Image createBlurredImage() {
	final GC gc = new GC(parent);
	final Image image = new Image(parent.getDisplay(), parent.getSize().x, parent.getSize().y);
	gc.copyArea(image, 0, 0);
	gc.dispose();

	return new Image(parent.getDisplay(), SWTGraphicUtil.blur(image.getImageData(), radius));

}
 
Example 6
Source File: ViewFreezer.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public void freeze() {
	release();
	if (sourceViewer instanceof SourceViewer) {
		Control viewerControl = ((SourceViewer) sourceViewer).getControl();
		if (viewerControl instanceof Composite) {
			Composite composite = (Composite) viewerControl;
			Display display = composite.getDisplay();

			// Flush pending redraw requests:
			while (!display.isDisposed() && display.readAndDispatch()) {
			}

			// Copy editor area:
			GC gc = new GC(composite);
			Point size;
			try {
				size = composite.getSize();
				image = new Image(gc.getDevice(), size.x, size.y);
				gc.copyArea(image, 0, 0);
			} finally {
				gc.dispose();
				gc = null;
			}

			// Persist editor area while executing refactoring:
			label = new Label(composite, SWT.NONE);
			label.setImage(image);
			label.setBounds(0, 0, size.x, size.y);
			label.moveAbove(null);
		}
	}
}
 
Example 7
Source File: CaptureDialog.java    From logbook with 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 8
Source File: SetCheckPoint2.java    From AndroidRobot with Apache License 2.0 5 votes vote down vote up
public void drawRectangle(GC gc) {
    offsetX = endX - startX;
    offsetY = endY - startY;
    if (gc != null) {
        gc.setLineWidth(3);
        gc.setForeground(new Color(Display.getDefault(), 255, 0, 0));
        setParams(startX, startY, offsetX, offsetY);
        gc.drawRectangle(startX, startY, offsetX, offsetY);
        tempImage = new Image(Display.getDefault(),
            ClassLoader.getSystemResourceAsStream("icons/temp.png"));
        gc.copyArea(tempImage, 0, 0);
        imagesList.add(image);
    }
}
 
Example 9
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Notice: Please dispose the image after done.
 * 
 * @param composite
 * @return
 */
public static Image newImageFromComposite( Composite composite )
{
	Point compositeSize = composite.getSize( );
	GC gc = new GC( composite );
	Image image = new Image( Display.getCurrent( ),
			compositeSize.x,
			compositeSize.y );
	gc.copyArea( image, 0, 0 );
	gc.dispose( );
	return image;
}
 
Example 10
Source File: AbstractVTestCase.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
private void capture(Rectangle bounds, String suffix) {
	GC gc = new GC(display);
	Image image = new Image(display, bounds);
	gc.copyArea(image, bounds.x, bounds.y);
	gc.dispose();

	ImageData[] da = new ImageData[] { image.getImageData() };
	image.dispose();

	ImageLoader il = new ImageLoader();
	il.data = da;

	StringBuilder sb = new StringBuilder();
	if (capturePath != null && capturePath.length() > 0) {
		sb.append(capturePath);
	} else {
		sb.append(System.getProperty("user.home"));
	}

	File path = new File(sb.toString());
	if (!path.exists()) {
		path.mkdirs();
	}

	sb.append(File.separator);
	sb.append(getName());
	if (suffix != null && suffix.length() > 0) {
		sb.append("-").append(suffix);
	}
	switch (captureFormat) {
	case SWT.IMAGE_BMP:
		sb.append(".bmp");
		break;
	case SWT.IMAGE_GIF:
		sb.append(".gif");
		break;
	case SWT.IMAGE_ICO:
		sb.append(".ico");
		break;
	case SWT.IMAGE_JPEG:
		sb.append(".jpg");
		break;
	case SWT.IMAGE_PNG:
		sb.append(".png");
		break;
	case SWT.IMAGE_TIFF:
		sb.append(".tiff");
		break;
	default:
		captureFormat = SWT.IMAGE_PNG;
		sb.append(".png");
		break;
	}

	il.save(sb.toString(), captureFormat);
}
 
Example 11
Source File: EmulatedNativeCheckBoxLabelProvider.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
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;
}