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 Evgeniya G. Maenkova
19: * @version $Revision$
20: */package javax.swing.text;
21:
22: import java.awt.Insets;
23: import java.awt.Rectangle;
24:
25: import javax.swing.plaf.basic.BasicTextUI;
26:
27: public class NavigationFilter {
28:
29: public abstract static class FilterBypass {
30:
31: public FilterBypass() {
32:
33: }
34:
35: public abstract Caret getCaret();
36:
37: public abstract void moveDot(int pos, Position.Bias bias);
38:
39: public abstract void setDot(int pos, Position.Bias bias);
40:
41: }
42:
43: public NavigationFilter() {
44:
45: }
46:
47: public int getNextVisualPositionFrom(final JTextComponent c,
48: final int pos, final Position.Bias bias,
49: final int direction, final Position.Bias[] biasRet)
50: throws BadLocationException {
51: if (c == null)
52: return 0;
53: BasicTextUI ui = (BasicTextUI) c.getUI();
54: View rootView = ui.getRootView(c);
55: Rectangle rect = c.getVisibleRect();
56: if (rect == null)
57: return 0;
58: Insets insets = c.getInsets();
59: rect.x += insets.left;
60: rect.y += insets.top;
61: rect.width -= insets.left + insets.right;
62: rect.height -= insets.top + insets.bottom;
63: return rootView.getNextVisualPositionFrom(pos, bias, rect,
64: direction, biasRet);
65: }
66:
67: public void moveDot(final NavigationFilter.FilterBypass filter,
68: final int pos, final Position.Bias bias) {
69: filter.moveDot(pos, bias);
70: }
71:
72: public void setDot(final NavigationFilter.FilterBypass filter,
73: final int pos, final Position.Bias bias) {
74: filter.setDot(pos, bias);
75: }
76:
77: }
|