Source Code Cross Referenced for CompositeView_VisualPositionTest.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:        package javax.swing.text;
018:
019:        import java.awt.Shape;
020:        import java.util.ArrayList;
021:        import java.util.List;
022:
023:        import javax.swing.text.Position.Bias;
024:
025:        import junit.framework.TestCase;
026:
027:        /**
028:         * Tests how <code>CompositeView</code> traverses view hierarchy to calculate
029:         * next visual position.
030:         *
031:         * <p>The behaviour is tested using <code>BoxView</code>
032:         * (instead of <code>CompositeView</code>),
033:         * and <code>GlyphView</code> instances are used as child views.
034:         *
035:         * <p>Only <code>View.EAST</code> (right) and <code>View.WEST</code> (left)
036:         * directions are tested here.
037:         */
038:        public class CompositeView_VisualPositionTest extends TestCase {
039:            private static class FlipCallResult {
040:                private final View view;
041:                private final int offset;
042:                private final Bias bias;
043:                private final boolean result;
044:
045:                FlipCallResult(final View view, final int offset,
046:                        final Bias bias, final boolean result) {
047:                    this .view = view;
048:                    this .offset = offset;
049:                    this .bias = bias;
050:                    this .result = result;
051:                }
052:
053:                void assertValues(final View view, final int offset,
054:                        final Bias bias, final boolean result) {
055:                    assertSame("Flip.view", view, this .view);
056:                    assertEquals("Flip.offset", offset, this .offset);
057:                    assertSame("Flip.bias", bias, this .bias);
058:                    assertEquals("Flip.result", result, this .result);
059:                }
060:            }
061:
062:            private static class VisPosCallResult {
063:                private final View view;
064:                private final int offset;
065:                private final Bias bias;
066:                private final int result;
067:                private final Bias resultBias;
068:
069:                VisPosCallResult(final View view, final int offset,
070:                        final Bias bias, final int result, final Bias resultBias) {
071:                    this .view = view;
072:                    this .offset = offset;
073:                    this .bias = bias;
074:                    this .result = result;
075:                    this .resultBias = resultBias;
076:                }
077:
078:                void assertValues(final View view, final int offset,
079:                        final Bias bias, final int result, final Bias resultBias) {
080:                    assertSame("VisPos.view", view, this .view);
081:                    assertEquals("VisPos.offset", offset, this .offset);
082:                    assertSame("VisPos.bias", bias, this .bias);
083:                    assertEquals("VisPos.result", result, this .result);
084:                    assertSame("VisPos.resultBias", resultBias, this .resultBias);
085:                }
086:            }
087:
088:            private static final Bias Forward = Bias.Forward;
089:            private static final Bias Backward = Bias.Backward;
090:
091:            private Document doc;
092:            private View view;
093:            private Element root;
094:            private int length;
095:            private Bias[] biasRet;
096:            private ViewFactory factory;
097:
098:            private List<VisPosCallResult> visPosCalled;
099:            private List<FlipCallResult> flipCalled;
100:
101:            private boolean boxViewFlip;
102:
103:            @Override
104:            protected void setUp() throws Exception {
105:                super .setUp();
106:                doc = new PlainDocument();
107:                doc.insertString(0, "line 1\nthe second line is rather long\n"
108:                        + "the third line", null);
109:                root = doc.getDefaultRootElement();
110:                length = doc.getLength();
111:
112:                factory = new ViewFactory() {
113:                    public View create(Element element) {
114:                        return new GlyphView(element) {
115:                            {
116:                                checkPainter();
117:                            }
118:
119:                            @Override
120:                            public int viewToModel(float fx, float fy, Shape a,
121:                                    Bias[] bias) {
122:                                fail(toString() + ".viewToModel is called");
123:                                return super .viewToModel(fx, fy, a, bias);
124:                            }
125:
126:                            @Override
127:                            public Shape modelToView(int pos, Shape a, Bias b)
128:                                    throws BadLocationException {
129:
130:                                fail(toString() + ".modelToView is called");
131:                                return super .modelToView(pos, a, b);
132:                            }
133:
134:                            @Override
135:                            public boolean isVisible() {
136:                                fail(toString() + ".isVisible() is called");
137:                                return super .isVisible();
138:                            }
139:
140:                            @Override
141:                            public int getNextVisualPositionFrom(int pos,
142:                                    Bias b, Shape a, int direction,
143:                                    Bias[] biasRet) throws BadLocationException {
144:                                final int result = super 
145:                                        .getNextVisualPositionFrom(pos, b, a,
146:                                                direction, biasRet);
147:                                visPosCalled.add(new VisPosCallResult(this ,
148:                                        pos, b, result, biasRet[0]));
149:                                return result;
150:                            }
151:
152:                            @Override
153:                            public String toString() {
154:                                return "GV[" + getStartOffset() + ", "
155:                                        + getEndOffset() + "]";
156:                            }
157:                        };
158:                    }
159:                };
160:                view = new BoxView(root, View.Y_AXIS) {
161:                    {
162:                        loadChildren(factory);
163:                    }
164:
165:                    @Override
166:                    public int viewToModel(float fx, float fy, Shape a,
167:                            Bias[] bias) {
168:                        fail("BV.viewToModel is called");
169:                        return super .viewToModel(fx, fy, a, bias);
170:                    }
171:
172:                    @Override
173:                    public Shape modelToView(int pos, Shape a, Bias b)
174:                            throws BadLocationException {
175:
176:                        fail("BV.modelToView is called");
177:                        return super .modelToView(pos, a, b);
178:                    }
179:
180:                    @Override
181:                    protected boolean flipEastAndWestAtEnds(int position,
182:                            Bias bias) {
183:                        final boolean result = position == 2 || position == 6
184:                                || position == 38 ? boxViewFlip : super 
185:                                .flipEastAndWestAtEnds(position, bias);
186:                        flipCalled.add(new FlipCallResult(this , position, bias,
187:                                result));
188:                        return result;
189:                    }
190:                };
191:                assertEquals(root.getElementCount(), view.getViewCount());
192:
193:                biasRet = new Bias[1];
194:
195:                visPosCalled = new ArrayList<VisPosCallResult>();
196:                flipCalled = new ArrayList<FlipCallResult>();
197:            }
198:
199:            public void testGetNextVisualPositionFrom_Right_01Edge_NonFlipped()
200:                    throws BadLocationException {
201:
202:                boxViewFlip = false;
203:
204:                // Forward
205:                assertNextPosition(7, Forward, 6, Forward, View.EAST);
206:                assertEquals(2, visPosCalled.size());
207:                visPosCalled.get(0).assertValues(view.getView(0), 6, Forward,
208:                        -1, null);
209:                visPosCalled.get(1).assertValues(view.getView(1), -1, Forward,
210:                        7, Forward);
211:
212:                assertEquals(1, flipCalled.size());
213:                flipCalled.get(0).assertValues(view, 6, Forward, false);
214:
215:                visPosCalled.clear();
216:                flipCalled.clear();
217:
218:                // Backward
219:                assertNextPosition(7, Forward, 6, Backward, View.EAST);
220:                assertEquals(2, visPosCalled.size());
221:                visPosCalled.get(0).assertValues(view.getView(0), 6, Backward,
222:                        -1, null);
223:                visPosCalled.get(1).assertValues(view.getView(1), -1, Backward,
224:                        7, Forward);
225:
226:                assertEquals(1, flipCalled.size());
227:                flipCalled.get(0).assertValues(view, 6, Backward, false);
228:
229:                visPosCalled.clear();
230:                flipCalled.clear();
231:            }
232:
233:            public void testGetNextVisualPositionFrom_Right_01Edge_Flipped()
234:                    throws BadLocationException {
235:
236:                boxViewFlip = true;
237:
238:                // Forward
239:                assertNextPosition(-1, null, 6, Forward, View.EAST);
240:                assertEquals(1, visPosCalled.size());
241:                visPosCalled.get(0).assertValues(view.getView(0), 6, Forward,
242:                        -1, null);
243:
244:                assertEquals(1, flipCalled.size());
245:                flipCalled.get(0).assertValues(view, 6, Forward, true);
246:
247:                visPosCalled.clear();
248:                flipCalled.clear();
249:
250:                // Backward
251:                assertNextPosition(-1, null, 6, Backward, View.EAST);
252:                assertEquals(1, visPosCalled.size());
253:                visPosCalled.get(0).assertValues(view.getView(0), 6, Backward,
254:                        -1, null);
255:
256:                assertEquals(1, flipCalled.size());
257:                flipCalled.get(0).assertValues(view, 6, Backward, true);
258:
259:                visPosCalled.clear();
260:                flipCalled.clear();
261:            }
262:
263:            public void testGetNextVisualPositionFrom_Right_12Edge_NonFlipped()
264:                    throws BadLocationException {
265:
266:                boxViewFlip = false;
267:
268:                // Forward
269:                assertNextPosition(39, Forward, 38, Forward, View.EAST);
270:                assertEquals(1, visPosCalled.size());
271:                visPosCalled.get(0).assertValues(view.getView(2), 38, Forward,
272:                        39, Forward);
273:
274:                assertEquals(1, flipCalled.size());
275:                flipCalled.get(0).assertValues(view, 38, Forward, false);
276:
277:                visPosCalled.clear();
278:                flipCalled.clear();
279:
280:                // Backward
281:                assertNextPosition(39, Forward, 38, Backward, View.EAST);
282:                assertEquals(3, visPosCalled.size());
283:                visPosCalled.get(0).assertValues(view.getView(1), 38, Backward,
284:                        -1, null);
285:                visPosCalled.get(1).assertValues(view.getView(2), -1, Backward,
286:                        38, Forward);
287:                visPosCalled.get(2).assertValues(view.getView(2), 38, Forward,
288:                        39, Forward);
289:
290:                assertEquals(2, flipCalled.size());
291:                flipCalled.get(0).assertValues(view, 38, Backward, false);
292:                flipCalled.get(0).assertValues(view, 38, Backward, false);
293:
294:                visPosCalled.clear();
295:                flipCalled.clear();
296:            }
297:
298:            public void testGetNextVisualPositionFrom_Right_12Edge_Flipped()
299:                    throws BadLocationException {
300:
301:                boxViewFlip = true;
302:
303:                // Forward
304:                assertNextPosition(39, Forward, 38, Forward, View.EAST);
305:                assertEquals(1, visPosCalled.size());
306:                visPosCalled.get(0).assertValues(view.getView(2), 38, Forward,
307:                        39, Forward);
308:
309:                assertEquals(1, flipCalled.size());
310:                flipCalled.get(0).assertValues(view, 38, Forward, true);
311:
312:                visPosCalled.clear();
313:                flipCalled.clear();
314:
315:                // Backward
316:                assertNextPosition(0, Forward, 38, Backward, View.EAST);
317:                assertEquals(2, visPosCalled.size());
318:                visPosCalled.get(0).assertValues(view.getView(1), 38, Backward,
319:                        -1, null);
320:                visPosCalled.get(1).assertValues(view.getView(0), -1, Backward,
321:                        0, Forward);
322:
323:                assertEquals(1, flipCalled.size());
324:                flipCalled.get(0).assertValues(view, 38, Backward, true);
325:
326:                visPosCalled.clear();
327:                flipCalled.clear();
328:            }
329:
330:            public void testGetNextVisualPositionFrom_Right_0Middle_NonFlipped()
331:                    throws BadLocationException {
332:
333:                boxViewFlip = false;
334:
335:                // Forward
336:                assertNextPosition(3, Forward, 2, Forward, View.EAST);
337:                assertEquals(1, visPosCalled.size());
338:                visPosCalled.get(0).assertValues(view.getView(0), 2, Forward,
339:                        3, Forward);
340:
341:                assertEquals(1, flipCalled.size());
342:                flipCalled.get(0).assertValues(view, 2, Forward, false);
343:
344:                visPosCalled.clear();
345:                flipCalled.clear();
346:
347:                // Backward
348:                assertNextPosition(3, Forward, 2, Backward, View.EAST);
349:                assertEquals(1, visPosCalled.size());
350:                visPosCalled.get(0).assertValues(view.getView(0), 2, Backward,
351:                        3, Forward);
352:
353:                assertEquals(1, flipCalled.size());
354:                flipCalled.get(0).assertValues(view, 2, Backward, false);
355:
356:                visPosCalled.clear();
357:                flipCalled.clear();
358:            }
359:
360:            public void testGetNextVisualPositionFrom_Right_0Middle_Flipped()
361:                    throws BadLocationException {
362:
363:                boxViewFlip = true;
364:
365:                // Forward
366:                assertNextPosition(3, Forward, 2, Forward, View.EAST);
367:                assertEquals(1, visPosCalled.size());
368:                visPosCalled.get(0).assertValues(view.getView(0), 2, Forward,
369:                        3, Forward);
370:
371:                assertEquals(1, flipCalled.size());
372:                flipCalled.get(0).assertValues(view, 2, Forward, true);
373:
374:                visPosCalled.clear();
375:                flipCalled.clear();
376:
377:                // Backward
378:                assertNextPosition(3, Forward, 2, Backward, View.EAST);
379:                assertEquals(1, visPosCalled.size());
380:                visPosCalled.get(0).assertValues(view.getView(0), 2, Backward,
381:                        3, Forward);
382:
383:                assertEquals(1, flipCalled.size());
384:                flipCalled.get(0).assertValues(view, 2, Backward, true);
385:
386:                visPosCalled.clear();
387:                flipCalled.clear();
388:            }
389:
390:            public void testGetNextVisualPositionFrom_Right_AtBeginning0()
391:                    throws BadLocationException {
392:
393:                // Forward
394:                assertNextPosition(1, Forward, 0, Forward, View.EAST);
395:                assertEquals(1, visPosCalled.size());
396:                visPosCalled.get(0).assertValues(view.getView(0), 0, Forward,
397:                        1, Forward);
398:
399:                assertEquals(1, flipCalled.size());
400:                flipCalled.get(0).assertValues(view, 0, Forward, false);
401:
402:                visPosCalled.clear();
403:                flipCalled.clear();
404:
405:                // Backward
406:                assertNextPosition(1, Forward, 0, Backward, View.EAST);
407:                assertEquals(1, visPosCalled.size());
408:                visPosCalled.get(0).assertValues(view.getView(0), 0, Backward,
409:                        1, Forward);
410:
411:                assertEquals(1, flipCalled.size());
412:                flipCalled.get(0).assertValues(view, 0, Backward, false);
413:
414:                visPosCalled.clear();
415:                flipCalled.clear();
416:            }
417:
418:            public void testGetNextVisualPositionFrom_Right_AtBeginningMinus1()
419:                    throws BadLocationException {
420:
421:                assertEquals(-1, view.getViewIndex(-1, Forward));
422:
423:                // Forward
424:                assertNextPosition(0, Forward, -1, Forward, View.EAST);
425:                assertEquals(1, visPosCalled.size());
426:                visPosCalled.get(0).assertValues(view.getView(0), -1, Forward,
427:                        0, Forward);
428:
429:                assertEquals(0, flipCalled.size());
430:
431:                visPosCalled.clear();
432:                flipCalled.clear();
433:
434:                // Backward
435:                assertNextPosition(0, Forward, -1, Backward, View.EAST);
436:                assertEquals(1, visPosCalled.size());
437:                visPosCalled.get(0).assertValues(view.getView(0), -1, Backward,
438:                        0, Forward);
439:
440:                assertEquals(0, flipCalled.size());
441:
442:                visPosCalled.clear();
443:                flipCalled.clear();
444:            }
445:
446:            public void testGetNextVisualPositionFrom_Right_AtBeginningMinus2()
447:                    throws BadLocationException {
448:
449:                assertEquals(-1, view.getViewIndex(-2, Forward));
450:                try {
451:                    assertNextPosition(length, Forward, -2, Forward, View.EAST);
452:                    fail("ArrayIndexOutOfBoundsException is expected");
453:                } catch (ArrayIndexOutOfBoundsException e) {
454:                    // expected
455:                }
456:            }
457:
458:            public void testGetNextVisualPositionFrom_Right_AtEndLength()
459:                    throws BadLocationException {
460:
461:                assertEquals(2, view.getViewIndex(length, Forward));
462:
463:                // Forward
464:                assertNextPosition(-1, null, length, Forward, View.EAST);
465:                assertEquals(1, visPosCalled.size());
466:                visPosCalled.get(0).assertValues(view.getView(2), length,
467:                        Forward, -1, null);
468:
469:                assertEquals(1, flipCalled.size());
470:                flipCalled.get(0).assertValues(view, length, Forward, false);
471:
472:                visPosCalled.clear();
473:                flipCalled.clear();
474:
475:                // Backward
476:                assertNextPosition(-1, null, length, Backward, View.EAST);
477:                assertEquals(1, visPosCalled.size());
478:                visPosCalled.get(0).assertValues(view.getView(2), length,
479:                        Backward, -1, null);
480:
481:                assertEquals(1, flipCalled.size());
482:                flipCalled.get(0).assertValues(view, length, Backward, false);
483:
484:                visPosCalled.clear();
485:                flipCalled.clear();
486:            }
487:
488:            public void testGetNextVisualPositionFrom_Right_AtEndLength1()
489:                    throws BadLocationException {
490:
491:                assertEquals(-1, view.getViewIndex(length + 1, Forward));
492:                try {
493:                    assertNextPosition(length, Forward, length + 1, Forward,
494:                            View.EAST);
495:                    fail("ArrayIndexOutOfBoundsException is expected");
496:                } catch (ArrayIndexOutOfBoundsException e) {
497:                    // expected
498:                }
499:            }
500:
501:            public void testGetNextVisualPositionFrom_Left_01Edge_NonFlipped()
502:                    throws BadLocationException {
503:
504:                boxViewFlip = false;
505:
506:                // Forward
507:                assertNextPosition(5, Forward, 6, Forward, View.WEST);
508:                assertEquals(1, visPosCalled.size());
509:                visPosCalled.get(0).assertValues(view.getView(0), 6, Forward,
510:                        5, Forward);
511:
512:                assertEquals(1, flipCalled.size());
513:                flipCalled.get(0).assertValues(view, 6, Forward, false);
514:
515:                visPosCalled.clear();
516:                flipCalled.clear();
517:
518:                // Backward
519:                assertNextPosition(5, Forward, 6, Backward, View.WEST);
520:                assertEquals(1, visPosCalled.size());
521:                visPosCalled.get(0).assertValues(view.getView(0), 6, Backward,
522:                        5, Forward);
523:
524:                assertEquals(1, flipCalled.size());
525:                flipCalled.get(0).assertValues(view, 6, Backward, false);
526:
527:                visPosCalled.clear();
528:                flipCalled.clear();
529:            }
530:
531:            public void testGetNextVisualPositionFrom_Left_01Edge_Flipped()
532:                    throws BadLocationException {
533:
534:                boxViewFlip = true;
535:
536:                // Forward
537:                assertNextPosition(5, Forward, 6, Forward, View.WEST);
538:                assertEquals(1, visPosCalled.size());
539:                visPosCalled.get(0).assertValues(view.getView(0), 6, Forward,
540:                        5, Forward);
541:
542:                assertEquals(1, flipCalled.size());
543:                flipCalled.get(0).assertValues(view, 6, Forward, true);
544:
545:                visPosCalled.clear();
546:                flipCalled.clear();
547:
548:                // Backward
549:                assertNextPosition(5, Forward, 6, Backward, View.WEST);
550:                assertEquals(1, visPosCalled.size());
551:                visPosCalled.get(0).assertValues(view.getView(0), 6, Backward,
552:                        5, Forward);
553:
554:                assertEquals(1, flipCalled.size());
555:                flipCalled.get(0).assertValues(view, 6, Backward, true);
556:
557:                visPosCalled.clear();
558:                flipCalled.clear();
559:            }
560:
561:            public void testGetNextVisualPositionFrom_Left_12Edge_NonFlipped()
562:                    throws BadLocationException {
563:
564:                boxViewFlip = false;
565:
566:                // Forward
567:                assertNextPosition(37, Forward, 38, Forward, View.WEST);
568:                assertEquals(2, visPosCalled.size());
569:                visPosCalled.get(0).assertValues(view.getView(2), 38, Forward,
570:                        -1, null);
571:                visPosCalled.get(1).assertValues(view.getView(1), -1, Forward,
572:                        37, Forward);
573:
574:                assertEquals(1, flipCalled.size());
575:                flipCalled.get(0).assertValues(view, 38, Forward, false);
576:
577:                visPosCalled.clear();
578:                flipCalled.clear();
579:
580:                // Backward
581:                assertNextPosition(37, Forward, 38, Backward, View.WEST);
582:                assertEquals(1, visPosCalled.size());
583:                visPosCalled.get(0).assertValues(view.getView(1), 38, Backward,
584:                        37, Forward);
585:
586:                assertEquals(1, flipCalled.size());
587:                flipCalled.get(0).assertValues(view, 38, Backward, false);
588:
589:                visPosCalled.clear();
590:                flipCalled.clear();
591:            }
592:
593:            public void testGetNextVisualPositionFrom_Left_12Edge_Flipped()
594:                    throws BadLocationException {
595:
596:                boxViewFlip = true;
597:
598:                // Forward
599:                assertNextPosition(-1, null, 38, Forward, View.WEST);
600:                assertEquals(1, visPosCalled.size());
601:                visPosCalled.get(0).assertValues(view.getView(2), 38, Forward,
602:                        -1, null);
603:
604:                assertEquals(1, flipCalled.size());
605:                flipCalled.get(0).assertValues(view, 38, Forward, true);
606:
607:                visPosCalled.clear();
608:                flipCalled.clear();
609:
610:                // Backward
611:                assertNextPosition(37, Forward, 38, Backward, View.WEST);
612:                assertEquals(1, visPosCalled.size());
613:                visPosCalled.get(0).assertValues(view.getView(1), 38, Backward,
614:                        37, Forward);
615:
616:                assertEquals(1, flipCalled.size());
617:                flipCalled.get(0).assertValues(view, 38, Backward, true);
618:
619:                visPosCalled.clear();
620:                flipCalled.clear();
621:            }
622:
623:            public void testGetNextVisualPositionFrom_Left_0Middle_NonFlipped()
624:                    throws BadLocationException {
625:
626:                boxViewFlip = false;
627:
628:                // Forward
629:                assertNextPosition(1, Forward, 2, Forward, View.WEST);
630:                assertEquals(1, visPosCalled.size());
631:                visPosCalled.get(0).assertValues(view.getView(0), 2, Forward,
632:                        1, Forward);
633:
634:                assertEquals(1, flipCalled.size());
635:                flipCalled.get(0).assertValues(view, 2, Forward, false);
636:
637:                visPosCalled.clear();
638:                flipCalled.clear();
639:
640:                // Backward
641:                assertNextPosition(1, Forward, 2, Backward, View.WEST);
642:                assertEquals(1, visPosCalled.size());
643:                visPosCalled.get(0).assertValues(view.getView(0), 2, Backward,
644:                        1, Forward);
645:
646:                assertEquals(1, flipCalled.size());
647:                flipCalled.get(0).assertValues(view, 2, Backward, false);
648:
649:                visPosCalled.clear();
650:                flipCalled.clear();
651:            }
652:
653:            public void testGetNextVisualPositionFrom_Left_0Middle_Flipped()
654:                    throws BadLocationException {
655:
656:                boxViewFlip = true;
657:
658:                // Forward
659:                assertNextPosition(1, Forward, 2, Forward, View.WEST);
660:                assertEquals(1, visPosCalled.size());
661:                visPosCalled.get(0).assertValues(view.getView(0), 2, Forward,
662:                        1, Forward);
663:
664:                assertEquals(1, flipCalled.size());
665:                flipCalled.get(0).assertValues(view, 2, Forward, true);
666:
667:                visPosCalled.clear();
668:                flipCalled.clear();
669:
670:                // Backward
671:                assertNextPosition(1, Forward, 2, Backward, View.WEST);
672:                assertEquals(1, visPosCalled.size());
673:                visPosCalled.get(0).assertValues(view.getView(0), 2, Backward,
674:                        1, Forward);
675:
676:                assertEquals(1, flipCalled.size());
677:                flipCalled.get(0).assertValues(view, 2, Backward, true);
678:
679:                visPosCalled.clear();
680:                flipCalled.clear();
681:            }
682:
683:            public void testGetNextVisualPositionFrom_Left_AtBeginning0()
684:                    throws BadLocationException {
685:
686:                // Forward
687:                assertNextPosition(-1, null, 0, Forward, View.WEST);
688:                assertEquals(1, visPosCalled.size());
689:                visPosCalled.get(0).assertValues(view.getView(0), 0, Forward,
690:                        -1, null);
691:
692:                assertEquals(1, flipCalled.size());
693:                flipCalled.get(0).assertValues(view, 0, Forward, false);
694:
695:                visPosCalled.clear();
696:                flipCalled.clear();
697:
698:                // Backward
699:                assertNextPosition(-1, null, 0, Backward, View.WEST);
700:                assertEquals(1, visPosCalled.size());
701:                visPosCalled.get(0).assertValues(view.getView(0), 0, Backward,
702:                        -1, null);
703:
704:                assertEquals(1, flipCalled.size());
705:                flipCalled.get(0).assertValues(view, 0, Backward, false);
706:
707:                visPosCalled.clear();
708:                flipCalled.clear();
709:            }
710:
711:            public void testGetNextVisualPositionFrom_Left_AtBeginningMinus1()
712:                    throws BadLocationException {
713:
714:                // Forward
715:                assertNextPosition(length, Forward, -1, Forward, View.WEST);
716:                assertEquals(1, visPosCalled.size());
717:                visPosCalled.get(0).assertValues(view.getView(2), -1, Forward,
718:                        length, Forward);
719:
720:                assertEquals(0, flipCalled.size());
721:
722:                visPosCalled.clear();
723:                flipCalled.clear();
724:
725:                // Backward
726:                assertNextPosition(length, Forward, -1, Backward, View.WEST);
727:                assertEquals(1, visPosCalled.size());
728:                visPosCalled.get(0).assertValues(view.getView(2), -1, Backward,
729:                        length, Forward);
730:
731:                assertEquals(0, flipCalled.size());
732:                //        flipCalled.get(0).assertValues(view, 0, Backward, false);
733:
734:                visPosCalled.clear();
735:                flipCalled.clear();
736:            }
737:
738:            public void testGetNextVisualPositionFrom_Left_AtBeginningMinus2()
739:                    throws BadLocationException {
740:
741:                try {
742:                    assertNextPosition(length, Forward, -2, Forward, View.WEST);
743:                    fail("ArrayIndexOutOfBoundsException is expected");
744:                } catch (ArrayIndexOutOfBoundsException e) {
745:                    // expected
746:                }
747:            }
748:
749:            public void testGetNextVisualPositionFrom_Left_AtEndLength()
750:                    throws BadLocationException {
751:
752:                // Forward
753:                assertNextPosition(length - 1, Forward, length, Forward,
754:                        View.WEST);
755:                assertEquals(1, visPosCalled.size());
756:                visPosCalled.get(0).assertValues(view.getView(2), length,
757:                        Forward, length - 1, Forward);
758:
759:                assertEquals(1, flipCalled.size());
760:                flipCalled.get(0).assertValues(view, length, Forward, false);
761:
762:                visPosCalled.clear();
763:                flipCalled.clear();
764:
765:                // Backward
766:                assertNextPosition(length - 1, Forward, length, Backward,
767:                        View.WEST);
768:                assertEquals(1, visPosCalled.size());
769:                visPosCalled.get(0).assertValues(view.getView(2), length,
770:                        Backward, length - 1, Forward);
771:
772:                assertEquals(1, flipCalled.size());
773:                flipCalled.get(0).assertValues(view, length, Backward, false);
774:
775:                visPosCalled.clear();
776:                flipCalled.clear();
777:            }
778:
779:            public void testGetNextVisualPositionFrom_Left_AtEndLength1()
780:                    throws BadLocationException {
781:
782:                try {
783:                    assertNextPosition(length, Forward, length + 1, Forward,
784:                            View.WEST);
785:                    fail("ArrayIndexOutOfBoundsException is expected");
786:                } catch (ArrayIndexOutOfBoundsException e) {
787:                    // expected
788:                }
789:            }
790:
791:            private void assertNextPosition(final int expectedPosition,
792:                    final Bias expectedBias, final int position,
793:                    final Bias bias, final int direction)
794:                    throws BadLocationException {
795:
796:                biasRet[0] = null;
797:                assertEquals(bias + " at " + position, expectedPosition, view
798:                        .getNextVisualPositionFrom(position, bias, null,
799:                                direction, biasRet));
800:                assertSame(expectedBias, biasRet[0]);
801:            }
802:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.