001: /*
002: * @(#)QtRobotHelper.java 1.8 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package java.awt;
028:
029: import java.awt.*;
030: import java.awt.image.*;
031: import java.awt.event.*;
032:
033: import sun.awt.RobotHelper;
034:
035: class QtRobotHelper extends RobotHelper {
036: QtGraphicsDevice qtDevice;
037: Rectangle bounds;
038:
039: public static native void init();
040:
041: public native void doMouseActionNative(int x, int y, int buttons,
042: boolean pressed);
043:
044: public void doMouseAction(int x, int y, int buttons, boolean pressed) {
045: doMouseActionNative(x, y, buttons, pressed);
046: }
047:
048: private static native void pCreateScreenCapture(int screenPSD,
049: int imagePSD, int x, int y, int width, int height);
050:
051: private static native int pGetScreenPixel(int psd, int x, int y);
052:
053: //public native void doKeyAction(int keySym, boolean pressed);
054: public native void doKeyActionNative(int keySym, boolean pressed);
055:
056: public void doKeyAction(int keySym, boolean pressed) {
057: doKeyActionNative(keySym, pressed);
058: }
059:
060: public native void doKeyActionOnWidget(int KeySym, int widgetType,
061: boolean pressed);
062:
063: static {
064: init();
065: }
066:
067: public QtRobotHelper(GraphicsDevice graphicsDevice)
068: throws AWTException {
069: if (graphicsDevice.getClass().getName().indexOf(
070: "QtGraphicsDevice") == -1) {
071: throw new IllegalArgumentException(
072: "screen device is not on QT");
073: }
074: qtDevice = (QtGraphicsDevice) graphicsDevice;
075: }
076:
077: public BufferedImage getScreenImage(Rectangle screenRect) {
078:
079: /* clip the region based on PBP's frame bounds */
080: if (bounds == null)
081: bounds = qtDevice.getDefaultConfiguration().getBounds();
082: screenRect = screenRect.intersection(bounds);
083:
084: QtImage image = new QtImage(screenRect.width,
085: screenRect.height, (QtGraphicsConfiguration) qtDevice
086: .getDefaultConfiguration());
087:
088: pCreateScreenCapture(qtDevice.psd, image.psd, screenRect.x,
089: screenRect.y, screenRect.width, screenRect.height);
090: /* return subImage, to get a BufferedImage object */
091: return image.getSubimage(0, 0, screenRect.width,
092: screenRect.height);
093: }
094:
095: public Color getPixelColor(int x, int y) {
096: ColorModel cm = qtDevice.getDefaultConfiguration()
097: .getColorModel();
098: int rgb;
099: rgb = pGetScreenPixel(qtDevice.psd, x, y);
100: Color color = new Color(cm.getRGB(rgb));
101:
102: return color;
103: }
104: }
|