001: /*
002: * @(#)QtRobotHelper.java 1.5 04/08/19
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 sun.awt.qt;
028:
029: import java.awt.*;
030: import java.awt.image.*;
031: import java.awt.event.*;
032:
033: import sun.awt.RobotHelper;
034:
035: public class QtRobotHelper extends RobotHelper {
036: GraphicsDevice qtDevice;
037:
038: public static native void init();
039:
040: public native void doMouseActionNative(int x, int y, int buttons,
041: boolean pressed);
042:
043: public void doMouseAction(int x, int y, int buttons, boolean pressed) {
044: doMouseActionNative(x, y, buttons, pressed);
045: }
046:
047: native int getPixel(int x, int y);
048:
049: public native void getPixelsNative(int pixelArray[], int x, int y,
050: int width, int height);
051:
052: public void getPixels(int pixelArray[], int x, int y, int width,
053: int height) {
054: getPixelsNative(pixelArray, x, y, width, height);
055: }
056:
057: public native void doKeyActionNative(int keySym, boolean pressed);
058:
059: public void doKeyAction(int keySym, boolean pressed) {
060: doKeyActionNative(keySym, pressed);
061: }
062:
063: public native void doKeyActionOnWidget(int KeySym, int widgetType,
064: boolean pressed);
065:
066: static {
067: //java.security.AccessController.doPrivileged
068: // (new sun.security.action.LoadLibraryAction("qtrobot"));
069: //System.out.println("Successfully loaded qtrobot lib");
070: init();
071: }
072:
073: public QtRobotHelper(GraphicsDevice graphicsDevice)
074: throws AWTException {
075: // if (!(graphicsDevice instanceof QtGraphicsDevice)) {
076: // throw new
077: // IllegalArgumentException("screen device is not on QT");
078: // }
079: qtDevice = graphicsDevice;
080: }
081:
082: public BufferedImage getScreenImage(Rectangle screenRect) {
083:
084: GraphicsConfiguration graphicsConfiguration = qtDevice
085: .getDefaultConfiguration();
086:
087: BufferedImage image = graphicsConfiguration
088: .createCompatibleImage(screenRect.width,
089: screenRect.height);
090: int rgbArray[] = new int[screenRect.width * screenRect.height];
091: /* get the pixels */
092:
093: getPixels(rgbArray, screenRect.x, screenRect.y,
094: screenRect.width, screenRect.height);
095: /* and copy them to the image */
096:
097: image.setRGB(0, 0, screenRect.width, screenRect.height,
098: rgbArray, 0, screenRect.width);
099: return image;
100: }
101:
102: public Color getPixelColor(int x, int y) {
103: int pixelValue = getPixel(x, y);
104: ColorModel cm = qtDevice.getDefaultConfiguration()
105: .getColorModel();
106: Color color = new Color(cm.getRGB(pixelValue));
107: //return new Color(cm.getRGB(pixelValue));
108: return color;
109: }
110:
111: }
|