001: /*
002: * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025: package sun.awt.X11;
026:
027: import java.awt.*;
028: import java.awt.peer.*;
029: import sun.awt.X11GraphicsConfig;
030:
031: class XRobotPeer implements RobotPeer {
032: private X11GraphicsConfig xgc = null;
033: /*
034: * native implementation uses some static shared data (pipes, processes)
035: * so use a class lock to synchronize native method calls
036: */
037: static Object robotLock = new Object();
038:
039: XRobotPeer(GraphicsConfiguration gc) {
040: this .xgc = (X11GraphicsConfig) gc;
041: setup();
042: }
043:
044: public void dispose() {
045: // does nothing
046: }
047:
048: public void mouseMove(int x, int y) {
049: mouseMoveImpl(xgc, x, y);
050: }
051:
052: public void mousePress(int buttons) {
053: mousePressImpl(buttons);
054: }
055:
056: public void mouseRelease(int buttons) {
057: mouseReleaseImpl(buttons);
058: }
059:
060: public void mouseWheel(int wheelAmt) {
061: mouseWheelImpl(wheelAmt);
062: }
063:
064: public void keyPress(int keycode) {
065: keyPressImpl(keycode);
066: }
067:
068: public void keyRelease(int keycode) {
069: keyReleaseImpl(keycode);
070: }
071:
072: public int getRGBPixel(int x, int y) {
073: int pixelArray[] = new int[1];
074: getRGBPixelsImpl(xgc, x, y, 1, 1, pixelArray);
075: return pixelArray[0];
076: }
077:
078: public int[] getRGBPixels(Rectangle bounds) {
079: int pixelArray[] = new int[bounds.width * bounds.height];
080: getRGBPixelsImpl(xgc, bounds.x, bounds.y, bounds.width,
081: bounds.height, pixelArray);
082: return pixelArray;
083: }
084:
085: private static native synchronized void setup();
086:
087: private static native synchronized void mouseMoveImpl(
088: X11GraphicsConfig xgc, int x, int y);
089:
090: private static native synchronized void mousePressImpl(int buttons);
091:
092: private static native synchronized void mouseReleaseImpl(int buttons);
093:
094: private static native synchronized void mouseWheelImpl(int wheelAmt);
095:
096: private static native synchronized void keyPressImpl(int keycode);
097:
098: private static native synchronized void keyReleaseImpl(int keycode);
099:
100: private static native synchronized void getRGBPixelsImpl(
101: X11GraphicsConfig xgc, int x, int y, int width, int height,
102: int pixelArray[]);
103: }
|