Source Code Cross Referenced for GridProcessorTest.java in  » Ajax » NextApp-Echo2 » nextapp » echo2 » webcontainer » test » 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 » Ajax » NextApp Echo2 » nextapp.echo2.webcontainer.test 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /* 
0002:         * This file is part of the Echo Web Application Framework (hereinafter "Echo").
0003:         * Copyright (C) 2002-2005 NextApp, Inc.
0004:         *
0005:         * Version: MPL 1.1/GPL 2.0/LGPL 2.1
0006:         *
0007:         * The contents of this file are subject to the Mozilla Public License Version
0008:         * 1.1 (the "License"); you may not use this file except in compliance with
0009:         * the License. You may obtain a copy of the License at
0010:         * http://www.mozilla.org/MPL/
0011:         *
0012:         * Software distributed under the License is distributed on an "AS IS" basis,
0013:         * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
0014:         * for the specific language governing rights and limitations under the
0015:         * License.
0016:         *
0017:         * Alternatively, the contents of this file may be used under the terms of
0018:         * either the GNU General Public License Version 2 or later (the "GPL"), or
0019:         * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
0020:         * in which case the provisions of the GPL or the LGPL are applicable instead
0021:         * of those above. If you wish to allow use of your version of this file only
0022:         * under the terms of either the GPL or the LGPL, and not to allow others to
0023:         * use your version of this file under the terms of the MPL, indicate your
0024:         * decision by deleting the provisions above and replace them with the notice
0025:         * and other provisions required by the GPL or the LGPL. If you do not delete
0026:         * the provisions above, a recipient may use your version of this file under
0027:         * the terms of any one of the MPL, the GPL or the LGPL.
0028:         */
0029:
0030:        package nextapp.echo2.webcontainer.test;
0031:
0032:        import nextapp.echo2.app.Extent;
0033:        import nextapp.echo2.app.Grid;
0034:        import nextapp.echo2.app.Label;
0035:        import nextapp.echo2.app.layout.GridLayoutData;
0036:        import nextapp.echo2.webcontainer.syncpeer.GridProcessor;
0037:        import junit.framework.TestCase;
0038:
0039:        /**
0040:         * Unit tests for <code>GridProcessor</code>.
0041:         */
0042:        public class GridProcessorTest extends TestCase {
0043:
0044:            /**
0045:             * Test retrieving column widths and row heights.
0046:             */
0047:            public void testBasicColumnWidthAndRowHeight() {
0048:                Grid grid = new Grid(3);
0049:                for (int i = 0; i < 12; ++i) {
0050:                    grid.add(new Label());
0051:                }
0052:                for (int i = 0; i < 4; ++i) {
0053:                    grid.setColumnWidth(i, new Extent(i + 1));
0054:                    grid.setRowHeight(i, new Extent((i + 1) * 10));
0055:                }
0056:
0057:                GridProcessor gridProcessor = new GridProcessor(grid);
0058:                assertEquals(3, gridProcessor.getColumnCount());
0059:                assertEquals(4, gridProcessor.getRowCount());
0060:                assertEquals(new Extent(1), gridProcessor.getColumnWidth(0));
0061:                assertEquals(new Extent(2), gridProcessor.getColumnWidth(1));
0062:                assertEquals(new Extent(3), gridProcessor.getColumnWidth(2));
0063:                assertEquals(new Extent(10), gridProcessor.getRowHeight(0));
0064:                assertEquals(new Extent(20), gridProcessor.getRowHeight(1));
0065:                assertEquals(new Extent(30), gridProcessor.getRowHeight(2));
0066:                assertEquals(new Extent(40), gridProcessor.getRowHeight(3));
0067:
0068:                grid.setOrientation(Grid.ORIENTATION_VERTICAL);
0069:                gridProcessor = new GridProcessor(grid);
0070:                assertEquals(4, gridProcessor.getColumnCount());
0071:                assertEquals(3, gridProcessor.getRowCount());
0072:                assertEquals(new Extent(1), gridProcessor.getColumnWidth(0));
0073:                assertEquals(new Extent(2), gridProcessor.getColumnWidth(1));
0074:                assertEquals(new Extent(3), gridProcessor.getColumnWidth(2));
0075:                assertEquals(new Extent(4), gridProcessor.getColumnWidth(3));
0076:                assertEquals(new Extent(10), gridProcessor.getRowHeight(0));
0077:                assertEquals(new Extent(20), gridProcessor.getRowHeight(1));
0078:                assertEquals(new Extent(30), gridProcessor.getRowHeight(2));
0079:            }
0080:
0081:            /**
0082:             * Test a grid with no child components.
0083:             */
0084:            public void testEmptyGrid() {
0085:                Grid grid = new Grid();
0086:                GridProcessor gridProcessor = new GridProcessor(grid);
0087:                assertEquals(0, gridProcessor.getColumnCount());
0088:                assertEquals(0, gridProcessor.getRowCount());
0089:            }
0090:
0091:            /** 
0092:             * Test behavior of Grid with very little content.
0093:             * This is a special case for the <code>GridProcessor</code>.
0094:             *  __ __ __ __
0095:             * |  |XX|XX|XX|
0096:             * |__|XX|XX|XX|
0097:             */
0098:
0099:            public void testLessThanSize() {
0100:                Grid grid = new Grid();
0101:                grid.setSize(4);
0102:
0103:                grid.add(new Label());
0104:
0105:                GridProcessor gridProcessor = new GridProcessor(grid);
0106:                assertEquals(1, gridProcessor.getColumnCount());
0107:                assertEquals(1, gridProcessor.getRowCount());
0108:            }
0109:
0110:            /** 
0111:             * Test behavior of Grid with very little content and a needless
0112:             * row span.
0113:             * This is a special case for the <code>GridProcessor</code>.
0114:             *  __ __ __ __
0115:             * |  |XX|XX|XX|
0116:             * |  |XX|XX|XX|
0117:             * |  |XX|XX|XX|
0118:             * |  |XX|XX|XX|
0119:             * |  |XX|XX|XX|
0120:             * |__|XX|XX|XX|
0121:             */
0122:
0123:            public void testLessThanSizeWithRowSpan() {
0124:                Grid grid = new Grid();
0125:                grid.setSize(4);
0126:
0127:                Label label = new Label();
0128:                GridLayoutData gridLayoutData = new GridLayoutData();
0129:                gridLayoutData.setRowSpan(3);
0130:                label.setLayoutData(gridLayoutData);
0131:                grid.add(label);
0132:
0133:                GridProcessor gridProcessor = new GridProcessor(grid);
0134:                assertEquals(1, gridProcessor.getColumnCount());
0135:                assertEquals(1, gridProcessor.getRowCount());
0136:            }
0137:
0138:            /**
0139:             * Tests span collisions.
0140:             * 
0141:             * Requested:   Rendered:
0142:             *  __ __ __     __ __ __
0143:             * |0 |VC|1 |   |0 |VC|1 |
0144:             * |__|  |__|   |__|  |__|
0145:             * |HC \/   |   |HC|  |2 |
0146:             * |__ /\ __|   |__|  |__|
0147:             * |2 |  |3 |   |3 |  |  |
0148:             * |__|__|__|   |__|__|__|
0149:             */
0150:            public void testInvalidAttemptCollision() {
0151:                GridLayoutData layoutData;
0152:                Grid grid = new Grid(3);
0153:                grid.add(new Label("0"));
0154:                Label verticalCollider = new Label("VC");
0155:                layoutData = new GridLayoutData();
0156:                layoutData.setRowSpan(3);
0157:                verticalCollider.setLayoutData(layoutData);
0158:                grid.add(verticalCollider);
0159:                grid.add(new Label("1"));
0160:                Label horizontalCollider = new Label("HC");
0161:                layoutData = new GridLayoutData();
0162:                layoutData.setColumnSpan(3);
0163:                horizontalCollider.setLayoutData(layoutData);
0164:                grid.add(horizontalCollider);
0165:                grid.add(new Label("2"));
0166:                grid.add(new Label("3"));
0167:                GridProcessor gridProcessor = new GridProcessor(grid);
0168:                assertEquals("0", ((Label) gridProcessor.getContent(0, 0))
0169:                        .getText());
0170:                assertEquals("VC", ((Label) gridProcessor.getContent(1, 0))
0171:                        .getText());
0172:                assertEquals("1", ((Label) gridProcessor.getContent(2, 0))
0173:                        .getText());
0174:                assertEquals("HC", ((Label) gridProcessor.getContent(0, 1))
0175:                        .getText());
0176:                assertEquals("VC", ((Label) gridProcessor.getContent(1, 1))
0177:                        .getText());
0178:                assertEquals("2", ((Label) gridProcessor.getContent(2, 1))
0179:                        .getText());
0180:                assertEquals("3", ((Label) gridProcessor.getContent(0, 2))
0181:                        .getText());
0182:                assertEquals("VC", ((Label) gridProcessor.getContent(1, 2))
0183:                        .getText());
0184:            }
0185:
0186:            /**
0187:             * Tests row reduction to ensure proper rendering of the following:
0188:             * 
0189:             * (specified)   (rendered)
0190:             *  __ __         __ __
0191:             * |0 |1 |    0  |0 |1 |
0192:             * |  |  |       |__|  |
0193:             * |XX|  |    1  |XX|  |
0194:             * |XX|  |       |XX|__|
0195:             * |XX|  |    2
0196:             * |XX|  |
0197:             * |XX|  |    3
0198:             * |XX|__|
0199:             */
0200:            public void testOutOfBoundsRowSpan() {
0201:                Grid grid = new Grid();
0202:                grid.add(new Label());
0203:
0204:                Label label = new Label();
0205:                GridLayoutData layoutData = new GridLayoutData();
0206:                layoutData.setRowSpan(4);
0207:                label.setLayoutData(layoutData);
0208:                grid.add(label);
0209:
0210:                GridProcessor gridProcessor = new GridProcessor(grid);
0211:
0212:                // Verify Grid size is correct.
0213:                assertEquals(2, gridProcessor.getColumnCount());
0214:                assertEquals(2, gridProcessor.getRowCount());
0215:
0216:                // Verify components are at correct positions.
0217:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0218:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0219:                assertEquals(-1, gridProcessor.getComponentIndex(0, 1));
0220:                assertEquals(1, gridProcessor.getComponentIndex(1, 1));
0221:
0222:                // Verify x-spans were untouched.
0223:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
0224:                assertEquals(1, gridProcessor.getColumnSpan(1, 0));
0225:                assertEquals(-1, gridProcessor.getColumnSpan(0, 1));
0226:                assertEquals(1, gridProcessor.getColumnSpan(1, 1));
0227:
0228:                // Verify y-spans were properly reduced.
0229:                assertEquals(1, gridProcessor.getRowSpan(0, 0));
0230:                assertEquals(2, gridProcessor.getRowSpan(1, 0));
0231:                assertEquals(-1, gridProcessor.getRowSpan(0, 1));
0232:                assertEquals(2, gridProcessor.getRowSpan(1, 1));
0233:            }
0234:
0235:            /**
0236:             * Tests column reduction to ensure proper rendering of the following:
0237:             * 
0238:             *  0  1  2  3  4  5  6    (specified column)
0239:             *  __ _____ ___________
0240:             * |0 |1    |2    |3    |
0241:             * |__|_____|_____|_____|
0242:             * |4 |5    |6 |7 |8    |
0243:             * |__|_____|__|__|     |
0244:             * |9 |10   |11   |     |
0245:             * |__|_____|_____|_____|
0246:             * 
0247:             * 0   1     2  3  4       (rendered column)
0248:             */
0249:            public void testReduceColumnComplex() {
0250:                Grid grid = new Grid();
0251:
0252:                // Configure Grid Content
0253:                grid.setSize(7);
0254:                for (int i = 0; i < 12; ++i) {
0255:                    Label label = new Label(Integer.toString(i));
0256:                    if (i == 1 || i == 2 || i == 3 || i == 5 || i == 8
0257:                            || i == 10 || i == 11) {
0258:                        GridLayoutData layoutData = new GridLayoutData();
0259:                        layoutData.setColumnSpan(2);
0260:                        if (i == 8) {
0261:                            layoutData.setRowSpan(2);
0262:                        }
0263:                        label.setLayoutData(layoutData);
0264:                    }
0265:                    grid.add(label);
0266:                }
0267:
0268:                // Set Column Sizes
0269:                grid.setColumnWidth(0, new Extent(1));
0270:                grid.setColumnWidth(1, new Extent(2));
0271:                grid.setColumnWidth(2, new Extent(4));
0272:                grid.setColumnWidth(3, new Extent(8));
0273:                grid.setColumnWidth(4, new Extent(16));
0274:                grid.setColumnWidth(5, new Extent(32));
0275:                grid.setColumnWidth(6, new Extent(64));
0276:
0277:                GridProcessor gridProcessor = new GridProcessor(grid);
0278:
0279:                // Verify Grid size is correct.
0280:                assertEquals(5, gridProcessor.getColumnCount());
0281:                assertEquals(3, gridProcessor.getRowCount());
0282:
0283:                // Verify components are at correct positions.
0284:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0285:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0286:                assertEquals(2, gridProcessor.getComponentIndex(2, 0));
0287:                assertEquals(2, gridProcessor.getComponentIndex(3, 0));
0288:                assertEquals(3, gridProcessor.getComponentIndex(4, 0));
0289:                assertEquals(4, gridProcessor.getComponentIndex(0, 1));
0290:                assertEquals(5, gridProcessor.getComponentIndex(1, 1));
0291:                assertEquals(6, gridProcessor.getComponentIndex(2, 1));
0292:                assertEquals(7, gridProcessor.getComponentIndex(3, 1));
0293:                assertEquals(8, gridProcessor.getComponentIndex(4, 1));
0294:                assertEquals(9, gridProcessor.getComponentIndex(0, 2));
0295:                assertEquals(10, gridProcessor.getComponentIndex(1, 2));
0296:                assertEquals(11, gridProcessor.getComponentIndex(2, 2));
0297:                assertEquals(11, gridProcessor.getComponentIndex(3, 2));
0298:                assertEquals(8, gridProcessor.getComponentIndex(4, 2));
0299:
0300:                // Verify x-spans were property reduced.
0301:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
0302:                assertEquals(1, gridProcessor.getColumnSpan(1, 0));
0303:                assertEquals(2, gridProcessor.getColumnSpan(2, 0));
0304:                assertEquals(2, gridProcessor.getColumnSpan(3, 0));
0305:                assertEquals(1, gridProcessor.getColumnSpan(4, 0));
0306:                assertEquals(1, gridProcessor.getColumnSpan(0, 1));
0307:                assertEquals(1, gridProcessor.getColumnSpan(1, 1));
0308:                assertEquals(1, gridProcessor.getColumnSpan(2, 1));
0309:                assertEquals(1, gridProcessor.getColumnSpan(3, 1));
0310:                assertEquals(1, gridProcessor.getColumnSpan(4, 1));
0311:                assertEquals(1, gridProcessor.getColumnSpan(0, 2));
0312:                assertEquals(1, gridProcessor.getColumnSpan(1, 2));
0313:                assertEquals(2, gridProcessor.getColumnSpan(2, 2));
0314:                assertEquals(2, gridProcessor.getColumnSpan(3, 2));
0315:                assertEquals(1, gridProcessor.getColumnSpan(4, 2));
0316:
0317:                // Verify y-spans were untouched.
0318:                assertEquals(1, gridProcessor.getRowSpan(0, 0));
0319:                assertEquals(1, gridProcessor.getRowSpan(1, 0));
0320:                assertEquals(1, gridProcessor.getRowSpan(2, 0));
0321:                assertEquals(1, gridProcessor.getRowSpan(3, 0));
0322:                assertEquals(1, gridProcessor.getRowSpan(4, 0));
0323:                assertEquals(1, gridProcessor.getRowSpan(0, 1));
0324:                assertEquals(1, gridProcessor.getRowSpan(1, 1));
0325:                assertEquals(1, gridProcessor.getRowSpan(3, 1));
0326:                assertEquals(2, gridProcessor.getRowSpan(4, 1));
0327:                assertEquals(1, gridProcessor.getRowSpan(0, 2));
0328:                assertEquals(1, gridProcessor.getRowSpan(1, 2));
0329:                assertEquals(1, gridProcessor.getRowSpan(2, 2));
0330:                assertEquals(1, gridProcessor.getRowSpan(3, 2));
0331:                assertEquals(2, gridProcessor.getRowSpan(4, 2));
0332:
0333:                // Verify column sizes were properly combined.
0334:                assertEquals(new Extent(1), gridProcessor.getColumnWidth(0));
0335:                assertEquals(new Extent(6), gridProcessor.getColumnWidth(1));
0336:                assertEquals(new Extent(8), gridProcessor.getColumnWidth(2));
0337:                assertEquals(new Extent(16), gridProcessor.getColumnWidth(3));
0338:                assertEquals(new Extent(96), gridProcessor.getColumnWidth(4));
0339:            }
0340:
0341:            /**
0342:             * Tests column reduction to ensure the column #2 is not rendered.
0343:             * 
0344:             *  0  1  2  3   (specified column)
0345:             *  __ _____ __
0346:             * |0 |1    |2 |
0347:             * |__|_____|__|
0348:             * |3 |4    |5 |
0349:             * |__|_____|__|
0350:             * 
0351:             * 0   1     2   (rendered column)
0352:             */
0353:            public void testReduceColumnSimple() {
0354:                Grid grid = new Grid();
0355:                grid.setSize(4);
0356:                for (int i = 0; i < 6; ++i) {
0357:                    Label label = new Label(Integer.toString(i));
0358:                    if (i == 1 || i == 4) {
0359:                        GridLayoutData layoutData = new GridLayoutData();
0360:                        layoutData.setColumnSpan(2);
0361:                        label.setLayoutData(layoutData);
0362:                    }
0363:                    grid.add(label);
0364:                }
0365:                GridProcessor gridProcessor = new GridProcessor(grid);
0366:                assertEquals(3, gridProcessor.getColumnCount());
0367:                assertEquals(2, gridProcessor.getRowCount());
0368:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0369:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0370:                assertEquals(2, gridProcessor.getComponentIndex(2, 0));
0371:                assertEquals(3, gridProcessor.getComponentIndex(0, 1));
0372:                assertEquals(4, gridProcessor.getComponentIndex(1, 1));
0373:                assertEquals(5, gridProcessor.getComponentIndex(2, 1));
0374:            }
0375:
0376:            /**
0377:             * Tests column reduction to ensure proper rendering of the following:
0378:             *            specified  rendered              
0379:             *  __ __ __  row:       row:
0380:             * |0 |1 |2 |   
0381:             * |__|__|__|     0        0
0382:             * |3 |4 |5 |
0383:             * |  |  |  |     1        1
0384:             * |  |  |  |
0385:             * |__|__|__|     2
0386:             * |6 |7 |8 |
0387:             * |  |__|  |     3        2
0388:             * |  |9 |  |
0389:             * |__|__|__|     4        3
0390:             * |10|11   |
0391:             * |  |     |     5        4
0392:             * |  |     |
0393:             * |__|_____|     6
0394:             */
0395:            public void testReduceRowComplex() {
0396:                Grid grid = new Grid();
0397:
0398:                // Configure Grid Content
0399:                grid.setSize(3);
0400:                for (int i = 0; i < 12; ++i) {
0401:                    Label label = new Label(Integer.toString(i));
0402:                    if (i == 3 || i == 4 || i == 5 || i == 6 || i == 8
0403:                            || i == 10 || i == 11) {
0404:                        GridLayoutData layoutData = new GridLayoutData();
0405:                        layoutData.setRowSpan(2);
0406:                        if (i == 11) {
0407:                            layoutData.setColumnSpan(2);
0408:                        }
0409:                        label.setLayoutData(layoutData);
0410:                    }
0411:                    grid.add(label);
0412:                }
0413:
0414:                // Set Row Sizes
0415:                grid.setRowHeight(0, new Extent(1));
0416:                grid.setRowHeight(1, new Extent(2));
0417:                grid.setRowHeight(2, new Extent(4));
0418:                grid.setRowHeight(3, new Extent(8));
0419:                grid.setRowHeight(4, new Extent(16));
0420:                grid.setRowHeight(5, new Extent(32));
0421:                grid.setRowHeight(6, new Extent(64));
0422:
0423:                GridProcessor gridProcessor = new GridProcessor(grid);
0424:
0425:                // Verify Grid size is correct.
0426:                assertEquals(3, gridProcessor.getColumnCount());
0427:                assertEquals(5, gridProcessor.getRowCount());
0428:
0429:                // Verify components are at correct positions.
0430:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0431:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0432:                assertEquals(2, gridProcessor.getComponentIndex(2, 0));
0433:                assertEquals(3, gridProcessor.getComponentIndex(0, 1));
0434:                assertEquals(4, gridProcessor.getComponentIndex(1, 1));
0435:                assertEquals(5, gridProcessor.getComponentIndex(2, 1));
0436:                assertEquals(6, gridProcessor.getComponentIndex(0, 2));
0437:                assertEquals(7, gridProcessor.getComponentIndex(1, 2));
0438:                assertEquals(8, gridProcessor.getComponentIndex(2, 2));
0439:                assertEquals(6, gridProcessor.getComponentIndex(0, 3));
0440:                assertEquals(9, gridProcessor.getComponentIndex(1, 3));
0441:                assertEquals(8, gridProcessor.getComponentIndex(2, 3));
0442:                assertEquals(10, gridProcessor.getComponentIndex(0, 4));
0443:                assertEquals(11, gridProcessor.getComponentIndex(1, 4));
0444:                assertEquals(11, gridProcessor.getComponentIndex(2, 4));
0445:
0446:                // Verify x-spans were untouched.
0447:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
0448:                assertEquals(1, gridProcessor.getColumnSpan(1, 0));
0449:                assertEquals(1, gridProcessor.getColumnSpan(2, 0));
0450:                assertEquals(1, gridProcessor.getColumnSpan(0, 1));
0451:                assertEquals(1, gridProcessor.getColumnSpan(1, 1));
0452:                assertEquals(1, gridProcessor.getColumnSpan(2, 1));
0453:                assertEquals(1, gridProcessor.getColumnSpan(0, 2));
0454:                assertEquals(1, gridProcessor.getColumnSpan(1, 2));
0455:                assertEquals(1, gridProcessor.getColumnSpan(2, 2));
0456:                assertEquals(1, gridProcessor.getColumnSpan(0, 3));
0457:                assertEquals(1, gridProcessor.getColumnSpan(1, 3));
0458:                assertEquals(1, gridProcessor.getColumnSpan(2, 3));
0459:                assertEquals(1, gridProcessor.getColumnSpan(0, 4));
0460:                assertEquals(2, gridProcessor.getColumnSpan(1, 4));
0461:                assertEquals(2, gridProcessor.getColumnSpan(2, 4));
0462:
0463:                // Verify y-spans were properly reduced.
0464:                assertEquals(1, gridProcessor.getRowSpan(0, 0));
0465:                assertEquals(1, gridProcessor.getRowSpan(1, 0));
0466:                assertEquals(1, gridProcessor.getRowSpan(2, 0));
0467:                assertEquals(1, gridProcessor.getRowSpan(0, 1));
0468:                assertEquals(1, gridProcessor.getRowSpan(1, 1));
0469:                assertEquals(1, gridProcessor.getRowSpan(2, 1));
0470:                assertEquals(2, gridProcessor.getRowSpan(0, 2));
0471:                assertEquals(1, gridProcessor.getRowSpan(1, 2));
0472:                assertEquals(2, gridProcessor.getRowSpan(2, 2));
0473:                assertEquals(2, gridProcessor.getRowSpan(0, 3));
0474:                assertEquals(1, gridProcessor.getRowSpan(1, 3));
0475:                assertEquals(2, gridProcessor.getRowSpan(2, 3));
0476:                assertEquals(1, gridProcessor.getRowSpan(0, 4));
0477:                assertEquals(1, gridProcessor.getRowSpan(1, 4));
0478:                assertEquals(1, gridProcessor.getRowSpan(2, 4));
0479:
0480:                // Verify column sizes were properly combined.
0481:                assertEquals(new Extent(1), gridProcessor.getRowHeight(0));
0482:                assertEquals(new Extent(6), gridProcessor.getRowHeight(1));
0483:                assertEquals(new Extent(8), gridProcessor.getRowHeight(2));
0484:                assertEquals(new Extent(16), gridProcessor.getRowHeight(3));
0485:                assertEquals(new Extent(96), gridProcessor.getRowHeight(4));
0486:            }
0487:
0488:            /**
0489:             * Tests row reduction to ensure the row #2 is not rendered.
0490:             * 
0491:             *  __ __  Row:
0492:             * |0 |1 |  0
0493:             * |__|__|
0494:             * |2 |3 |  1
0495:             * |  |  |
0496:             * |  |  |  2
0497:             * |__|__|
0498:             * |4 |5 |  3
0499:             * |__|__|
0500:             */
0501:            public void testReduceRowSimple() {
0502:                Grid grid = new Grid();
0503:                grid.setSize(2);
0504:                for (int i = 0; i < 6; ++i) {
0505:                    Label label = new Label(Integer.toString(i));
0506:                    if (i == 2 || i == 3) {
0507:                        GridLayoutData layoutData = new GridLayoutData();
0508:                        layoutData.setRowSpan(2);
0509:                        label.setLayoutData(layoutData);
0510:                    }
0511:                    grid.add(label);
0512:                }
0513:                GridProcessor gridProcessor = new GridProcessor(grid);
0514:                assertEquals(2, gridProcessor.getColumnCount());
0515:                assertEquals(3, gridProcessor.getRowCount());
0516:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0517:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0518:                assertEquals(2, gridProcessor.getComponentIndex(0, 1));
0519:                assertEquals(3, gridProcessor.getComponentIndex(1, 1));
0520:                assertEquals(4, gridProcessor.getComponentIndex(0, 2));
0521:                assertEquals(5, gridProcessor.getComponentIndex(1, 2));
0522:            }
0523:
0524:            /**
0525:             * Test Grid with row and column reduction
0526:             * 
0527:             * (specified)      
0528:             * 0  1  2    (spec) (rend)
0529:             *  __ _____
0530:             * |0 |1    |   0     0
0531:             * |__|_____|
0532:             * |2 |3    |   1     1
0533:             * |  |     |
0534:             * |  |     |   2
0535:             * |__|_____|
0536:             * 
0537:             * 0   1
0538:             * (rendered)
0539:             */
0540:            public void testReduceColumnAndRowSimple() {
0541:                Grid grid = new Grid();
0542:                grid.setSize(3);
0543:                for (int i = 0; i < 4; ++i) {
0544:                    Label label = new Label(Integer.toString(i));
0545:                    if (i > 0) {
0546:                        GridLayoutData layoutData = new GridLayoutData();
0547:                        if (i == 1 || i == 3) {
0548:                            layoutData.setColumnSpan(2);
0549:                        }
0550:                        if (i == 2 || i == 3) {
0551:                            layoutData.setRowSpan(2);
0552:                        }
0553:                        label.setLayoutData(layoutData);
0554:                    }
0555:                    grid.add(label);
0556:                }
0557:
0558:                GridProcessor gridProcessor = new GridProcessor(grid);
0559:
0560:                // Verify Grid size is correct.
0561:                assertEquals(2, gridProcessor.getColumnCount());
0562:                assertEquals(2, gridProcessor.getRowCount());
0563:
0564:                // Verify components are at correct positions.
0565:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0566:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0567:                assertEquals(2, gridProcessor.getComponentIndex(0, 1));
0568:                assertEquals(3, gridProcessor.getComponentIndex(1, 1));
0569:
0570:                // Verify x-spans were properly reduced.
0571:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
0572:                assertEquals(1, gridProcessor.getColumnSpan(1, 0));
0573:                assertEquals(1, gridProcessor.getColumnSpan(0, 1));
0574:                assertEquals(1, gridProcessor.getColumnSpan(1, 1));
0575:
0576:                // Verify y-spans were properly reduced.
0577:                assertEquals(1, gridProcessor.getRowSpan(0, 0));
0578:                assertEquals(1, gridProcessor.getRowSpan(1, 0));
0579:                assertEquals(1, gridProcessor.getRowSpan(0, 1));
0580:                assertEquals(1, gridProcessor.getRowSpan(1, 1));
0581:            }
0582:
0583:            /**
0584:             * Test reduction of symmetric column spans.
0585:             * 
0586:             *  0  1  2  3  (specified)
0587:             *  ________ __
0588:             * |        |  |
0589:             * |________|__|
0590:             * |        |  |
0591:             * |________|__|
0592:             * |        |  |
0593:             * |________|__|
0594:             * 
0595:             *  0        1  (rendered)         
0596:             */
0597:            public void testReduceColumnLong() {
0598:                Grid grid = new Grid();
0599:                grid.setSize(4);
0600:
0601:                for (int i = 0; i < 6; ++i) {
0602:                    Label label = new Label(Integer.toString(i));
0603:                    if (i % 2 == 0) {
0604:                        GridLayoutData layoutData = new GridLayoutData();
0605:                        layoutData.setColumnSpan(3);
0606:                        label.setLayoutData(layoutData);
0607:                    }
0608:                    grid.add(label);
0609:                }
0610:
0611:                GridProcessor gridProcessor = new GridProcessor(grid);
0612:
0613:                // Verify Grid size is correct.
0614:                assertEquals(2, gridProcessor.getColumnCount());
0615:                assertEquals(3, gridProcessor.getRowCount());
0616:
0617:                // Verify components are at correct positions.
0618:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0619:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0620:                assertEquals(2, gridProcessor.getComponentIndex(0, 1));
0621:                assertEquals(3, gridProcessor.getComponentIndex(1, 1));
0622:                assertEquals(4, gridProcessor.getComponentIndex(0, 2));
0623:                assertEquals(5, gridProcessor.getComponentIndex(1, 2));
0624:
0625:                // Verify x-spans were properly reduced.
0626:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
0627:                assertEquals(1, gridProcessor.getColumnSpan(1, 0));
0628:                assertEquals(1, gridProcessor.getColumnSpan(0, 1));
0629:                assertEquals(1, gridProcessor.getColumnSpan(1, 1));
0630:                assertEquals(1, gridProcessor.getColumnSpan(0, 2));
0631:                assertEquals(1, gridProcessor.getColumnSpan(1, 2));
0632:
0633:                // Verify y-spans were untouched.
0634:                assertEquals(1, gridProcessor.getRowSpan(0, 0));
0635:                assertEquals(1, gridProcessor.getRowSpan(1, 0));
0636:                assertEquals(1, gridProcessor.getRowSpan(0, 1));
0637:                assertEquals(1, gridProcessor.getRowSpan(1, 1));
0638:                assertEquals(1, gridProcessor.getRowSpan(0, 2));
0639:                assertEquals(1, gridProcessor.getRowSpan(1, 2));
0640:            }
0641:
0642:            /**
0643:             * Test reduction of symmetric row spans.
0644:             * 
0645:             *  __ __ __  (spec)  (rend)  
0646:             * |  |  |  |     
0647:             * |  |  |  |   0      0       
0648:             * |  |  |  |     
0649:             * |  |  |  |   1    
0650:             * |  |  |  | 
0651:             * |__|__|__|   2
0652:             * |  |  |  | 
0653:             * |__|__|__|   3      1
0654:             */
0655:            public void testReduceRowLong() {
0656:                Grid grid = new Grid();
0657:                grid.setSize(3);
0658:
0659:                for (int i = 0; i < 6; ++i) {
0660:                    Label label = new Label(Integer.toString(i));
0661:                    if (i < 3) {
0662:                        GridLayoutData layoutData = new GridLayoutData();
0663:                        layoutData.setRowSpan(3);
0664:                        label.setLayoutData(layoutData);
0665:                    }
0666:                    grid.add(label);
0667:                }
0668:
0669:                GridProcessor gridProcessor = new GridProcessor(grid);
0670:
0671:                // Verify Grid size is correct.
0672:                assertEquals(3, gridProcessor.getColumnCount());
0673:                assertEquals(2, gridProcessor.getRowCount());
0674:
0675:                // Verify components are at correct positions.
0676:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0677:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0678:                assertEquals(2, gridProcessor.getComponentIndex(2, 0));
0679:                assertEquals(3, gridProcessor.getComponentIndex(0, 1));
0680:                assertEquals(4, gridProcessor.getComponentIndex(1, 1));
0681:                assertEquals(5, gridProcessor.getComponentIndex(2, 1));
0682:
0683:                // Verify x-spans were untouched.
0684:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
0685:                assertEquals(1, gridProcessor.getColumnSpan(1, 0));
0686:                assertEquals(1, gridProcessor.getColumnSpan(2, 0));
0687:                assertEquals(1, gridProcessor.getColumnSpan(0, 1));
0688:                assertEquals(1, gridProcessor.getColumnSpan(1, 1));
0689:                assertEquals(1, gridProcessor.getColumnSpan(2, 1));
0690:
0691:                // Verify y-spans were properly reduced.
0692:                assertEquals(1, gridProcessor.getRowSpan(0, 0));
0693:                assertEquals(1, gridProcessor.getRowSpan(1, 0));
0694:                assertEquals(1, gridProcessor.getRowSpan(2, 0));
0695:                assertEquals(1, gridProcessor.getRowSpan(0, 1));
0696:                assertEquals(1, gridProcessor.getRowSpan(1, 1));
0697:                assertEquals(1, gridProcessor.getRowSpan(2, 1));
0698:            }
0699:
0700:            /**
0701:             *  Test Grid that consists a single row-spanned and column-spanned cell.
0702:             *  
0703:             *  0  1  2
0704:             *  __ __ __
0705:             * |0       |  0
0706:             * |        |
0707:             * |        |  1
0708:             * |        |
0709:             * |        |  2
0710:             * |        |
0711:             * |        |  3
0712:             * |        |
0713:             * |        |  4
0714:             * |________|
0715:             */
0716:            public void testReduceColumnAndRowOneBigCell() {
0717:                Grid grid = new Grid();
0718:                grid.setSize(3);
0719:                Label label = new Label("0");
0720:                GridLayoutData layoutData = new GridLayoutData();
0721:                layoutData.setColumnSpan(3);
0722:                layoutData.setRowSpan(5);
0723:                label.setLayoutData(layoutData);
0724:                grid.add(label);
0725:
0726:                GridProcessor gridProcessor = new GridProcessor(grid);
0727:
0728:                // Verify Grid size is correct.
0729:                assertEquals(1, gridProcessor.getColumnCount());
0730:                assertEquals(1, gridProcessor.getRowCount());
0731:
0732:                // Verify components are at correct positions.
0733:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0734:
0735:                // Verify x-spans and y-spans were properly reduced.
0736:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
0737:                assertEquals(1, gridProcessor.getRowSpan(0, 0));
0738:            }
0739:
0740:            /**
0741:             * Tests a grid with a cell spanning two rows:
0742:             *  __ __
0743:             * |0 |1 |
0744:             * |__|__|
0745:             * |2 |3 |
0746:             * |  |__|
0747:             * |  |4 |
0748:             * |__|__|
0749:             * |5 |6 |
0750:             * |__|__|
0751:             */
0752:            public void testRowSpanSimple() {
0753:                Grid grid = new Grid();
0754:                for (int i = 0; i < 7; ++i) {
0755:                    Label label = new Label(Integer.toString(i));
0756:                    if (i == 2) {
0757:                        GridLayoutData layoutData = new GridLayoutData();
0758:                        layoutData.setRowSpan(2);
0759:                        label.setLayoutData(layoutData);
0760:                    }
0761:                    grid.add(label);
0762:                }
0763:
0764:                GridProcessor gridProcessor = new GridProcessor(grid);
0765:
0766:                // Verify Grid size is correct.
0767:                assertEquals(2, gridProcessor.getColumnCount());
0768:                assertEquals(4, gridProcessor.getRowCount());
0769:
0770:                // Verify components are at correct positions.
0771:                assertEquals("0", ((Label) gridProcessor.getContent(0, 0))
0772:                        .getText());
0773:                assertEquals("1", ((Label) gridProcessor.getContent(1, 0))
0774:                        .getText());
0775:                assertEquals("2", ((Label) gridProcessor.getContent(0, 1))
0776:                        .getText());
0777:                assertEquals("3", ((Label) gridProcessor.getContent(1, 1))
0778:                        .getText());
0779:                assertEquals("2", ((Label) gridProcessor.getContent(0, 2))
0780:                        .getText());
0781:                assertEquals("4", ((Label) gridProcessor.getContent(1, 2))
0782:                        .getText());
0783:                assertEquals("5", ((Label) gridProcessor.getContent(0, 3))
0784:                        .getText());
0785:                assertEquals("6", ((Label) gridProcessor.getContent(1, 3))
0786:                        .getText());
0787:            }
0788:
0789:            /**
0790:             * Test a simple grid consisting of ten cells in default 2 columns and 5 rows.
0791:             *  __ __
0792:             * |0 |1 |
0793:             * |__|__|
0794:             * |2 |3 |
0795:             * |__|__|
0796:             * |4 |5 |
0797:             * |__|__|
0798:             * |6 |7 |
0799:             * |__|__|
0800:             * |8 |9 |
0801:             * |__|__|
0802:             */
0803:            public void testSimple() {
0804:                Grid grid = new Grid();
0805:                for (int i = 0; i < 10; ++i) {
0806:                    grid.add(new Label("test"));
0807:                }
0808:
0809:                GridProcessor gridProcessor = new GridProcessor(grid);
0810:
0811:                // Verify Grid size is correct.
0812:                assertEquals(2, gridProcessor.getColumnCount());
0813:                assertEquals(5, gridProcessor.getRowCount());
0814:            }
0815:
0816:            /**
0817:             * Test a a simple Grid consisting of ten cells with one of them 
0818:             * spanning two columns. 
0819:             *  __ __
0820:             * |0 |1 |
0821:             * |__|__|
0822:             * |2 |3 |
0823:             * |__|__|
0824:             * |4    |
0825:             * |_____|
0826:             * |5 |6 |
0827:             * |__|__|
0828:             * |7 |8 |
0829:             * |__|__|
0830:             * |9 |XX|
0831:             * |__|XX|
0832:             */
0833:            public void testSimpleWithColumnSpan() {
0834:                Grid grid = new Grid();
0835:                for (int i = 0; i < 10; ++i) {
0836:                    Label label = new Label();
0837:                    if (i == 4) {
0838:                        GridLayoutData layoutData = new GridLayoutData();
0839:                        layoutData.setColumnSpan(2);
0840:                        label.setLayoutData(layoutData);
0841:                    }
0842:                    grid.add(label);
0843:                }
0844:
0845:                GridProcessor gridProcessor = new GridProcessor(grid);
0846:
0847:                // Verify Grid size is correct.
0848:                assertEquals(2, gridProcessor.getColumnCount());
0849:                assertEquals(6, gridProcessor.getRowCount());
0850:
0851:                // Verify components are at correct positions.
0852:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0853:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0854:                assertEquals(2, gridProcessor.getComponentIndex(0, 1));
0855:                assertEquals(3, gridProcessor.getComponentIndex(1, 1));
0856:                assertEquals(4, gridProcessor.getComponentIndex(0, 2));
0857:                assertEquals(4, gridProcessor.getComponentIndex(1, 2));
0858:                assertEquals(5, gridProcessor.getComponentIndex(0, 3));
0859:                assertEquals(6, gridProcessor.getComponentIndex(1, 3));
0860:                assertEquals(7, gridProcessor.getComponentIndex(0, 4));
0861:                assertEquals(8, gridProcessor.getComponentIndex(1, 4));
0862:                assertEquals(9, gridProcessor.getComponentIndex(0, 5));
0863:                assertEquals(-1, gridProcessor.getComponentIndex(1, 5));
0864:
0865:                // Verify x-spans were untouched.
0866:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
0867:                assertEquals(1, gridProcessor.getColumnSpan(1, 0));
0868:                assertEquals(1, gridProcessor.getColumnSpan(0, 1));
0869:                assertEquals(1, gridProcessor.getColumnSpan(1, 1));
0870:                assertEquals(2, gridProcessor.getColumnSpan(0, 2));
0871:                assertEquals(2, gridProcessor.getColumnSpan(1, 2));
0872:                assertEquals(1, gridProcessor.getColumnSpan(0, 3));
0873:                assertEquals(1, gridProcessor.getColumnSpan(1, 3));
0874:                assertEquals(1, gridProcessor.getColumnSpan(0, 4));
0875:                assertEquals(1, gridProcessor.getColumnSpan(1, 4));
0876:                assertEquals(1, gridProcessor.getColumnSpan(0, 5));
0877:                assertEquals(-1, gridProcessor.getColumnSpan(1, 5));
0878:
0879:                // Verify y-spans were properly reduced.
0880:                assertEquals(1, gridProcessor.getRowSpan(0, 0));
0881:                assertEquals(1, gridProcessor.getRowSpan(1, 0));
0882:                assertEquals(1, gridProcessor.getRowSpan(0, 1));
0883:                assertEquals(1, gridProcessor.getRowSpan(1, 1));
0884:                assertEquals(1, gridProcessor.getRowSpan(0, 2));
0885:                assertEquals(1, gridProcessor.getRowSpan(1, 2));
0886:                assertEquals(1, gridProcessor.getRowSpan(0, 3));
0887:                assertEquals(1, gridProcessor.getRowSpan(1, 3));
0888:                assertEquals(1, gridProcessor.getRowSpan(0, 4));
0889:                assertEquals(1, gridProcessor.getRowSpan(1, 4));
0890:                assertEquals(1, gridProcessor.getRowSpan(0, 5));
0891:                assertEquals(-1, gridProcessor.getRowSpan(1, 5));
0892:            }
0893:
0894:            /**
0895:             * Test a a simple Grid consisting of ten cells with one of them 
0896:             * spanning three columns (even though only two are available). 
0897:             *  __ __
0898:             * |0 |1 |
0899:             * |__|__|
0900:             * |2 |3 |
0901:             * |__|__|__
0902:             * |4       |
0903:             * |________|
0904:             * |5 |6 |
0905:             * |__|__|
0906:             * |7 |8 |
0907:             * |__|__|
0908:             * |9 |XX|
0909:             * |__|XX|
0910:             */
0911:            public void testSimpleWithOversidedColumnSpan() {
0912:                Grid grid = new Grid();
0913:                for (int i = 0; i < 10; ++i) {
0914:                    Label label = new Label();
0915:                    if (i == 4) {
0916:                        GridLayoutData layoutData = new GridLayoutData();
0917:                        layoutData.setColumnSpan(3);
0918:                        label.setLayoutData(layoutData);
0919:                    }
0920:                    grid.add(label);
0921:                }
0922:
0923:                GridProcessor gridProcessor = new GridProcessor(grid);
0924:
0925:                // Verify Grid size is correct.
0926:                assertEquals(2, gridProcessor.getColumnCount());
0927:                assertEquals(6, gridProcessor.getRowCount());
0928:
0929:                // Verify components are at correct positions.
0930:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
0931:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
0932:                assertEquals(2, gridProcessor.getComponentIndex(0, 1));
0933:                assertEquals(3, gridProcessor.getComponentIndex(1, 1));
0934:                assertEquals(4, gridProcessor.getComponentIndex(0, 2));
0935:                assertEquals(4, gridProcessor.getComponentIndex(1, 2));
0936:                assertEquals(5, gridProcessor.getComponentIndex(0, 3));
0937:                assertEquals(6, gridProcessor.getComponentIndex(1, 3));
0938:                assertEquals(7, gridProcessor.getComponentIndex(0, 4));
0939:                assertEquals(8, gridProcessor.getComponentIndex(1, 4));
0940:                assertEquals(9, gridProcessor.getComponentIndex(0, 5));
0941:                assertEquals(-1, gridProcessor.getComponentIndex(1, 5));
0942:
0943:                // Verify x-spans were untouched for the most part,
0944:                // except for oversized cell which is reduced.
0945:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
0946:                assertEquals(1, gridProcessor.getColumnSpan(1, 0));
0947:                assertEquals(1, gridProcessor.getColumnSpan(0, 1));
0948:                assertEquals(1, gridProcessor.getColumnSpan(1, 1));
0949:                assertEquals(2, gridProcessor.getColumnSpan(0, 2));
0950:                assertEquals(2, gridProcessor.getColumnSpan(1, 2));
0951:                assertEquals(1, gridProcessor.getColumnSpan(0, 3));
0952:                assertEquals(1, gridProcessor.getColumnSpan(1, 3));
0953:                assertEquals(1, gridProcessor.getColumnSpan(0, 4));
0954:                assertEquals(1, gridProcessor.getColumnSpan(1, 4));
0955:                assertEquals(1, gridProcessor.getColumnSpan(0, 5));
0956:                assertEquals(-1, gridProcessor.getColumnSpan(1, 5));
0957:
0958:                // Verify y-spans were properly reduced.
0959:                assertEquals(1, gridProcessor.getRowSpan(0, 0));
0960:                assertEquals(1, gridProcessor.getRowSpan(1, 0));
0961:                assertEquals(1, gridProcessor.getRowSpan(0, 1));
0962:                assertEquals(1, gridProcessor.getRowSpan(1, 1));
0963:                assertEquals(1, gridProcessor.getRowSpan(0, 2));
0964:                assertEquals(1, gridProcessor.getRowSpan(1, 2));
0965:                assertEquals(1, gridProcessor.getRowSpan(0, 3));
0966:                assertEquals(1, gridProcessor.getRowSpan(1, 3));
0967:                assertEquals(1, gridProcessor.getRowSpan(0, 4));
0968:                assertEquals(1, gridProcessor.getRowSpan(1, 4));
0969:                assertEquals(1, gridProcessor.getRowSpan(0, 5));
0970:                assertEquals(-1, gridProcessor.getRowSpan(1, 5));
0971:            }
0972:
0973:            /**
0974:             * Test staggered row-spanned cells:
0975:             *  __ __
0976:             * |0 |1 |
0977:             * |  |__|
0978:             * |  |2 |
0979:             * |__|  |
0980:             * |3 |  |
0981:             * |__|__|
0982:             */
0983:            public void testStaggeredSpans() {
0984:                Grid grid = new Grid();
0985:                for (int i = 0; i < 4; ++i) {
0986:                    Label label = new Label();
0987:                    if (i % 2 == 0) {
0988:                        GridLayoutData gridLayoutData = new GridLayoutData();
0989:                        gridLayoutData.setRowSpan(2);
0990:                        label.setLayoutData(gridLayoutData);
0991:                    }
0992:                    grid.add(label);
0993:                }
0994:
0995:                GridProcessor gridProcessor = new GridProcessor(grid);
0996:
0997:                // Verify Grid size is correct.
0998:                assertEquals(2, gridProcessor.getColumnCount());
0999:                assertEquals(3, gridProcessor.getRowCount());
1000:
1001:                // Verify components are at correct positions.
1002:                assertEquals(0, gridProcessor.getComponentIndex(0, 0));
1003:                assertEquals(1, gridProcessor.getComponentIndex(1, 0));
1004:                assertEquals(0, gridProcessor.getComponentIndex(0, 1));
1005:                assertEquals(2, gridProcessor.getComponentIndex(1, 1));
1006:                assertEquals(3, gridProcessor.getComponentIndex(0, 2));
1007:                assertEquals(2, gridProcessor.getComponentIndex(1, 2));
1008:
1009:                // Verify y-spans were untouched.
1010:                assertEquals(1, gridProcessor.getColumnSpan(0, 0));
1011:                assertEquals(1, gridProcessor.getColumnSpan(1, 0));
1012:                assertEquals(1, gridProcessor.getColumnSpan(0, 1));
1013:                assertEquals(1, gridProcessor.getColumnSpan(1, 1));
1014:                assertEquals(1, gridProcessor.getColumnSpan(0, 2));
1015:                assertEquals(1, gridProcessor.getColumnSpan(1, 2));
1016:
1017:                // Verify y-spans were untouched.
1018:                assertEquals(2, gridProcessor.getRowSpan(0, 0));
1019:                assertEquals(1, gridProcessor.getRowSpan(1, 0));
1020:                assertEquals(2, gridProcessor.getRowSpan(0, 1));
1021:                assertEquals(2, gridProcessor.getRowSpan(1, 1));
1022:                assertEquals(1, gridProcessor.getRowSpan(0, 2));
1023:                assertEquals(2, gridProcessor.getRowSpan(1, 2));
1024:            }
1025:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.