Source Code Cross Referenced for BorderArrangementTests.java in  » Chart » jfreechart » org » jfree » chart » block » junit » 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 » Chart » jfreechart » org.jfree.chart.block.junit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ===========================================================
002:         * JFreeChart : a free chart library for the Java(tm) platform
003:         * ===========================================================
004:         *
005:         * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006:         *
007:         * Project Info:  http://www.jfree.org/jfreechart/index.html
008:         *
009:         * This library is free software; you can redistribute it and/or modify it 
010:         * under the terms of the GNU Lesser General Public License as published by 
011:         * the Free Software Foundation; either version 2.1 of the License, or 
012:         * (at your option) any later version.
013:         *
014:         * This library is distributed in the hope that it will be useful, but 
015:         * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
016:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
017:         * License for more details.
018:         *
019:         * You should have received a copy of the GNU Lesser General Public
020:         * License along with this library; if not, write to the Free Software
021:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
022:         * USA.  
023:         *
024:         * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
025:         * in the United States and other countries.]
026:         *
027:         * ---------------------------
028:         * BorderArrangementTests.java
029:         * ---------------------------
030:         * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
031:         *
032:         * Original Author:  David Gilbert (for Object Refinery Limited);
033:         * Contributor(s):   -;
034:         *
035:         * $Id: BorderArrangementTests.java,v 1.1.2.1 2006/10/03 15:41:45 mungady Exp $
036:         *
037:         * Changes
038:         * -------
039:         * 22-Oct-2004 : Version 1 (DG);
040:         *
041:         */
042:
043:        package org.jfree.chart.block.junit;
044:
045:        import java.awt.Graphics2D;
046:        import java.awt.image.BufferedImage;
047:        import java.io.ByteArrayInputStream;
048:        import java.io.ByteArrayOutputStream;
049:        import java.io.ObjectInput;
050:        import java.io.ObjectInputStream;
051:        import java.io.ObjectOutput;
052:        import java.io.ObjectOutputStream;
053:
054:        import junit.framework.Test;
055:        import junit.framework.TestCase;
056:        import junit.framework.TestSuite;
057:
058:        import org.jfree.chart.block.Block;
059:        import org.jfree.chart.block.BlockContainer;
060:        import org.jfree.chart.block.BorderArrangement;
061:        import org.jfree.chart.block.EmptyBlock;
062:        import org.jfree.chart.block.LengthConstraintType;
063:        import org.jfree.chart.block.RectangleConstraint;
064:        import org.jfree.data.Range;
065:        import org.jfree.ui.RectangleEdge;
066:        import org.jfree.ui.Size2D;
067:
068:        /**
069:         * Tests for the {@link BorderArrangement} class.
070:         */
071:        public class BorderArrangementTests extends TestCase {
072:
073:            private static final double EPSILON = 0.0000000001;
074:
075:            /**
076:             * Returns the tests as a test suite.
077:             *
078:             * @return The test suite.
079:             */
080:            public static Test suite() {
081:                return new TestSuite(BorderArrangementTests.class);
082:            }
083:
084:            /**
085:             * Constructs a new set of tests.
086:             *
087:             * @param name  the name of the tests.
088:             */
089:            public BorderArrangementTests(String name) {
090:                super (name);
091:            }
092:
093:            /**
094:             * Confirm that the equals() method can distinguish all the required fields.
095:             */
096:            public void testEquals() {
097:                BorderArrangement b1 = new BorderArrangement();
098:                BorderArrangement b2 = new BorderArrangement();
099:                assertTrue(b1.equals(b2));
100:                assertTrue(b2.equals(b1));
101:
102:                b1.add(new EmptyBlock(99.0, 99.0), null);
103:                assertFalse(b1.equals(b2));
104:                b2.add(new EmptyBlock(99.0, 99.0), null);
105:                assertTrue(b1.equals(b2));
106:
107:                b1.add(new EmptyBlock(1.0, 1.0), RectangleEdge.LEFT);
108:                assertFalse(b1.equals(b2));
109:                b2.add(new EmptyBlock(1.0, 1.0), RectangleEdge.LEFT);
110:                assertTrue(b1.equals(b2));
111:
112:                b1.add(new EmptyBlock(2.0, 2.0), RectangleEdge.RIGHT);
113:                assertFalse(b1.equals(b2));
114:                b2.add(new EmptyBlock(2.0, 2.0), RectangleEdge.RIGHT);
115:                assertTrue(b1.equals(b2));
116:
117:                b1.add(new EmptyBlock(3.0, 3.0), RectangleEdge.TOP);
118:                assertFalse(b1.equals(b2));
119:                b2.add(new EmptyBlock(3.0, 3.0), RectangleEdge.TOP);
120:                assertTrue(b1.equals(b2));
121:
122:                b1.add(new EmptyBlock(4.0, 4.0), RectangleEdge.BOTTOM);
123:                assertFalse(b1.equals(b2));
124:                b2.add(new EmptyBlock(4.0, 4.0), RectangleEdge.BOTTOM);
125:                assertTrue(b1.equals(b2));
126:            }
127:
128:            /**
129:             * Immutable - cloning is not necessary.
130:             */
131:            public void testCloning() {
132:                BorderArrangement b1 = new BorderArrangement();
133:                assertFalse(b1 instanceof  Cloneable);
134:            }
135:
136:            /**
137:             * Serialize an instance, restore it, and check for equality.
138:             */
139:            public void testSerialization() {
140:                BorderArrangement b1 = new BorderArrangement();
141:                BorderArrangement b2 = null;
142:                try {
143:                    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
144:                    ObjectOutput out = new ObjectOutputStream(buffer);
145:                    out.writeObject(b1);
146:                    out.close();
147:
148:                    ObjectInput in = new ObjectInputStream(
149:                            new ByteArrayInputStream(buffer.toByteArray()));
150:                    b2 = (BorderArrangement) in.readObject();
151:                    in.close();
152:                } catch (Exception e) {
153:                    fail(e.toString());
154:                }
155:                assertEquals(b1, b2);
156:            }
157:
158:            /**
159:             * Run some checks on sizing.
160:             */
161:            public void testSizing() {
162:                BlockContainer container = new BlockContainer(
163:                        new BorderArrangement());
164:                BufferedImage image = new BufferedImage(200, 100,
165:                        BufferedImage.TYPE_INT_RGB);
166:                Graphics2D g2 = image.createGraphics();
167:
168:                // TBLRC
169:                // 00000 - no items
170:                Size2D size = container.arrange(g2);
171:                assertEquals(0.0, size.width, EPSILON);
172:                assertEquals(0.0, size.height, EPSILON);
173:
174:                // TBLRC
175:                // 00001 - center item only
176:                container.add(new EmptyBlock(123.4, 567.8));
177:                size = container.arrange(g2);
178:                assertEquals(123.4, size.width, EPSILON);
179:                assertEquals(567.8, size.height, EPSILON);
180:
181:                // TBLRC
182:                // 00010 - right item only
183:                container.clear();
184:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
185:                size = container.arrange(g2);
186:                assertEquals(12.3, size.width, EPSILON);
187:                assertEquals(45.6, size.height, EPSILON);
188:
189:                // TBLRC
190:                // 00011 - right and center items
191:                container.clear();
192:                container.add(new EmptyBlock(10.0, 20.0));
193:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
194:                size = container.arrange(g2);
195:                assertEquals(22.3, size.width, EPSILON);
196:                assertEquals(45.6, size.height, EPSILON);
197:
198:                // try case where right item is shorter than center item
199:                container.clear();
200:                Block rb = new EmptyBlock(12.3, 15.6);
201:                container.add(new EmptyBlock(10.0, 20.0));
202:                container.add(rb, RectangleEdge.RIGHT);
203:                size = container.arrange(g2);
204:                assertEquals(22.3, size.width, EPSILON);
205:                assertEquals(20.0, size.height, EPSILON);
206:                assertEquals(20.0, rb.getBounds().getHeight(), EPSILON);
207:
208:                // TBLRC
209:                // 00100 - left item only
210:                container.clear();
211:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
212:                size = container.arrange(g2);
213:                assertEquals(12.3, size.width, EPSILON);
214:                assertEquals(45.6, size.height, EPSILON);
215:
216:                // TBLRC
217:                // 00101 - left and center items
218:                container.clear();
219:                container.add(new EmptyBlock(10.0, 20.0));
220:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
221:                size = container.arrange(g2);
222:                assertEquals(22.3, size.width, EPSILON);
223:                assertEquals(45.6, size.height, EPSILON);
224:
225:                // try case where left item is shorter than center item
226:                container.clear();
227:                Block lb = new EmptyBlock(12.3, 15.6);
228:                container.add(new EmptyBlock(10.0, 20.0));
229:                container.add(lb, RectangleEdge.LEFT);
230:                size = container.arrange(g2);
231:                assertEquals(22.3, size.width, EPSILON);
232:                assertEquals(20.0, size.height, EPSILON);
233:                assertEquals(20.0, lb.getBounds().getHeight(), EPSILON);
234:
235:                // TBLRC
236:                // 00110 - left and right items
237:                container.clear();
238:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
239:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
240:                size = container.arrange(g2);
241:                assertEquals(22.3, size.width, EPSILON);
242:                assertEquals(45.6, size.height, EPSILON);
243:
244:                // TBLRC
245:                // 00111 - left, right and center items
246:                container.clear();
247:                container.add(new EmptyBlock(10.0, 20.0));
248:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
249:                container.add(new EmptyBlock(5.4, 3.2), RectangleEdge.RIGHT);
250:                size = container.arrange(g2);
251:                assertEquals(27.7, size.width, EPSILON);
252:                assertEquals(45.6, size.height, EPSILON);
253:
254:                // TBLRC
255:                // 01000 - bottom item only
256:                container.clear();
257:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
258:                size = container.arrange(g2);
259:                assertEquals(12.3, size.width, EPSILON);
260:                assertEquals(45.6, size.height, EPSILON);
261:
262:                // TBLRC
263:                // 01001 - bottom and center only
264:                container.clear();
265:                container.add(new EmptyBlock(10.0, 20.0));
266:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
267:                size = container.arrange(g2);
268:                assertEquals(12.3, size.width, EPSILON);
269:                assertEquals(65.6, size.height, EPSILON);
270:
271:                // TBLRC
272:                // 01010 - bottom and right only
273:                container.clear();
274:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
275:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
276:                size = container.arrange(g2);
277:                assertEquals(12.3, size.width, EPSILON);
278:                assertEquals(65.6, size.height, EPSILON);
279:
280:                // TBLRC
281:                // 01011 - bottom, right and center
282:                container.clear();
283:                container.add(new EmptyBlock(21.0, 12.3));
284:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
285:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
286:                size = container.arrange(g2);
287:                assertEquals(31.0, size.width, EPSILON);
288:                assertEquals(65.6, size.height, EPSILON);
289:
290:                // TBLRC
291:                // 01100
292:                container.clear();
293:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
294:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
295:                size = container.arrange(g2);
296:                assertEquals(12.3, size.width, EPSILON);
297:                assertEquals(65.6, size.height, EPSILON);
298:
299:                // TBLRC
300:                // 01101 - bottom, left and center
301:                container.clear();
302:                container.add(new EmptyBlock(21.0, 12.3));
303:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
304:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
305:                size = container.arrange(g2);
306:                assertEquals(31.0, size.width, EPSILON);
307:                assertEquals(65.6, size.height, EPSILON);
308:
309:                // TBLRC
310:                // 01110 - bottom. left and right
311:                container.clear();
312:                container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
313:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
314:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
315:                size = container.arrange(g2);
316:                assertEquals(31.0, size.width, EPSILON);
317:                assertEquals(65.6, size.height, EPSILON);
318:
319:                // TBLRC
320:                // 01111
321:                container.clear();
322:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
323:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
324:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
325:                container.add(new EmptyBlock(9.0, 10.0));
326:                size = container.arrange(g2);
327:                assertEquals(21.0, size.width, EPSILON);
328:                assertEquals(14.0, size.height, EPSILON);
329:
330:                // TBLRC
331:                // 10000 - top item only
332:                container.clear();
333:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
334:                size = container.arrange(g2);
335:                assertEquals(12.3, size.width, EPSILON);
336:                assertEquals(45.6, size.height, EPSILON);
337:
338:                // TBLRC
339:                // 10001 - top and center only
340:                container.clear();
341:                container.add(new EmptyBlock(10.0, 20.0));
342:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
343:                size = container.arrange(g2);
344:                assertEquals(12.3, size.width, EPSILON);
345:                assertEquals(65.6, size.height, EPSILON);
346:
347:                // TBLRC
348:                // 10010 - right and top only
349:                container.clear();
350:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
351:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
352:                size = container.arrange(g2);
353:                assertEquals(12.3, size.width, EPSILON);
354:                assertEquals(65.6, size.height, EPSILON);
355:
356:                // TBLRC
357:                // 10011 - top, right and center
358:                container.clear();
359:                container.add(new EmptyBlock(21.0, 12.3));
360:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
361:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
362:                size = container.arrange(g2);
363:                assertEquals(33.3, size.width, EPSILON);
364:                assertEquals(65.6, size.height, EPSILON);
365:
366:                // TBLRC
367:                // 10100 - top and left only
368:                container.clear();
369:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
370:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
371:                size = container.arrange(g2);
372:                assertEquals(12.3, size.width, EPSILON);
373:                assertEquals(65.6, size.height, EPSILON);
374:
375:                // TBLRC
376:                // 10101 - top, left and center
377:                container.clear();
378:                container.add(new EmptyBlock(21.0, 12.3));
379:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
380:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
381:                size = container.arrange(g2);
382:                assertEquals(33.3, size.width, EPSILON);
383:                assertEquals(65.6, size.height, EPSILON);
384:
385:                // TBLRC
386:                // 10110 - top, left and right
387:                container.clear();
388:                container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
389:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
390:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
391:                size = container.arrange(g2);
392:                assertEquals(33.3, size.width, EPSILON);
393:                assertEquals(65.6, size.height, EPSILON);
394:
395:                // TBLRC
396:                // 10111
397:                container.clear();
398:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
399:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
400:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
401:                container.add(new EmptyBlock(9.0, 10.0));
402:                size = container.arrange(g2);
403:                assertEquals(21.0, size.width, EPSILON);
404:                assertEquals(12.0, size.height, EPSILON);
405:
406:                // TBLRC
407:                // 11000 - top and bottom only
408:                container.clear();
409:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
410:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
411:                size = container.arrange(g2);
412:                assertEquals(12.3, size.width, EPSILON);
413:                assertEquals(65.6, size.height, EPSILON);
414:
415:                // TBLRC
416:                // 11001
417:                container.clear();
418:                container.add(new EmptyBlock(21.0, 12.3));
419:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
420:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
421:                size = container.arrange(g2);
422:                assertEquals(21.0, size.width, EPSILON);
423:                assertEquals(77.9, size.height, EPSILON);
424:
425:                // TBLRC
426:                // 11010 - top, bottom and right
427:                container.clear();
428:                container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
429:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
430:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
431:                size = container.arrange(g2);
432:                assertEquals(21.0, size.width, EPSILON);
433:                assertEquals(77.9, size.height, EPSILON);
434:
435:                // TBLRC
436:                // 11011
437:                container.clear();
438:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
439:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
440:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
441:                container.add(new EmptyBlock(9.0, 10.0));
442:                size = container.arrange(g2);
443:                assertEquals(16.0, size.width, EPSILON);
444:                assertEquals(16.0, size.height, EPSILON);
445:
446:                // TBLRC
447:                // 11100
448:                container.clear();
449:                container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.LEFT);
450:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
451:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
452:                size = container.arrange(g2);
453:                assertEquals(21.0, size.width, EPSILON);
454:                assertEquals(77.9, size.height, EPSILON);
455:
456:                // TBLRC
457:                // 11101
458:                container.clear();
459:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
460:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
461:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
462:                container.add(new EmptyBlock(9.0, 10.0));
463:                size = container.arrange(g2);
464:                assertEquals(14.0, size.width, EPSILON);
465:                assertEquals(16.0, size.height, EPSILON);
466:
467:                // TBLRC
468:                // 11110
469:                container.clear();
470:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
471:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
472:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
473:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
474:                size = container.arrange(g2);
475:                assertEquals(12.0, size.width, EPSILON);
476:                assertEquals(14.0, size.height, EPSILON);
477:
478:                // TBLRC
479:                // 11111 - all
480:                container.clear();
481:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
482:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
483:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
484:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
485:                container.add(new EmptyBlock(9.0, 10.0));
486:                size = container.arrange(g2);
487:                assertEquals(21.0, size.width, EPSILON);
488:                assertEquals(16.0, size.height, EPSILON);
489:
490:            }
491:
492:            /**
493:             * Run some checks on sizing when there is a fixed width constraint.
494:             */
495:            public void testSizingWithWidthConstraint() {
496:                RectangleConstraint constraint = new RectangleConstraint(10.0,
497:                        new Range(10.0, 10.0), LengthConstraintType.FIXED, 0.0,
498:                        new Range(0.0, 0.0), LengthConstraintType.NONE);
499:
500:                BlockContainer container = new BlockContainer(
501:                        new BorderArrangement());
502:                BufferedImage image = new BufferedImage(200, 100,
503:                        BufferedImage.TYPE_INT_RGB);
504:                Graphics2D g2 = image.createGraphics();
505:
506:                // TBLRC
507:                // 00001 - center item only
508:                container.add(new EmptyBlock(5.0, 6.0));
509:                Size2D size = container.arrange(g2, constraint);
510:                assertEquals(10.0, size.width, EPSILON);
511:                assertEquals(6.0, size.height, EPSILON);
512:
513:                container.clear();
514:                container.add(new EmptyBlock(15.0, 16.0));
515:                size = container.arrange(g2, constraint);
516:                assertEquals(10.0, size.width, EPSILON);
517:                assertEquals(16.0, size.height, EPSILON);
518:
519:                // TBLRC
520:                // 00010 - right item only
521:                container.clear();
522:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
523:                size = container.arrange(g2, constraint);
524:                assertEquals(10.0, size.width, EPSILON);
525:                assertEquals(45.6, size.height, EPSILON);
526:
527:                // TBLRC
528:                // 00011 - right and center items
529:                container.clear();
530:                container.add(new EmptyBlock(7.0, 20.0));
531:                container.add(new EmptyBlock(8.0, 45.6), RectangleEdge.RIGHT);
532:                size = container.arrange(g2, constraint);
533:                assertEquals(10.0, size.width, EPSILON);
534:                assertEquals(45.6, size.height, EPSILON);
535:
536:                // TBLRC
537:                // 00100 - left item only
538:                container.clear();
539:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
540:                size = container.arrange(g2, constraint);
541:                assertEquals(10.0, size.width, EPSILON);
542:                assertEquals(45.6, size.height, EPSILON);
543:
544:                // TBLRC
545:                // 00101 - left and center items
546:                container.clear();
547:                container.add(new EmptyBlock(10.0, 20.0));
548:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
549:                size = container.arrange(g2, constraint);
550:                assertEquals(10.0, size.width, EPSILON);
551:                assertEquals(45.6, size.height, EPSILON);
552:
553:                // TBLRC
554:                // 00110 - left and right items
555:                container.clear();
556:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
557:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
558:                size = container.arrange(g2, constraint);
559:                assertEquals(10.0, size.width, EPSILON);
560:                assertEquals(45.6, size.height, EPSILON);
561:
562:                // TBLRC
563:                // 00111 - left, right and center items
564:                container.clear();
565:                container.add(new EmptyBlock(10.0, 20.0));
566:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
567:                container.add(new EmptyBlock(5.4, 3.2), RectangleEdge.RIGHT);
568:                size = container.arrange(g2, constraint);
569:                assertEquals(10.0, size.width, EPSILON);
570:                assertEquals(45.6, size.height, EPSILON);
571:
572:                // TBLRC
573:                // 01000 - bottom item only
574:                container.clear();
575:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
576:                size = container.arrange(g2, constraint);
577:                assertEquals(10.0, size.width, EPSILON);
578:                assertEquals(45.6, size.height, EPSILON);
579:
580:                // TBLRC
581:                // 01001 - bottom and center only
582:                container.clear();
583:                container.add(new EmptyBlock(10.0, 20.0));
584:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
585:                size = container.arrange(g2, constraint);
586:                assertEquals(10.0, size.width, EPSILON);
587:                assertEquals(65.6, size.height, EPSILON);
588:
589:                // TBLRC
590:                // 01010 - bottom and right only
591:                container.clear();
592:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
593:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
594:                size = container.arrange(g2, constraint);
595:                assertEquals(10.0, size.width, EPSILON);
596:                assertEquals(65.6, size.height, EPSILON);
597:
598:                // TBLRC
599:                // 01011 - bottom, right and center
600:                container.clear();
601:                container.add(new EmptyBlock(21.0, 12.3));
602:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
603:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
604:                size = container.arrange(g2, constraint);
605:                assertEquals(10.0, size.width, EPSILON);
606:                assertEquals(65.6, size.height, EPSILON);
607:
608:                // TBLRC
609:                // 01100
610:                container.clear();
611:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
612:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
613:                size = container.arrange(g2, constraint);
614:                assertEquals(10.0, size.width, EPSILON);
615:                assertEquals(65.6, size.height, EPSILON);
616:
617:                // TBLRC
618:                // 01101 - bottom, left and center
619:                container.clear();
620:                container.add(new EmptyBlock(21.0, 12.3));
621:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
622:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
623:                size = container.arrange(g2, constraint);
624:                assertEquals(10.0, size.width, EPSILON);
625:                assertEquals(65.6, size.height, EPSILON);
626:
627:                // TBLRC
628:                // 01110 - bottom. left and right
629:                container.clear();
630:                container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
631:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
632:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
633:                size = container.arrange(g2, constraint);
634:                assertEquals(10.0, size.width, EPSILON);
635:                assertEquals(65.6, size.height, EPSILON);
636:
637:                // TBLRC
638:                // 01111
639:                container.clear();
640:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
641:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
642:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
643:                container.add(new EmptyBlock(9.0, 10.0));
644:                size = container.arrange(g2, constraint);
645:                assertEquals(10.0, size.width, EPSILON);
646:                assertEquals(14.0, size.height, EPSILON);
647:
648:                // TBLRC
649:                // 10000 - top item only
650:                container.clear();
651:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
652:                size = container.arrange(g2, constraint);
653:                assertEquals(10.0, size.width, EPSILON);
654:                assertEquals(45.6, size.height, EPSILON);
655:
656:                // TBLRC
657:                // 10001 - top and center only
658:                container.clear();
659:                container.add(new EmptyBlock(10.0, 20.0));
660:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
661:                size = container.arrange(g2, constraint);
662:                assertEquals(10.0, size.width, EPSILON);
663:                assertEquals(65.6, size.height, EPSILON);
664:
665:                // TBLRC
666:                // 10010 - right and top only
667:                container.clear();
668:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
669:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
670:                size = container.arrange(g2, constraint);
671:                assertEquals(10.0, size.width, EPSILON);
672:                assertEquals(65.6, size.height, EPSILON);
673:
674:                // TBLRC
675:                // 10011 - top, right and center
676:                container.clear();
677:                container.add(new EmptyBlock(21.0, 12.3));
678:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
679:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
680:                size = container.arrange(g2, constraint);
681:                assertEquals(10.0, size.width, EPSILON);
682:                assertEquals(65.6, size.height, EPSILON);
683:
684:                // TBLRC
685:                // 10100 - top and left only
686:                container.clear();
687:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
688:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
689:                size = container.arrange(g2, constraint);
690:                assertEquals(10.0, size.width, EPSILON);
691:                assertEquals(65.6, size.height, EPSILON);
692:
693:                // TBLRC
694:                // 10101 - top, left and center
695:                container.clear();
696:                container.add(new EmptyBlock(21.0, 12.3));
697:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
698:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
699:                size = container.arrange(g2, constraint);
700:                assertEquals(10.0, size.width, EPSILON);
701:                assertEquals(65.6, size.height, EPSILON);
702:
703:                // TBLRC
704:                // 10110 - top, left and right
705:                container.clear();
706:                container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
707:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
708:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
709:                size = container.arrange(g2, constraint);
710:                assertEquals(10.0, size.width, EPSILON);
711:                assertEquals(65.6, size.height, EPSILON);
712:
713:                // TBLRC
714:                // 10111
715:                container.clear();
716:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
717:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
718:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
719:                container.add(new EmptyBlock(9.0, 10.0));
720:                size = container.arrange(g2, constraint);
721:                assertEquals(10.0, size.width, EPSILON);
722:                assertEquals(12.0, size.height, EPSILON);
723:
724:                // TBLRC
725:                // 11000 - top and bottom only
726:                container.clear();
727:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
728:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
729:                size = container.arrange(g2, constraint);
730:                assertEquals(10.0, size.width, EPSILON);
731:                assertEquals(65.6, size.height, EPSILON);
732:
733:                // TBLRC
734:                // 11001
735:                container.clear();
736:                container.add(new EmptyBlock(21.0, 12.3));
737:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
738:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
739:                size = container.arrange(g2, constraint);
740:                assertEquals(10.0, size.width, EPSILON);
741:                assertEquals(77.9, size.height, EPSILON);
742:
743:                // TBLRC
744:                // 11010 - top, bottom and right
745:                container.clear();
746:                container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
747:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
748:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
749:                size = container.arrange(g2, constraint);
750:                assertEquals(10.0, size.width, EPSILON);
751:                assertEquals(77.9, size.height, EPSILON);
752:
753:                // TBLRC
754:                // 11011
755:                container.clear();
756:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
757:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
758:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
759:                container.add(new EmptyBlock(9.0, 10.0));
760:                size = container.arrange(g2, constraint);
761:                assertEquals(10.0, size.width, EPSILON);
762:                assertEquals(16.0, size.height, EPSILON);
763:
764:                // TBLRC
765:                // 11100
766:                container.clear();
767:                container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.LEFT);
768:                container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
769:                container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
770:                size = container.arrange(g2, constraint);
771:                assertEquals(10.0, size.width, EPSILON);
772:                assertEquals(77.9, size.height, EPSILON);
773:
774:                // TBLRC
775:                // 11101
776:                container.clear();
777:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
778:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
779:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
780:                container.add(new EmptyBlock(9.0, 10.0));
781:                size = container.arrange(g2, constraint);
782:                assertEquals(10.0, size.width, EPSILON);
783:                assertEquals(16.0, size.height, EPSILON);
784:
785:                // TBLRC
786:                // 11110
787:                container.clear();
788:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
789:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
790:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
791:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
792:                size = container.arrange(g2, constraint);
793:                assertEquals(10.0, size.width, EPSILON);
794:                assertEquals(14.0, size.height, EPSILON);
795:
796:                // TBLRC
797:                // 11111 - all
798:                container.clear();
799:                container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
800:                container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
801:                container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
802:                container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
803:                container.add(new EmptyBlock(9.0, 10.0));
804:                size = container.arrange(g2, constraint);
805:                assertEquals(10.0, size.width, EPSILON);
806:                assertEquals(16.0, size.height, EPSILON);
807:
808:                // TBLRC
809:                // 00000 - no items
810:                container.clear();
811:                size = container.arrange(g2, constraint);
812:                assertEquals(10.0, size.width, EPSILON);
813:                assertEquals(0.0, size.height, EPSILON);
814:
815:            }
816:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.