KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > block > junit > BorderArrangementTests


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * ---------------------------
28  * BorderArrangementTests.java
29  * ---------------------------
30  * (C) Copyright 2004, 2005, by Object Refinery Limited and Contributors.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): -;
34  *
35  * $Id: BorderArrangementTests.java,v 1.1.2.1 2006/10/03 15:41:45 mungady Exp $
36  *
37  * Changes
38  * -------
39  * 22-Oct-2004 : Version 1 (DG);
40  *
41  */

42
43 package org.jfree.chart.block.junit;
44
45 import java.awt.Graphics2D JavaDoc;
46 import java.awt.image.BufferedImage JavaDoc;
47 import java.io.ByteArrayInputStream JavaDoc;
48 import java.io.ByteArrayOutputStream JavaDoc;
49 import java.io.ObjectInput JavaDoc;
50 import java.io.ObjectInputStream JavaDoc;
51 import java.io.ObjectOutput JavaDoc;
52 import java.io.ObjectOutputStream JavaDoc;
53
54 import junit.framework.Test;
55 import junit.framework.TestCase;
56 import junit.framework.TestSuite;
57
58 import org.jfree.chart.block.Block;
59 import org.jfree.chart.block.BlockContainer;
60 import org.jfree.chart.block.BorderArrangement;
61 import org.jfree.chart.block.EmptyBlock;
62 import org.jfree.chart.block.LengthConstraintType;
63 import org.jfree.chart.block.RectangleConstraint;
64 import org.jfree.data.Range;
65 import org.jfree.ui.RectangleEdge;
66 import org.jfree.ui.Size2D;
67
68 /**
69  * Tests for the {@link BorderArrangement} class.
70  */

71 public class BorderArrangementTests extends TestCase {
72
73     private static final double EPSILON = 0.0000000001;
74     
75     /**
76      * Returns the tests as a test suite.
77      *
78      * @return The test suite.
79      */

80     public static Test suite() {
81         return new TestSuite(BorderArrangementTests.class);
82     }
83
84     /**
85      * Constructs a new set of tests.
86      *
87      * @param name the name of the tests.
88      */

89     public BorderArrangementTests(String JavaDoc name) {
90         super(name);
91     }
92     
93     /**
94      * Confirm that the equals() method can distinguish all the required fields.
95      */

96     public void testEquals() {
97         BorderArrangement b1 = new BorderArrangement();
98         BorderArrangement b2 = new BorderArrangement();
99         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 JavaDoc);
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 JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
144             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
145             out.writeObject(b1);
146             out.close();
147
148             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(
149                 new ByteArrayInputStream JavaDoc(buffer.toByteArray())
150             );
151             b2 = (BorderArrangement) in.readObject();
152             in.close();
153         }
154         catch (Exception JavaDoc e) {
155             fail(e.toString());
156         }
157         assertEquals(b1, b2);
158     }
159     
160     /**
161      * Run some checks on sizing.
162      */

