Source Code Cross Referenced for Robot.java in  » Apache-Harmony-Java-SE » java-package » java » awt » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.awt 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Pavel Dolgov, Dmitry A. Durnev
019:         * @version $Revision$
020:         */package java.awt;
021:
022:        import java.awt.event.InputEvent;
023:        import java.awt.image.BufferedImage;
024:        import java.lang.reflect.InvocationTargetException;
025:
026:        import org.apache.harmony.awt.internal.nls.Messages;
027:        import org.apache.harmony.awt.wtk.NativeRobot;
028:
029:        public class Robot {
030:
031:            private int autoDelay;
032:            private boolean autoWaitForIdle;
033:
034:            private final NativeRobot nativeRobot;
035:
036:            public Robot() throws AWTException {
037:                this (GraphicsEnvironment.getLocalGraphicsEnvironment()
038:                        .getDefaultScreenDevice());
039:            }
040:
041:            public Robot(GraphicsDevice screen) throws AWTException {
042:                Toolkit.checkHeadless();
043:                if ((screen == null)
044:                        || (screen.getType() != GraphicsDevice.TYPE_RASTER_SCREEN)) {
045:                    // awt.129=Not a screen device
046:                    throw new IllegalArgumentException(Messages
047:                            .getString("awt.129")); //$NON-NLS-1$
048:                }
049:                SecurityManager sm = System.getSecurityManager();
050:                if (sm != null) {
051:                    sm.checkPermission(new AWTPermission("createRobot")); //$NON-NLS-1$
052:                }
053:                // create(or get) native robot instance
054:                // for the specified screen
055:                Toolkit tk = Toolkit.getDefaultToolkit();
056:                nativeRobot = tk.getWTK().getNativeRobot(screen);
057:            }
058:
059:            @Override
060:            public String toString() {
061:                /* The format is based on 1.5 release behavior 
062:                 * which can be revealed by the following code:
063:                 * System.out.println(new Robot());
064:                 */
065:
066:                return getClass().getName() + "[" + "autoDelay = " + autoDelay + //$NON-NLS-1$ //$NON-NLS-2$
067:                        ", autoWaitForIdle = " + autoWaitForIdle + "]"; //$NON-NLS-1$ //$NON-NLS-2$
068:            }
069:
070:            public BufferedImage createScreenCapture(Rectangle screenRect) {
071:                SecurityManager sm = System.getSecurityManager();
072:                if (sm != null) {
073:                    sm.checkPermission(new AWTPermission("readDisplayPixels")); //$NON-NLS-1$
074:                }
075:                if (screenRect.isEmpty()) {
076:                    // awt.13D=Rectangle width and height must be > 0
077:                    throw new IllegalArgumentException(Messages
078:                            .getString("awt.13D")); //$NON-NLS-1$
079:                }
080:
081:                return nativeRobot.createScreenCapture(screenRect);
082:            }
083:
084:            public void delay(int ms) {
085:                checkDelay(ms);
086:                try {
087:                    Thread.sleep(ms);
088:                } catch (InterruptedException e) {
089:                }
090:            }
091:
092:            public int getAutoDelay() {
093:                return autoDelay;
094:            }
095:
096:            public Color getPixelColor(int x, int y) {
097:                return nativeRobot.getPixel(x, y);
098:            }
099:
100:            public boolean isAutoWaitForIdle() {
101:                return autoWaitForIdle;
102:            }
103:
104:            public void keyPress(int keycode) {
105:                nativeRobot.keyEvent(keycode, true);
106:                doWait();
107:            }
108:
109:            public void keyRelease(int keycode) {
110:                nativeRobot.keyEvent(keycode, false);
111:                doWait();
112:            }
113:
114:            public void mouseMove(int x, int y) {
115:                nativeRobot.mouseMove(x, y);
116:                doWait();
117:            }
118:
119:            public void mousePress(int buttons) {
120:                checkButtons(buttons);
121:                nativeRobot.mouseButton(buttons, true);
122:                doWait();
123:            }
124:
125:            public void mouseRelease(int buttons) {
126:                checkButtons(buttons);
127:                nativeRobot.mouseButton(buttons, false);
128:                doWait();
129:            }
130:
131:            public void mouseWheel(int wheelAmt) {
132:                nativeRobot.mouseWheel(wheelAmt);
133:                doWait();
134:            }
135:
136:            public void setAutoDelay(int ms) {
137:                checkDelay(ms);
138:                autoDelay = ms;
139:            }
140:
141:            public void setAutoWaitForIdle(boolean isOn) {
142:                autoWaitForIdle = isOn;
143:            }
144:
145:            public void waitForIdle() {
146:                if (EventQueue.isDispatchThread()) {
147:                    // awt.13E=Cannot call method from the event dispatcher thread
148:                    throw new IllegalThreadStateException(Messages
149:                            .getString("awt.13E")); //$NON-NLS-1$
150:                }
151:                try {
152:                    EventQueue.invokeAndWait(new Runnable() {
153:
154:                        public void run() {
155:                            // just do nothing
156:                        }
157:
158:                    });
159:                } catch (InterruptedException e) {
160:                    e.printStackTrace();
161:                } catch (InvocationTargetException e) {
162:                    e.printStackTrace();
163:                }
164:            }
165:
166:            private void checkDelay(int ms) {
167:                if ((ms < 0) || (ms > 60000)) {
168:                    // awt.13F=Delay must be to 0 to 60,000ms
169:                    throw new IllegalArgumentException(Messages
170:                            .getString("awt.13F")); //$NON-NLS-1$
171:                }
172:            }
173:
174:            private void checkButtons(int buttons) {
175:                int mask = (InputEvent.BUTTON1_MASK | InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK);
176:                if ((buttons & mask) != buttons) {
177:                    // awt.140=Invalid combination of button flags
178:                    throw new IllegalArgumentException(Messages
179:                            .getString("awt.140")); //$NON-NLS-1$
180:                }
181:            }
182:
183:            private void doWait() {
184:                // first wait for idle if necessary:
185:                if (isAutoWaitForIdle()) {
186:                    waitForIdle();
187:                }
188:                // now sleep if autoDelay is > 0
189:                int delay = getAutoDelay();
190:                if (delay > 0) {
191:                    delay(delay);
192:                }
193:            }
194:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.