01 /*
02 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
03 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04 *
05 * This code is free software; you can redistribute it and/or modify it
06 * under the terms of the GNU General Public License version 2 only, as
07 * published by the Free Software Foundation. Sun designates this
08 * particular file as subject to the "Classpath" exception as provided
09 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25 package javax.swing.text;
26
27 /**
28 * Represents a location within a document. It is intended to abstract away
29 * implementation details of the document and enable specification of
30 * positions within the document that are capable of tracking of change as
31 * the document is edited.
32 * <p>
33 * A {@code Position} object points at a location between two characters.
34 * As the surrounding content is altered, the {@code Position} object
35 * adjusts its offset automatically to reflect the changes. If content is
36 * inserted or removed before the {@code Position} object's location, then the
37 * {@code Position} increments or decrements its offset, respectively,
38 * so as to point to the same location. If a portion of the document is removed
39 * that contains a {@code Position}'s offset, then the {@code Position}'s
40 * offset becomes that of the beginning of the removed region. For example, if
41 * a {@code Position} has an offset of 5 and the region 2-10 is removed, then
42 * the {@code Position}'s offset becomes 2.
43 * <p>
44 * {@code Position} with an offset of 0 is a special case. It never changes its
45 * offset while document content is altered.
46 *
47 * @author Timothy Prinzing
48 * @version 1.26 05/05/07
49 */
50 public interface Position {
51
52 /**
53 * Fetches the current offset within the document.
54 *
55 * @return the offset >= 0
56 */
57 public int getOffset();
58
59 /**
60 * A typesafe enumeration to indicate bias to a position
61 * in the model. A position indicates a location between
62 * two characters. The bias can be used to indicate an
63 * interest toward one of the two sides of the position
64 * in boundary conditions where a simple offset is
65 * ambiguous.
66 */
67 public static final class Bias {
68
69 /**
70 * Indicates to bias toward the next character
71 * in the model.
72 */
73 public static final Bias Forward = new Bias("Forward");
74
75 /**
76 * Indicates a bias toward the previous character
77 * in the model.
78 */
79 public static final Bias Backward = new Bias("Backward");
80
81 /**
82 * string representation
83 */
84 public String toString() {
85 return name;
86 }
87
88 private Bias(String name) {
89 this .name = name;
90 }
91
92 private String name;
93 }
94 }
|