01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: /**
18: * @author Alexey A. Ivanov
19: * @version $Revision$
20: */package javax.swing.text;
21:
22: import java.awt.Rectangle;
23: import javax.swing.text.CompositeView_ModelViewTest.WithChildrenView;
24: import junit.framework.TestCase;
25:
26: public class View_GetViewIndexTest extends TestCase {
27: private PlainDocument doc; // Document used in tests
28:
29: private ViewFactory factory; // View factory used to create new views
30:
31: private Element root; // Default root element of the document
32:
33: private Rectangle shape; // View allocation (area to render into)
34:
35: private CompositeView view; // View object used in tests
36:
37: private static final int LINE_HEIGHT = CompositeView_ModelViewTest.LINE_HEIGHT;
38:
39: /**
40: * Tests int View.getViewIndex(float, float, Shape)
41: */
42: public void testGetViewIndexFloatFloatShape() {
43: assertEquals(-1, view.getViewIndex(0, 0, shape));
44: assertEquals(0, view.getViewIndex(shape.x, shape.y, shape));
45: assertEquals(0, view.getViewIndex(shape.x + shape.width - 1,
46: shape.y + LINE_HEIGHT - 1, shape));
47: assertEquals(-1, view.getViewIndex(shape.x + shape.width,
48: shape.y + LINE_HEIGHT, shape));
49: assertEquals(-1, view.getViewIndex(shape.x - 1, shape.y
50: + LINE_HEIGHT, shape));
51: assertEquals(1, view.getViewIndex(shape.x, shape.y
52: + LINE_HEIGHT, shape));
53: assertEquals(1, view.getViewIndex(shape.x + shape.width - 1,
54: shape.y + LINE_HEIGHT, shape));
55: assertEquals(2, view.getViewIndex(shape.x, shape.y + 2
56: * LINE_HEIGHT, shape));
57: assertEquals(2, view.getViewIndex(shape.x + shape.width - 1,
58: shape.y + 2 * LINE_HEIGHT, shape));
59: }
60:
61: @Override
62: protected void setUp() throws Exception {
63: super .setUp();
64: doc = new PlainDocument();
65: doc.insertString(0, "1\n2\n3", null);
66: // 0123456789 012345678901
67: // 0 1 2
68: root = doc.getDefaultRootElement();
69: view = new WithChildrenView(root);
70: factory = new ViewTestHelpers.ChildrenFactory();
71: view.loadChildren(factory);
72: shape = new Rectangle(100, 200, 190, 560);
73: CompositeView_ModelViewTest.shape = shape;
74: }
75: }
|