Source Code Cross Referenced for OverlayLayoutTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Alexander T. Simbirtsev
019:         * @version $Revision$
020:         * Created on 22.12.2004
021:
022:         */package javax.swing;
023:
024:        import java.awt.AWTError;
025:        import java.awt.Container;
026:        import java.awt.Dimension;
027:        import java.awt.Panel;
028:        import java.awt.Point;
029:        import java.io.ByteArrayInputStream;
030:        import java.io.ByteArrayOutputStream;
031:        import java.io.IOException;
032:        import java.io.InputStream;
033:        import java.io.ObjectInputStream;
034:        import java.io.ObjectOutputStream;
035:        import javax.swing.border.EmptyBorder;
036:
037:        public class OverlayLayoutTest extends SwingTestCase {
038:            protected OverlayLayout layout = null;
039:
040:            public static void main(final String[] args) {
041:                junit.textui.TestRunner.run(OverlayLayoutTest.class);
042:            }
043:
044:            public void testOverlayLayout() {
045:                Container container = new JPanel();
046:                boolean thrown = false;
047:                try {
048:                    layout = new OverlayLayout(container);
049:                } catch (AWTError e) {
050:                    thrown = true;
051:                }
052:                assertFalse("No exception thrown", thrown);
053:                thrown = false;
054:                try {
055:                    layout = new OverlayLayout(null);
056:                } catch (AWTError e) {
057:                    thrown = true;
058:                }
059:                assertFalse("No exception thrown", thrown);
060:            }
061:
062:            /*
063:             * Class under test for void addLayoutComponent(Component, Object)
064:             */
065:            public void testAddLayoutComponentComponentObject() {
066:                Container container = new JPanel();
067:                JComponent component1 = new JPanel();
068:                JComponent component2 = new JPanel();
069:                JComponent component3 = new JPanel();
070:                JComponent component4 = new JPanel();
071:                OverlayLayout layout = new OverlayLayout(container);
072:                container.add(component1);
073:                container.add(component2);
074:                component1.setMinimumSize(new Dimension(50, 50));
075:                component2.setMinimumSize(new Dimension(70, 80));
076:                component3.setMinimumSize(new Dimension(90, 70));
077:                component4.setMinimumSize(new Dimension(80, 120));
078:                assertEquals("Sizes ", new Dimension(70, 80), layout
079:                        .minimumLayoutSize(container));
080:                container.add(component3);
081:                assertEquals("Sizes ", new Dimension(70, 80), layout
082:                        .minimumLayoutSize(container));
083:                layout.addLayoutComponent(component3, null);
084:                assertEquals("Sizes ", new Dimension(90, 80), layout
085:                        .minimumLayoutSize(container));
086:                container.add(component4);
087:                assertEquals("Sizes ", new Dimension(90, 80), layout
088:                        .minimumLayoutSize(container));
089:                layout.addLayoutComponent(component4, null);
090:                assertEquals("Sizes ", new Dimension(90, 120), layout
091:                        .minimumLayoutSize(container));
092:            }
093:
094:            public void testPreferredLayoutSize() {
095:                JComponent container = new JPanel();
096:                JComponent component1 = new JPanel();
097:                JComponent component2 = new JPanel();
098:                JComponent component3 = new JPanel();
099:                JComponent component4 = new JPanel();
100:                component1.setPreferredSize(new Dimension(41, 26));
101:                component2.setPreferredSize(new Dimension(48, 26));
102:                component3.setPreferredSize(new Dimension(55, 26));
103:                component4.setPreferredSize(new Dimension(62, 26));
104:                layout = new OverlayLayout(container);
105:                container.add(component1);
106:                container.add(component2);
107:                assertEquals("Preferred size: ", new Dimension(48, 26), layout
108:                        .preferredLayoutSize(container));
109:                component1.setPreferredSize(new Dimension(50, 50));
110:                component2.setPreferredSize(new Dimension(70, 120));
111:                component3.setPreferredSize(new Dimension(90, 150));
112:                component4.setPreferredSize(new Dimension(80, 90));
113:                layout = new OverlayLayout(container);
114:                assertEquals("Preferred size: ", new Dimension(70, 120), layout
115:                        .preferredLayoutSize(container));
116:                container.add(component3);
117:                layout = new OverlayLayout(container);
118:                assertEquals("Preferred size: ", new Dimension(90, 150), layout
119:                        .preferredLayoutSize(container));
120:                container.add(component4);
121:                layout = new OverlayLayout(container);
122:                assertEquals("Preferred size: ", new Dimension(90, 150), layout
123:                        .preferredLayoutSize(container));
124:                container = new JPanel();
125:                container.add(component1);
126:                container.add(component2);
127:                component1.setAlignmentX(0.75f);
128:                component2.setAlignmentY(0.75f);
129:                component3.setAlignmentX(0.25f);
130:                component4.setAlignmentY(0.25f);
131:                layout = new OverlayLayout(container);
132:                assertEquals("Preferred size: ", new Dimension(72, 120), layout
133:                        .preferredLayoutSize(container));
134:                container.add(component3);
135:                layout = new OverlayLayout(container);
136:                assertEquals("Preferred size: ", new Dimension(105, 165),
137:                        layout.preferredLayoutSize(container));
138:                container.add(component4);
139:                layout = new OverlayLayout(container);
140:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
141:                assertEquals("Preferred size: ", new Dimension(148, 205),
142:                        layout.preferredLayoutSize(container));
143:            }
144:
145:            public void testMinimumLayoutSize() {
146:                JComponent container = new JPanel();
147:                JComponent component1 = new JPanel();
148:                JComponent component2 = new JPanel();
149:                JComponent component3 = new JPanel();
150:                JComponent component4 = new JPanel();
151:                component1.setMinimumSize(new Dimension(41, 26));
152:                component2.setMinimumSize(new Dimension(48, 26));
153:                component3.setMinimumSize(new Dimension(55, 26));
154:                component4.setMinimumSize(new Dimension(62, 26));
155:                layout = new OverlayLayout(container);
156:                container.add(component1);
157:                container.add(component2);
158:                assertEquals("Minimum size: ", new Dimension(48, 26), layout
159:                        .minimumLayoutSize(container));
160:                component1.setMinimumSize(new Dimension(50, 50));
161:                component2.setMinimumSize(new Dimension(70, 120));
162:                component3.setMinimumSize(new Dimension(90, 150));
163:                component4.setMinimumSize(new Dimension(80, 90));
164:                layout = new OverlayLayout(container);
165:                assertEquals("Minimum size: ", new Dimension(70, 120), layout
166:                        .minimumLayoutSize(container));
167:                container.add(component3);
168:                layout = new OverlayLayout(container);
169:                assertEquals("Minimum size: ", new Dimension(90, 150), layout
170:                        .minimumLayoutSize(container));
171:                container.add(component4);
172:                layout = new OverlayLayout(container);
173:                assertEquals("Minimum size: ", new Dimension(90, 150), layout
174:                        .minimumLayoutSize(container));
175:                container = new JPanel();
176:                container.add(component1);
177:                container.add(component2);
178:                component1.setAlignmentX(0.75f);
179:                component2.setAlignmentY(0.75f);
180:                component3.setAlignmentX(0.25f);
181:                component4.setAlignmentY(0.25f);
182:                layout = new OverlayLayout(container);
183:                assertEquals("Minimum size: ", new Dimension(72, 120), layout
184:                        .minimumLayoutSize(container));
185:                container.add(component3);
186:                layout = new OverlayLayout(container);
187:                assertEquals("Minimum size: ", new Dimension(105, 165), layout
188:                        .minimumLayoutSize(container));
189:                container.add(component4);
190:                layout = new OverlayLayout(container);
191:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
192:                assertEquals("Minimum size: ", new Dimension(148, 205), layout
193:                        .minimumLayoutSize(container));
194:            }
195:
196:            public void testMaximumLayoutSize() {
197:                JComponent container = new JPanel();
198:                JComponent component1 = new JPanel();
199:                JComponent component2 = new JPanel();
200:                JComponent component3 = new JPanel();
201:                JComponent component4 = new JPanel();
202:                component1.setMaximumSize(new Dimension(41, 26));
203:                component2.setMaximumSize(new Dimension(48, 26));
204:                component3.setMaximumSize(new Dimension(55, 26));
205:                component4.setMaximumSize(new Dimension(62, 26));
206:                layout = new OverlayLayout(container);
207:                container.add(component1);
208:                container.add(component2);
209:                assertEquals("Maximum size: ", new Dimension(48, 26), layout
210:                        .maximumLayoutSize(container));
211:                component1.setMaximumSize(new Dimension(50, 50));
212:                component2.setMaximumSize(new Dimension(70, 120));
213:                component3.setMaximumSize(new Dimension(90, 150));
214:                component4.setMaximumSize(new Dimension(80, 90));
215:                layout = new OverlayLayout(container);
216:                assertEquals("Maximum size: ", new Dimension(70, 120), layout
217:                        .maximumLayoutSize(container));
218:                container.add(component3);
219:                layout = new OverlayLayout(container);
220:                assertEquals("Maximum size: ", new Dimension(90, 150), layout
221:                        .maximumLayoutSize(container));
222:                container.add(component4);
223:                layout = new OverlayLayout(container);
224:                assertEquals("Maximum size: ", new Dimension(90, 150), layout
225:                        .maximumLayoutSize(container));
226:                container = new JPanel();
227:                container.add(component1);
228:                container.add(component2);
229:                component1.setAlignmentX(0.75f);
230:                component2.setAlignmentY(0.75f);
231:                component3.setAlignmentX(0.25f);
232:                component4.setAlignmentY(0.25f);
233:                layout = new OverlayLayout(container);
234:                assertEquals("Maximum size: ", new Dimension(72, 120), layout
235:                        .maximumLayoutSize(container));
236:                container.add(component3);
237:                layout = new OverlayLayout(container);
238:                assertEquals("Maximum size: ", new Dimension(105, 165), layout
239:                        .maximumLayoutSize(container));
240:                container.add(component4);
241:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
242:                layout = new OverlayLayout(container);
243:                assertEquals("Maximum size: ", new Dimension(148, 205), layout
244:                        .maximumLayoutSize(container));
245:            }
246:
247:            /*
248:             * Class under test for void addLayoutComponent(String, Component)
249:             */
250:            public void testAddLayoutComponentStringComponent() {
251:                Container container = new JPanel();
252:                JComponent component1 = new JPanel();
253:                JComponent component2 = new JPanel();
254:                JComponent component3 = new JPanel();
255:                JComponent component4 = new JPanel();
256:                component1.setMinimumSize(new Dimension(34, 26));
257:                component2.setMinimumSize(new Dimension(34, 26));
258:                component3.setMinimumSize(new Dimension(34, 26));
259:                component4.setMinimumSize(new Dimension(34, 26));
260:                component1.setPreferredSize(new Dimension(34, 26));
261:                component2.setPreferredSize(new Dimension(34, 26));
262:                component3.setPreferredSize(new Dimension(34, 26));
263:                component4.setPreferredSize(new Dimension(34, 26));
264:                component1.setMaximumSize(new Dimension(34, 26));
265:                component2.setMaximumSize(new Dimension(34, 26));
266:                component3.setMaximumSize(new Dimension(34, 26));
267:                component4.setMaximumSize(new Dimension(34, 26));
268:                OverlayLayout layout = new OverlayLayout(container);
269:                container.add(component1);
270:                container.add(component2);
271:                component1.setMinimumSize(new Dimension(50, 50));
272:                component2.setMinimumSize(new Dimension(70, 80));
273:                component3.setMinimumSize(new Dimension(90, 70));
274:                component4.setMinimumSize(new Dimension(80, 120));
275:                assertEquals("Sizes ", new Dimension(70, 80), layout
276:                        .minimumLayoutSize(container));
277:                container.add(component3);
278:                assertEquals("Sizes ", new Dimension(70, 80), layout
279:                        .minimumLayoutSize(container));
280:                layout.addLayoutComponent("name", component3);
281:                assertEquals("Sizes ", new Dimension(90, 80), layout
282:                        .minimumLayoutSize(container));
283:                container.add(component4);
284:                assertEquals("Sizes ", new Dimension(90, 80), layout
285:                        .minimumLayoutSize(container));
286:                layout.addLayoutComponent("name", component4);
287:                assertEquals("Sizes ", new Dimension(90, 120), layout
288:                        .minimumLayoutSize(container));
289:            }
290:
291:            public void testLayoutContainer1() {
292:                JComponent container = new JPanel();
293:                JComponent component1 = new JPanel();
294:                JComponent component2 = new JPanel();
295:                JComponent component3 = new JPanel();
296:                JComponent component4 = new JPanel();
297:                component4.setMinimumSize(new Dimension(41, 26));
298:                component3.setMinimumSize(new Dimension(48, 26));
299:                component2.setMinimumSize(new Dimension(55, 26));
300:                component1.setMinimumSize(new Dimension(62, 26));
301:                component4.setPreferredSize(new Dimension(41, 26));
302:                component3.setPreferredSize(new Dimension(48, 26));
303:                component2.setPreferredSize(new Dimension(55, 26));
304:                component1.setPreferredSize(new Dimension(62, 26));
305:                component4.setMaximumSize(new Dimension(41, 26));
306:                component3.setMaximumSize(new Dimension(48, 26));
307:                component2.setMaximumSize(new Dimension(55, 26));
308:                component1.setMaximumSize(new Dimension(62, 26));
309:                layout = new OverlayLayout(container);
310:                container.setLayout(layout);
311:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
312:                container.add(component1);
313:                container.add(component2);
314:                container.add(component3);
315:                container.add(component4);
316:                component1.setAlignmentX(0);
317:                component2.setAlignmentX(0.2f);
318:                component3.setAlignmentX(0.3f);
319:                component4.setAlignmentX(1);
320:                component1.setAlignmentY(0);
321:                component2.setAlignmentY(0.2f);
322:                component3.setAlignmentY(0.3f);
323:                component4.setAlignmentY(1);
324:                JDialog window = new JDialog();
325:                window.getContentPane().add(container);
326:                window.pack();
327:                assertEquals("Container's minimum requirements", new Dimension(
328:                        143, 92), layout.minimumLayoutSize(container));
329:                assertEquals("Container's preferred requirements",
330:                        new Dimension(143, 92), layout
331:                                .preferredLayoutSize(container));
332:                assertEquals("Container's maximum requirements", new Dimension(
333:                        143, 92), layout.maximumLayoutSize(container));
334:                assertEquals("Component1 location ", new Point(61, 46),
335:                        component1.getLocation());
336:                assertEquals("Component2 location ", new Point(50, 41),
337:                        component2.getLocation());
338:                assertEquals("Component3 location ", new Point(47, 39),
339:                        component3.getLocation());
340:                assertEquals("Component4 location ", new Point(20, 20),
341:                        component4.getLocation());
342:            }
343:
344:            @SuppressWarnings("deprecation")
345:            public void testLayoutContainer2() {
346:                JWindow window = new JWindow();
347:                JComponent panel = new JPanel();
348:                JComponent panel1 = new JPanel();
349:                JComponent panel2 = new JPanel();
350:                JComponent panel3 = new JPanel();
351:                panel1.setPreferredSize(new Dimension(100, 100));
352:                panel2.setPreferredSize(new Dimension(100, 100));
353:                panel3.setPreferredSize(new Dimension(100, 100));
354:                panel1.setMaximumSize(new Dimension(100, 100));
355:                panel2.setMaximumSize(new Dimension(100, 100));
356:                panel3.setMaximumSize(new Dimension(100, 100));
357:                panel1.setMinimumSize(new Dimension(100, 100));
358:                panel2.setMinimumSize(new Dimension(100, 100));
359:                panel3.setMinimumSize(new Dimension(100, 100));
360:                panel.setPreferredSize(new Dimension(300, 300));
361:                panel.setLayout(new OverlayLayout(panel));
362:                panel1.setAlignmentX(1.0f);
363:                panel2.setAlignmentX(0.3f);
364:                panel3.setAlignmentX(0.0f);
365:                panel1.setAlignmentY(1.0f);
366:                panel2.setAlignmentY(0.3f);
367:                panel3.setAlignmentY(0.0f);
368:                panel.add(panel1);
369:                panel.add(panel2);
370:                panel.add(panel3);
371:                window.setSize(150, 150);
372:                window.getContentPane().add(panel);
373:                window.show();
374:                assertEquals("component's location ", new Point(0, 0), panel1
375:                        .getLocation());
376:                assertEquals("component's location ", new Point(45, 45), panel2
377:                        .getLocation());
378:                assertEquals("component's location ", new Point(75, 75), panel3
379:                        .getLocation());
380:            }
381:
382:            public void testInvalidateLayout() {
383:                Container container = new JPanel();
384:                JComponent component1 = new JPanel();
385:                JComponent component2 = new JPanel();
386:                JComponent component3 = new JPanel();
387:                JComponent component4 = new JPanel();
388:                OverlayLayout layout = new OverlayLayout(container);
389:                container.add(component1);
390:                container.add(component2);
391:                component1.setMinimumSize(new Dimension(50, 50));
392:                component2.setMinimumSize(new Dimension(70, 80));
393:                component3.setMinimumSize(new Dimension(90, 70));
394:                component4.setMinimumSize(new Dimension(80, 120));
395:                assertEquals("Sizes ", new Dimension(70, 80), layout
396:                        .minimumLayoutSize(container));
397:                container.add(component3);
398:                layout.invalidateLayout(container);
399:                assertEquals("Sizes ", new Dimension(90, 80), layout
400:                        .minimumLayoutSize(container));
401:                container.add(component4);
402:                layout.invalidateLayout(container);
403:                assertEquals("Sizes ", new Dimension(90, 120), layout
404:                        .minimumLayoutSize(container));
405:            }
406:
407:            public void testGetLayoutAlignmentY() {
408:                Container container = new JPanel();
409:                JComponent component1 = new JPanel();
410:                JComponent component2 = new JPanel();
411:                JComponent component3 = new JPanel();
412:                JComponent component4 = new JPanel();
413:                component1.setPreferredSize(new Dimension(10, 10));
414:                component2.setPreferredSize(new Dimension(10, 10));
415:                component3.setPreferredSize(new Dimension(10, 10));
416:                component4.setPreferredSize(new Dimension(10, 10));
417:                component1.setMinimumSize(new Dimension(10, 10));
418:                component2.setMinimumSize(new Dimension(10, 10));
419:                component3.setMinimumSize(new Dimension(10, 10));
420:                component4.setMinimumSize(new Dimension(10, 10));
421:                component1.setMaximumSize(new Dimension(10, 10));
422:                component2.setMaximumSize(new Dimension(10, 10));
423:                component3.setMaximumSize(new Dimension(10, 10));
424:                component4.setMaximumSize(new Dimension(10, 10));
425:                OverlayLayout layout = new OverlayLayout(container);
426:                container.add(component1);
427:                container.add(component2);
428:                float value1 = 0.02f;
429:                float value2 = 0.47f;
430:                float value3 = 0.51f;
431:                float value4 = 0.94f;
432:                component1.setAlignmentY(value1);
433:                component2.setAlignmentY(value2);
434:                component3.setAlignmentY(value3);
435:                component4.setAlignmentY(value4);
436:                assertEquals("Alignment ", 0.2857143f, layout
437:                        .getLayoutAlignmentY(container), 1e-5f);
438:                container.add(component3);
439:                layout = new OverlayLayout(container);
440:                assertEquals("Alignment ", 0.333333f, layout
441:                        .getLayoutAlignmentY(container), 1e-5f);
442:                container.add(component4);
443:                layout = new OverlayLayout(container);
444:                assertEquals("Alignment ", 0.4736842f, layout
445:                        .getLayoutAlignmentY(container), 1e-5f);
446:            }
447:
448:            public void testGetLayoutAlignmentX() {
449:                Container container = new JPanel();
450:                JComponent component1 = new JPanel();
451:                JComponent component2 = new JPanel();
452:                JComponent component3 = new JPanel();
453:                JComponent component4 = new JPanel();
454:                component1.setMinimumSize(new Dimension(34, 26));
455:                component2.setMinimumSize(new Dimension(34, 26));
456:                component3.setMinimumSize(new Dimension(34, 26));
457:                component4.setMinimumSize(new Dimension(34, 26));
458:                component1.setPreferredSize(new Dimension(34, 26));
459:                component2.setPreferredSize(new Dimension(34, 26));
460:                component3.setPreferredSize(new Dimension(34, 26));
461:                component4.setPreferredSize(new Dimension(34, 26));
462:                component1.setMaximumSize(new Dimension(34, 26));
463:                component2.setMaximumSize(new Dimension(34, 26));
464:                component3.setMaximumSize(new Dimension(34, 26));
465:                component4.setMaximumSize(new Dimension(34, 26));
466:                OverlayLayout layout = new OverlayLayout(container);
467:                container.add(component1);
468:                container.add(component2);
469:                float value1 = 0.02f;
470:                float value2 = 0.47f;
471:                float value3 = 0.51f;
472:                float value4 = 0.94f;
473:                component1.setAlignmentX(value1);
474:                component2.setAlignmentX(value2);
475:                component3.setAlignmentX(value3);
476:                component4.setAlignmentX(value4);
477:                assertEquals("Alignment ", 0.306122f, layout
478:                        .getLayoutAlignmentX(container), 1e-5f);
479:                container.add(component3);
480:                layout = new OverlayLayout(container);
481:                assertEquals("Alignment ", 0.333333f, layout
482:                        .getLayoutAlignmentX(container), 1e-5f);
483:                container.add(component4);
484:                layout = new OverlayLayout(container);
485:                assertEquals("Alignment ", 0.4769230f, layout
486:                        .getLayoutAlignmentX(container), 1e-5f);
487:            }
488:
489:            public void testRemoveLayoutComponent() {
490:                Container container = new JPanel();
491:                JComponent component1 = new JPanel();
492:                JComponent component2 = new JPanel();
493:                JComponent component3 = new JPanel();
494:                JComponent component4 = new JPanel();
495:                OverlayLayout layout = new OverlayLayout(container);
496:                container.add(component1);
497:                container.add(component2);
498:                container.add(component3);
499:                container.add(component4);
500:                component1.setMinimumSize(new Dimension(50, 50));
501:                component2.setMinimumSize(new Dimension(70, 80));
502:                component3.setMinimumSize(new Dimension(90, 70));
503:                component4.setMinimumSize(new Dimension(80, 120));
504:                assertEquals("Sizes ", new Dimension(90, 120), layout
505:                        .minimumLayoutSize(container));
506:                container.remove(component4);
507:                assertEquals("Sizes ", new Dimension(90, 120), layout
508:                        .minimumLayoutSize(container));
509:                container.add(component4);
510:                layout.removeLayoutComponent(component4);
511:                container.remove(component4);
512:                assertEquals("Sizes ", new Dimension(90, 80), layout
513:                        .minimumLayoutSize(container));
514:                container.remove(component3);
515:                assertEquals("Sizes ", new Dimension(90, 80), layout
516:                        .minimumLayoutSize(container));
517:                container.add(component3);
518:                layout.removeLayoutComponent(component3);
519:                container.remove(component3);
520:                assertEquals("Sizes ", new Dimension(70, 80), layout
521:                        .minimumLayoutSize(container));
522:            }
523:
524:            // Layout sharing testcases and so on
525:            public void testSharingLayout() {
526:                Container container = new JPanel();
527:                layout = new OverlayLayout(container);
528:                boolean thrown = false;
529:                String text = null;
530:                try {
531:                    layout.getLayoutAlignmentY(new JPanel());
532:                } catch (AWTError e) {
533:                    thrown = true;
534:                    text = e.getMessage();
535:                }
536:                assertTrue("AWTError exception thrown", thrown);
537:                assertEquals(text, "OverlayLayout can't be shared");
538:                thrown = false;
539:                text = null;
540:                try {
541:                    layout.getLayoutAlignmentX(new JPanel());
542:                } catch (AWTError e) {
543:                    thrown = true;
544:                    text = e.getMessage();
545:                }
546:                assertTrue("AWTError exception thrown", thrown);
547:                assertEquals(text, "OverlayLayout can't be shared");
548:                thrown = false;
549:                text = null;
550:                try {
551:                    layout.invalidateLayout(new JPanel());
552:                } catch (AWTError e) {
553:                    thrown = true;
554:                    text = e.getMessage();
555:                }
556:                assertTrue("AWTError exception thrown", thrown);
557:                assertEquals(text, "OverlayLayout can't be shared");
558:                thrown = false;
559:                text = null;
560:                try {
561:                    layout.maximumLayoutSize(new JPanel());
562:                } catch (AWTError e) {
563:                    thrown = true;
564:                    text = e.getMessage();
565:                }
566:                assertTrue("AWTError exception thrown", thrown);
567:                assertEquals(text, "OverlayLayout can't be shared");
568:                thrown = false;
569:                text = null;
570:                try {
571:                    layout.layoutContainer(new JPanel());
572:                } catch (AWTError e) {
573:                    thrown = true;
574:                    text = e.getMessage();
575:                }
576:                assertTrue("AWTError exception thrown", thrown);
577:                assertEquals(text, "OverlayLayout can't be shared");
578:                thrown = false;
579:                text = null;
580:                try {
581:                    layout.preferredLayoutSize(new JPanel());
582:                } catch (AWTError e) {
583:                    thrown = true;
584:                    text = e.getMessage();
585:                }
586:                assertTrue("AWTError exception thrown", thrown);
587:                assertEquals(text, "OverlayLayout can't be shared");
588:                thrown = false;
589:                text = null;
590:                try {
591:                    layout.minimumLayoutSize(new JPanel());
592:                } catch (AWTError e) {
593:                    thrown = true;
594:                    text = e.getMessage();
595:                }
596:                assertTrue("AWTError exception thrown", thrown);
597:                assertEquals(text, "OverlayLayout can't be shared");
598:            }
599:
600:            public void testWriteObject() throws IOException {
601:                Container container = new JPanel();
602:                OverlayLayout layout1 = new OverlayLayout(container);
603:                ByteArrayOutputStream fo = new ByteArrayOutputStream();
604:                ObjectOutputStream so = new ObjectOutputStream(fo);
605:                so.writeObject(layout1);
606:                so.flush();
607:            }
608:
609:            public void testReadObject() throws ClassNotFoundException,
610:                    IOException {
611:                Container container = new Panel();
612:                OverlayLayout layout1 = new OverlayLayout(container);
613:                ByteArrayOutputStream fo = new ByteArrayOutputStream();
614:                ObjectOutputStream so = new ObjectOutputStream(fo);
615:                so.writeObject(layout1);
616:                so.flush();
617:                InputStream fi = new ByteArrayInputStream(fo.toByteArray());
618:                ObjectInputStream si = new ObjectInputStream(fi);
619:                OverlayLayout resurrectedLayout = (OverlayLayout) si
620:                        .readObject();
621:                assertNotNull(resurrectedLayout);
622:            }
623:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.