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 javax.swing.JFrame;
024: import javax.swing.JTextArea;
025: import javax.swing.SwingConstants;
026: import javax.swing.SwingTestCase;
027: import javax.swing.text.Position.Bias;
028:
029: /**
030: * A bunch of tests for getNextVisualPositionFrom method in bidirectional
031: * context. Our implementation differs from the 1.5.
032: *
033: */
034: public class PlainViewI18N_VisualPositionTest extends SwingTestCase {
035: private Document doc;
036:
037: private View view;
038:
039: private Rectangle shape;
040:
041: private JFrame frame;
042:
043: private JTextArea area;
044:
045: private Bias[] bias;
046:
047: private int length;
048:
049: private static final Bias FW = Bias.Forward;
050:
051: private static final Bias BW = Bias.Backward;
052:
053: private int[] nextPositionEF = { 1, 2, 3, 4, 5, 7, 7, 8, 9, 10, 11,
054: 14, 14, 12, 15, 18, 15, 16, 19, 20, 21, 22, 22 };
055:
056: // 0 1 2 3 4 5 6 7 8 9
057: private int[] nextPositionEB = { -1, 2, 1, 4, 3, 6, 7, 6, 9, 10,
058: 11, 10, 14, 12, 13, 18, 15, 16, 17, 20, 21, 22, 22 };
059:
060: private int[] nextPositionWF = { 0, 2, 1, 4, 3, 4, 7, 6, 7, 8, 11,
061: 10, 13, 14, 12, 16, 17, 18, 15, 18, 19, 20, 21 };
062:
063: // 0 1 2 3 4 5 6 7 8 9
064: private int[] nextPositionWB = { 0, 0, 1, 2, 3, 4, 5, 5, 7, 8, 9,
065: 10, 11, 14, 11, 14, 17, 18, 15, 18, 19, 20, 21 };
066:
067: private Bias[] nextBiasEF = { BW, FW, BW, FW, FW, BW, FW, FW, FW,
068: BW, FW, BW, FW, FW, BW, FW, FW, FW, FW, FW, FW, FW, FW };
069:
070: // 0 1 2 3 4 5 6 7 8 9
071: private Bias[] nextBiasEB = { FW, BW, FW, BW, FW, FW, BW, FW, FW,
072: FW, BW, FW, BW, FW, FW, BW, FW, FW, FW, FW, FW, FW, FW };
073:
074: private Bias[] nextBiasWF = { FW, BW, FW, BW, FW, FW, BW, FW, FW,
075: FW, BW, FW, FW, BW, FW, FW, FW, BW, FW, FW, FW, FW, FW };
076:
077: // 0 1 2 3 4 5 6 7 8 9
078: private Bias[] nextBiasWB = { FW, FW, BW, FW, BW, FW, FW, FW, FW,
079: FW, FW, BW, FW, FW, FW, FW, FW, FW, BW, FW, FW, FW, FW };
080:
081: @Override
082: protected void setUp() throws Exception {
083: super .setUp();
084: frame = new JFrame("PlainViewI18N Visual Position Test");
085: area = new JTextArea("a\u05DCb\u05DDc\n" +
086: // 01 23 45
087: "\u05DE123\u05DF\n" +
088: // 6 7890 1
089: "\u05DC\u05DD\t\u05DE\u05DF\u05E0abcd");
090: // 2 3 4 5 6 7 8901
091: frame.getContentPane().add(area);
092: frame.setSize(150, 100);
093: frame.pack();
094: doc = area.getDocument();
095: length = doc.getLength();
096: view = area.getUI().getRootView(area).getView(0);
097: shape = area.getVisibleRect();
098: bias = new Bias[1];
099: }
100:
101: @Override
102: protected void tearDown() throws Exception {
103: frame.dispose();
104: super .tearDown();
105: }
106:
107: public void testGetNextVisualPositionEastForward()
108: throws BadLocationException {
109: if (!isHarmony()) {
110: return;
111: }
112: for (int i = 0; i <= length; i++) {
113: int next = view.getNextVisualPositionFrom(i, FW, shape,
114: SwingConstants.EAST, bias);
115: assertEquals("@ " + i, nextPositionEF[i], next);
116: assertSame("@ " + i, nextBiasEF[i], bias[0]);
117: bias[0] = null;
118: }
119: }
120:
121: public void testGetNextVisualPositionEastBackward()
122: throws BadLocationException {
123: if (!isHarmony()) {
124: return;
125: }
126: for (int i = 0; i <= length; i++) {
127: int next = view.getNextVisualPositionFrom(i, BW, shape,
128: SwingConstants.EAST, bias);
129: assertEquals("@ " + i, nextPositionEB[i], next);
130: assertSame("@ " + i, nextBiasEB[i], bias[0]);
131: bias[0] = null;
132: }
133: }
134:
135: public void testGetNextVisualPositionWestForward()
136: throws BadLocationException {
137: if (!isHarmony()) {
138: return;
139: }
140: for (int i = 0; i <= length; i++) {
141: int next = view.getNextVisualPositionFrom(i, FW, shape,
142: SwingConstants.WEST, bias);
143: assertEquals("@ " + i, nextPositionWF[i], next);
144: assertSame("@ " + i, nextBiasWF[i], bias[0]);
145: bias[0] = null;
146: }
147: }
148:
149: public void testGetNextVisualPositionWestBackward()
150: throws BadLocationException {
151: if (!isHarmony()) {
152: return;
153: }
154: for (int i = 0; i <= length; i++) {
155: int next = view.getNextVisualPositionFrom(i, BW, shape,
156: SwingConstants.WEST, bias);
157: assertEquals("@ " + i, nextPositionWB[i], next);
158: assertSame("@ " + i, nextBiasWB[i], bias[0]);
159: bias[0] = null;
160: }
161: }
162: }
|