jdk/src/share/classes/javax/swing/text/Caret.java
author darcy
Thu, 27 Aug 2009 11:48:35 -0700
changeset 3709 e7cf22d025bb
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6876628: @throw instead of @throws in two ParagraphView classes Reviewed-by: peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.Action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.event.ChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A place within a document view that represents where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * things can be inserted into the document model.  A caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * has a position in the document referred to as a dot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The dot is where the caret is currently located in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * model.  There is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * a second position maintained by the caret that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the other end of a selection called mark.  If there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * no selection the dot and mark will be equal.  If a selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * exists, the two values will be different.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * The dot can be placed by either calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <code>setDot</code> or <code>moveDot</code>.  Setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * the dot has the effect of removing any selection that may
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * have previously existed.  The dot and mark will be equal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Moving the dot has the effect of creating a selection as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * the mark is left at whatever position it previously had.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
public interface Caret {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Called when the UI is being installed into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * interface of a JTextComponent.  This can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * to gain access to the model that is being navigated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * by the implementation of this interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param c the JTextComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public void install(JTextComponent c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Called when the UI is being removed from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * interface of a JTextComponent.  This is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * unregister any listeners that were attached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param c the JTextComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    public void deinstall(JTextComponent c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Renders the caret. This method is called by UI classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param g the graphics context
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public void paint(Graphics g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Adds a listener to track whenever the caret position
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * has been changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @param l the change listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public void addChangeListener(ChangeListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Removes a listener that was tracking caret position changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param l the change listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public void removeChangeListener(ChangeListener l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * Determines if the caret is currently visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @return true if the caret is visible else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public boolean isVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Sets the visibility of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param v  true if the caret should be shown,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *  and false if the caret should be hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public void setVisible(boolean v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * Determines if the selection is currently visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * @return true if the caret is visible else false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public boolean isSelectionVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Sets the visibility of the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * @param v  true if the caret should be shown,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *  and false if the caret should be hidden
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public void setSelectionVisible(boolean v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Set the current caret visual location.  This can be used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * moving between lines that have uneven end positions (such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * when caret up or down actions occur).  If text flows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * left-to-right or right-to-left the x-coordinate will indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * the desired navigation location for vertical movement.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * the text flow is top-to-bottom, the y-coordinate will indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * the desired navigation location for horizontal movement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param p  the Point to use for the saved position.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *   can be null to indicate there is no visual location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public void setMagicCaretPosition(Point p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Gets the current caret visual location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @return the visual position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @see #setMagicCaretPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public Point getMagicCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Sets the blink rate of the caret.  This determines if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * and how fast the caret blinks, commonly used as one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * way to attract attention to the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param rate  the delay in milliseconds >= 0.  If this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *  zero the caret will not blink.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public void setBlinkRate(int rate);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * Gets the blink rate of the caret.  This determines if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * and how fast the caret blinks, commonly used as one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * way to attract attention to the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return the delay in milliseconds >= 0.  If this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *  zero the caret will not blink.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public int getBlinkRate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * Fetches the current position of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @return the position >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    public int getDot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Fetches the current position of the mark.  If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * is a selection, the mark will not be the same as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * the dot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @return the position >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    public int getMark();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * Sets the caret position to some position.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * causes the mark to become the same as the dot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * effectively setting the selection range to zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * If the parameter is negative or beyond the length of the document,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * the caret is placed at the beginning or at the end, respectively.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param dot  the new position to set the caret to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    public void setDot(int dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Moves the caret position (dot) to some other position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * leaving behind the mark.  This is useful for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * making selections.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param dot  the new position to move the caret to >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    public void moveDot(int dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
};