001: /*
002: * Copyright 1999-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.motif;
026:
027: import java.awt.*;
028: import java.awt.peer.*;
029: import java.security.*;
030: import sun.awt.X11GraphicsConfig;
031:
032: class MRobotPeer implements RobotPeer {
033: private X11GraphicsConfig xgc = null;
034: /*
035: * native implementation uses some static shared data (pipes, processes)
036: * so use a class lock to synchronize native method calls
037: */
038: static Object robotLock = new Object();
039:
040: MRobotPeer(GraphicsConfiguration gc) {
041: this .xgc = (X11GraphicsConfig) gc;
042: setup();
043: }
044:
045: public void dispose() {
046: // does nothing
047: }
048:
049: public void mouseMove(int x, int y) {
050: mouseMoveImpl(xgc, x, y);
051: }
052:
053: public void mousePress(int buttons) {
054: mousePressImpl(buttons);
055: }
056:
057: public void mouseRelease(int buttons) {
058: mouseReleaseImpl(buttons);
059: }
060:
061: public void mouseWheel(int wheelAmt) {
062: mouseWheelImpl(wheelAmt);
063: }
064:
065: public void keyPress(int keycode) {
066: keyPressImpl(keycode);
067: }
068:
069: public void keyRelease(int keycode) {
070: keyReleaseImpl(keycode);
071: }
072:
073: public int getRGBPixel(int x, int y) {
074: int pixelArray[] = new int[1];
075: getRGBPixelsImpl(xgc, x, y, 1, 1, pixelArray);
076: return pixelArray[0];
077: }
078:
079: public int[] getRGBPixels(Rectangle bounds) {
080: int pixelArray[] = new int[bounds.width * bounds.height];
081: getRGBPixelsImpl(xgc, bounds.x, bounds.y, bounds.width,
082: bounds.height, pixelArray);
083: return pixelArray;
084: }
085:
086: private static native synchronized void setup();
087:
088: private static native synchronized void mouseMoveImpl(
089: X11GraphicsConfig xgc, int x, int y);
090:
091: private static native synchronized void mousePressImpl(int buttons);
092:
093: private static native synchronized void mouseReleaseImpl(int buttons);
094:
095: private static native synchronized void mouseWheelImpl(int wheelAmt);
096:
097: private static native synchronized void keyPressImpl(int keycode);
098:
099: private static native synchronized void keyReleaseImpl(int keycode);
100:
101: private static native synchronized void getRGBPixelsImpl(
102: X11GraphicsConfig xgc, int x, int y, int width, int height,
103: int pixelArray[]);
104: }
|