Source Code Cross Referenced for TestSizeChanged.java in  » 6.0-JDK-Modules » j2me » javax » microedition » lcdui » 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 Modules » j2me » javax.microedition.lcdui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *   
003:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:
027:        package javax.microedition.lcdui;
028:
029:        import com.sun.midp.i3test.*;
030:        import javax.microedition.lcdui.*;
031:        import javax.microedition.midlet.*;
032:        import com.sun.midp.chameleon.skins.*;
033:        import com.sun.midp.midlet.MIDletStateHandler;
034:        import com.sun.midp.util.DummyMIDlet;
035:
036:        /**
037:         * This test case is meant to verify that the <code>sizeChanged</code>
038:         * method of a Canvas is called correctly in every instance where it
039:         * is required by the MIDP specification.
040:         * It is triggered by the addition or removal of a title, ticker,
041:         * or both.  It may also be triggered in the event that 
042:         * the full screen and non-full screen display is toggled.
043:         *
044:         * <code>sizeChanged</code>  should be called when the canvas is 
045:         * visible, or in the event the canvas is not shown, <code>sizeChanged</code>
046:         * should be called before <code>paint</code> is called.  
047:         */
048:        public class TestSizeChanged extends TestCase {
049:
050:            /**
051:             * Name for this test grouping
052:             */
053:            static final String testName = "SizeChanged";
054:
055:            // We define a set of constants that are set by pulling values
056:            // out of the various skin classes (ie. TitleSkin, TickerSkin, etc).
057:
058:            /**
059:             * Width of the screen in non fullscreen mode
060:             */
061:            protected static int STD_WIDTH;
062:
063:            /**
064:             * Height of the screen in non fullscreen mode
065:             */
066:            protected static int STD_HEIGHT;
067:
068:            // Note that although for chameleon's standard spec, the fullscreen
069:            // height and the standard height are the same, this may not be the
070:            // case for all implementations. Including both here allows the test
071:            // to be valid in both circumstances.
072:
073:            /**
074:             * Height of the screen in fulscreen mode
075:             */
076:            protected static int FS_HEIGHT;
077:
078:            /**
079:             * Height of the title bar
080:             */
081:            protected static int TITLE_HEIGHT;
082:
083:            /**
084:             * Height of the ticker
085:             */
086:            protected static int TICKER_HEIGHT;
087:
088:            /**
089:             * Height of the soft button bar
090:             */
091:            protected static int SOFTBTN_HEIGHT;
092:
093:            /**
094:             * The Display to use to view our test canvases
095:             */
096:            protected Display display;
097:
098:            /**
099:             * Test ticker, used for sizing only
100:             */
101:            protected Ticker ticker;
102:
103:            /**
104:             * Construct a new SizeChanged test. The constructor
105:             * initializes all sizing constants from the chameleon
106:             * skin files.
107:             */
108:            public TestSizeChanged() {
109:                // Initialize the constants
110:
111:                STD_WIDTH = ScreenSkin.WIDTH;
112:                STD_HEIGHT = ScreenSkin.HEIGHT;
113:                FS_HEIGHT = ScreenSkin.FULLHEIGHT;
114:                TITLE_HEIGHT = TitleSkin.HEIGHT;
115:                TICKER_HEIGHT = TickerSkin.HEIGHT;
116:                SOFTBTN_HEIGHT = SoftButtonSkin.HEIGHT;
117:
118:                ticker = new Ticker("Canvas sizeChanged() tests...");
119:            }
120:
121:            /**
122:             * This is a utility method which checks values passed by 
123:             * <code>sizeChanged</code> against passed in values. It 
124:             * ensures that the method should have been called by waiting
125:             * for the canvas to be visible on the screen.
126:             *
127:             * @param canvas the canvas to test
128:             * @param WIDTH the <b>correct</b> width the canvas should be after the
129:             *              most recent <code>sizeChanged</code> call
130:             * @param HEIGHT the <b>correct</b> height the canvas should be after the
131:             *               most recent <code>sizeChanged</code> call
132:             */
133:            protected void checkCanvasSizeChanged(TestCanvas canvas, int WIDTH,
134:                    int HEIGHT) {
135:                synchronized (canvas) {
136:                    display.setCurrent(canvas);
137:                    try {
138:                        canvas.wait();
139:                    } catch (InterruptedException ie) {
140:                    } catch (IllegalMonitorStateException im) {
141:                        fail("Unexpected monitor exception");
142:                        return;
143:                    }
144:                }
145:
146:                // Now the canvas should be showing on the screen, we test
147:                // our assertions about <code>sizeChanged</code> being called
148:                assertEquals("Checking for Canvas.sizeChanged() width update",
149:                        WIDTH, canvas.checkSizeWidth());
150:                assertEquals("Checking for Canvas.sizeChanged() height update",
151:                        HEIGHT, canvas.checkSizeHeight());
152:            }
153:
154:            /**
155:             * This is a utility method which checks values passed by 
156:             * <code>sizeChanged</code> against passed in values. It 
157:             * ensures that the method should have been called by waiting
158:             * for the canvas to be visible on the screen.
159:             *
160:             * @param canvas the canvas to test
161:             * @param WIDTH the <b>correct</b> width the canvas should be after the
162:             *              most recent <code>sizeChanged</code> call
163:             * @param HEIGHT the <b>correct</b> height the canvas should be after the
164:             *               most recent <code>sizeChanged</code> call
165:             */
166:            protected void checkCurrentCanvasSizeChanged(TestCanvas canvas,
167:                    int WIDTH, int HEIGHT) {
168:                synchronized (canvas) {
169:                    //display.setCurrent(canvas);
170:                    try {
171:                        canvas.wait();
172:                    } catch (InterruptedException ie) {
173:                    } catch (IllegalMonitorStateException im) {
174:                        fail("Unexpected monitor exception");
175:                        return;
176:                    }
177:                }
178:
179:                // Now the canvas should be showing on the screen, we test
180:                // our assertions about <code>sizeChanged</code> being called
181:                assertEquals("Checking for Canvas.sizeChanged() width update",
182:                        WIDTH, canvas.checkSizeWidth());
183:                assertEquals("Checking for Canvas.sizeChanged() height update",
184:                        HEIGHT, canvas.checkSizeHeight());
185:            }
186:
187:            /*
188:             * Tests 1-4 involve adding components to a Canvas which is not
189:             * the current display, and checking to see that the proper
190:             * <code>sizeChanged()</code> occurs whenthe Canvas is brought to 
191:             * the foreground with a <code>display.setCurrent()</code> call.
192:             */
193:
194:            /**
195:             * This test is for a canvas with no title and no ticker set in
196:             * standard screen mode.  The canvas is set to the current display 
197:             * causing <code>sizeChanged</code> to be called.
198:             */
199:            protected void testOne() {
200:                declare(testName
201:                        + " 1: bg->fg: std-screen, no title, no ticker");
202:
203:                TestCanvas canvas = new TestCanvas();
204:
205:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
206:                        - SOFTBTN_HEIGHT);
207:            }
208:
209:            /**
210:             * This test is for a canvas with a title set in standard screen mode.
211:             * The canvas is set to the current display causing <code>sizeChanged</code> 
212:             * to be called.
213:             */
214:            protected void testTwo() {
215:                declare(testName + " 2: bg->fg: std-screen, add title");
216:
217:                TestCanvas canvas = new TestCanvas();
218:                canvas.setTitle("SizeChanged Test 2");
219:
220:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
221:                        - SOFTBTN_HEIGHT - TITLE_HEIGHT);
222:            }
223:
224:            /**
225:             * This test is for a canvas with a title and ticker set in standard 
226:             * screen mode.  The canvas is set to the current display causing 
227:             * <code>sizeChanged</code> to be called.
228:             */
229:            protected void testThree() {
230:                declare(testName
231:                        + " 3: bg->fg: std-screen, add title, add ticker");
232:
233:                TestCanvas canvas = new TestCanvas();
234:                canvas.setTitle("sizeChanged Test 3");
235:                canvas.setTicker(ticker);
236:
237:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
238:                        - SOFTBTN_HEIGHT - TICKER_HEIGHT - TITLE_HEIGHT);
239:            }
240:
241:            /**
242:             * This test is for a canvas with a ticker set in standard screen mode.
243:             * The canvas is set to the current display causing <code>sizeChanged</code> 
244:             * to be called.
245:             */
246:            protected void testFour() {
247:                declare(testName + " 4: bg->fg: std-screen, add ticker");
248:
249:                TestCanvas canvas = new TestCanvas();
250:                canvas.setTicker(ticker);
251:
252:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
253:                        - SOFTBTN_HEIGHT - TICKER_HEIGHT);
254:            }
255:
256:            /*
257:             * Tests 5-8 involve removing components from a Canvas which is not
258:             * the current display, and checking to see that the proper
259:             * <code>sizeChanged()</code> occurs whenthe Canvas is brought to 
260:             * the foreground with a <code>display.setCurrent()</code> call.
261:             */
262:
263:            /**
264:             * This test is for a canvas with a title and a ticker set in
265:             * standard screen mode.  The canvas is set to the current display 
266:             * causing <code>sizeChanged</code> to be called.
267:             */
268:            protected void testFive() {
269:                declare(testName
270:                        + " 5: bg->fg: std-screen, with title & ticker");
271:
272:                TestCanvas tmpCanvas = new TestCanvas();
273:                TestCanvas canvas = new TestCanvas();
274:
275:                display.setCurrent(canvas);
276:
277:                canvas.setTitle("SizeChanged test 5");
278:                canvas.setTicker(ticker);
279:
280:                display.setCurrent(tmpCanvas);
281:
282:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
283:                        - SOFTBTN_HEIGHT - TITLE_HEIGHT - TICKER_HEIGHT);
284:            }
285:
286:            /**
287:             * This test is for a canvas with a title and ticker set in standard 
288:             * screen mode.  The ticker is removed, and the canvas is set to the 
289:             * current display causing <code>sizeChanged</code> to be called.
290:             */
291:            protected void testSix() {
292:                declare(testName
293:                        + " 6: bg->fg: std-screen, with title & ticker."
294:                        + "  remove ticker");
295:
296:                TestCanvas tmpCanvas = new TestCanvas();
297:                TestCanvas canvas = new TestCanvas();
298:
299:                display.setCurrent(canvas);
300:
301:                canvas.setTitle("SizeChanged Test 6");
302:                canvas.setTicker(ticker);
303:
304:                display.setCurrent(tmpCanvas);
305:
306:                canvas.setTicker(null);
307:
308:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
309:                        - SOFTBTN_HEIGHT - TITLE_HEIGHT);
310:            }
311:
312:            /**
313:             * This test is for a canvas with a title and ticker set in standard 
314:             * screen mode.  The title is removed, and the canvas is set to the current 
315:             * display causing <code>sizeChanged</code> to be called.
316:             */
317:            protected void testSeven() {
318:                declare(testName
319:                        + " 7: bg->fg: std-screen, with title & ticker."
320:                        + "  remove title");
321:
322:                TestCanvas tmpCanvas = new TestCanvas();
323:                TestCanvas canvas = new TestCanvas();
324:
325:                display.setCurrent(canvas);
326:
327:                canvas.setTitle("SizeChanged Test 7");
328:                canvas.setTicker(ticker);
329:
330:                display.setCurrent(tmpCanvas);
331:
332:                canvas.setTitle(null);
333:
334:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
335:                        - SOFTBTN_HEIGHT - TICKER_HEIGHT);
336:            }
337:
338:            /**
339:             * This test is for a canvas with a title and ticker set in standard 
340:             * screen mode.  The ticker and title are removed, and the canvas is 
341:             * set to the current display causing <code>sizeChanged</code> 
342:             * to be called.
343:             */
344:            protected void testEight() {
345:                declare(testName
346:                        + " 8: bg->fg: std-screen, with title & ticker."
347:                        + "  remove both ticker and title");
348:
349:                TestCanvas tmpCanvas = new TestCanvas();
350:                TestCanvas canvas = new TestCanvas();
351:
352:                display.setCurrent(canvas);
353:
354:                canvas.setTitle("SizeChanged Test 8");
355:                canvas.setTicker(ticker);
356:
357:                display.setCurrent(tmpCanvas);
358:
359:                canvas.setTicker(null);
360:                canvas.setTitle(null);
361:
362:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
363:                        - SOFTBTN_HEIGHT);
364:            }
365:
366:            /**
367:             * This test is for a canvas with a title and ticker set in standard 
368:             * screen mode.  FullScreen mode is then set on the Canvas and it is
369:             * set to the current display causing <code>sizeChanged</code> 
370:             * to be called.
371:             */
372:            protected void testNine() {
373:                declare(testName
374:                        + " 9: bg->fg: std-screen, with title & ticker."
375:                        + "  set fullscreen mode");
376:
377:                TestCanvas tmpCanvas = new TestCanvas();
378:                TestCanvas canvas = new TestCanvas();
379:
380:                display.setCurrent(canvas);
381:
382:                canvas.setTitle("SizeChanged Test 9");
383:                canvas.setTicker(ticker);
384:
385:                display.setCurrent(tmpCanvas);
386:
387:                canvas.toggleFullscreen(true);
388:
389:                checkCanvasSizeChanged(canvas, STD_WIDTH, FS_HEIGHT
390:                        - SOFTBTN_HEIGHT);
391:            }
392:
393:            /**
394:             * This test is for a canvas with a title and ticker set in full 
395:             * screen mode.  Standard mode is then set on the Canvas and it is
396:             * set to the current display causing <code>sizeChanged</code> 
397:             * to be called.
398:             */
399:            protected void testTen() {
400:                declare(testName
401:                        + " 10: bg->fg: full-screen, with title & ticker."
402:                        + "  set std-screen mode");
403:
404:                TestCanvas tmpCanvas = new TestCanvas();
405:                TestCanvas canvas = new TestCanvas();
406:
407:                display.setCurrent(canvas);
408:
409:                canvas.toggleFullscreen(true);
410:                canvas.setTitle("SizeChanged Test 10");
411:                canvas.setTicker(ticker);
412:
413:                display.setCurrent(tmpCanvas);
414:
415:                canvas.toggleFullscreen(false);
416:
417:                checkCanvasSizeChanged(canvas, STD_WIDTH, FS_HEIGHT
418:                        - SOFTBTN_HEIGHT - TICKER_HEIGHT - TITLE_HEIGHT);
419:            }
420:
421:            /**
422:             * Test 11 involves removing components from a Canvas which is
423:             * the current display, and checking to see that the proper
424:             * <code>sizeChanged()</code> occurs after each removal
425:             */
426:            protected void testEleven() {
427:                declare(testName
428:                        + " 11: in fg: std-screen, with title & ticker."
429:                        + " remove title, then ticker.");
430:
431:                TestCanvas tmpCanvas = new TestCanvas();
432:                TestCanvas canvas = new TestCanvas();
433:
434:                display.setCurrent(tmpCanvas);
435:
436:                canvas.setTitle("SizeChanged test 11");
437:                canvas.setTicker(ticker);
438:
439:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
440:                        - SOFTBTN_HEIGHT - TITLE_HEIGHT - TICKER_HEIGHT);
441:
442:                canvas.setTitle(null);
443:                checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
444:                        - SOFTBTN_HEIGHT - TICKER_HEIGHT);
445:
446:                canvas.setTicker(null);
447:                checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
448:                        - SOFTBTN_HEIGHT);
449:            }
450:
451:            /**
452:             * Test 12 involves adding components from a canvas which is
453:             * current display, and checking to see that the proper
454:             * <code>sizeChanged</code> call occurs after each addition.
455:             */
456:            protected void testTwelve() {
457:                declare(testName
458:                        + " 12: in fg: std-screen.  add title, then ticker");
459:
460:                TestCanvas canvas = new TestCanvas();
461:
462:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
463:                        - SOFTBTN_HEIGHT);
464:
465:                canvas.setTitle("SizeChanged Test 12");
466:                checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
467:                        - SOFTBTN_HEIGHT - TITLE_HEIGHT);
468:
469:                canvas.setTicker(ticker);
470:                checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
471:                        - SOFTBTN_HEIGHT - TITLE_HEIGHT - TICKER_HEIGHT);
472:            }
473:
474:            /**
475:             * Test 13 involves changing to fullScreen mode and back on
476:             * a canvas which is the current display, and checking to see that the proper
477:             * <code>sizeChanged</code> call occurs after each change.
478:             */
479:            protected void testThirteen() {
480:                declare(testName
481:                        + " 13: in fg: std-screen, with title & ticker."
482:                        + " remove title, then ticker.");
483:
484:                TestCanvas tmpCanvas = new TestCanvas();
485:                TestCanvas canvas = new TestCanvas();
486:
487:                display.setCurrent(tmpCanvas);
488:
489:                canvas.setTitle("SizeChanged test 13");
490:                canvas.setTicker(ticker);
491:
492:                checkCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
493:                        - SOFTBTN_HEIGHT - TITLE_HEIGHT - TICKER_HEIGHT);
494:
495:                canvas.toggleFullscreen(true);
496:                checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
497:                        - SOFTBTN_HEIGHT);
498:
499:                canvas.toggleFullscreen(false);
500:                checkCurrentCanvasSizeChanged(canvas, STD_WIDTH, STD_HEIGHT
501:                        - SOFTBTN_HEIGHT - TITLE_HEIGHT - TICKER_HEIGHT);
502:            }
503:
504:            /**
505:             * Overridden from TestCase parent. This method will kick off each
506:             * individual test
507:             */
508:            public void runTests() {
509:
510:                MIDletStateHandler msHandler = MIDletStateHandler
511:                        .getMidletStateHandler();
512:                // Start a new instance of DummyMIDlet
513:                try {
514:                    msHandler.startMIDlet("com.sun.midp.util.DummyMIDlet",
515:                            "DummyMIDlet");
516:                } catch (Exception cnf) {
517:                    return;
518:                }
519:
520:                // Wait for async request to be processed 
521:                while (DummyMIDlet.midlet == null) {
522:                    try {
523:                        Thread.sleep(100);
524:                    } catch (InterruptedException ie) {
525:                        ;
526:                    }
527:                }
528:
529:                MIDlet midlet = DummyMIDlet.midlet;
530:                display = Display.getDisplay(midlet);
531:
532:                testOne();
533:                testTwo();
534:                testThree();
535:                testFour();
536:                testFive();
537:                testSix();
538:                testSeven();
539:                testEight();
540:                testNine();
541:                testTen();
542:                testEleven();
543:                testTwelve();
544:                testThirteen();
545:
546:                // Notify the system that our midlet is done
547:                midlet.notifyDestroyed();
548:                try {
549:                    ((DummyMIDlet) midlet).destroyApp(true);
550:                } catch (MIDletStateChangeException ignore) {
551:                }
552:            }
553:
554:            /**
555:             * Inner canvas class which notifies the main TestCase when
556:             * a particular canvas has become visible. This allows the
557:             * main TestCase know that <code>sizeChanged</code> should have 
558:             * been called by a specific time.
559:             */
560:            class TestCanvas extends Canvas {
561:
562:                /**
563:                 * Most recent width value in a <code>sizeChanged</code> call.
564:                 * Reset to -1 when <code>checkSizeWidth</code> is called.
565:                 */
566:                private int curW = -1;
567:
568:                /**
569:                 * Most recent height value in a <code>sizeChanged</code> call.
570:                 * Reset to -1 when <code>checkSizeHeight</code> is called.
571:                 */
572:                private int curH = -1;
573:
574:                /**
575:                 * Construct a new TestCanvas given the parent test handler.
576:                 */
577:                public TestCanvas() {
578:                    super ();
579:                }
580:
581:                /**
582:                 * Returns the most recent width from a <code>sizeChanged</code>
583:                 * call and resets <code>curW</code> to -1
584:                 * @return width from the most recent sizeChanged call
585:                 */
586:                public int checkSizeWidth() {
587:                    int tmp;
588:                    tmp = curW;
589:                    curW = -1;
590:                    return tmp;
591:                }
592:
593:                /**
594:                 * Returns the most recent height from a <code>sizeChanged</code>
595:                 * call and resets <code>curH</code> to -1
596:                 * @return heightfrom the most recent sizeChanged call
597:                 */
598:                public int checkSizeHeight() {
599:                    int tmp;
600:                    tmp = curH;
601:                    curH = -1;
602:                    return tmp;
603:                }
604:
605:                /**
606:                 * Used to remotely toggle this canvas's fullscreen mode
607:                 *
608:                 * @param onOff true if this canvas should go to fullscreen mode
609:                 */
610:                public void toggleFullscreen(boolean onOff) {
611:                    super .setFullScreenMode(onOff);
612:                }
613:
614:                /**
615:                 * This notifies the canvas that it's available size for drawing
616:                 * has changed (due to a title, ticker, or fullscreen mode change)
617:                 *
618:                 * @param w the new width in pixels of the drawable area of the
619:                 * <code>Canvas</code>
620:                 * @param h the new height in pixels of the drawable area of
621:                 * the <code>Canvas</code>
622:                 */
623:                protected void sizeChanged(int w, int h) {
624:                    curW = w;
625:                    curH = h;
626:                }
627:
628:                /** 
629:                 * Just a default white fill. The test programmatically changes
630:                 * screens so it would be too fast to write anything useful anyway,
631:                 * as the user wouldn't have time to read it.
632:                 *
633:                 * @param g the Graphics to paint with
634:                 */
635:                protected void paint(Graphics g) {
636:                    int c = g.getColor();
637:
638:                    // IMPL_NOTE: 
639:                    // remove this once chameleon sizeChanged() code is working.
640:                    // This line is used to fake sizeChanged() being called before paint().
641:                    // It appears sizeChanged is not being called in the chameleon code...
642:                    // ...but we don't know why.
643:                    this .sizeChanged(this .getWidth(), this .getHeight());
644:
645:                    g.setColor(0xFFFFFF);
646:                    g.fillRect(g.getClipX(), g.getClipY(), g.getClipWidth(), g
647:                            .getClipHeight());
648:                    g.setColor(c);
649:
650:                    // The spec guarantees us that paint can only be called when
651:                    // the Canvas is visible, that is, isShown() returns true.
652:                    synchronized (this ) {
653:                        try {
654:                            this .notify();
655:                        } catch (IllegalMonitorStateException e) {
656:                            // If the other wait()ing thread doesn't get
657:                            // interrupted, the whole test will block anyway, so
658:                            // we rely on wait/notify to be working correctly
659:                        }
660:                    }
661:                }
662:            }
663:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.