163     public void testSizing() {
164         BlockContainer container = new BlockContainer(new BorderArrangement());
165         BufferedImage JavaDoc image = new BufferedImage JavaDoc(
166             200, 100, BufferedImage.TYPE_INT_RGB
167         );
168         Graphics2D JavaDoc g2 = image.createGraphics();
169         
170         // TBLRC
171
// 00000 - no items
172
Size2D size = container.arrange(g2);
173         assertEquals(0.0, size.width, EPSILON);
174         assertEquals(0.0, size.height, EPSILON);
175         
176         // TBLRC
177
// 00001 - center item only
178
container.add(new EmptyBlock(123.4, 567.8));
179         size = container.arrange(g2);
180         assertEquals(123.4, size.width, EPSILON);
181         assertEquals(567.8, size.height, EPSILON);
182
183         // TBLRC
184
// 00010 - right item only
185
container.clear();
186         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
187         size = container.arrange(g2);
188         assertEquals(12.3, size.width, EPSILON);
189         assertEquals(45.6, size.height, EPSILON);
190         
191         // TBLRC
192
// 00011 - right and center items
193
container.clear();
194         container.add(new EmptyBlock(10.0, 20.0));
195         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
196         size = container.arrange(g2);
197         assertEquals(22.3, size.width, EPSILON);
198         assertEquals(45.6, size.height, EPSILON);
199         
200         // try case where right item is shorter than center item
201
container.clear();
202         Block rb = new EmptyBlock(12.3, 15.6);
203         container.add(new EmptyBlock(10.0, 20.0));
204         container.add(rb, RectangleEdge.RIGHT);
205         size = container.arrange(g2);
206         assertEquals(22.3, size.width, EPSILON);
207         assertEquals(20.0, size.height, EPSILON);
208         assertEquals(20.0, rb.getBounds().getHeight(), EPSILON);
209
210         // TBLRC
211
// 00100 - left item only
212
container.clear();
213         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
214         size = container.arrange(g2);
215         assertEquals(12.3, size.width, EPSILON);
216         assertEquals(45.6, size.height, EPSILON);
217         
218         // TBLRC
219
// 00101 - left and center items
220
container.clear();
221         container.add(new EmptyBlock(10.0, 20.0));
222         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
223         size = container.arrange(g2);
224         assertEquals(22.3, size.width, EPSILON);
225         assertEquals(45.6, size.height, EPSILON);
226         
227         // try case where left item is shorter than center item
228
container.clear();
229         Block lb = new EmptyBlock(12.3, 15.6);
230         container.add(new EmptyBlock(10.0, 20.0));
231         container.add(lb, RectangleEdge.LEFT);
232         size = container.arrange(g2);
233         assertEquals(22.3, size.width, EPSILON);
234         assertEquals(20.0, size.height, EPSILON);
235         assertEquals(20.0, lb.getBounds().getHeight(), EPSILON);
236         
237         // TBLRC
238
// 00110 - left and right items
239
container.clear();
240         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
241         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
242         size = container.arrange(g2);
243         assertEquals(22.3, size.width, EPSILON);
244         assertEquals(45.6, size.height, EPSILON);
245         
246         // TBLRC
247
// 00111 - left, right and center items
248
container.clear();
249         container.add(new EmptyBlock(10.0, 20.0));
250         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
251         container.add(new EmptyBlock(5.4, 3.2), RectangleEdge.RIGHT);
252         size = container.arrange(g2);
253         assertEquals(27.7, size.width, EPSILON);
254         assertEquals(45.6, size.height, EPSILON);
255         
256         // TBLRC
257
// 01000 - bottom item only
258
container.clear();
259         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
260         size = container.arrange(g2);
261         assertEquals(12.3, size.width, EPSILON);
262         assertEquals(45.6, size.height, EPSILON);
263         
264         // TBLRC
265
// 01001 - bottom and center only
266
container.clear();
267         container.add(new EmptyBlock(10.0, 20.0));
268         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
269         size = container.arrange(g2);
270         assertEquals(12.3, size.width, EPSILON);
271         assertEquals(65.6, size.height, EPSILON);
272         
273         // TBLRC
274
// 01010 - bottom and right only
275
container.clear();
276         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
277         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
278         size = container.arrange(g2);
279         assertEquals(12.3, size.width, EPSILON);
280         assertEquals(65.6, size.height, EPSILON);
281         
282         // TBLRC
283
// 01011 - bottom, right and center
284
container.clear();
285         container.add(new EmptyBlock(21.0, 12.3));
286         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
287         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
288         size = container.arrange(g2);
289         assertEquals(31.0, size.width, EPSILON);
290         assertEquals(65.6, size.height, EPSILON);
291         
292         // TBLRC
293
// 01100
294
container.clear();
295         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
296         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
297         size = container.arrange(g2);
298         assertEquals(12.3, size.width, EPSILON);
299         assertEquals(65.6, size.height, EPSILON);
300         
301         // TBLRC
302
// 01101 - bottom, left and center
303
container.clear();
304         container.add(new EmptyBlock(21.0, 12.3));
305         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
306         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
307         size = container.arrange(g2);
308         assertEquals(31.0, size.width, EPSILON);
309         assertEquals(65.6, size.height, EPSILON);
310         
311         // TBLRC
312
// 01110 - bottom. left and right
313
container.clear();
314         container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
315         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
316         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
317         size = container.arrange(g2);
318         assertEquals(31.0, size.width, EPSILON);
319         assertEquals(65.6, size.height, EPSILON);
320         
321         // TBLRC
322
// 01111
323
container.clear();
324         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
325         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
326         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
327         container.add(new EmptyBlock(9.0, 10.0));
328         size = container.arrange(g2);
329         assertEquals(21.0, size.width, EPSILON);
330         assertEquals(14.0, size.height, EPSILON);
331         
332         // TBLRC
333
// 10000 - top item only
334
container.clear();
335         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
336         size = container.arrange(g2);
337         assertEquals(12.3, size.width, EPSILON);
338         assertEquals(45.6, size.height, EPSILON);
339         
340         // TBLRC
341
// 10001 - top and center only
342
container.clear();
343         container.add(new EmptyBlock(10.0, 20.0));
344         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
345         size = container.arrange(g2);
346         assertEquals(12.3, size.width, EPSILON);
347         assertEquals(65.6, size.height, EPSILON);
348                 
349         // TBLRC
350
// 10010 - right and top only
351
container.clear();
352         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
353         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
354         size = container.arrange(g2);
355         assertEquals(12.3, size.width, EPSILON);
356         assertEquals(65.6, size.height, EPSILON);
357         
358         // TBLRC
359
// 10011 - top, right and center
360
container.clear();
361         container.add(new EmptyBlock(21.0, 12.3));
362         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
363         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
364         size = container.arrange(g2);
365         assertEquals(33.3, size.width, EPSILON);
366         assertEquals(65.6, size.height, EPSILON);
367
368         // TBLRC
369
// 10100 - top and left only
370
container.clear();
371         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
372         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
373         size = container.arrange(g2);
374         assertEquals(12.3, size.width, EPSILON);
375         assertEquals(65.6, size.height, EPSILON);
376         
377         // TBLRC
378
// 10101 - top, left and center
379
container.clear();
380         container.add(new EmptyBlock(21.0, 12.3));
381         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
382         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
383         size = container.arrange(g2);
384         assertEquals(33.3, size.width, EPSILON);
385         assertEquals(65.6, size.height, EPSILON);
386         
387         // TBLRC
388
// 10110 - top, left and right
389
container.clear();
390         container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
391         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
392         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
393         size = container.arrange(g2);
394         assertEquals(33.3, size.width, EPSILON);
395         assertEquals(65.6, size.height, EPSILON);
396         
397         // TBLRC
398
// 10111
399
container.clear();
400         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
401         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
402         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
403         container.add(new EmptyBlock(9.0, 10.0));
404         size = container.arrange(g2);
405         assertEquals(21.0, size.width, EPSILON);
406         assertEquals(12.0, size.height, EPSILON);
407
408         // TBLRC
409
// 11000 - top and bottom only
410
container.clear();
411         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
412         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
413         size = container.arrange(g2);
414         assertEquals(12.3, size.width, EPSILON);
415         assertEquals(65.6, size.height, EPSILON);
416         
417         // TBLRC
418
// 11001
419
container.clear();
420         container.add(new EmptyBlock(21.0, 12.3));
421         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
422         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
423         size = container.arrange(g2);
424         assertEquals(21.0, size.width, EPSILON);
425         assertEquals(77.9, size.height, EPSILON);
426         
427         // TBLRC
428
// 11010 - top, bottom and right
429
container.clear();
430         container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
431         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
432         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
433         size = container.arrange(g2);
434         assertEquals(21.0, size.width, EPSILON);
435         assertEquals(77.9, size.height, EPSILON);
436                 
437         // TBLRC
438
// 11011
439
container.clear();
440         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
441         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
442         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
443         container.add(new EmptyBlock(9.0, 10.0));
444         size = container.arrange(g2);
445         assertEquals(16.0, size.width, EPSILON);
446         assertEquals(16.0, size.height, EPSILON);
447         
448         // TBLRC
449
// 11100
450
container.clear();
451         container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.LEFT);
452         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
453         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
454         size = container.arrange(g2);
455         assertEquals(21.0, size.width, EPSILON);
456         assertEquals(77.9, size.height, EPSILON);
457
458         // TBLRC
459
// 11101
460
container.clear();
461         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
462         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
463         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
464         container.add(new EmptyBlock(9.0, 10.0));
465         size = container.arrange(g2);
466         assertEquals(14.0, size.width, EPSILON);
467         assertEquals(16.0, size.height, EPSILON);
468         
469         // TBLRC
470
// 11110
471
container.clear();
472         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
473         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
474         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
475         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
476         size = container.arrange(g2);
477         assertEquals(12.0, size.width, EPSILON);
478         assertEquals(14.0, size.height, EPSILON);
479         
480         // TBLRC
481
// 11111 - all
482
container.clear();
483         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
484         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
485         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
486         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
487         container.add(new EmptyBlock(9.0, 10.0));
488         size = container.arrange(g2);
489         assertEquals(21.0, size.width, EPSILON);
490         assertEquals(16.0, size.height, EPSILON);
491
492     }
493     
494     /**
495      * Run some checks on sizing when there is a fixed width constraint.
496      */

