Source Code Cross Referenced for FlowLayoutTest.java in  » Apache-Harmony-Java-SE » java-package » java » awt » 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 » java package » java.awt 
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 Michael Danilov
019:         * @version $Revision$
020:         */package java.awt;
021:
022:        @SuppressWarnings("serial")
023:        public class FlowLayoutTest extends AWTTestCase {
024:
025:            class TestButton extends Button {
026:                TestButton(String name, Dimension min, Dimension pref) {
027:                    super (name);
028:
029:                    setMinimumSize(min);
030:                    setPreferredSize(pref);
031:                }
032:            }
033:
034:            private final int MIN_SIZE = 50;
035:            private final int PREF_SIZE = 100;
036:            private final TestButton b1, b2, b3, b4, b5;
037:            private FlowLayout layout;
038:            private Frame frame;
039:
040:            @Override
041:            protected void setUp() throws Exception {
042:                super .setUp();
043:
044:                frame = new Frame();
045:                layout = new FlowLayout();
046:                frame.setLayout(layout);
047:                frame.setVisible(true);
048:            }
049:
050:            @Override
051:            protected void tearDown() throws Exception {
052:                frame.dispose();
053:                super .tearDown();
054:            }
055:
056:            public FlowLayoutTest() {
057:                Dimension min = new Dimension(MIN_SIZE, MIN_SIZE), pref = new Dimension(
058:                        PREF_SIZE, PREF_SIZE);
059:                b1 = new TestButton("1", min, pref);
060:                b2 = new TestButton("2", min, pref);
061:                b3 = new TestButton("3", min, pref);
062:                b4 = new TestButton("4", min, pref);
063:                b5 = new TestButton("5", min, pref);
064:            }
065:
066:            public static void main(String[] args) {
067:                junit.textui.TestRunner.run(FlowLayoutTest.class);
068:            }
069:
070:            public final void testToString() {
071:                layout = new FlowLayout(FlowLayout.LEADING, 10, 20);
072:                assertTrue(new String(
073:                        "java.awt.FlowLayout[hgap=10,vgap=20,align=leading]")
074:                        .equals(layout.toString()));
075:                layout = new FlowLayout(FlowLayout.LEFT, 0, 0);
076:                assertTrue(new String(
077:                        "java.awt.FlowLayout[hgap=0,vgap=0,align=left]")
078:                        .equals(layout.toString()));
079:                layout = new FlowLayout(FlowLayout.RIGHT, 0, 0);
080:                assertTrue(new String(
081:                        "java.awt.FlowLayout[hgap=0,vgap=0,align=right]")
082:                        .equals(layout.toString()));
083:                layout = new FlowLayout(FlowLayout.TRAILING, 0, 0);
084:                assertTrue(new String(
085:                        "java.awt.FlowLayout[hgap=0,vgap=0,align=trailing]")
086:                        .equals(layout.toString()));
087:                layout = new FlowLayout(FlowLayout.CENTER, 0, 0);
088:                assertTrue(new String(
089:                        "java.awt.FlowLayout[hgap=0,vgap=0,align=center]")
090:                        .equals(layout.toString()));
091:            }
092:
093:            public final void testFlowLayoutint() {
094:                layout = new FlowLayout(FlowLayout.TRAILING);
095:                assertEquals(layout.getAlignment(), FlowLayout.TRAILING);
096:                assertEquals(layout.getHgap(), 5);
097:                assertEquals(layout.getVgap(), 5);
098:                layout = new FlowLayout(FlowLayout.CENTER);
099:                assertEquals(layout.getAlignment(), FlowLayout.CENTER);
100:                layout = new FlowLayout(FlowLayout.LEFT);
101:                assertEquals(layout.getAlignment(), FlowLayout.LEFT);
102:                layout = new FlowLayout(FlowLayout.LEADING);
103:                assertEquals(layout.getAlignment(), FlowLayout.LEADING);
104:                layout = new FlowLayout(FlowLayout.RIGHT);
105:                assertEquals(layout.getAlignment(), FlowLayout.RIGHT);
106:            }
107:
108:            public final void testFlowLayout() {
109:                FlowLayout layout = new FlowLayout();
110:                assertEquals(layout.getAlignment(), FlowLayout.CENTER);
111:                assertEquals(layout.getHgap(), 5);
112:                assertEquals(layout.getVgap(), 5);
113:            }
114:
115:            public final void testFlowLayoutintintint() {
116:                FlowLayout layout = new FlowLayout(FlowLayout.TRAILING, 7, 7);
117:                assertEquals(layout.getAlignment(), FlowLayout.TRAILING);
118:                assertEquals(layout.getHgap(), 7);
119:                assertEquals(layout.getVgap(), 7);
120:            }
121:
122:            public final void testGetSetAlignment() {
123:                int align = FlowLayout.LEADING;
124:                layout.setAlignment(align);
125:                assertEquals(align, layout.getAlignment());
126:                layout.setAlignment(align = FlowLayout.CENTER);
127:                assertEquals(align, layout.getAlignment());
128:                layout.setAlignment(align = FlowLayout.RIGHT);
129:                assertEquals(align, layout.getAlignment());
130:                layout.setAlignment(align = FlowLayout.TRAILING);
131:                assertEquals(align, layout.getAlignment());
132:                layout.setAlignment(align = FlowLayout.LEFT);
133:                assertEquals(align, layout.getAlignment());
134:
135:                layout.setAlignment(align = 5);
136:                assertEquals(align, layout.getAlignment());
137:                layout.setAlignment(align = -1);
138:                assertEquals(align, layout.getAlignment());
139:
140:            }
141:
142:            public final void testGetSetHgap() {
143:                layout.setHgap(10);
144:                assertEquals(layout.getHgap(), 10);
145:                layout.setHgap(-1);
146:                assertEquals(layout.getHgap(), -1);
147:            }
148:
149:            public final void testGetSetVgap() {
150:                layout.setVgap(10);
151:                assertEquals(layout.getVgap(), 10);
152:                layout.setVgap(-1);
153:                assertEquals(layout.getVgap(), -1);
154:            }
155:
156:            public final void testMinimumLayoutSize() {
157:                Dimension expected = new Dimension();
158:                Insets insets = frame.getInsets();
159:
160:                expected.setSize(insets.left + insets.right, insets.top
161:                        + insets.bottom);
162:                Dimension defMinSize = layout
163:                        .minimumLayoutSize(new Container() {
164:                        });
165:                expected.width += defMinSize.width;
166:                expected.height += defMinSize.height;
167:                assertEquals(expected, layout.minimumLayoutSize(frame));
168:
169:                frame.add(b1);
170:                frame.add(b2);
171:                frame.add(b3);
172:                frame.add(b4);
173:                b5.setFont(new Font("dialog", Font.PLAIN, 20));
174:                frame.add(b5);
175:                layout.setVgap(10);
176:                layout.setHgap(20);
177:
178:                expected.width = insets.left + insets.right
179:                        + b1.getMinimumSize().width + b2.getMinimumSize().width
180:                        + b3.getMinimumSize().width + b4.getMinimumSize().width
181:                        + b5.getMinimumSize().width + 6 * layout.getHgap();
182:                expected.height = insets.bottom
183:                        + insets.top
184:                        + Math.max(b1.getMinimumSize().height, Math.max(b2
185:                                .getMinimumSize().height, Math.max(b3
186:                                .getMinimumSize().height, Math.max(b4
187:                                .getMinimumSize().height,
188:                                b5.getMinimumSize().height)))) + 2
189:                        * layout.getVgap();
190:                assertEquals(layout.minimumLayoutSize(frame), expected);
191:            }
192:
193:            public final void testPreferredLayoutSize() {
194:                Dimension expected = new Dimension();
195:                Insets insets = frame.getInsets();
196:
197:                expected.setSize(insets.left + insets.right, insets.top
198:                        + insets.bottom);
199:                Dimension defPrefSize = layout
200:                        .preferredLayoutSize(new Container() {
201:                        });
202:                expected.width += defPrefSize.width;
203:                expected.height += defPrefSize.height;
204:                assertEquals(expected, layout.preferredLayoutSize(frame));
205:
206:                frame.add(b1);
207:                frame.add(b2);
208:                frame.add(b3);
209:                frame.add(b4);
210:                b5.setFont(new Font("dialog", Font.PLAIN, 20));
211:                frame.add(b5);
212:                layout.setVgap(10);
213:                layout.setHgap(20);
214:
215:                expected.width = insets.left + insets.right
216:                        + b1.getPreferredSize().width
217:                        + b2.getPreferredSize().width
218:                        + b3.getPreferredSize().width
219:                        + b4.getPreferredSize().width
220:                        + b5.getPreferredSize().width + 6 * layout.getHgap();
221:                expected.height = insets.bottom
222:                        + insets.top
223:                        + Math.max(b1.getPreferredSize().height, Math.max(b2
224:                                .getPreferredSize().height, Math.max(b3
225:                                .getPreferredSize().height, Math.max(b4
226:                                .getPreferredSize().height, b5
227:                                .getPreferredSize().height)))) + 2
228:                        * layout.getVgap();
229:                assertEquals(layout.preferredLayoutSize(frame), expected);
230:            }
231:
232:            public final void testAddLayoutComponent() {
233:                Container c = new Container();
234:                c.add(b1);
235:                c.add(b2);
236:                layout.addLayoutComponent("", b3);
237:                assertEquals(new Dimension(), b1.getSize());
238:                assertEquals(new Dimension(), b2.getSize());
239:                assertEquals(new Dimension(), b3.getSize());
240:                layout.layoutContainer(c);
241:                assertEquals(b1.getPreferredSize(), b1.getSize());
242:                assertEquals(b2.getPreferredSize(), b2.getSize());
243:                // verify that addLayoutComponent has no effect:
244:                assertEquals(new Dimension(), b3.getSize());
245:            }
246:
247:            public final void testRemoveLayoutComponent() {
248:                Container c = new Container();
249:                c.add(b1);
250:                c.add(b2);
251:                layout.removeLayoutComponent(b2);
252:                assertEquals(new Dimension(), b1.getSize());
253:                assertEquals(new Dimension(), b2.getSize());
254:                layout.layoutContainer(c);
255:                assertEquals(b1.getPreferredSize(), b1.getSize());
256:                // verify that removeLayoutComponent has no effect:
257:                assertEquals(b2.getPreferredSize(), b2.getSize());
258:
259:            }
260:
261:            public final void testLayoutContainer() {
262:
263:                frame.add(b1);
264:                frame.add(b2);
265:                frame.add(b3);
266:                layout.setHgap(10);
267:                layout.setVgap(20);
268:
269:                layout.setAlignment(FlowLayout.LEFT);
270:                frame.validate();
271:                checkLeft();
272:                layout.setAlignment(FlowLayout.RIGHT);
273:                frame.validate();
274:                checkRight();
275:                layout.setAlignment(FlowLayout.CENTER);
276:                frame.validate();
277:                checkCenter();
278:                frame
279:                        .setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
280:                layout.setAlignment(FlowLayout.LEADING);
281:                frame.validate();
282:                checkLeft();
283:                layout.setAlignment(FlowLayout.TRAILING);
284:                frame.validate();
285:                checkRight();
286:                frame
287:                        .setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
288:                layout.setAlignment(FlowLayout.LEADING);
289:                frame.validate();
290:                checkRightInverted();
291:                layout.setAlignment(FlowLayout.TRAILING);
292:                frame.validate();
293:                checkLeftInverted();
294:                layout.setAlignment(FlowLayout.LEFT);
295:                frame
296:                        .setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
297:                b2.setFont(new Font("dialog", Font.PLAIN, 20));
298:                frame.validate();
299:                checkLeftSized();
300:
301:            }
302:
303:            private void checkLeftSized() {
304:                Insets insets = frame.getInsets();
305:
306:                frame.setSize(layout.preferredLayoutSize(frame));
307:                frame.validate();
308:                int x = insets.left + layout.getHgap();
309:                int y = insets.top + layout.getVgap();
310:                int diff = (b2.getSize().height - b1.getSize().height) / 2;
311:                assertEquals(b1.getBounds(),
312:                        new Rectangle(x, y + diff, b1.getPreferredSize().width,
313:                                b1.getPreferredSize().height));
314:                x += b1.getPreferredSize().width + layout.getHgap();
315:                assertEquals(b2.getBounds(),
316:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
317:                                .getPreferredSize().height));
318:                x += b2.getPreferredSize().width + layout.getHgap();
319:                assertEquals(b3.getBounds(),
320:                        new Rectangle(x, y + diff, b3.getPreferredSize().width,
321:                                b3.getPreferredSize().height));
322:
323:                frame.setSize(layout.preferredLayoutSize(frame).width - 1,
324:                        layout.preferredLayoutSize(frame).height);
325:                frame.validate();
326:                x = insets.left + layout.getHgap();
327:                y = insets.top + layout.getVgap();
328:                assertEquals(b1.getBounds(),
329:                        new Rectangle(x, y + diff, b1.getPreferredSize().width,
330:                                b1.getPreferredSize().height));
331:                x += b1.getPreferredSize().width + layout.getHgap();
332:                assertEquals(b2.getBounds(),
333:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
334:                                .getPreferredSize().height));
335:                x = insets.left + layout.getHgap();
336:                y += layout.getVgap()
337:                        + Math.max(b1.getPreferredSize().height, b2
338:                                .getPreferredSize().height);
339:                assertEquals(b3.getBounds(),
340:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
341:                                .getPreferredSize().height));
342:            }
343:
344:            private void checkLeftInverted() {
345:                Insets insets = frame.getInsets();
346:
347:                frame.setSize(layout.preferredLayoutSize(frame));
348:                frame.validate();
349:                int x = insets.left + layout.getHgap();
350:                int y = insets.top + layout.getVgap();
351:                assertEquals(b3.getBounds(),
352:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
353:                                .getPreferredSize().height));
354:                x += b3.getPreferredSize().width + layout.getHgap();
355:                assertEquals(b2.getBounds(),
356:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
357:                                .getPreferredSize().height));
358:                x += b2.getPreferredSize().width + layout.getHgap();
359:                assertEquals(b1.getBounds(),
360:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
361:                                .getPreferredSize().height));
362:
363:                frame.setSize(layout.preferredLayoutSize(frame).width + 1,
364:                        layout.preferredLayoutSize(frame).height);
365:                frame.validate();
366:                x = insets.left + layout.getHgap();
367:                y = insets.top + layout.getVgap();
368:                assertEquals(b3.getBounds(),
369:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
370:                                .getPreferredSize().height));
371:                x += b3.getPreferredSize().width + layout.getHgap();
372:                assertEquals(b2.getBounds(),
373:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
374:                                .getPreferredSize().height));
375:                x += b2.getPreferredSize().width + layout.getHgap();
376:                assertEquals(b1.getBounds(),
377:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
378:                                .getPreferredSize().height));
379:
380:                frame.setSize(layout.preferredLayoutSize(frame).width - 1,
381:                        layout.preferredLayoutSize(frame).height);
382:                frame.validate();
383:                x = insets.left + layout.getHgap();
384:                y = insets.top + layout.getVgap();
385:                assertEquals(b2.getBounds(),
386:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
387:                                .getPreferredSize().height));
388:                x += b2.getPreferredSize().width + layout.getHgap();
389:                assertEquals(b1.getBounds(),
390:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
391:                                .getPreferredSize().height));
392:                x = insets.left + layout.getHgap();
393:                y += layout.getVgap()
394:                        + Math.max(b1.getPreferredSize().height, b2
395:                                .getPreferredSize().height);
396:                assertEquals(b3.getBounds(),
397:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
398:                                .getPreferredSize().height));
399:            }
400:
401:            private void checkRightInverted() {
402:                Insets insets = frame.getInsets();
403:
404:                frame.setSize(layout.preferredLayoutSize(frame));
405:                frame.validate();
406:                int x = insets.left + layout.getHgap();
407:                int y = insets.top + layout.getVgap();
408:                assertEquals(b3.getBounds(),
409:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
410:                                .getPreferredSize().height));
411:                x += b3.getPreferredSize().width + layout.getHgap();
412:                assertEquals(b2.getBounds(),
413:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
414:                                .getPreferredSize().height));
415:                x += b2.getPreferredSize().width + layout.getHgap();
416:                assertEquals(b1.getBounds(),
417:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
418:                                .getPreferredSize().height));
419:
420:                frame.setSize(layout.preferredLayoutSize(frame).width + 1,
421:                        layout.preferredLayoutSize(frame).height);
422:                frame.validate();
423:                x = insets.left + layout.getHgap() + 1;
424:                y = insets.top + layout.getVgap();
425:                assertEquals(b3.getBounds(),
426:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
427:                                .getPreferredSize().height));
428:                x += b3.getPreferredSize().width + layout.getHgap();
429:                assertEquals(b2.getBounds(),
430:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
431:                                .getPreferredSize().height));
432:                x += b2.getPreferredSize().width + layout.getHgap();
433:                assertEquals(b1.getBounds(),
434:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
435:                                .getPreferredSize().height));
436:
437:                frame.setSize(layout.preferredLayoutSize(frame).width - 1,
438:                        layout.preferredLayoutSize(frame).height);
439:                frame.validate();
440:                x = frame.getSize().width - insets.right - layout.getHgap()
441:                        - b1.getPreferredSize().width;
442:                y = insets.top + layout.getVgap();
443:                assertEquals(b1.getBounds(),
444:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
445:                                .getPreferredSize().height));
446:                x -= b1.getPreferredSize().width + layout.getHgap();
447:                assertEquals(b2.getBounds(),
448:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
449:                                .getPreferredSize().height));
450:                x = frame.getSize().width - insets.right - layout.getHgap()
451:                        - b3.getPreferredSize().width;
452:                y += layout.getVgap()
453:                        + Math.max(b1.getPreferredSize().height, b2
454:                                .getPreferredSize().height);
455:                assertEquals(b3.getBounds(),
456:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
457:                                .getPreferredSize().height));
458:            }
459:
460:            private void checkCenter() {
461:                Insets insets = frame.getInsets();
462:
463:                frame.setSize(layout.preferredLayoutSize(frame));
464:                frame.validate();
465:                int x = insets.left + layout.getHgap();
466:                int y = insets.top + layout.getVgap();
467:                assertEquals(b1.getBounds(),
468:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
469:                                .getPreferredSize().height));
470:                x += b1.getPreferredSize().width + layout.getHgap();
471:                assertEquals(b2.getBounds(),
472:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
473:                                .getPreferredSize().height));
474:                x += b2.getPreferredSize().width + layout.getHgap();
475:                assertEquals(b3.getBounds(),
476:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
477:                                .getPreferredSize().height));
478:
479:                frame.setSize(layout.preferredLayoutSize(frame).width + 2,
480:                        layout.preferredLayoutSize(frame).height);
481:                frame.validate();
482:                x = insets.left + layout.getHgap() + 1;
483:                y = insets.top + layout.getVgap();
484:                assertEquals(b1.getBounds(),
485:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
486:                                .getPreferredSize().height));
487:                x += b1.getPreferredSize().width + layout.getHgap();
488:                assertEquals(b2.getBounds(),
489:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
490:                                .getPreferredSize().height));
491:                x += b2.getPreferredSize().width + layout.getHgap();
492:                assertEquals(b3.getBounds(),
493:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
494:                                .getPreferredSize().height));
495:
496:                frame.setSize(layout.preferredLayoutSize(frame).width - 1,
497:                        layout.preferredLayoutSize(frame).height);
498:                frame.validate();
499:                x = insets.left + layout.getHgap()
500:                        + (b3.getPreferredSize().width + layout.getHgap() - 1)
501:                        / 2;
502:                y = insets.top + layout.getVgap();
503:                assertEquals(b1.getBounds(),
504:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
505:                                .getPreferredSize().height));
506:                x += b1.getPreferredSize().width + layout.getHgap();
507:                assertEquals(b2.getBounds(),
508:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
509:                                .getPreferredSize().height));
510:                x = insets.left
511:                        + (frame.getSize().width - insets.left - insets.right - b3
512:                                .getPreferredSize().width) / 2;
513:                y += layout.getVgap()
514:                        + Math.max(b1.getPreferredSize().height, b2
515:                                .getPreferredSize().height);
516:                assertEquals(b3.getBounds(),
517:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
518:                                .getPreferredSize().height));
519:            }
520:
521:            private void checkRight() {
522:                Insets insets = frame.getInsets();
523:
524:                frame.setSize(layout.preferredLayoutSize(frame));
525:                frame.validate();
526:                int x = insets.left + layout.getHgap();
527:                int y = insets.top + layout.getVgap();
528:                assertEquals(b1.getBounds(),
529:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
530:                                .getPreferredSize().height));
531:                x += b1.getPreferredSize().width + layout.getHgap();
532:                assertEquals(b2.getBounds(),
533:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
534:                                .getPreferredSize().height));
535:                x += b2.getPreferredSize().width + layout.getHgap();
536:                assertEquals(b3.getBounds(),
537:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
538:                                .getPreferredSize().height));
539:
540:                frame.setSize(layout.preferredLayoutSize(frame).width + 1,
541:                        layout.preferredLayoutSize(frame).height);
542:                frame.validate();
543:                x = insets.left + layout.getHgap() + 1;
544:                y = insets.top + layout.getVgap();
545:                assertEquals(b1.getBounds(),
546:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
547:                                .getPreferredSize().height));
548:                x += b1.getPreferredSize().width + layout.getHgap();
549:                assertEquals(b2.getBounds(),
550:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
551:                                .getPreferredSize().height));
552:                x += b2.getPreferredSize().width + layout.getHgap();
553:                assertEquals(b3.getBounds(),
554:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
555:                                .getPreferredSize().height));
556:
557:                frame.setSize(layout.preferredLayoutSize(frame).width - 1,
558:                        layout.preferredLayoutSize(frame).height);
559:                frame.validate();
560:                x = frame.getSize().width - insets.right - layout.getHgap()
561:                        - b2.getPreferredSize().width;
562:                y = insets.top + layout.getVgap();
563:                assertEquals(b2.getBounds(),
564:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
565:                                .getPreferredSize().height));
566:                x -= b2.getPreferredSize().width + layout.getHgap();
567:                assertEquals(b1.getBounds(),
568:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
569:                                .getPreferredSize().height));
570:                x = frame.getSize().width - insets.right - layout.getHgap()
571:                        - b3.getPreferredSize().width;
572:                y += layout.getVgap()
573:                        + Math.max(b1.getPreferredSize().height, b2
574:                                .getPreferredSize().height);
575:                assertEquals(b3.getBounds(),
576:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
577:                                .getPreferredSize().height));
578:            }
579:
580:            private void checkLeft() {
581:                Insets insets = frame.getInsets();
582:
583:                frame.setSize(layout.preferredLayoutSize(frame));
584:                frame.validate();
585:                int x = insets.left + layout.getHgap();
586:                int y = insets.top + layout.getVgap();
587:                assertEquals(b1.getBounds(),
588:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
589:                                .getPreferredSize().height));
590:                x += b1.getPreferredSize().width + layout.getHgap();
591:                assertEquals(b2.getBounds(),
592:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
593:                                .getPreferredSize().height));
594:                x += b2.getPreferredSize().width + layout.getHgap();
595:                assertEquals(b3.getBounds(),
596:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
597:                                .getPreferredSize().height));
598:
599:                frame.setSize(layout.preferredLayoutSize(frame).width + 1,
600:                        layout.preferredLayoutSize(frame).height);
601:                frame.validate();
602:                x = insets.left + layout.getHgap();
603:                y = insets.top + layout.getVgap();
604:                assertEquals(b1.getBounds(),
605:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
606:                                .getPreferredSize().height));
607:                x += b1.getPreferredSize().width + layout.getHgap();
608:                assertEquals(b2.getBounds(),
609:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
610:                                .getPreferredSize().height));
611:                x += b2.getPreferredSize().width + layout.getHgap();
612:                assertEquals(b3.getBounds(),
613:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
614:                                .getPreferredSize().height));
615:
616:                frame.setSize(layout.preferredLayoutSize(frame).width - 1,
617:                        layout.preferredLayoutSize(frame).height);
618:                frame.validate();
619:                x = insets.left + layout.getHgap();
620:                y = insets.top + layout.getVgap();
621:                assertEquals(b1.getBounds(),
622:                        new Rectangle(x, y, b1.getPreferredSize().width, b1
623:                                .getPreferredSize().height));
624:                x += b1.getPreferredSize().width + layout.getHgap();
625:                assertEquals(b2.getBounds(),
626:                        new Rectangle(x, y, b2.getPreferredSize().width, b2
627:                                .getPreferredSize().height));
628:                x = insets.left + layout.getHgap();
629:                y += layout.getVgap()
630:                        + Math.max(b1.getPreferredSize().height, b2
631:                                .getPreferredSize().height);
632:                assertEquals(b3.getBounds(),
633:                        new Rectangle(x, y, b3.getPreferredSize().width, b3
634:                                .getPreferredSize().height));
635:            }
636:
637:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.