Java Code Examples for java.awt.Window#paint()

The following examples show how to use java.awt.Window#paint() . 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: RemoteAWTService.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static Snapshot[] getGUISnapshots() {
    List snapshots = new ArrayList();   //System.err.println("gGUI: thread = "+Thread.currentThread());
    Window[] windows = Window.getWindows(); //System.err.println("gGUI: windows = "+windows.length);
    for (int wi = 0; wi < windows.length; wi++) {
        Window w = windows[wi]; //System.err.println("gGUI: w["+wi+"] = "+w+", is visible = "+w.isVisible());
        if (!w.isVisible()) {
            continue;
        }
        Dimension d = w.getSize();  //System.err.println("gGUI:  size = "+d);
        if (d.width == 0 || d.height == 0) {
            continue;
        }
        BufferedImage bi = new BufferedImage(d.width, d.height, BufferedImage.TYPE_INT_ARGB);
        Graphics2D g = bi.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_DEFAULT);
        w.paint(g);
        Raster raster = bi.getData();
        Object data = raster.getDataElements(0, 0, d.width, d.height, null);
        int[] dataArr;  //System.err.println("gGUI: data = "+data);
        if (data instanceof int[]) {
            dataArr = (int[]) data;
        } else {
            continue;
        }
        String title = null;
        if (w instanceof Frame) {
            title = ((Frame) w).getTitle();
        } else if (w instanceof Dialog) {
            title = ((Dialog) w).getTitle();
        }   //System.err.println("gGUI: title = "+title);
        snapshots.add(new Snapshot(w, title, d.width, d.height, dataArr));
    }
    Snapshot[] snapshotArr = (Snapshot[]) snapshots.toArray(new Snapshot[] {});
    lastGUISnapshots = snapshotArr;
    return snapshotArr;
}
 
Example 2
Source File: DragWindow.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private BufferedImage createTabImage() {
    GraphicsConfiguration config = GraphicsEnvironment.getLocalGraphicsEnvironment()
                .getDefaultScreenDevice().getDefaultConfiguration();

    //the tab rectangle must be painted by top-level window otherwise the transparent 
    //button icons will be messed up
    Window parentWindow = SwingUtilities.getWindowAncestor(container.getComponent());
    Rectangle rect = SwingUtilities.convertRectangle(container.getComponent(), tabRectangle, parentWindow);
    BufferedImage res = config.createCompatibleImage(tabRectangle.width, tabRectangle.height);
    Graphics2D g = res.createGraphics();
    g.translate(-rect.x, -rect.y);
    g.setClip(rect);
    parentWindow.paint(g);
    return res;
}
 
Example 3
Source File: ReportManager.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method to screenshot a window into a buffer (must be called on the
 * EDT).
 * 
 * @param w
 *          the window to render
 * @return the rendered window.
 */
public static BufferedImage render(Window w) {
	// Don't use java.awt.Robot for this! We want the window itself, not what's
	// on screen.
	Dimension size = w.getSize();
	BufferedImage img = new BufferedImage(size.width, size.height,
			BufferedImage.TYPE_INT_ARGB);
	Graphics gr = img.createGraphics();
	w.paint(gr);
	gr.dispose();
	return img;
}