Source Code Cross Referenced for ScriptPage.java in  » XML-UI » xui32 » com » xoetrope » carousel » testpilot » 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 » XML UI » xui32 » com.xoetrope.carousel.testpilot 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.xoetrope.carousel.testpilot;
002:
003:        import java.util.Collections;
004:        import java.util.HashMap;
005:        import java.util.Map;
006:        import java.util.StringTokenizer;
007:
008:        import java.awt.AWTException;
009:        import java.awt.Component;
010:        import java.awt.Container;
011:        import java.awt.Frame;
012:        import java.awt.GraphicsDevice;
013:        import java.awt.Robot;
014:        import java.awt.Window;
015:        import javax.swing.SwingUtilities;
016:
017:        import net.xoetrope.swing.XButton;
018:        import net.xoetrope.xui.XPage;
019:        import java.awt.GraphicsConfiguration;
020:        import java.util.Hashtable;
021:
022:        /**
023:         * Support for common scripting operations
024:         * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
025:         * the GNU Public License (GPL), please see license.txt for more details. If
026:         * you make commercial use of this software you must purchase a commercial
027:         * license from Xoetrope.</p>
028:         * <p> $Revision: 1.2 $</p>
029:         */
030:        public class ScriptPage extends XPage {
031:            protected Object mainClassObject;
032:            protected XButton btnStart, btnBack;
033:            private static Hashtable baseNames;
034:
035:            /** Hashmap of GraphicDevice's to Robot's. **/
036:            protected static Map robots = Collections
037:                    .synchronizedMap(new HashMap());
038:
039:            public ScriptPage() {
040:                if (baseNames == null)
041:                    baseNames = new Hashtable();
042:            }
043:
044:            /**
045:             * Set the instance of the class whose events are being recorded.
046:             * @param obj
047:             */
048:            public void setMainClassObject(Object obj) {
049:                if (mainClassObject != obj)
050:                    btnStart.setEnabled(obj != null);
051:                mainClassObject = obj;
052:            }
053:
054:            /**
055:             * Get a reference to a component for recording in the script
056:             * @param srcComp the component object
057:             * @return the name/reference
058:             */
059:            public String getComponentReference(Component srcComp) {
060:                String name = "";
061:                while (!(srcComp instanceof  Frame)) {
062:                    String compName = srcComp.getName();
063:                    Container parent = srcComp.getParent();
064:                    if ((compName != null) && (compName.length() > 0)
065:                            && !usesConstructedName(srcComp, compName)) {
066:                        name = "[" + compName + "]" + name;
067:                    } else {
068:                        Component[] children = parent.getComponents();
069:                        for (int i = 0; i < children.length; i++) {
070:                            if (children[i] == srcComp) {
071:                                name = "[" + Integer.toString(i) + "]" + name;
072:                                break;
073:                            }
074:                        }
075:                    }
076:                    srcComp = parent;
077:                }
078:
079:                return name;
080:            }
081:
082:            /**
083:             * Get the referenced component
084:             * @param compName the component name
085:             * @return the component object
086:             */
087:            public Component getReferenceComponent(String compName) {
088:                Component comp;
089:                Component parent = (Component) mainClassObject;
090:                if ((compName == null) || (compName.length() == 0))
091:                    return parent;
092:
093:                XPage page;
094:                StringTokenizer st = new StringTokenizer(compName, "]");
095:                while (st.hasMoreTokens()) {
096:                    String token = st.nextToken();
097:                    token = token.substring(1);
098:                    int compIdx = -1;
099:                    try {
100:                        compIdx = Integer.parseInt(token);
101:                    } catch (NumberFormatException ex) {
102:                    }
103:                    if (compIdx >= 0)
104:                        parent = ((Container) parent).getComponent(compIdx);
105:                    else {
106:                        // Try looking the component up by name
107:                        int numComponents = ((Container) parent)
108:                                .getComponentCount();
109:                        for (int i = 0; i < numComponents; i++) {
110:                            if (((Container) parent).getComponent(i).getName()
111:                                    .equals(token)) {
112:                                parent = ((Container) parent).getComponent(i);
113:                                break;
114:                            }
115:                        }
116:                    }
117:                }
118:                return parent;
119:            }
120:
121:            private boolean usesConstructedName(Component srcComp,
122:                    String compName) {
123:                try {
124:                    String baseName = (String) baseNames.get(srcComp.getClass()
125:                            .getName());
126:                    int len = 0;
127:                    if (baseName == null) {
128:                        Component newComp = (Component) srcComp.getClass()
129:                                .newInstance();
130:                        baseName = newComp.getName();
131:                        if (baseName == null)
132:                            return false;
133:                        while (Character.isDigit(baseName
134:                                .charAt(len = (baseName.length() - 1)))) {
135:                            baseName = baseName.substring(0, len);
136:                        }
137:                        baseNames.put(srcComp.getClass().getName(), baseName);
138:                    }
139:                    while (Character.isDigit(compName.charAt(len = (compName
140:                            .length() - 1)))) {
141:                        compName = compName.substring(0, len);
142:
143:                    }
144:                    return compName.equals(baseName);
145:                } catch (InstantiationException ex) {
146:                    return true;
147:                } catch (IllegalAccessException ex) {
148:                    return true;
149:                }
150:            }
151:
152:            /** Return a Robot for the given Component.  Makes sure it's aimed
153:             * at the correct screen. **/
154:            public RobotWrapper getRobot(Component c)
155:                    throws IllegalStateException, AWTException {
156:                Window w;
157:                if (c instanceof  Window)
158:                    w = (Window) c;
159:                else
160:                    w = SwingUtilities.windowForComponent(c);
161:                if (w == null)
162:                    throw new IllegalStateException(
163:                            "Window not found for Component: " + c);
164:
165:                GraphicsConfiguration gc = w.getGraphicsConfiguration();
166:                GraphicsDevice gd = gc.getDevice();
167:                if (!robots.containsKey(gd)) {
168:                    Robot r = new Robot(gd);
169:                    r.setAutoDelay(0);
170:                    r.setAutoWaitForIdle(true);
171:                    robots.put(gd, new RobotWrapper(r, gc.getBounds().x));
172:                }
173:
174:                return (RobotWrapper) robots.get(gd);
175:            }
176:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.