497     public void testSizingWithWidthConstraint() {
498         RectangleConstraint constraint = new RectangleConstraint(
499             10.0, new Range(10.0, 10.0), LengthConstraintType.FIXED,
500             0.0, new Range(0.0, 0.0), LengthConstraintType.NONE
501         );
502                 
503         BlockContainer container = new BlockContainer(new BorderArrangement());
504         BufferedImage JavaDoc image = new BufferedImage JavaDoc(
505             200, 100, BufferedImage.TYPE_INT_RGB
506         );
507         Graphics2D JavaDoc g2 = image.createGraphics();
508         
509         // TBLRC
510
// 00001 - center item only
511
container.add(new EmptyBlock(5.0, 6.0));
512         Size2D size = container.arrange(g2, constraint);
513         assertEquals(10.0, size.width, EPSILON);
514         assertEquals(6.0, size.height, EPSILON);
515         
516         container.clear();
517         container.add(new EmptyBlock(15.0, 16.0));
518         size = container.arrange(g2, constraint);
519         assertEquals(10.0, size.width, EPSILON);
520         assertEquals(16.0, size.height, EPSILON);
521
522         // TBLRC
523
// 00010 - right item only
524
container.clear();
525         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
526         size = container.arrange(g2, constraint);
527         assertEquals(10.0, size.width, EPSILON);
528         assertEquals(45.6, size.height, EPSILON);
529         
530         // TBLRC
531
// 00011 - right and center items
532
container.clear();
533         container.add(new EmptyBlock(7.0, 20.0));
534         container.add(new EmptyBlock(8.0, 45.6), RectangleEdge.RIGHT);
535         size = container.arrange(g2, constraint);
536         assertEquals(10.0, size.width, EPSILON);
537         assertEquals(45.6, size.height, EPSILON);
538         
539         // TBLRC
540
// 00100 - left item only
541
container.clear();
542         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
543         size = container.arrange(g2, constraint);
544         assertEquals(10.0, size.width, EPSILON);
545         assertEquals(45.6, size.height, EPSILON);
546         
547         // TBLRC
548
// 00101 - left and center items
549
container.clear();
550         container.add(new EmptyBlock(10.0, 20.0));
551         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
552         size = container.arrange(g2, constraint);
553         assertEquals(10.0, size.width, EPSILON);
554         assertEquals(45.6, size.height, EPSILON);
555         
556         // TBLRC
557
// 00110 - left and right items
558
container.clear();
559         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
560         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
561         size = container.arrange(g2, constraint);
562         assertEquals(10.0, size.width, EPSILON);
563         assertEquals(45.6, size.height, EPSILON);
564         
565         // TBLRC
566
// 00111 - left, right and center items
567
container.clear();
568         container.add(new EmptyBlock(10.0, 20.0));
569         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
570         container.add(new EmptyBlock(5.4, 3.2), RectangleEdge.RIGHT);
571         size = container.arrange(g2, constraint);
572         assertEquals(10.0, size.width, EPSILON);
573         assertEquals(45.6, size.height, EPSILON);
574         
575         // TBLRC
576
// 01000 - bottom item only
577
container.clear();
578         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
579         size = container.arrange(g2, constraint);
580         assertEquals(10.0, size.width, EPSILON);
581         assertEquals(45.6, size.height, EPSILON);
582         
583         // TBLRC
584
// 01001 - bottom and center only
585
container.clear();
586         container.add(new EmptyBlock(10.0, 20.0));
587         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
588         size = container.arrange(g2, constraint);
589         assertEquals(10.0, size.width, EPSILON);
590         assertEquals(65.6, size.height, EPSILON);
591         
592         // TBLRC
593
// 01010 - bottom and right only
594
container.clear();
595         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
596         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
597         size = container.arrange(g2, constraint);
598         assertEquals(10.0, size.width, EPSILON);
599         assertEquals(65.6, size.height, EPSILON);
600         
601         // TBLRC
602
// 01011 - bottom, right and center
603
container.clear();
604         container.add(new EmptyBlock(21.0, 12.3));
605         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
606         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
607         size = container.arrange(g2, constraint);
608         assertEquals(10.0, size.width, EPSILON);
609         assertEquals(65.6, size.height, EPSILON);
610         
611         // TBLRC
612
// 01100
613
container.clear();
614         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
615         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
616         size = container.arrange(g2, constraint);
617         assertEquals(10.0, size.width, EPSILON);
618         assertEquals(65.6, size.height, EPSILON);
619         
620         // TBLRC
621
// 01101 - bottom, left and center
622
container.clear();
623         container.add(new EmptyBlock(21.0, 12.3));
624         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
625         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
626         size = container.arrange(g2, constraint);
627         assertEquals(10.0, size.width, EPSILON);
628         assertEquals(65.6, size.height, EPSILON);
629         
630         // TBLRC
631
// 01110 - bottom. left and right
632
container.clear();
633         container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
634         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
635         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
636         size = container.arrange(g2, constraint);
637         assertEquals(10.0, size.width, EPSILON);
638         assertEquals(65.6, size.height, EPSILON);
639         
640         // TBLRC
641
// 01111
642
container.clear();
643         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
644         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
645         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
646         container.add(new EmptyBlock(9.0, 10.0));
647         size = container.arrange(g2, constraint);
648         assertEquals(10.0, size.width, EPSILON);
649         assertEquals(14.0, size.height, EPSILON);
650         
651         // TBLRC
652
// 10000 - top item only
653
container.clear();
654         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
655         size = container.arrange(g2, constraint);
656         assertEquals(10.0, size.width, EPSILON);
657         assertEquals(45.6, size.height, EPSILON);
658         
659         // TBLRC
660
// 10001 - top and center only
661
container.clear();
662         container.add(new EmptyBlock(10.0, 20.0));
663         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
664         size = container.arrange(g2, constraint);
665         assertEquals(10.0, size.width, EPSILON);
666         assertEquals(65.6, size.height, EPSILON);
667                 
668         // TBLRC
669
// 10010 - right and top only
670
container.clear();
671         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.RIGHT);
672         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
673         size = container.arrange(g2, constraint);
674         assertEquals(10.0, size.width, EPSILON);
675         assertEquals(65.6, size.height, EPSILON);
676         
677         // TBLRC
678
// 10011 - top, right and center
679
container.clear();
680         container.add(new EmptyBlock(21.0, 12.3));
681         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
682         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.RIGHT);
683         size = container.arrange(g2, constraint);
684         assertEquals(10.0, size.width, EPSILON);
685         assertEquals(65.6, size.height, EPSILON);
686
687         // TBLRC
688
// 10100 - top and left only
689
container.clear();
690         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.LEFT);
691         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.TOP);
692         size = container.arrange(g2, constraint);
693         assertEquals(10.0, size.width, EPSILON);
694         assertEquals(65.6, size.height, EPSILON);
695         
696         // TBLRC
697
// 10101 - top, left and center
698
container.clear();
699         container.add(new EmptyBlock(21.0, 12.3));
700         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
701         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
702         size = container.arrange(g2, constraint);
703         assertEquals(10.0, size.width, EPSILON);
704         assertEquals(65.6, size.height, EPSILON);
705         
706         // TBLRC
707
// 10110 - top, left and right
708
container.clear();
709         container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
710         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
711         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.LEFT);
712         size = container.arrange(g2, constraint);
713         assertEquals(10.0, size.width, EPSILON);
714         assertEquals(65.6, size.height, EPSILON);
715         
716         // TBLRC
717
// 10111
718
container.clear();
719         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
720         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
721         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
722         container.add(new EmptyBlock(9.0, 10.0));
723         size = container.arrange(g2, constraint);
724         assertEquals(10.0, size.width, EPSILON);
725         assertEquals(12.0, size.height, EPSILON);
726
727         // TBLRC
728
// 11000 - top and bottom only
729
container.clear();
730         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
731         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
732         size = container.arrange(g2, constraint);
733         assertEquals(10.0, size.width, EPSILON);
734         assertEquals(65.6, size.height, EPSILON);
735         
736         // TBLRC
737
// 11001
738
container.clear();
739         container.add(new EmptyBlock(21.0, 12.3));
740         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
741         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
742         size = container.arrange(g2, constraint);
743         assertEquals(10.0, size.width, EPSILON);
744         assertEquals(77.9, size.height, EPSILON);
745         
746         // TBLRC
747
// 11010 - top, bottom and right
748
container.clear();
749         container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.RIGHT);
750         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
751         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
752         size = container.arrange(g2, constraint);
753         assertEquals(10.0, size.width, EPSILON);
754         assertEquals(77.9, size.height, EPSILON);
755                 
756         // TBLRC
757
// 11011
758
container.clear();
759         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
760         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
761         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
762         container.add(new EmptyBlock(9.0, 10.0));
763         size = container.arrange(g2, constraint);
764         assertEquals(10.0, size.width, EPSILON);
765         assertEquals(16.0, size.height, EPSILON);
766         
767         // TBLRC
768
// 11100
769
container.clear();
770         container.add(new EmptyBlock(21.0, 12.3), RectangleEdge.LEFT);
771         container.add(new EmptyBlock(10.0, 20.0), RectangleEdge.TOP);
772         container.add(new EmptyBlock(12.3, 45.6), RectangleEdge.BOTTOM);
773         size = container.arrange(g2, constraint);
774         assertEquals(10.0, size.width, EPSILON);
775         assertEquals(77.9, size.height, EPSILON);
776
777         // TBLRC
778
// 11101
779
container.clear();
780         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
781         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
782         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
783         container.add(new EmptyBlock(9.0, 10.0));
784         size = container.arrange(g2, constraint);
785         assertEquals(10.0, size.width, EPSILON);
786         assertEquals(16.0, size.height, EPSILON);
787         
788         // TBLRC
789
// 11110
790
container.clear();
791         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
792         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
793         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
794         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
795         size = container.arrange(g2, constraint);
796         assertEquals(10.0, size.width, EPSILON);
797         assertEquals(14.0, size.height, EPSILON);
798         
799         // TBLRC
800
// 11111 - all
801
container.clear();
802         container.add(new EmptyBlock(1.0, 2.0), RectangleEdge.TOP);
803         container.add(new EmptyBlock(3.0, 4.0), RectangleEdge.BOTTOM);
804         container.add(new EmptyBlock(5.0, 6.0), RectangleEdge.LEFT);
805         container.add(new EmptyBlock(7.0, 8.0), RectangleEdge.RIGHT);
806         container.add(new EmptyBlock(9.0, 10.0));
807         size = container.arrange(g2, constraint);
808         assertEquals(10.0, size.width, EPSILON);
809         assertEquals(16.0, size.height, EPSILON);
810
811         // TBLRC
812
// 00000 - no items
813
container.clear();
814         size = container.arrange(g2, constraint);
815         assertEquals(10.0, size.width, EPSILON);
816         assertEquals(0.0, size.height, EPSILON);
817         
818     }
819 }
820
821
Popular Tags