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: package javax.swing.text;
18:
19: import static junit.framework.Assert.assertEquals;
20: import static junit.framework.Assert.assertSame;
21:
22: import java.awt.Shape;
23:
24: import javax.swing.text.Position.Bias;
25:
26: /**
27: * Utility class to support testing of
28: * <code>View.getNextVisualPositionFrom</code> method.
29: */
30: public final class VisualPositionHelper {
31: private static final Bias[] biasRet = new Bias[1];
32: private static final Bias[] biases = new Bias[] { Bias.Forward,
33: Bias.Backward };
34:
35: private VisualPositionHelper() {
36: }
37:
38: public static void assertNextPosition(final int expectedPosition,
39: final int offset, final int direction, final View view,
40: final Shape allocation) throws BadLocationException {
41:
42: for (Bias bias : biases) {
43: biasRet[0] = null;
44: assertEquals(bias + " from " + offset, expectedPosition,
45: view.getNextVisualPositionFrom(offset, bias,
46: allocation, direction, biasRet));
47: assertSame(Bias.Forward, biasRet[0]);
48: }
49: }
50:
51: public static void assertNextBiasedPosition(
52: final int expectedPosition, final int offset,
53: final int direction, final View view,
54: final Shape allocation, final Bias bias)
55: throws BadLocationException {
56:
57: biasRet[0] = null;
58: assertEquals(bias + " from " + offset, expectedPosition, view
59: .getNextVisualPositionFrom(offset, bias, allocation,
60: direction, biasRet));
61: assertSame(Bias.Forward, biasRet[0]);
62: }
63:
64: public static void assertNextForwardPosition(
65: final int expectedPosition, final int offset,
66: final int direction, final View view, final Shape allocation)
67: throws BadLocationException {
68:
69: assertNextBiasedPosition(expectedPosition, offset, direction,
70: view, allocation, Bias.Forward);
71: }
72:
73: public static void assertNextBackwardPosition(
74: final int expectedPosition, final int offset,
75: final int direction, final View view, final Shape allocation)
76: throws BadLocationException {
77:
78: assertNextBiasedPosition(expectedPosition, offset, direction,
79: view, allocation, Bias.Backward);
80: }
81: }
|