Source Code Cross Referenced for BoxLayoutTest.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:         */package javax.swing;
021:
022:        import java.awt.AWTError;
023:        import java.awt.Container;
024:        import java.awt.Dimension;
025:        import java.awt.Panel;
026:        import java.awt.Point;
027:        import java.io.ByteArrayInputStream;
028:        import java.io.ByteArrayOutputStream;
029:        import java.io.IOException;
030:        import java.io.InputStream;
031:        import java.io.ObjectInputStream;
032:        import java.io.ObjectOutputStream;
033:        import javax.swing.border.EmptyBorder;
034:
035:        public class BoxLayoutTest extends SwingTestCase {
036:            protected BoxLayout layout = null;
037:
038:            public void testBoxLayout() {
039:                Container container = new JPanel();
040:                boolean thrown = false;
041:                String text = null;
042:                try {
043:                    layout = new BoxLayout(container, BoxLayout.LINE_AXIS);
044:                } catch (AWTError e) {
045:                    thrown = true;
046:                }
047:                assertFalse("No exception thrown", thrown);
048:                thrown = false;
049:                text = null;
050:                try {
051:                    layout = new BoxLayout(container, 300);
052:                } catch (AWTError e) {
053:                    thrown = true;
054:                    text = e.getMessage();
055:                }
056:                assertTrue("AWTError exception thrown", thrown);
057:                assertEquals(text, "Invalid axis");
058:                thrown = false;
059:                text = null;
060:                try {
061:                    layout = new BoxLayout(null, BoxLayout.Y_AXIS);
062:                } catch (AWTError e) {
063:                    thrown = true;
064:                }
065:                assertFalse("No exception thrown", thrown);
066:            }
067:
068:            /*
069:             * this method is not used by this class so ther's no need to test it
070:             */
071:            public void testAddLayoutComponentComponentObject() {
072:            }
073:
074:            public void testPreferredLayoutSize() {
075:                JComponent container1 = new JPanel();
076:                JComponent container2 = new JPanel();
077:                JComponent component11 = new JPanel();
078:                component11.setPreferredSize(new Dimension(41, 26));
079:                JComponent component21 = new JPanel();
080:                component21.setPreferredSize(new Dimension(48, 26));
081:                JComponent component31 = new JPanel();
082:                component31.setPreferredSize(new Dimension(55, 26));
083:                JComponent component41 = new JPanel();
084:                component41.setPreferredSize(new Dimension(62, 26));
085:                JComponent component12 = new JPanel();
086:                component12.setPreferredSize(new Dimension(62, 26));
087:                JComponent component22 = new JPanel();
088:                component22.setPreferredSize(new Dimension(55, 26));
089:                JComponent component32 = new JPanel();
090:                component32.setPreferredSize(new Dimension(48, 26));
091:                JComponent component42 = new JPanel();
092:                component42.setPreferredSize(new Dimension(41, 26));
093:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
094:                BoxLayout layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
095:                container1.add(component11);
096:                container1.add(component21);
097:                container2.add(component12);
098:                container2.add(component22);
099:                assertEquals("1 Sizes coinside:", new Dimension(89, 26),
100:                        layout1.preferredLayoutSize(container1));
101:                assertEquals("2 Sizes coinside:", new Dimension(62, 52),
102:                        layout2.preferredLayoutSize(container2));
103:                component11.setPreferredSize(new Dimension(50, 50));
104:                component21.setPreferredSize(new Dimension(70, 150));
105:                component31.setPreferredSize(new Dimension(90, 120));
106:                component41.setPreferredSize(new Dimension(80, 90));
107:                component12.setPreferredSize(new Dimension(50, 50));
108:                component22.setPreferredSize(new Dimension(70, 150));
109:                component32.setPreferredSize(new Dimension(90, 120));
110:                component42.setPreferredSize(new Dimension(80, 90));
111:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
112:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
113:                assertEquals("1 Sizes coinside:", new Dimension(120, 150),
114:                        layout1.preferredLayoutSize(container1));
115:                assertEquals("2 Sizes coinside:", new Dimension(70, 200),
116:                        layout2.preferredLayoutSize(container2));
117:                container1.add(component31);
118:                container2.add(component32);
119:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
120:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
121:                assertEquals("1 Sizes coinside:", new Dimension(210, 150),
122:                        layout1.preferredLayoutSize(container1));
123:                assertEquals("2 Sizes coinside:", new Dimension(90, 320),
124:                        layout2.preferredLayoutSize(container2));
125:                container1.add(component41);
126:                container2.add(component42);
127:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
128:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
129:                container1.setBorder(new EmptyBorder(20, 20, 20, 20));
130:                container2.setBorder(new EmptyBorder(20, 20, 20, 20));
131:                assertEquals("1 Sizes coinside:", new Dimension(330, 190),
132:                        layout1.preferredLayoutSize(container1));
133:                assertEquals("2 Sizes coinside:", new Dimension(130, 450),
134:                        layout2.preferredLayoutSize(container2));
135:            }
136:
137:            public void testLayoutInvisibleChild() {
138:                JComponent container1 = new JPanel();
139:                JComponent component1 = new JPanel();
140:                component1.setPreferredSize(new Dimension(41, 26));
141:                component1.setVisible(false);
142:                container1.add(component1);
143:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
144:                assertEquals(new Dimension(), layout1
145:                        .preferredLayoutSize(container1));
146:            }
147:
148:            public void testMinimumLayoutSize() {
149:                JComponent container1 = new JPanel();
150:                JComponent container2 = new JPanel();
151:                JComponent component11 = new JPanel();
152:                component11.setMinimumSize(new Dimension(41, 26));
153:                JComponent component21 = new JPanel();
154:                component21.setMinimumSize(new Dimension(48, 26));
155:                JComponent component31 = new JPanel();
156:                component31.setMinimumSize(new Dimension(55, 26));
157:                JComponent component41 = new JPanel();
158:                component41.setMinimumSize(new Dimension(62, 26));
159:                JComponent component12 = new JPanel();
160:                component12.setMinimumSize(new Dimension(62, 26));
161:                JComponent component22 = new JPanel();
162:                component22.setMinimumSize(new Dimension(55, 26));
163:                JComponent component32 = new JPanel();
164:                component32.setMinimumSize(new Dimension(48, 26));
165:                JComponent component42 = new JPanel();
166:                component42.setMinimumSize(new Dimension(41, 26));
167:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
168:                BoxLayout layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
169:                container1.add(component11);
170:                container1.add(component21);
171:                container2.add(component12);
172:                container2.add(component22);
173:                assertEquals("1 Sizes coinside:", new Dimension(89, 26),
174:                        layout1.minimumLayoutSize(container1));
175:                assertEquals("2 Sizes coinside:", new Dimension(62, 52),
176:                        layout2.minimumLayoutSize(container2));
177:                component11.setMinimumSize(new Dimension(50, 50));
178:                component21.setMinimumSize(new Dimension(70, 150));
179:                component31.setMinimumSize(new Dimension(90, 120));
180:                component41.setMinimumSize(new Dimension(80, 90));
181:                component12.setMinimumSize(new Dimension(50, 50));
182:                component22.setMinimumSize(new Dimension(70, 150));
183:                component32.setMinimumSize(new Dimension(90, 120));
184:                component42.setMinimumSize(new Dimension(80, 90));
185:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
186:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
187:                assertEquals("1 Sizes coinside:", new Dimension(120, 150),
188:                        layout1.minimumLayoutSize(container1));
189:                assertEquals("2 Sizes coinside:", new Dimension(70, 200),
190:                        layout2.minimumLayoutSize(container2));
191:                container1.add(component31);
192:                container2.add(component32);
193:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
194:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
195:                assertEquals("1 Sizes coinside:", new Dimension(210, 150),
196:                        layout1.minimumLayoutSize(container1));
197:                assertEquals("2 Sizes coinside:", new Dimension(90, 320),
198:                        layout2.minimumLayoutSize(container2));
199:                container1.add(component41);
200:                container2.add(component42);
201:                container1.setBorder(new EmptyBorder(20, 20, 20, 20));
202:                container2.setBorder(new EmptyBorder(20, 20, 20, 20));
203:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
204:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
205:                assertEquals("1 Sizes coinside:", new Dimension(330, 190),
206:                        layout1.minimumLayoutSize(container1));
207:                assertEquals("2 Sizes coinside:", new Dimension(130, 450),
208:                        layout2.minimumLayoutSize(container2));
209:            }
210:
211:            public void testMaximumLayoutSize1() {
212:                JComponent container1 = new JPanel();
213:                JComponent container2 = new JPanel();
214:                JComponent component11 = new JPanel();
215:                component11.setMaximumSize(new Dimension(41, 26));
216:                JComponent component21 = new JPanel();
217:                component21.setMaximumSize(new Dimension(48, 26));
218:                JComponent component31 = new JPanel();
219:                component31.setMaximumSize(new Dimension(55, 26));
220:                JComponent component41 = new JPanel();
221:                component41.setMaximumSize(new Dimension(62, 26));
222:                JComponent component12 = new JPanel();
223:                component12.setMaximumSize(new Dimension(62, 26));
224:                JComponent component22 = new JPanel();
225:                component22.setMaximumSize(new Dimension(55, 26));
226:                JComponent component32 = new JPanel();
227:                component32.setMaximumSize(new Dimension(48, 26));
228:                JComponent component42 = new JPanel();
229:                component42.setMaximumSize(new Dimension(41, 26));
230:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
231:                BoxLayout layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
232:                container1.add(component11);
233:                container1.add(component21);
234:                container2.add(component12);
235:                container2.add(component22);
236:                assertEquals("1 Sizes coinside:", new Dimension(89, 26),
237:                        layout1.maximumLayoutSize(container1));
238:                assertEquals("2 Sizes coinside:", new Dimension(62, 52),
239:                        layout2.maximumLayoutSize(container2));
240:                component11.setMaximumSize(new Dimension(50, 50));
241:                component21.setMaximumSize(new Dimension(70, 150));
242:                component31.setMaximumSize(new Dimension(90, 120));
243:                component41.setMaximumSize(new Dimension(80, 90));
244:                component12.setMaximumSize(new Dimension(50, 50));
245:                component22.setMaximumSize(new Dimension(70, 150));
246:                component32.setMaximumSize(new Dimension(90, 120));
247:                component42.setMaximumSize(new Dimension(80, 90));
248:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
249:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
250:                assertEquals("1 Sizes coinside:", new Dimension(120, 150),
251:                        layout1.maximumLayoutSize(container1));
252:                assertEquals("2 Sizes coinside:", new Dimension(70, 200),
253:                        layout2.maximumLayoutSize(container2));
254:                container1.add(component31);
255:                container2.add(component32);
256:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
257:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
258:                assertEquals("1 Sizes coinside:", new Dimension(210, 150),
259:                        layout1.maximumLayoutSize(container1));
260:                assertEquals("2 Sizes coinside:", new Dimension(90, 320),
261:                        layout2.maximumLayoutSize(container2));
262:                container1.add(component41);
263:                container2.add(component42);
264:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
265:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
266:                container1.setBorder(new EmptyBorder(20, 20, 20, 20));
267:                container2.setBorder(new EmptyBorder(20, 20, 20, 20));
268:                assertEquals("1 Sizes coinside:", new Dimension(330, 190),
269:                        layout1.maximumLayoutSize(container1));
270:                assertEquals("2 Sizes coinside:", new Dimension(130, 450),
271:                        layout2.maximumLayoutSize(container2));
272:            }
273:
274:            public void testMaximumLayoutSize2() {
275:                Container container1 = new JPanel();
276:                Container container2 = new JPanel();
277:                JComponent component11 = new JPanel();
278:                JComponent component21 = new JPanel();
279:                JComponent component12 = new JPanel();
280:                JComponent component22 = new JPanel();
281:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
282:                BoxLayout layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
283:                container1.add(component11);
284:                container1.add(component21);
285:                container2.add(component12);
286:                container2.add(component22);
287:                assertEquals("Maximum size 1: ", new Dimension(
288:                        2 * Short.MAX_VALUE, Short.MAX_VALUE), layout1
289:                        .maximumLayoutSize(container1));
290:                assertEquals("Maximum size 2: ", new Dimension(Short.MAX_VALUE,
291:                        2 * Short.MAX_VALUE), layout2
292:                        .maximumLayoutSize(container2));
293:            }
294:
295:            /*
296:             * this method is not used by this class so ther's no need to test it
297:             */
298:            public void testAddLayoutComponentStringComponent() {
299:            }
300:
301:            public void testLayoutContainerVertical() {
302:                JComponent container = new JPanel();
303:                JComponent component1 = new JPanel();
304:                component1.setMinimumSize(new Dimension(62, 26));
305:                component1.setPreferredSize(new Dimension(62, 26));
306:                component1.setMaximumSize(new Dimension(62, 26));
307:                JComponent component2 = new JPanel();
308:                component2.setMinimumSize(new Dimension(55, 26));
309:                component2.setPreferredSize(new Dimension(55, 26));
310:                component2.setMaximumSize(new Dimension(55, 26));
311:                JComponent component3 = new JPanel();
312:                component3.setMinimumSize(new Dimension(48, 26));
313:                component3.setPreferredSize(new Dimension(48, 26));
314:                component3.setMaximumSize(new Dimension(48, 26));
315:                JComponent component4 = new JPanel();
316:                component4.setMinimumSize(new Dimension(41, 26));
317:                component4.setPreferredSize(new Dimension(41, 26));
318:                component4.setMaximumSize(new Dimension(41, 26));
319:                BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
320:                container.setLayout(layout);
321:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
322:                container.add(component1);
323:                container.add(component2);
324:                container.add(component3);
325:                container.add(component4);
326:                component1.setAlignmentX(0);
327:                component2.setAlignmentX(0.2f);
328:                component3.setAlignmentX(0.3f);
329:                component4.setAlignmentX(1);
330:                JFrame window2 = new JFrame();
331:                window2.getContentPane().add(container);
332:                window2.pack();
333:                assertEquals("Container's minimum requirements", new Dimension(
334:                        143, 144), layout.minimumLayoutSize(container));
335:                assertEquals("Container's preferred requirements",
336:                        new Dimension(143, 144), layout
337:                                .preferredLayoutSize(container));
338:                assertEquals("Container's maximum requirements", new Dimension(
339:                        143, 144), layout.maximumLayoutSize(container));
340:                assertEquals("Component1 location ", new Point(61, 20),
341:                        component1.getLocation());
342:                assertEquals("Component2 location ", new Point(50, 46),
343:                        component2.getLocation());
344:                assertEquals("Component3 location ", new Point(47, 72),
345:                        component3.getLocation());
346:                assertEquals("Component4 location ", new Point(20, 98),
347:                        component4.getLocation());
348:                window2.dispose();
349:            }
350:
351:            public void testLayoutContainerHorizontal() {
352:                JComponent container = new JPanel();
353:                JComponent component1 = new JPanel();
354:                component1.setMinimumSize(new Dimension(41, 26));
355:                component1.setPreferredSize(new Dimension(41, 26));
356:                component1.setMaximumSize(new Dimension(41, 26));
357:                JComponent component2 = new JPanel();
358:                component2.setMinimumSize(new Dimension(48, 26));
359:                component2.setPreferredSize(new Dimension(48, 26));
360:                component2.setMaximumSize(new Dimension(48, 26));
361:                JComponent component3 = new JPanel();
362:                component3.setMinimumSize(new Dimension(55, 26));
363:                component3.setPreferredSize(new Dimension(55, 26));
364:                component3.setMaximumSize(new Dimension(55, 26));
365:                JComponent component4 = new JPanel();
366:                component4.setMinimumSize(new Dimension(62, 26));
367:                component4.setPreferredSize(new Dimension(62, 26));
368:                component4.setMaximumSize(new Dimension(62, 26));
369:                BoxLayout layout = new BoxLayout(container, BoxLayout.X_AXIS);
370:                container.setLayout(layout);
371:                container.setBorder(new EmptyBorder(20, 20, 20, 20));
372:                container.add(component1);
373:                container.add(component2);
374:                container.add(component3);
375:                container.add(component4);
376:                component1.setPreferredSize(new Dimension(70, 150));
377:                component2.setPreferredSize(new Dimension(70, 150));
378:                component3.setPreferredSize(new Dimension(90, 120));
379:                component4.setPreferredSize(new Dimension(80, 90));
380:                component1.setAlignmentY(0);
381:                component2.setAlignmentY(0.2f);
382:                component3.setAlignmentY(0.3f);
383:                component4.setAlignmentY(1);
384:                JFrame window = new JFrame();
385:                window.getContentPane().add(container);
386:                window.pack();
387:                assertEquals("Container's minimum requirements", new Dimension(
388:                        246, 92), layout.minimumLayoutSize(container));
389:                assertEquals("Container's preferred requirements",
390:                        new Dimension(350, 280), layout
391:                                .preferredLayoutSize(container));
392:                assertEquals("Container's maximum requirements", new Dimension(
393:                        246, 92), layout.maximumLayoutSize(container));
394:                assertEquals("Component1 - Locations coinside:", new Point(20,
395:                        140), component1.getLocation());
396:                assertEquals("Component2 - Locations coinside:", new Point(61,
397:                        135), component2.getLocation());
398:                assertEquals("Component3 - Locations coinside:", new Point(109,
399:                        133), component3.getLocation());
400:                assertEquals("Component4 - Locations coinside:", new Point(164,
401:                        114), component4.getLocation());
402:                window.dispose();
403:            }
404:
405:            public void testInvalidateLayout() {
406:                Container container1 = new MyPanel();
407:                Container container2 = new MyPanel();
408:                JComponent component11 = new JPanel();
409:                JComponent component21 = new JPanel();
410:                JComponent component31 = new JPanel();
411:                JComponent component41 = new JPanel();
412:                JComponent component12 = new JPanel();
413:                JComponent component22 = new JPanel();
414:                JComponent component32 = new JPanel();
415:                JComponent component42 = new JPanel();
416:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
417:                BoxLayout layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
418:                container1.add(component11);
419:                container1.add(component21);
420:                container2.add(component21);
421:                container2.add(component22);
422:                component11.setMinimumSize(new Dimension(50, 50));
423:                component21.setMinimumSize(new Dimension(70, 150));
424:                component31.setMinimumSize(new Dimension(90, 120));
425:                component41.setMinimumSize(new Dimension(80, 90));
426:                component12.setMinimumSize(new Dimension(50, 50));
427:                component22.setMinimumSize(new Dimension(70, 150));
428:                component32.setMinimumSize(new Dimension(90, 120));
429:                component42.setMinimumSize(new Dimension(80, 90));
430:                assertEquals("1 Sizes coinside:", new Dimension(50, 50),
431:                        layout1.minimumLayoutSize(container1));
432:                assertEquals("2 Sizes coinside:", new Dimension(70, 300),
433:                        layout2.minimumLayoutSize(container2));
434:                container1.add(component31);
435:                container2.add(component32);
436:                layout1.invalidateLayout(container1);
437:                layout2.invalidateLayout(container2);
438:                assertEquals("1 Sizes coinside:", new Dimension(140, 120),
439:                        layout1.minimumLayoutSize(container1));
440:                assertEquals("2 Sizes coinside:", new Dimension(90, 420),
441:                        layout2.minimumLayoutSize(container2));
442:                container1.add(component41);
443:                container2.add(component42);
444:                layout1.invalidateLayout(container1);
445:                layout2.invalidateLayout(container2);
446:                assertEquals("1 Sizes coinside:", new Dimension(220, 120),
447:                        layout1.minimumLayoutSize(container1));
448:                assertEquals("2 Sizes coinside:", new Dimension(90, 510),
449:                        layout2.minimumLayoutSize(container2));
450:            }
451:
452:            // Layout sharing testcases and so on
453:            public void testSharingLayout() {
454:                layout = new BoxLayout(new JPanel(), BoxLayout.LINE_AXIS);
455:                try {
456:                    layout.getLayoutAlignmentY(new JPanel());
457:                    fail("Exception must be thrown");
458:                } catch (AWTError e) {
459:                }
460:                try {
461:                    layout.getLayoutAlignmentX(new JPanel());
462:                    fail("Exception must be thrown");
463:                } catch (AWTError e) {
464:                }
465:                try {
466:                    layout.invalidateLayout(new JPanel());
467:                    fail("Exception must be thrown");
468:                } catch (AWTError e) {
469:                }
470:                try {
471:                    layout.maximumLayoutSize(new JPanel());
472:                    fail("Exception must be thrown");
473:                } catch (AWTError e) {
474:                }
475:                try {
476:                    layout.layoutContainer(new JPanel());
477:                    fail("Exception must be thrown");
478:                } catch (AWTError e) {
479:                }
480:                try {
481:                    layout.preferredLayoutSize(new JPanel());
482:                    fail("Exception must be thrown");
483:                } catch (AWTError e) {
484:                }
485:                try {
486:                    layout.minimumLayoutSize(new JPanel());
487:                    fail("Exception must be thrown");
488:                } catch (AWTError e) {
489:                }
490:            }
491:
492:            class MyPanel extends JPanel {
493:                private static final long serialVersionUID = 1L;
494:
495:                MyPanel() {
496:                    setPreferredSize(new Dimension(10, 10));
497:                    setMinimumSize(new Dimension(10, 10));
498:                    setMaximumSize(new Dimension(10, 10));
499:                }
500:            }
501:
502:            public void testGetLayoutAlignmentY() {
503:                Container container1 = new MyPanel();
504:                Container container2 = new MyPanel();
505:                JComponent component11 = new MyPanel();
506:                JComponent component21 = new MyPanel();
507:                JComponent component31 = new MyPanel();
508:                JComponent component41 = new MyPanel();
509:                JComponent component12 = new MyPanel();
510:                JComponent component22 = new MyPanel();
511:                JComponent component32 = new MyPanel();
512:                JComponent component42 = new MyPanel();
513:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.Y_AXIS);
514:                BoxLayout layout2 = new BoxLayout(container2, BoxLayout.X_AXIS);
515:                container1.add(component11);
516:                container1.add(component21);
517:                container2.add(component12);
518:                container2.add(component22);
519:                float value1 = 0.02f;
520:                float value2 = 0.47f;
521:                float value3 = 0.51f;
522:                float value4 = 0.94f;
523:                float defaultValue = 0.5f;
524:                component11.setAlignmentY(value1);
525:                component21.setAlignmentY(value2);
526:                component31.setAlignmentY(value3);
527:                component41.setAlignmentY(value4);
528:                component12.setAlignmentY(value1);
529:                component22.setAlignmentY(value2);
530:                component32.setAlignmentY(value3);
531:                component42.setAlignmentY(value4);
532:                assertEquals("Alignments coinside:", 0.2857143, layout2
533:                        .getLayoutAlignmentY(container2), 1e-5f);
534:                assertEquals("Alignments coinside:", defaultValue, layout1
535:                        .getLayoutAlignmentY(container1), 1e-5f);
536:                container1.add(component31);
537:                container2.add(component32);
538:                layout1 = new BoxLayout(container1, BoxLayout.Y_AXIS);
539:                layout2 = new BoxLayout(container2, BoxLayout.X_AXIS);
540:                assertEquals("Alignments coinside:", 0.33333334, layout2
541:                        .getLayoutAlignmentY(container2), 1e-5f);
542:                assertEquals("Alignments coinside:", defaultValue, layout1
543:                        .getLayoutAlignmentY(container1), 1e-5f);
544:                container1.add(component41);
545:                container2.add(component42);
546:                layout1 = new BoxLayout(container1, BoxLayout.Y_AXIS);
547:                layout2 = new BoxLayout(container2, BoxLayout.X_AXIS);
548:                assertEquals("Alignments coinside:", 0.47368422, layout2
549:                        .getLayoutAlignmentY(container2), 1e-5f);
550:                assertEquals("Alignments coinside:", defaultValue, layout1
551:                        .getLayoutAlignmentY(container1), 1e-5f);
552:            }
553:
554:            public void testGetLayoutAlignmentX() {
555:                Container container1 = new JPanel();
556:                Container container2 = new JPanel();
557:                JComponent component11 = new JPanel();
558:                JComponent component21 = new JPanel();
559:                JComponent component31 = new JPanel();
560:                JComponent component41 = new JPanel();
561:                JComponent component12 = new JPanel();
562:                JComponent component22 = new JPanel();
563:                JComponent component32 = new JPanel();
564:                JComponent component42 = new JPanel();
565:                component11.setMinimumSize(new Dimension(34, 10));
566:                component11.setPreferredSize(new Dimension(34, 10));
567:                component11.setMaximumSize(new Dimension(34, 10));
568:                component21.setMinimumSize(new Dimension(34, 10));
569:                component21.setPreferredSize(new Dimension(34, 10));
570:                component21.setMaximumSize(new Dimension(34, 10));
571:                component31.setMinimumSize(new Dimension(34, 10));
572:                component31.setPreferredSize(new Dimension(34, 10));
573:                component31.setMaximumSize(new Dimension(34, 10));
574:                component41.setMinimumSize(new Dimension(34, 10));
575:                component41.setPreferredSize(new Dimension(34, 10));
576:                component41.setMaximumSize(new Dimension(34, 10));
577:                component12.setMinimumSize(new Dimension(34, 10));
578:                component12.setPreferredSize(new Dimension(34, 10));
579:                component12.setMaximumSize(new Dimension(34, 10));
580:                component22.setMinimumSize(new Dimension(34, 10));
581:                component22.setPreferredSize(new Dimension(34, 10));
582:                component22.setMaximumSize(new Dimension(34, 10));
583:                component32.setMinimumSize(new Dimension(34, 10));
584:                component32.setPreferredSize(new Dimension(34, 10));
585:                component32.setMaximumSize(new Dimension(34, 10));
586:                component42.setMinimumSize(new Dimension(34, 10));
587:                component42.setPreferredSize(new Dimension(34, 10));
588:                component42.setMaximumSize(new Dimension(34, 10));
589:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
590:                BoxLayout layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
591:                container1.add(component11);
592:                container1.add(component21);
593:                container2.add(component12);
594:                container2.add(component22);
595:                float value1 = 0.02f;
596:                float value2 = 0.47f;
597:                float value3 = 0.51f;
598:                float value4 = 0.94f;
599:                float defaultValue = 0.5f;
600:                component11.setAlignmentX(value1);
601:                component21.setAlignmentX(value2);
602:                component31.setAlignmentX(value3);
603:                component41.setAlignmentX(value4);
604:                component12.setAlignmentX(value1);
605:                component22.setAlignmentX(value2);
606:                component32.setAlignmentX(value3);
607:                component42.setAlignmentX(value4);
608:                assertEquals("Alignments coinside:", defaultValue, layout1
609:                        .getLayoutAlignmentX(container1), 1e-5f);
610:                assertEquals("Alignments coinside:", 0.30612245, layout2
611:                        .getLayoutAlignmentX(container2), 1e-5f);
612:                container1.add(component31);
613:                container2.add(component32);
614:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
615:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
616:                assertEquals("Alignments coinside:", defaultValue, layout1
617:                        .getLayoutAlignmentX(container1), 1e-5f);
618:                assertEquals("Alignments coinside:", 0.33333334, layout2
619:                        .getLayoutAlignmentX(container2), 1e-5f);
620:                container1.add(component41);
621:                container2.add(component42);
622:                layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
623:                layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
624:                assertEquals("Alignments coinside:", defaultValue, layout1
625:                        .getLayoutAlignmentX(container1), 1e-5f);
626:                assertEquals("Alignments coinside:", 0.47692308, layout2
627:                        .getLayoutAlignmentX(container2), 1e-5f);
628:            }
629:
630:            /*
631:             * this method is not used by this class so ther's no need to test it
632:             */
633:            public void testRemoveLayoutComponent() {
634:            }
635:
636:            public void testWriteObject() throws IOException {
637:                Container container1 = new Panel();
638:                Container container2 = new Panel();
639:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
640:                BoxLayout layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
641:                ByteArrayOutputStream fo = new ByteArrayOutputStream();
642:                ObjectOutputStream so = new ObjectOutputStream(fo);
643:                so.writeObject(layout1);
644:                so.flush();
645:                fo = new ByteArrayOutputStream();
646:                so = new ObjectOutputStream(fo);
647:                so.writeObject(layout2);
648:                so.flush();
649:            }
650:
651:            public void testReadObject() throws IOException,
652:                    ClassNotFoundException {
653:                Container container1 = new Panel();
654:                Container container2 = new Panel();
655:                BoxLayout layout1 = new BoxLayout(container1, BoxLayout.X_AXIS);
656:                BoxLayout layout2 = new BoxLayout(container2, BoxLayout.Y_AXIS);
657:                ByteArrayOutputStream fo = new ByteArrayOutputStream();
658:                ObjectOutputStream so = new ObjectOutputStream(fo);
659:                so.writeObject(layout1);
660:                so.flush();
661:                InputStream fi = new ByteArrayInputStream(fo.toByteArray());
662:                ObjectInputStream si = new ObjectInputStream(fi);
663:                BoxLayout resurrectedLayout = (BoxLayout) si.readObject();
664:                assertNotNull(resurrectedLayout);
665:                fo = new ByteArrayOutputStream();
666:                so = new ObjectOutputStream(fo);
667:                so.writeObject(layout2);
668:                so.flush();
669:                fi = new ByteArrayInputStream(fo.toByteArray());
670:                si = new ObjectInputStream(fi);
671:                resurrectedLayout = (BoxLayout) si.readObject();
672:                assertNotNull(resurrectedLayout);
673:            }
674:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.