Source Code Cross Referenced for XEmbedServerTester.java in  » 6.0-JDK-Platform » solaris » sun » awt » X11 » 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 » 6.0 JDK Platform » solaris » sun.awt.X11 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:
026:        package sun.awt.X11;
027:
028:        //import static sun.awt.X11.XEmbed.*;
029:        import java.awt.*;
030:        import java.awt.event.*;
031:        import java.util.logging.*;
032:        import static sun.awt.X11.XConstants.*;
033:        import java.util.LinkedList;
034:
035:        /**
036:         * Test XEmbed server implementation. See file:///home/dom/bugs/4931668/test_plan.html for
037:         * specification and references.
038:         */
039:        public class XEmbedServerTester implements  XEventDispatcher {
040:            private static final Logger xembedLog = Logger
041:                    .getLogger("sun.awt.X11.xembed.XEmbedServerTester");
042:            private final Object EVENT_LOCK = new Object();
043:            static final int SYSTEM_EVENT_MASK = 0x8000;
044:            int my_version, server_version;
045:            XEmbedHelper xembed = new XEmbedHelper();
046:            boolean focused;
047:            int focusedKind;
048:            int focusedServerComponent;
049:            boolean reparent;
050:            long parent;
051:            boolean windowActive;
052:            boolean xembedActive;
053:            XBaseWindow window;
054:            volatile int eventWaited = -1, eventReceived = -1;
055:            int mapped;
056:            int accel_key, accel_keysym, accel_mods;
057:            static Rectangle initialBounds = new Rectangle(0, 0, 100, 100);
058:            Robot robot;
059:            Rectangle serverBounds[]; // first rectangle is for the server frame, second is for dummy frame, others are for its children
060:            private static final int SERVER_BOUNDS = 0, OTHER_FRAME = 1,
061:                    SERVER_FOCUS = 2, SERVER_MODAL = 3, MODAL_CLOSE = 4;
062:
063:            LinkedList<Integer> events = new LinkedList<Integer>();
064:
065:            private XEmbedServerTester(Rectangle serverBounds[], long parent) {
066:                this .parent = parent;
067:                focusedKind = -1;
068:                focusedServerComponent = -1;
069:                reparent = false;
070:                windowActive = false;
071:                xembedActive = false;
072:                my_version = XEmbedHelper.XEMBED_VERSION;
073:                mapped = XEmbedHelper.XEMBED_MAPPED;
074:                this .serverBounds = serverBounds;
075:                if (serverBounds.length < 5) {
076:                    throw new IllegalArgumentException(
077:                            "There must be at least five areas: server-activation, server-deactivation, server-focus, "
078:                                    + "server-modal show, modal-close");
079:                }
080:                try {
081:                    robot = new Robot();
082:                    robot.setAutoDelay(100);
083:                } catch (Exception e) {
084:                    throw new RuntimeException("Can't create robot");
085:                }
086:                initAccel();
087:                xembedLog.finer("XEmbed client(tester), embedder window: "
088:                        + Long.toHexString(parent));
089:            }
090:
091:            public static XEmbedServerTester getTester(
092:                    Rectangle serverBounds[], long parent) {
093:                return new XEmbedServerTester(serverBounds, parent);
094:            }
095:
096:            private void dumpReceivedEvents() {
097:                xembedLog.finer("Events received so far:");
098:                int pos = 0;
099:                for (Integer event : events) {
100:                    xembedLog.finer((pos++) + ":"
101:                            + XEmbedHelper.msgidToString(event));
102:                }
103:                xembedLog.finer("End of event dump");
104:            }
105:
106:            public void test1_1() {
107:                int res = embedCompletely();
108:                waitWindowActivated(res);
109:                requestFocus();
110:                deactivateServer();
111:                res = activateServer(getEventPos());
112:                waitFocusGained(res);
113:                checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
114:            }
115:
116:            public void test1_2() {
117:                int res = embedCompletely();
118:                waitWindowActivated(res);
119:                requestFocus();
120:                checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
121:            }
122:
123:            public void test1_3() {
124:                embedCompletely();
125:                deactivateServer();
126:                requestFocusNoWait();
127:                checkNotFocused();
128:            }
129:
130:            public void test1_4() {
131:                embedCompletely();
132:                deactivateServer();
133:                requestFocusNoWait();
134:                checkNotFocused();
135:                int res = getEventPos();
136:                activateServer(res);
137:                waitFocusGained(res);
138:                checkFocusGained(XEmbedHelper.XEMBED_FOCUS_CURRENT);
139:            }
140:
141:            public void test1_5() {
142:                int res = embedCompletely();
143:                waitWindowActivated(res);
144:                checkWindowActivated();
145:            }
146:
147:            public void test1_6() {
148:                int res = embedCompletely();
149:                waitWindowActivated(res);
150:                requestFocus();
151:                res = deactivateServer();
152:                checkFocused();
153:            }
154:
155:            public void test1_7() {
156:                int res = embedCompletely();
157:                waitWindowActivated(res);
158:                requestFocus();
159:                focusServer();
160:                checkFocusLost();
161:            }
162:
163:            public void test2_5() {
164:                int res = embedCompletely();
165:                waitWindowActivated(res);
166:                requestFocus();
167:                focusServerNext();
168:                checkFocusedServerNext();
169:                checkFocusLost();
170:            }
171:
172:            public void test2_6() {
173:                int res = embedCompletely();
174:                waitWindowActivated(res);
175:                requestFocus();
176:                focusServerPrev();
177:                checkFocusedServerPrev();
178:                checkFocusLost();
179:            }
180:
181:            public void test3_1() {
182:                reparent = false;
183:                embedCompletely();
184:            }
185:
186:            public void test3_2() {
187:                embedCompletely();
188:                int res = getEventPos();
189:                sendMessage(XEmbedHelper._SUN_XEMBED_START);
190:                waitEmbeddedNotify(res);
191:            }
192:
193:            public void test3_3() {
194:                reparent = true;
195:                embedCompletely();
196:            }
197:
198:            public void test3_4() {
199:                my_version = 10;
200:                embedCompletely();
201:                if (server_version != XEmbedHelper.XEMBED_VERSION) {
202:                    throw new RuntimeException("Version " + server_version
203:                            + " is not minimal");
204:                }
205:            }
206:
207:            public void test3_5() {
208:                embedCompletely();
209:
210:                window.destroy();
211:                // TODO: how can we detect that XEmbed ended?  So far we are
212:                // just checking that XEmbed server won't end up with an
213:                // exception, which should end up testing, hopefully.
214:
215:                // Sleep before exiting the tester application
216:                sleep(1000);
217:            }
218:
219:            public void test3_6() {
220:                embedCompletely();
221:
222:                sleep(1000);
223:                XToolkit.awtLock();
224:                try {
225:                    XlibWrapper.XUnmapWindow(XToolkit.getDisplay(), window
226:                            .getWindow());
227:                    XlibWrapper
228:                            .XReparentWindow(XToolkit.getDisplay(), window
229:                                    .getWindow(), XToolkit
230:                                    .getDefaultRootWindow(), 0, 0);
231:                } finally {
232:                    XToolkit.awtUnlock();
233:                }
234:
235:                int res = getEventPos();
236:
237:                activateServerNoWait(res);
238:
239:                sleep(1000);
240:                if (checkEventList(res, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
241:                    throw new RuntimeException(
242:                            "Focus was been given to the client after XEmbed has ended");
243:                }
244:            }
245:
246:            public void test4_1() {
247:                mapped = XEmbedHelper.XEMBED_MAPPED;
248:                int res = getEventPos();
249:                embedCompletely();
250:                sleep(1000);
251:                checkMapped();
252:            }
253:
254:            public void test4_2() {
255:                mapped = 0;
256:                embedCompletely();
257:                sleep(1000);
258:
259:                int res = getEventPos();
260:                mapped = XEmbedHelper.XEMBED_MAPPED;
261:                updateEmbedInfo();
262:                sleep(1000);
263:                checkMapped();
264:            }
265:
266:            public void test4_3() {
267:                int res = getEventPos();
268:                mapped = XEmbedHelper.XEMBED_MAPPED;
269:                embedCompletely();
270:
271:                res = getEventPos();
272:                mapped = 0;
273:                updateEmbedInfo();
274:                sleep(1000);
275:                checkNotMapped();
276:            }
277:
278:            public void test4_4() {
279:                mapped = 0;
280:                embedCompletely();
281:                sleep(1000);
282:                if (XlibUtil.getWindowMapState(window.getWindow()) != XlibWrapper.IsUnmapped) {
283:                    throw new RuntimeException("Client has been mapped");
284:                }
285:            }
286:
287:            public void test6_1_1() {
288:                embedCompletely();
289:                registerAccelerator();
290:                focusServer();
291:                int res = pressAccelKey();
292:                waitForEvent(res, XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR);
293:            }
294:
295:            public void test6_1_2() {
296:                embedCompletely();
297:                registerAccelerator();
298:                focusServer();
299:                deactivateServer();
300:                int res = pressAccelKey();
301:                sleep(1000);
302:                if (checkEventList(res,
303:                        XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
304:                    throw new RuntimeException(
305:                            "Accelerator has been activated in inactive embedder");
306:                }
307:            }
308:
309:            public void test6_1_3() {
310:                embedCompletely();
311:                registerAccelerator();
312:                focusServer();
313:                deactivateServer();
314:                unregisterAccelerator();
315:                int res = pressAccelKey();
316:                sleep(1000);
317:                if (checkEventList(res,
318:                        XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
319:                    throw new RuntimeException(
320:                            "Accelerator has been activated after unregistering");
321:                }
322:            }
323:
324:            public void test6_1_4() {
325:                embedCompletely();
326:                registerAccelerator();
327:                requestFocus();
328:                int res = pressAccelKey();
329:                sleep(1000);
330:                if (checkEventList(res,
331:                        XEmbedHelper.XEMBED_ACTIVATE_ACCELERATOR) != -1) {
332:                    throw new RuntimeException(
333:                            "Accelerator has been activated in focused client");
334:                }
335:            }
336:
337:            public void test6_2_1() {
338:                embedCompletely();
339:                grabKey();
340:                focusServer();
341:                int res = pressAccelKey();
342:                waitSystemEvent(res, KeyPress);
343:            }
344:
345:            public void test6_2_2() {
346:                embedCompletely();
347:                grabKey();
348:                focusServer();
349:                deactivateServer();
350:                int res = pressAccelKey();
351:                sleep(1000);
352:                if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
353:                    throw new RuntimeException(
354:                            "Accelerator has been activated in inactive embedder");
355:                }
356:            }
357:
358:            public void test6_2_3() {
359:                embedCompletely();
360:                grabKey();
361:                focusServer();
362:                deactivateServer();
363:                ungrabKey();
364:                int res = pressAccelKey();
365:                sleep(1000);
366:                if (checkEventList(res, SYSTEM_EVENT_MASK | KeyPress) != -1) {
367:                    throw new RuntimeException(
368:                            "Accelerator has been activated after unregistering");
369:                }
370:            }
371:
372:            public void test6_2_4() {
373:                embedCompletely();
374:                grabKey();
375:                requestFocus();
376:                int res = pressAccelKey();
377:                sleep(1000);
378:                int pos = checkEventList(res, SYSTEM_EVENT_MASK | KeyPress);
379:                if (pos != -1) {
380:                    pos = checkEventList(pos + 1, SYSTEM_EVENT_MASK | KeyPress);
381:                    if (pos != -1) { // Second event
382:                        throw new RuntimeException(
383:                                "Accelerator has been activated in focused client");
384:                    }
385:                }
386:            }
387:
388:            public void test7_1() {
389:                embedCompletely();
390:                int res = showModalDialog();
391:                waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
392:            }
393:
394:            public void test7_2() {
395:                embedCompletely();
396:                int res = showModalDialog();
397:                waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_ON);
398:                res = hideModalDialog();
399:                waitForEvent(res, XEmbedHelper.XEMBED_MODALITY_OFF);
400:            }
401:
402:            public void test9_1() {
403:                embedCompletely();
404:                requestFocus();
405:                int res = pressAccelKey();
406:                waitForEvent(res, SYSTEM_EVENT_MASK | KeyPress);
407:            }
408:
409:            private int embed() {
410:                int res = getEventPos();
411:                XToolkit.awtLock();
412:                try {
413:                    XCreateWindowParams params = new XCreateWindowParams(
414:                            new Object[] {
415:                                    XBaseWindow.PARENT_WINDOW,
416:                                    new Long(reparent ? XToolkit
417:                                            .getDefaultRootWindow() : parent),
418:                                    XBaseWindow.BOUNDS,
419:                                    initialBounds,
420:                                    XBaseWindow.EMBEDDED,
421:                                    Boolean.TRUE,
422:                                    XBaseWindow.VISIBLE,
423:                                    Boolean
424:                                            .valueOf(mapped == XEmbedHelper.XEMBED_MAPPED),
425:                                    XBaseWindow.EVENT_MASK,
426:                                    new Long(VisibilityChangeMask
427:                                            | StructureNotifyMask
428:                                            | SubstructureNotifyMask
429:                                            | KeyPressMask) });
430:                    window = new XBaseWindow(params);
431:
432:                    xembedLog.finer("Created tester window: " + window);
433:
434:                    XToolkit.addEventDispatcher(window.getWindow(), this );
435:                    updateEmbedInfo();
436:                    if (reparent) {
437:                        xembedLog.finer("Reparenting to embedder");
438:                        XlibWrapper.XReparentWindow(XToolkit.getDisplay(),
439:                                window.getWindow(), parent, 0, 0);
440:                    }
441:                } finally {
442:                    XToolkit.awtUnlock();
443:                }
444:                return res;
445:            }
446:
447:            private void updateEmbedInfo() {
448:                long[] info = new long[] { my_version, mapped };
449:                long data = Native.card32ToData(info);
450:                try {
451:                    XEmbedHelper.XEmbedInfo.setAtomData(window.getWindow(),
452:                            data, info.length);
453:                } finally {
454:                    XEmbedHelper.unsafe.freeMemory(data);
455:                }
456:            }
457:
458:            private int getEventPos() {
459:                synchronized (EVENT_LOCK) {
460:                    return events.size();
461:                }
462:            }
463:
464:            private int embedCompletely() {
465:                xembedLog.fine("Embedding completely");
466:                int res = getEventPos();
467:                embed();
468:                waitEmbeddedNotify(res);
469:                return res;
470:            }
471:
472:            private int requestFocus() {
473:                xembedLog.fine("Requesting focus");
474:                int res = getEventPos();
475:                sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
476:                waitFocusGained(res);
477:                return res;
478:            }
479:
480:            private int requestFocusNoWait() {
481:                xembedLog.fine("Requesting focus without wait");
482:                int res = getEventPos();
483:                sendMessage(XEmbedHelper.XEMBED_REQUEST_FOCUS);
484:                return res;
485:            }
486:
487:            private int activateServer(int prev) {
488:                int res = activateServerNoWait(prev);
489:                waitWindowActivated(res);
490:                return res;
491:            }
492:
493:            private int activateServerNoWait(int prev) {
494:                xembedLog.fine("Activating server");
495:                int res = getEventPos();
496:                if (checkEventList(prev, XEmbedHelper.XEMBED_WINDOW_ACTIVATE) != -1) {
497:                    xembedLog.fine("Activation already received");
498:                    return res;
499:                }
500:                Point loc = serverBounds[SERVER_BOUNDS].getLocation();
501:                loc.x += serverBounds[SERVER_BOUNDS].getWidth() / 2;
502:                loc.y += 5;
503:                robot.mouseMove(loc.x, loc.y);
504:                robot.mousePress(InputEvent.BUTTON1_MASK);
505:                robot.mouseRelease(InputEvent.BUTTON1_MASK);
506:                return res;
507:            }
508:
509:            private int deactivateServer() {
510:                xembedLog.fine("Deactivating server");
511:                int res = getEventPos();
512:                Point loc = serverBounds[OTHER_FRAME].getLocation();
513:                loc.x += serverBounds[OTHER_FRAME].getWidth() / 2;
514:                loc.y += serverBounds[OTHER_FRAME].getHeight() / 2;
515:                robot.mouseMove(loc.x, loc.y);
516:                robot.mousePress(InputEvent.BUTTON1_MASK);
517:                robot.delay(50);
518:                robot.mouseRelease(InputEvent.BUTTON1_MASK);
519:                waitWindowDeactivated(res);
520:                return res;
521:            }
522:
523:            private int focusServer() {
524:                xembedLog.fine("Focusing server");
525:                boolean weFocused = focused;
526:                int res = getEventPos();
527:                Point loc = serverBounds[SERVER_FOCUS].getLocation();
528:                loc.x += 5;
529:                loc.y += 5;
530:                robot.mouseMove(loc.x, loc.y);
531:                robot.mousePress(InputEvent.BUTTON1_MASK);
532:                robot.delay(50);
533:                robot.mouseRelease(InputEvent.BUTTON1_MASK);
534:                if (weFocused) {
535:                    waitFocusLost(res);
536:                }
537:                return res;
538:            }
539:
540:            private int focusServerNext() {
541:                xembedLog.fine("Focusing next server component");
542:                int res = getEventPos();
543:                sendMessage(XEmbedHelper.XEMBED_FOCUS_NEXT);
544:                waitFocusLost(res);
545:                return res;
546:            }
547:
548:            private int focusServerPrev() {
549:                xembedLog.fine("Focusing previous server component");
550:                int res = getEventPos();
551:                sendMessage(XEmbedHelper.XEMBED_FOCUS_PREV);
552:                waitFocusLost(res);
553:                return res;
554:            }
555:
556:            private void waitEmbeddedNotify(int pos) {
557:                waitForEvent(pos, XEmbedHelper.XEMBED_EMBEDDED_NOTIFY);
558:            }
559:
560:            private void waitFocusGained(int pos) {
561:                waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_IN);
562:            }
563:
564:            private void waitFocusLost(int pos) {
565:                waitForEvent(pos, XEmbedHelper.XEMBED_FOCUS_OUT);
566:            }
567:
568:            private void waitWindowActivated(int pos) {
569:                waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_ACTIVATE);
570:            }
571:
572:            private void waitWindowDeactivated(int pos) {
573:                waitForEvent(pos, XEmbedHelper.XEMBED_WINDOW_DEACTIVATE);
574:            }
575:
576:            private void waitSystemEvent(int position, int event) {
577:                waitForEvent(position, event | SYSTEM_EVENT_MASK);
578:            }
579:
580:            private void waitForEvent(int position, int event) {
581:                synchronized (EVENT_LOCK) {
582:                    // Check for already received events after the request
583:                    if (checkEventList(position, event) != -1) {
584:                        xembedLog.finer("The event "
585:                                + XEmbedHelper.msgidToString(event)
586:                                + " has already been received");
587:                        return;
588:                    }
589:
590:                    if (eventReceived == event) {
591:                        // Already received
592:                        xembedLog.finer("Already received "
593:                                + XEmbedHelper.msgidToString(event));
594:                        return;
595:                    }
596:                    eventReceived = -1;
597:                    eventWaited = event;
598:                    xembedLog.finer("Waiting for "
599:                            + XEmbedHelper.msgidToString(event)
600:                            + " starting from " + position);
601:                    try {
602:                        EVENT_LOCK.wait(3000);
603:                    } catch (InterruptedException ie) {
604:                        xembedLog.log(Level.WARNING, "Event wait interrupted",
605:                                ie);
606:                    }
607:                    eventWaited = -1;
608:                    if (checkEventList(position, event) == -1) {
609:                        dumpReceivedEvents();
610:                        throw new RuntimeException("Didn't receive event "
611:                                + XEmbedHelper.msgidToString(event)
612:                                + " but recevied "
613:                                + XEmbedHelper.msgidToString(eventReceived));
614:                    } else {
615:                        xembedLog.finer("Successfully recevied "
616:                                + XEmbedHelper.msgidToString(event));
617:                    }
618:                }
619:            }
620:
621:            /**
622:             * Checks if the <code>event</code> is already in a list at position >= <code>position</code>
623:             */
624:            private int checkEventList(int position, int event) {
625:                if (position == -1) {
626:                    return -1;
627:                }
628:                synchronized (EVENT_LOCK) {
629:                    for (int i = position; i < events.size(); i++) {
630:                        if (events.get(i) == event) {
631:                            return i;
632:                        }
633:                    }
634:                    return -1;
635:                }
636:            }
637:
638:            private void checkFocusedServerNext() {
639:                if (focusedServerComponent != 0) {
640:                    throw new RuntimeException(
641:                            "Wrong focused server component, should be 0, but it is "
642:                                    + focusedServerComponent);
643:                }
644:            }
645:
646:            private void checkFocusedServerPrev() {
647:                if (focusedServerComponent != 2) {
648:                    throw new RuntimeException(
649:                            "Wrong focused server component, should be 2, but it is "
650:                                    + focusedServerComponent);
651:                }
652:            }
653:
654:            private void checkFocusGained(int kind) {
655:                if (!focused) {
656:                    throw new RuntimeException("Didn't receive FOCUS_GAINED");
657:                }
658:                if (focusedKind != kind) {
659:                    throw new RuntimeException("Kinds don't match, required: "
660:                            + kind + ", current: " + focusedKind);
661:                }
662:            }
663:
664:            private void checkNotFocused() {
665:                if (focused) {
666:                    throw new RuntimeException("Focused");
667:                }
668:            }
669:
670:            private void checkFocused() {
671:                if (!focused) {
672:                    throw new RuntimeException("Not Focused");
673:                }
674:            }
675:
676:            private void checkFocusLost() {
677:                checkNotFocused();
678:                if (focusedKind != XEmbedHelper.XEMBED_FOCUS_OUT) {
679:                    throw new RuntimeException("Didn't receive FOCUS_LOST");
680:                }
681:            }
682:
683:            private void checkWindowActivated() {
684:                if (!windowActive) {
685:                    throw new RuntimeException("Window is not active");
686:                }
687:            }
688:
689:            private void checkMapped() {
690:                if (XlibUtil.getWindowMapState(window.getWindow()) == XlibWrapper.IsUnmapped) {
691:                    throw new RuntimeException("Client is not mapped");
692:                }
693:            }
694:
695:            private void checkNotMapped() {
696:                if (XlibUtil.getWindowMapState(window.getWindow()) != XlibWrapper.IsUnmapped) {
697:                    throw new RuntimeException("Client is mapped");
698:                }
699:            }
700:
701:            private void sendMessage(int message) {
702:                xembed.sendMessage(parent, message);
703:            }
704:
705:            private void sendMessage(int message, int detail, long data1,
706:                    long data2) {
707:                xembed.sendMessage(parent, message, detail, data1, data2);
708:            }
709:
710:            public void dispatchEvent(XEvent ev) {
711:                if (ev.get_type() == ClientMessage) {
712:                    XClientMessageEvent msg = ev.get_xclient();
713:                    if (msg.get_message_type() == xembed.XEmbed.getAtom()) {
714:                        if (xembedLog.isLoggable(Level.FINE))
715:                            xembedLog.fine("Embedded message: "
716:                                    + XEmbedHelper.msgidToString((int) msg
717:                                            .get_data(1)));
718:                        switch ((int) msg.get_data(1)) {
719:                        case XEmbedHelper.XEMBED_EMBEDDED_NOTIFY: // Notification about embedding protocol start
720:                            xembedActive = true;
721:                            server_version = (int) msg.get_data(3);
722:                            break;
723:                        case XEmbedHelper.XEMBED_WINDOW_ACTIVATE:
724:                            windowActive = true;
725:                            break;
726:                        case XEmbedHelper.XEMBED_WINDOW_DEACTIVATE:
727:                            windowActive = false;
728:                            break;
729:                        case XEmbedHelper.XEMBED_FOCUS_IN: // We got focus!
730:                            focused = true;
731:                            focusedKind = (int) msg.get_data(2);
732:                            break;
733:                        case XEmbedHelper.XEMBED_FOCUS_OUT:
734:                            focused = false;
735:                            focusedKind = XEmbedHelper.XEMBED_FOCUS_OUT;
736:                            focusedServerComponent = (int) msg.get_data(2);
737:                            break;
738:                        }
739:                        synchronized (EVENT_LOCK) {
740:                            events.add((int) msg.get_data(1));
741:
742:                            xembedLog.finer("Tester is waiting for "
743:                                    + XEmbedHelper.msgidToString(eventWaited));
744:                            if ((int) msg.get_data(1) == eventWaited) {
745:                                eventReceived = (int) msg.get_data(1);
746:                                xembedLog
747:                                        .finer("Notifying waiting object for event "
748:                                                + System
749:                                                        .identityHashCode(EVENT_LOCK));
750:                                EVENT_LOCK.notifyAll();
751:                            }
752:                        }
753:                    }
754:                } else {
755:                    synchronized (EVENT_LOCK) {
756:                        int eventID = (int) ev.get_type() | SYSTEM_EVENT_MASK;
757:                        events.add(eventID);
758:
759:                        xembedLog.finer("Tester is waiting for "
760:                                + XEmbedHelper.msgidToString(eventWaited)
761:                                + ", but we received " + ev + "("
762:                                + XEmbedHelper.msgidToString(eventID) + ")");
763:                        if (eventID == eventWaited) {
764:                            eventReceived = eventID;
765:                            xembedLog.finer("Notifying waiting object"
766:                                    + System.identityHashCode(EVENT_LOCK));
767:                            EVENT_LOCK.notifyAll();
768:                        }
769:                    }
770:                }
771:            }
772:
773:            private void sleep(int amount) {
774:                try {
775:                    Thread.sleep(amount);
776:                } catch (Exception e) {
777:                }
778:            }
779:
780:            private void registerAccelerator() {
781:                sendMessage(XEmbedHelper.XEMBED_REGISTER_ACCELERATOR, 1,
782:                        accel_keysym, accel_mods);
783:            }
784:
785:            private void unregisterAccelerator() {
786:                sendMessage(XEmbedHelper.XEMBED_UNREGISTER_ACCELERATOR, 1, 0, 0);
787:            }
788:
789:            private int pressAccelKey() {
790:                int res = getEventPos();
791:                robot.keyPress(accel_key);
792:                robot.keyRelease(accel_key);
793:                return res;
794:            }
795:
796:            private void initAccel() {
797:                accel_key = KeyEvent.VK_A;
798:                accel_keysym = XWindow.getKeySymForAWTKeyCode(accel_key);
799:                accel_mods = 0;
800:            }
801:
802:            private void grabKey() {
803:                sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_GRAB_KEY, 0,
804:                        accel_keysym, accel_mods);
805:            }
806:
807:            private void ungrabKey() {
808:                sendMessage(XEmbedHelper.NON_STANDARD_XEMBED_GTK_UNGRAB_KEY, 0,
809:                        accel_keysym, accel_mods);
810:            }
811:
812:            private int showModalDialog() {
813:                xembedLog.fine("Showing modal dialog");
814:                int res = getEventPos();
815:                Point loc = serverBounds[SERVER_MODAL].getLocation();
816:                loc.x += 5;
817:                loc.y += 5;
818:                robot.mouseMove(loc.x, loc.y);
819:                robot.mousePress(InputEvent.BUTTON1_MASK);
820:                robot.delay(50);
821:                robot.mouseRelease(InputEvent.BUTTON1_MASK);
822:                return res;
823:            }
824:
825:            private int hideModalDialog() {
826:                xembedLog.fine("Hide modal dialog");
827:                int res = getEventPos();
828:                //         Point loc = serverBounds[MODAL_CLOSE].getLocation();
829:                //         loc.x += 5;
830:                //         loc.y += 5;
831:                //         robot.mouseMove(loc.x, loc.y);
832:                //         robot.mousePress(InputEvent.BUTTON1_MASK);
833:                //         robot.delay(50);
834:                //         robot.mouseRelease(InputEvent.BUTTON1_MASK);        
835:                robot.keyPress(KeyEvent.VK_SPACE);
836:                robot.keyRelease(KeyEvent.VK_SPACE);
837:                return res;
838:            }
839:
840:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.