Source Code Cross Referenced for TestCanvasSizing.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.chameleon.skins.*;
030:        import com.sun.midp.i3test.TestCase;
031:        import com.sun.midp.util.LcduiTestCanvas;
032:        import com.sun.midp.util.LcduiTestMIDlet;
033:        import com.sun.midp.configurator.Constants;
034:
035:        /**
036:         * This test case does extensive testing on the proper sizing
037:         * of Canvas. It validates the size reported to a Canvas under
038:         * various conditions, such as a canvas with a title, a ticker,
039:         * in standard screen mode, in fullscreen mode, as well as a
040:         * canvas which is newly created versus showing on the screen.
041:         */
042:        public class TestCanvasSizing extends TestCase {
043:
044:            /** Test Name */
045:            static final String testName = "CanvasSizing";
046:
047:            // We define a set of constants that are set by pulling values
048:            // out of the various skin classes (ie. TitleSkin, TickerSkin, etc).
049:
050:            /** Screen width in normal mode */
051:            protected static int STD_WIDTH;
052:            /** Screen height in normal mode */
053:            protected static int STD_HEIGHT;
054:
055:            // Note that although for chameleon's standard spec, the fullscreen
056:            // height and the standard height are the same, this may not be the
057:            // case for all implementations. Including both here allows the test
058:            // to be valid in both circumstances.
059:
060:            /** Screen width in fullsize mode */
061:            protected static int FS_WIDTH;
062:            /** Screen height in fullsize mode */
063:            protected static int FS_HEIGHT;
064:
065:            /** Title height */
066:            protected static int TITLE_HEIGHT;
067:
068:            /** Ticker height */
069:            protected static int TICKER_HEIGHT;
070:
071:            /** Softbutton height */
072:            protected static int SOFTBTN_HEIGHT;
073:
074:            /** The Display to use to view our test canvases */
075:            protected Display display;
076:
077:            /** Test ticker, used for sizing only */
078:            protected Ticker ticker;
079:
080:            /**
081:             * Construct a new CanvasSizing test. The constructor
082:             * initializes all sizing constants from the chameleon
083:             * skin files.
084:             */
085:            public TestCanvasSizing() {
086:                // Initialize the constants
087:
088:                STD_WIDTH = ScreenSkin.WIDTH;
089:                STD_HEIGHT = Constants.CHAM_HEIGHT;
090:                FS_WIDTH = Constants.CHAM_FULLWIDTH;
091:                FS_HEIGHT = Constants.CHAM_FULLHEIGHT;
092:                TITLE_HEIGHT = TitleSkin.HEIGHT;
093:                TICKER_HEIGHT = TickerSkin.HEIGHT;
094:                SOFTBTN_HEIGHT = SoftButtonSkin.HEIGHT;
095:
096:                ticker = new Ticker("Canvas sizing test");
097:            }
098:
099:            /**
100:             * This is a utility method which retrieves the canvas's size and
101:             * validates it against the passed in values after making sure 
102:             * the canvas is visible on the screen.
103:             *
104:             * @param canvas the canvas to test
105:             * @param WIDTH the <b>correct</b> width the canvas should be
106:             * @param HEIGHT the <b>correct</b> height the canvas should be
107:             */
108:            protected void checkCanvasSize(TestCanvas canvas, int WIDTH,
109:                    int HEIGHT) {
110:
111:                display.setCurrent(canvas);
112:
113:                if (!canvas.awaitPaint()) {
114:                    fail("checkCanvasSize: canvas not visible");
115:                    return;
116:                }
117:
118:                int w = canvas.getWidth();
119:                int h = canvas.getHeight();
120:                assertEquals("Checking canvas width (shown):", WIDTH, w);
121:                assertEquals("Checking canvas height (shown):", HEIGHT, h);
122:            }
123:
124:            /**
125:             * This test is for a canvas with a title and a ticker set in
126:             * standard screen mode.
127:             */
128:            protected void testOne() {
129:                declare(testName
130:                        + " 1: Standard screen mode with title and ticker.");
131:
132:                TestCanvas canvas = new TestCanvas();
133:                canvas.setTitle("CanvasSizing Test 1");
134:                canvas.setTicker(ticker);
135:
136:                checkCanvasSize(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT
137:                        - TITLE_HEIGHT - TICKER_HEIGHT);
138:            }
139:
140:            /**
141:             * This test is for a canvas with a title but no ticker set in
142:             * standard screen mode.
143:             */
144:            protected void testTwo() {
145:                declare(testName + " 2: Standard screen mode with title.");
146:
147:                TestCanvas canvas = new TestCanvas();
148:                canvas.setTitle("CanvasSizing Test 2");
149:
150:                checkCanvasSize(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT
151:                        - TITLE_HEIGHT);
152:            }
153:
154:            /**
155:             * This test is for a canvas with a ticker but no title set in
156:             * standard screen mode.
157:             */
158:            protected void testThree() {
159:                declare(testName + " 3: Standard screen mode with ticker.");
160:
161:                TestCanvas canvas = new TestCanvas();
162:                canvas.setTicker(ticker);
163:
164:                checkCanvasSize(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT
165:                        - TICKER_HEIGHT);
166:            }
167:
168:            /**
169:             * This test is for a canvas with no title and no ticker set in
170:             * standard screen mode.
171:             */
172:            protected void testFour() {
173:                declare(testName + " 4: Standard screen mode, plain.");
174:
175:                TestCanvas canvas = new TestCanvas();
176:
177:                checkCanvasSize(canvas, STD_WIDTH, STD_HEIGHT - SOFTBTN_HEIGHT);
178:            }
179:
180:            /**
181:             * This test is for a canvas with a title and a ticker set in
182:             * fullscreen mode.
183:             */
184:            protected void testFive() {
185:                declare(testName
186:                        + " 5: Fullsize screen mode with title and ticker.");
187:
188:                TestCanvas canvas = new TestCanvas();
189:                canvas.setTitle("CanvasSizing Test 5");
190:                canvas.setTicker(ticker);
191:                canvas.toggleFullscreen(true);
192:
193:                // NOTE: In fullscreen mode, the title and ticker shouldn't appear, as
194:                // per the chameleon UI spec: that area is then used by the canvas
195:                checkCanvasSize(canvas, FS_WIDTH, FS_HEIGHT);
196:            }
197:
198:            /**
199:             * This test is for a canvas with a title but no ticker set in
200:             * fullscreen mode.
201:             */
202:            protected void testSix() {
203:                declare(testName + " 6: Fullsize screen mode with title.");
204:
205:                TestCanvas canvas = new TestCanvas();
206:                canvas.setTitle("CanvasSizing Test 6");
207:                canvas.toggleFullscreen(true);
208:
209:                // NOTE: In fullscreen mode, the title and ticker shouldn't appear, as
210:                // per the chameleon UI spec: that area is then used by the canvas
211:                checkCanvasSize(canvas, FS_WIDTH, FS_HEIGHT);
212:            }
213:
214:            /**
215:             * This test is for a canvas with a ticker but no title set in
216:             * fullscreen mode.
217:             */
218:            protected void testSeven() {
219:                declare(testName + " 7: Fullsize screen mode with ticker.");
220:
221:                TestCanvas canvas = new TestCanvas();
222:                canvas.setTicker(ticker);
223:                canvas.toggleFullscreen(true);
224:
225:                // NOTE: In fullscreen mode, the title and ticker shouldn't appear, as
226:                // per the chameleon UI spec: that area is then used by the canvas
227:                checkCanvasSize(canvas, FS_WIDTH, FS_HEIGHT);
228:            }
229:
230:            /**
231:             * This test is for a canvas with no ticker and no title set in
232:             * fullscreen mode.
233:             */
234:            protected void testEight() {
235:                declare(testName + " 8: Fullsize screen mode, plain.");
236:
237:                TestCanvas canvas = new TestCanvas();
238:                canvas.toggleFullscreen(true);
239:
240:                // NOTE: In fullscreen mode, the title and ticker shouldn't appear, as
241:                // per the chameleon UI spec: that area is then used by the canvas
242:                checkCanvasSize(canvas, FS_WIDTH, FS_HEIGHT);
243:            }
244:
245:            /**
246:             * Overridden from TestCase parent. This method will kick off each
247:             * individual test
248:             */
249:            public void runTests() throws Throwable {
250:
251:                try {
252:                    LcduiTestMIDlet.invoke();
253:                    display = LcduiTestMIDlet.getDisplay();
254:
255:                    testOne();
256:                    testTwo();
257:                    testThree();
258:                    testFour();
259:                    testFive();
260:                    testSix();
261:                    testSeven();
262:                    testEight();
263:                } finally {
264:                    LcduiTestMIDlet.cleanup();
265:                }
266:            }
267:
268:            /**
269:             * Inner canvas class which notifies the main TestCase when
270:             * a particular canvas has become visible. This allows the
271:             * main TestCase to do sizing verification both before the
272:             * canvas becomes visible, and after.
273:             */
274:            class TestCanvas extends LcduiTestCanvas {
275:
276:                /**
277:                 * Used to remotely toggle this canvas's fullscreen mode
278:                 *
279:                 * @param onOff true if this canvas should go to fullscreen mode
280:                 */
281:                public void toggleFullscreen(boolean onOff) {
282:                    super .setFullScreenMode(onOff);
283:                }
284:
285:                /** 
286:                 * Just a default white fill. The test programmatically changes
287:                 * screens so it would be too fast to write anything useful anyway,
288:                 * as the user wouldn't have time to read it.
289:                 *
290:                 * @param g the Graphics to paint with
291:                 */
292:                public void paint1(Graphics g) {
293:                    int c = g.getColor();
294:                    g.setColor(0xFFFFFF);
295:                    g.fillRect(g.getClipX(), g.getClipY(), g.getClipWidth(), g
296:                            .getClipHeight());
297:                    g.setColor(c);
298:                }
299:            }
300:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.