Source Code Cross Referenced for FlowViewTest.java in  » Apache-Harmony-Java-SE » javax-package » javax » swing » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » javax package » javax.swing.text 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Alexey A. Ivanov
019:         * @version $Revision$
020:         */package javax.swing.text;
021:
022:        import java.awt.Rectangle;
023:        import java.util.ArrayList;
024:        import java.util.List;
025:        import javax.swing.BasicSwingTestCase;
026:        import javax.swing.SizeRequirements;
027:        import javax.swing.event.DocumentEvent;
028:        import javax.swing.text.FlowView.FlowStrategy;
029:        import javax.swing.text.ViewTestHelpers.ChildrenFactory;
030:        import javax.swing.text.ViewTestHelpers.ElementPartView;
031:
032:        /**
033:         * Tests the majority of methods of FlowView class.
034:         * @see javax.swing.text.FlowView_ChangesTest
035:         *
036:         */
037:        public class FlowViewTest extends BasicSwingTestCase {
038:            protected static class FlowViewImpl extends FlowView {
039:                private int count = 0;
040:
041:                public FlowViewImpl(final Element element, final int axis) {
042:                    super (element, axis);
043:                }
044:
045:                @Override
046:                protected View createRow() {
047:                    return new BoxView(getElement(),
048:                            getAxis() == Y_AXIS ? X_AXIS : Y_AXIS) {
049:                        private final int id = count++;
050:
051:                        @Override
052:                        public String toString() {
053:                            return "row(" + id + ")";
054:                        }
055:
056:                        @Override
057:                        protected void loadChildren(ViewFactory factory) {
058:                            return;
059:                        }
060:
061:                        @Override
062:                        public int getStartOffset() {
063:                            return getViewCount() > 0 ? getView(0)
064:                                    .getStartOffset() : super .getStartOffset();
065:                        }
066:
067:                        @Override
068:                        public int getEndOffset() {
069:                            int count = getViewCount();
070:                            return count > 0 ? getView(count - 1)
071:                                    .getEndOffset() : super .getEndOffset();
072:                        }
073:                    };
074:                }
075:
076:                @Override
077:                public String toString() {
078:                    return "flow";
079:                }
080:            }
081:
082:            protected static class FlowViewImplWithFactory extends FlowViewImpl {
083:                private final ViewFactory factory;
084:
085:                public FlowViewImplWithFactory(final Element element,
086:                        final int axis) {
087:                    this (element, axis, new ChildrenFactory());
088:                }
089:
090:                public FlowViewImplWithFactory(final Element element,
091:                        final int axis, final ViewFactory factory) {
092:                    super (element, axis);
093:                    this .factory = factory;
094:                }
095:
096:                @Override
097:                public ViewFactory getViewFactory() {
098:                    return factory;
099:                }
100:
101:                @Override
102:                public String toString() {
103:                    return "theFlow";
104:                }
105:            }
106:
107:            private Document doc;
108:
109:            private Element root;
110:
111:            private FlowView view;
112:
113:            @Override
114:            protected void setUp() throws Exception {
115:                super .setUp();
116:                doc = new PlainDocument();
117:                doc.insertString(0, "line1\nline2\nline3", null);
118:                root = doc.getDefaultRootElement();
119:                view = new FlowViewImpl(root, View.Y_AXIS);
120:            }
121:
122:            public void testSetParent() {
123:                assertNull(view.getParent());
124:                assertNull(view.layoutPool);
125:                assertEquals(0, view.getViewCount());
126:                assertNull(view.getViewFactory());
127:                final View parent = new BoxView(root, View.X_AXIS);
128:                view.setParent(parent);
129:                assertNotNull(view.getParent());
130:                assertEquals(0, view.getViewCount());
131:                assertNotNull(view.layoutPool);
132:                assertSame(view, view.layoutPool.getParent());
133:                assertSame(root, view.layoutPool.getElement());
134:                assertEquals(0, view.layoutPool.getViewCount());
135:            }
136:
137:            public void testSetParentWithFactory() {
138:                view = new FlowViewImplWithFactory(root, View.Y_AXIS);
139:                assertNull(view.getParent());
140:                assertNull(view.layoutPool);
141:                assertEquals(0, view.getViewCount());
142:                assertNotNull(view.getViewFactory());
143:                final View parent = new BoxView(root, View.X_AXIS);
144:                view.setParent(parent);
145:                assertNotNull(view.getParent());
146:                assertEquals(0, view.getViewCount());
147:                assertNotNull(view.layoutPool);
148:                assertSame(view, view.layoutPool.getParent());
149:                assertSame(root, view.layoutPool.getElement());
150:                assertEquals(root.getElementCount(), view.layoutPool
151:                        .getViewCount());
152:            }
153:
154:            /**
155:             * Tests <code>getViewIndexAtPosition()</code> when views represent entire
156:             * elements.
157:             */
158:            public void testGetViewIndexAtPositionEntire() {
159:                assertEquals(0, view.getViewCount());
160:                final ViewFactory vf = new ChildrenFactory();
161:                final Element first = root.getElement(0);
162:                final Element second = root.getElement(1);
163:                final int middle = (first.getStartOffset() + first
164:                        .getEndOffset()) / 2;
165:                View[] views = new View[] { vf.create(first), vf.create(second) };
166:                view.replace(0, 0, views);
167:                assertEquals(-1, view.getViewIndexAtPosition(-1));
168:                assertEquals(0, view.getViewIndexAtPosition(first
169:                        .getStartOffset()));
170:                assertEquals(0, view.getViewIndexAtPosition(middle));
171:                assertEquals(1, view.getViewIndexAtPosition(first
172:                        .getEndOffset()));
173:                assertEquals(1, view.getViewIndexAtPosition(second
174:                        .getStartOffset()));
175:                assertEquals(1, view.getViewIndexAtPosition(second
176:                        .getEndOffset() - 1));
177:                assertEquals(-1, view.getViewIndexAtPosition(second
178:                        .getEndOffset()));
179:                assertEquals(-1, view.getViewIndexAtPosition(second
180:                        .getEndOffset() + 2));
181:                assertNull(view.layoutPool);
182:            }
183:
184:            /**
185:             * Tests <code>getViewIndexAtPosition()</code> when views represent portions
186:             * of elements.
187:             */
188:            public void testGetViewIndexAtPositionPartial() {
189:                assertEquals(0, view.getViewCount());
190:                final ViewFactory vf = new ChildrenFactory();
191:                final Element first = root.getElement(0);
192:                final Element second = root.getElement(1);
193:                final int middle = (first.getStartOffset() + first
194:                        .getEndOffset()) / 2;
195:                View[] views = new View[] {
196:                        new ElementPartView(first, first.getStartOffset(),
197:                                middle),
198:                        new ElementPartView(first, middle, first.getEndOffset()),
199:                        vf.create(second) };
200:                view.replace(0, 0, views);
201:                assertEquals(-1, view.getViewIndexAtPosition(-1));
202:                assertEquals(0, view.getViewIndexAtPosition(first
203:                        .getStartOffset()));
204:                assertEquals(0, view.getViewIndexAtPosition(middle - 1));
205:                assertEquals(1, view.getViewIndexAtPosition(middle));
206:                assertEquals(1, view.getViewIndexAtPosition(middle + 1));
207:                assertEquals(1, view.getViewIndexAtPosition(first
208:                        .getEndOffset() - 1));
209:                assertEquals(2, view.getViewIndexAtPosition(first
210:                        .getEndOffset()));
211:                assertEquals(2, view.getViewIndexAtPosition(second
212:                        .getStartOffset()));
213:                assertEquals(2, view.getViewIndexAtPosition(second
214:                        .getEndOffset() - 1));
215:                assertEquals(-1, view.getViewIndexAtPosition(second
216:                        .getEndOffset()));
217:                assertEquals(-1, view.getViewIndexAtPosition(second
218:                        .getEndOffset() + 2));
219:                assertNull(view.layoutPool);
220:            }
221:
222:            public void testLoadChildren() {
223:                assertNull(view.layoutPool);
224:                assertNull(view.getViewFactory());
225:                view.loadChildren(new ChildrenFactory());
226:                assertNotNull(view.layoutPool);
227:                assertSame(view, view.layoutPool.getParent());
228:                assertSame(root, view.layoutPool.getElement());
229:                assertEquals(0, view.layoutPool.getViewCount());
230:            }
231:
232:            public void testLoadChildrenWithFactory() {
233:                view = new FlowViewImplWithFactory(root, View.Y_AXIS);
234:                assertNull(view.layoutPool);
235:                assertNotNull(view.getViewFactory());
236:                view.loadChildren(new ChildrenFactory());
237:                assertNotNull(view.layoutPool);
238:                assertSame(view, view.layoutPool.getParent());
239:                assertSame(root, view.layoutPool.getElement());
240:                assertEquals(root.getElementCount(), view.layoutPool
241:                        .getViewCount());
242:            }
243:
244:            public void testLoadChildrenWithFactoryEmtpyPool() {
245:                view = new FlowViewImplWithFactory(root, View.Y_AXIS);
246:                assertNull(view.layoutPool);
247:                assertNotNull(view.getViewFactory());
248:                view.loadChildren(null);
249:                assertNotNull(view.layoutPool);
250:                view.layoutPool.removeAll();
251:                view.loadChildren(null);
252:                assertEquals(root.getElementCount(), view.layoutPool
253:                        .getViewCount());
254:            }
255:
256:            public void testLoadChildrenEmtpyPoolNullFactory() {
257:                view = new FlowViewImplWithFactory(root, View.Y_AXIS);
258:                assertNull(view.layoutPool);
259:                assertNotNull(view.getViewFactory());
260:                view.loadChildren(null);
261:                assertNotNull(view.layoutPool);
262:                view.layoutPool.removeAll();
263:                ((CompositeView) view.layoutPool).loadChildren(null);
264:                assertEquals(0, view.layoutPool.getViewCount());
265:            }
266:
267:            public void testLoadChildrenStrategy() {
268:                final boolean[] called = new boolean[] { false };
269:                view = new FlowViewImplWithFactory(root, View.Y_AXIS);
270:                view.strategy = new FlowStrategy() {
271:                    @Override
272:                    public void insertUpdate(FlowView fv, DocumentEvent event,
273:                            Rectangle alloc) {
274:                        called[0] = true;
275:                        assertSame(view, fv);
276:                        assertNull(event);
277:                        assertNull(alloc);
278:                        super .insertUpdate(fv, event, alloc);
279:                    }
280:                };
281:                view.loadChildren(null);
282:                assertTrue(called[0]);
283:            }
284:
285:            public void testCalculateMinorAxisRequirements() {
286:                view.layoutPool = new PlainView(root) {
287:                    @Override
288:                    public float getPreferredSpan(int axis) {
289:                        return axis == X_AXIS ? -13 : 13;
290:                    }
291:
292:                    @Override
293:                    public float getMinimumSpan(int axis) {
294:                        return axis == X_AXIS ? -19 : 7;
295:                    }
296:
297:                    @Override
298:                    public float getMaximumSpan(int axis) {
299:                        return axis == X_AXIS ? -7 : 19;
300:                    }
301:
302:                    @Override
303:                    public float getAlignment(int axis) {
304:                        return axis == X_AXIS ? 0.312f : 0.213f;
305:                    }
306:                };
307:                SizeRequirements xSR = view.calculateMinorAxisRequirements(
308:                        View.X_AXIS, null);
309:                assertEquals(-19, xSR.minimum);
310:                assertEquals(-13, xSR.preferred);
311:                assertEquals(Integer.MAX_VALUE, xSR.maximum);
312:                assertEquals(0.5f, xSR.alignment, 1e-5f);
313:                SizeRequirements ySR = view.calculateMinorAxisRequirements(
314:                        View.Y_AXIS, xSR);
315:                assertSame(xSR, ySR);
316:                assertEquals(7, xSR.minimum);
317:                assertEquals(13, xSR.preferred);
318:                assertEquals(Integer.MAX_VALUE, xSR.maximum);
319:                assertEquals(0.5f, xSR.alignment, 1e-5f);
320:            }
321:
322:            public void testLayout() {
323:                final List<Integer> layoutChanges = new ArrayList<Integer>();
324:                final Marker prefMarker = new Marker();
325:                view = new FlowViewImplWithFactory(root, View.Y_AXIS) {
326:                    @Override
327:                    public void layoutChanged(int axis) {
328:                        layoutChanges.add(new Integer(axis));
329:                        super .layoutChanged(axis);
330:                    }
331:
332:                    @Override
333:                    public void preferenceChanged(View child, boolean width,
334:                            boolean height) {
335:                        assertNull(child);
336:                        assertFalse(width);
337:                        assertTrue(height);
338:                        prefMarker.setOccurred();
339:                        super .preferenceChanged(child, width, height);
340:                    }
341:                };
342:                view.loadChildren(null);
343:                assertEquals(root.getElementCount(), view.layoutPool
344:                        .getViewCount());
345:                assertEquals(0, view.getViewCount());
346:                layoutChanges.clear();
347:                assertFalse(view.isAllocationValid());
348:                assertEquals(Short.MAX_VALUE, view.layoutSpan);
349:                final boolean[] called = new boolean[] { false };
350:                final int width = 513;
351:                final int height = 137;
352:                view.strategy = new FlowStrategy() {
353:                    @Override
354:                    public void layout(FlowView fv) {
355:                        assertSame(view, fv);
356:                        super .layout(fv);
357:                        called[0] = true;
358:                    }
359:                };
360:                view.layout(width, height);
361:                assertEquals(width, view.layoutSpan);
362:                assertEquals(1, view.getViewCount());
363:                assertTrue(called[0]);
364:                assertTrue(view.isAllocationValid());
365:                assertEquals(2, layoutChanges.size());
366:                assertEquals(View.X_AXIS, layoutChanges.get(0).intValue());
367:                assertEquals(View.Y_AXIS, layoutChanges.get(1).intValue());
368:                layoutChanges.clear();
369:                called[0] = false;
370:                view.layout(width, height);
371:                assertFalse(called[0]);
372:                assertEquals(0, layoutChanges.size());
373:                view.layoutChanged(View.X_AXIS);
374:                layoutChanges.clear();
375:                assertFalse(view.isAllocationValid());
376:                view.layout(width, height);
377:                assertTrue(called[0]);
378:                assertEquals(0, layoutChanges.size());
379:                called[0] = false;
380:                view.layout(width, height - 1);
381:                assertFalse(called[0]);
382:                assertEquals(0, layoutChanges.size());
383:                view.layout(width - 1, height);
384:                assertEquals(width - 1, view.layoutSpan);
385:                assertTrue(called[0]);
386:                assertEquals(2, layoutChanges.size());
387:                assertEquals(View.X_AXIS, layoutChanges.get(0).intValue());
388:                assertEquals(View.Y_AXIS, layoutChanges.get(1).intValue());
389:                layoutChanges.clear();
390:                // Test if preferenceChanged() is called
391:                view.removeAll();
392:                int prefSpan = (int) view.getPreferredSpan(View.Y_AXIS);
393:                assertEquals(0, prefSpan);
394:                view.layout(width, height);
395:                assertTrue(view.getViewCount() != 0);
396:                assertEquals(getSpanY(), (int) view
397:                        .getPreferredSpan(View.Y_AXIS));
398:                assertEquals(isHarmony(), prefMarker.isOccurred());
399:            }
400:
401:            public void testFlowView() {
402:                assertSame(root, view.getElement());
403:                assertEquals(View.Y_AXIS, view.getAxis());
404:                assertEquals(Short.MAX_VALUE, view.layoutSpan);
405:                assertNull(view.layoutPool);
406:                assertNotNull(view.strategy);
407:                FlowView other = new FlowViewImpl(root, View.Y_AXIS);
408:                assertSame(view.strategy, other.strategy);
409:            }
410:
411:            public void testGetFlowAxis() {
412:                assertEquals(View.Y_AXIS, view.getAxis());
413:                assertEquals(View.X_AXIS, view.getFlowAxis());
414:                view = new FlowViewImpl(root, View.X_AXIS);
415:                assertEquals(View.X_AXIS, view.getAxis());
416:                assertEquals(View.Y_AXIS, view.getFlowAxis());
417:                view = new FlowViewImpl(root, 10);
418:                assertEquals(10, view.getAxis());
419:                assertEquals(View.Y_AXIS, view.getFlowAxis());
420:                view.setAxis(View.Y_AXIS);
421:                assertEquals(View.X_AXIS, view.getFlowAxis());
422:            }
423:
424:            public void testGetFlowStart() {
425:                assertEquals(0, view.getViewCount());
426:                assertEquals(0, view.getFlowStart(0));
427:                assertEquals(0, view.getFlowStart(1));
428:                assertEquals(0, view.getFlowStart(2));
429:                view.setInsets((short) 5, (short) 7, (short) 6, (short) 3);
430:                assertEquals(0, view.getFlowStart(0));
431:                assertEquals(0, view.getFlowStart(1));
432:                assertEquals(0, view.getFlowStart(2));
433:            }
434:
435:            public void testGetFlowSpan() {
436:                assertEquals(0, view.getViewCount());
437:                assertEquals(Short.MAX_VALUE, view.layoutSpan);
438:                view.layoutSpan = -10;
439:                assertEquals(-10, view.getFlowSpan(0));
440:                assertEquals(-10, view.getFlowSpan(1));
441:                assertEquals(-10, view.getFlowSpan(2));
442:                view.setInsets((short) 5, (short) 7, (short) 6, (short) 3);
443:                assertEquals(-10, view.getFlowSpan(0));
444:                assertEquals(-10, view.getFlowSpan(1));
445:                assertEquals(-10, view.getFlowSpan(2));
446:            }
447:
448:            public void testGetSpanNoRow() throws Exception {
449:                view = new FlowViewImplWithFactory(root, View.Y_AXIS);
450:                view.loadChildren(null);
451:                assertEquals(0, view.getViewCount());
452:                view.layoutPool.replace(1, view.layoutPool.getViewCount() - 1,
453:                        null);
454:                assertEquals(1, view.layoutPool.getViewCount());
455:                final View child = view.layoutPool.getView(0);
456:                int childX = (int) child.getPreferredSpan(View.X_AXIS);
457:                int childY = (int) child.getPreferredSpan(View.Y_AXIS);
458:                assertEquals(childX, (int) child.getMinimumSpan(View.X_AXIS));
459:                assertEquals(childY, (int) child.getMinimumSpan(View.Y_AXIS));
460:                assertEquals(childX, (int) child.getMaximumSpan(View.X_AXIS));
461:                assertEquals(childY, (int) child.getMaximumSpan(View.Y_AXIS));
462:                assertEquals(0, (int) view.layoutPool
463:                        .getMinimumSpan(View.X_AXIS));
464:                assertEquals(0, (int) view.layoutPool
465:                        .getMinimumSpan(View.Y_AXIS));
466:                assertEquals(childX, (int) view.layoutPool
467:                        .getPreferredSpan(View.X_AXIS));
468:                assertEquals(childY, (int) view.layoutPool
469:                        .getPreferredSpan(View.Y_AXIS));
470:                assertEquals(childX, (int) view.layoutPool
471:                        .getMaximumSpan(View.X_AXIS));
472:                assertEquals(childY, (int) view.layoutPool
473:                        .getMaximumSpan(View.Y_AXIS));
474:                assertEquals(0, (int) view.getMinimumSpan(View.X_AXIS));
475:                assertEquals(0, (int) view.getMinimumSpan(View.Y_AXIS));
476:                assertEquals(childX, (int) view.getPreferredSpan(View.X_AXIS));
477:                assertEquals(0, (int) view.getPreferredSpan(View.Y_AXIS));
478:                assertEquals(Integer.MAX_VALUE, (int) view
479:                        .getMaximumSpan(View.X_AXIS));
480:                assertEquals(0, (int) view.getMaximumSpan(View.Y_AXIS));
481:            }
482:
483:            public void testGetSpanOneRowNoChildren() throws Exception {
484:                view = new FlowViewImplWithFactory(root, View.Y_AXIS);
485:                view.loadChildren(null);
486:                assertEquals(0, view.getViewCount());
487:                view.layoutPool.replace(1, view.layoutPool.getViewCount() - 1,
488:                        null);
489:                assertEquals(1, view.layoutPool.getViewCount());
490:                final View row = view.createRow();
491:                view.append(row);
492:                final View child = view.layoutPool.getView(0);
493:                int childX = (int) child.getPreferredSpan(View.X_AXIS);
494:                int childY = (int) child.getPreferredSpan(View.Y_AXIS);
495:                assertEquals(childX, (int) child.getMinimumSpan(View.X_AXIS));
496:                assertEquals(childY, (int) child.getMinimumSpan(View.Y_AXIS));
497:                assertEquals(childX, (int) child.getMaximumSpan(View.X_AXIS));
498:                assertEquals(childY, (int) child.getMaximumSpan(View.Y_AXIS));
499:                assertEquals(0, (int) view.layoutPool
500:                        .getMinimumSpan(View.X_AXIS));
501:                assertEquals(0, (int) view.layoutPool
502:                        .getMinimumSpan(View.Y_AXIS));
503:                assertEquals(childX, (int) view.layoutPool
504:                        .getPreferredSpan(View.X_AXIS));
505:                assertEquals(childY, (int) view.layoutPool
506:                        .getPreferredSpan(View.Y_AXIS));
507:                assertEquals(childX, (int) view.layoutPool
508:                        .getMaximumSpan(View.X_AXIS));
509:                assertEquals(childY, (int) view.layoutPool
510:                        .getMaximumSpan(View.Y_AXIS));
511:                assertEquals(0, (int) view.getMinimumSpan(View.X_AXIS));
512:                assertEquals(0, (int) view.getMinimumSpan(View.Y_AXIS));
513:                assertEquals(childX, (int) view.getPreferredSpan(View.X_AXIS));
514:                assertEquals(0, (int) view.getPreferredSpan(View.Y_AXIS));
515:                assertEquals(Integer.MAX_VALUE, (int) view
516:                        .getMaximumSpan(View.X_AXIS));
517:                assertEquals(Integer.MAX_VALUE, (int) view
518:                        .getMaximumSpan(View.Y_AXIS));
519:            }
520:
521:            public void testGetSpanOneRowOneChild() throws Exception {
522:                view = new FlowViewImplWithFactory(root, View.Y_AXIS);
523:                view.loadChildren(null);
524:                assertEquals(0, view.getViewCount());
525:                view.layoutPool.replace(1, view.layoutPool.getViewCount() - 1,
526:                        null);
527:                assertEquals(1, view.layoutPool.getViewCount());
528:                final View row = view.createRow();
529:                view.append(row);
530:                final View child = view.layoutPool.getView(0);
531:                row.append(child);
532:                int childX = (int) child.getPreferredSpan(View.X_AXIS);
533:                int childY = (int) child.getPreferredSpan(View.Y_AXIS);
534:                assertEquals(childX, (int) child.getMinimumSpan(View.X_AXIS));
535:                assertEquals(childY, (int) child.getMinimumSpan(View.Y_AXIS));
536:                assertEquals(childX, (int) child.getMaximumSpan(View.X_AXIS));
537:                assertEquals(childY, (int) child.getMaximumSpan(View.Y_AXIS));
538:                assertEquals(0, (int) view.layoutPool
539:                        .getMinimumSpan(View.X_AXIS));
540:                assertEquals(0, (int) view.layoutPool
541:                        .getMinimumSpan(View.Y_AXIS));
542:                assertEquals(childX, (int) view.layoutPool
543:                        .getPreferredSpan(View.X_AXIS));
544:                assertEquals(childY, (int) view.layoutPool
545:                        .getPreferredSpan(View.Y_AXIS));
546:                assertEquals(childX, (int) view.layoutPool
547:                        .getMaximumSpan(View.X_AXIS));
548:                assertEquals(childY, (int) view.layoutPool
549:                        .getMaximumSpan(View.Y_AXIS));
550:                assertEquals(0, (int) view.getMinimumSpan(View.X_AXIS));
551:                assertEquals(childY, (int) view.getMinimumSpan(View.Y_AXIS));
552:                assertEquals(childX, (int) view.getPreferredSpan(View.X_AXIS));
553:                assertEquals(childY, (int) view.getPreferredSpan(View.Y_AXIS));
554:                assertEquals(Integer.MAX_VALUE, (int) view
555:                        .getMaximumSpan(View.X_AXIS));
556:                assertEquals(Integer.MAX_VALUE, (int) view
557:                        .getMaximumSpan(View.Y_AXIS));
558:            }
559:
560:            public void testGetSpanNoRowFlexible() throws Exception {
561:                ChildrenFactory factory = new ChildrenFactory();
562:                factory.makeFlexible();
563:                view = new FlowViewImplWithFactory(root, View.Y_AXIS, factory);
564:                view.loadChildren(null);
565:                assertEquals(0, view.getViewCount());
566:                view.layoutPool.replace(1, view.layoutPool.getViewCount() - 1,
567:                        null);
568:                assertEquals(1, view.layoutPool.getViewCount());
569:                final View child = view.layoutPool.getView(0);
570:                int childPrefX = (int) child.getPreferredSpan(View.X_AXIS);
571:                int childPrefY = (int) child.getPreferredSpan(View.Y_AXIS);
572:                assertEquals(0, (int) view.layoutPool
573:                        .getMinimumSpan(View.X_AXIS));
574:                assertEquals(0, (int) view.layoutPool
575:                        .getMinimumSpan(View.Y_AXIS));
576:                assertEquals(childPrefX, (int) view.layoutPool
577:                        .getPreferredSpan(View.X_AXIS));
578:                assertEquals(childPrefY, (int) view.layoutPool
579:                        .getPreferredSpan(View.Y_AXIS));
580:                assertEquals(childPrefX, (int) view.layoutPool
581:                        .getMaximumSpan(View.X_AXIS));
582:                assertEquals(childPrefY, (int) view.layoutPool
583:                        .getMaximumSpan(View.Y_AXIS));
584:                assertEquals(0, (int) view.getMinimumSpan(View.X_AXIS));
585:                assertEquals(0, (int) view.getMinimumSpan(View.Y_AXIS));
586:                assertEquals(childPrefX, (int) view
587:                        .getPreferredSpan(View.X_AXIS));
588:                assertEquals(0, (int) view.getPreferredSpan(View.Y_AXIS));
589:                assertEquals(Integer.MAX_VALUE, (int) view
590:                        .getMaximumSpan(View.X_AXIS));
591:                assertEquals(0, (int) view.getMaximumSpan(View.Y_AXIS));
592:            }
593:
594:            public void testGetSpanOneRowNoChildrenFlexible() throws Exception {
595:                ChildrenFactory factory = new ChildrenFactory();
596:                factory.makeFlexible();
597:                view = new FlowViewImplWithFactory(root, View.Y_AXIS, factory);
598:                view.loadChildren(null);
599:                assertEquals(0, view.getViewCount());
600:                view.layoutPool.replace(1, view.layoutPool.getViewCount() - 1,
601:                        null);
602:                assertEquals(1, view.layoutPool.getViewCount());
603:                final View row = view.createRow();
604:                view.append(row);
605:                final View child = view.layoutPool.getView(0);
606:                int childPrefX = (int) child.getPreferredSpan(View.X_AXIS);
607:                int childPrefY = (int) child.getPreferredSpan(View.Y_AXIS);
608:                assertEquals(0, (int) view.layoutPool
609:                        .getMinimumSpan(View.X_AXIS));
610:                assertEquals(0, (int) view.layoutPool
611:                        .getMinimumSpan(View.Y_AXIS));
612:                assertEquals(childPrefX, (int) view.layoutPool
613:                        .getPreferredSpan(View.X_AXIS));
614:                assertEquals(childPrefY, (int) view.layoutPool
615:                        .getPreferredSpan(View.Y_AXIS));
616:                assertEquals(childPrefX, (int) view.layoutPool
617:                        .getMaximumSpan(View.X_AXIS));
618:                assertEquals(childPrefY, (int) view.layoutPool
619:                        .getMaximumSpan(View.Y_AXIS));
620:                assertEquals(0, (int) view.getMinimumSpan(View.X_AXIS));
621:                assertEquals(0, (int) view.getMinimumSpan(View.Y_AXIS));
622:                assertEquals(childPrefX, (int) view
623:                        .getPreferredSpan(View.X_AXIS));
624:                assertEquals(0, (int) view.getPreferredSpan(View.Y_AXIS));
625:                assertEquals(Integer.MAX_VALUE, (int) view
626:                        .getMaximumSpan(View.X_AXIS));
627:                assertEquals(Integer.MAX_VALUE, (int) view
628:                        .getMaximumSpan(View.Y_AXIS));
629:            }
630:
631:            public void testGetSpanOneRowOneChildFlexible() throws Exception {
632:                ChildrenFactory factory = new ChildrenFactory();
633:                factory.makeFlexible();
634:                view = new FlowViewImplWithFactory(root, View.Y_AXIS, factory);
635:                view.loadChildren(null);
636:                assertEquals(0, view.getViewCount());
637:                view.layoutPool.replace(1, view.layoutPool.getViewCount() - 1,
638:                        null);
639:                assertEquals(1, view.layoutPool.getViewCount());
640:                final View row = view.createRow();
641:                view.append(row);
642:                final View child = view.layoutPool.getView(0);
643:                row.append(child);
644:                int childMinY = (int) child.getMinimumSpan(View.Y_AXIS);
645:                int childPrefX = (int) child.getPreferredSpan(View.X_AXIS);
646:                int childPrefY = (int) child.getPreferredSpan(View.Y_AXIS);
647:                assertEquals(0, (int) view.layoutPool
648:                        .getMinimumSpan(View.X_AXIS));
649:                assertEquals(0, (int) view.layoutPool
650:                        .getMinimumSpan(View.Y_AXIS));
651:                assertEquals(childPrefX, (int) view.layoutPool
652:                        .getPreferredSpan(View.X_AXIS));
653:                assertEquals(childPrefY, (int) view.layoutPool
654:                        .getPreferredSpan(View.Y_AXIS));
655:                assertEquals(childPrefX, (int) view.layoutPool
656:                        .getMaximumSpan(View.X_AXIS));
657:                assertEquals(childPrefY, (int) view.layoutPool
658:                        .getMaximumSpan(View.Y_AXIS));
659:                assertEquals(0, (int) view.getMinimumSpan(View.X_AXIS));
660:                assertEquals(childMinY, (int) view.getMinimumSpan(View.Y_AXIS));
661:                assertEquals(childPrefX, (int) view
662:                        .getPreferredSpan(View.X_AXIS));
663:                assertEquals(childPrefY, (int) view
664:                        .getPreferredSpan(View.Y_AXIS));
665:                assertEquals(Integer.MAX_VALUE, (int) view
666:                        .getMaximumSpan(View.X_AXIS));
667:                assertEquals(Integer.MAX_VALUE, (int) view
668:                        .getMaximumSpan(View.Y_AXIS));
669:            }
670:
671:            public void testGetAttributesLayoutPool() {
672:                view = new FlowViewImplWithFactory(root, View.Y_AXIS);
673:                view.loadChildren(null);
674:                assertSame(view.getAttributes(), view.layoutPool
675:                        .getAttributes());
676:                view.layoutPool.setParent(null);
677:                assertNull(view.layoutPool.getAttributes());
678:            }
679:
680:            private int getSpanY() {
681:                int span = 0;
682:                View row = view.getView(0);
683:                for (int i = 0; i < row.getViewCount(); i++) {
684:                    span = Math.max(span, (int) row.getView(i)
685:                            .getPreferredSpan(View.Y_AXIS));
686:                }
687:                return span;
688:            }
689:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.