jdk/src/java.desktop/share/classes/javax/swing/plaf/TextUI.java
author ddehaven
Tue, 19 Aug 2014 10:32:16 -0700
changeset 26037 508779ce6619
parent 26013 jdk/src/share/classes/javax/swing/plaf/TextUI.java@83b99f14245f
parent 25859 jdk/src/share/classes/javax/swing/plaf/TextUI.java@3317bb8137f4
child 39553 965a62655c4c
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.plaf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import javax.swing.Action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.BoundedRangeModel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Text editor user interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
public abstract class TextUI extends ComponentUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * Converts the given location in the model to a place in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * the view coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
    45
     * @param t the text component for which this UI is installed
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    46
     * @param pos  the local location in the model to translate >= 0
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
    47
     * @return the coordinates as a {@code Rectangle}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * @exception BadLocationException  if the given position does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *   represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public abstract Rectangle modelToView(JTextComponent t, int pos) throws BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Converts the given location in the model to a place in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * the view coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
    57
     * @param t the text component for which this UI is installed
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    58
     * @param pos  the local location in the model to translate >= 0
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
    59
     * @param bias the bias for the position
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
    60
     * @return the coordinates as a {@code Rectangle}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @exception BadLocationException  if the given position does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     *   represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public abstract Rectangle modelToView(JTextComponent t, int pos, Position.Bias bias) throws BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Converts the given place in the view coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * to the nearest representative location in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
    70
     * @param t the text component for which this UI is installed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param pt  the location in the view to translate.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *   should be in the same coordinate system as the mouse
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *   events.
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    74
     * @return the offset from the start of the document >= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public abstract int viewToModel(JTextComponent t, Point pt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * coordinate space of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
    82
     * @param t the text component for which this UI is installed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @param pt the location in the view to translate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *           This should be in the same coordinate system
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *           as the mouse events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * @param biasReturn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *           filled in by this method to indicate whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *           the point given is closer to the previous or the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *           character in the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @return the location within the model that best represents the
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    92
     *         given point in the view >= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    public abstract int viewToModel(JTextComponent t, Point pt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                                    Position.Bias[] biasReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Provides a way to determine the next visually represented model
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * location that one might place a caret.  Some views may not be visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * they might not be in the same order found in the model, or they just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * might not allow access to some of the locations in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param t the text component for which this UI is installed
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   104
     * @param pos the position to convert >= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @param b the bias for the position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param direction the direction from the current position that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *  be thought of as the arrow keys typically found on a keyboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *  This may be SwingConstants.WEST, SwingConstants.EAST,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *  SwingConstants.NORTH, or SwingConstants.SOUTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @param biasRet an array to contain the bias for the returned position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @return the location within the model that best represents the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *  location visual position
22260
c9185e010e03 8031082: Fix non-missing doclint problems in client libraries
darcy
parents: 20158
diff changeset
   113
     * @exception BadLocationException for a bad location within a document model
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @exception IllegalArgumentException for an invalid direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    public abstract int getNextVisualPositionFrom(JTextComponent t,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                         int pos, Position.Bias b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                         int direction, Position.Bias[] biasRet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                         throws BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Causes the portion of the view responsible for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * given part of the model to be repainted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   125
     * @param t the text component for which this UI is installed
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   126
     * @param p0 the beginning of the range >= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   127
     * @param p1 the end of the range >= p0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public abstract void damageRange(JTextComponent t, int p0, int p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * Causes the portion of the view responsible for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * given part of the model to be repainted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   135
     * @param t the text component for which this UI is installed
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   136
     * @param p0 the beginning of the range >= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   137
     * @param p1 the end of the range >= p0
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   138
     * @param firstBias the bias of the first character position, toward the
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   139
     *        previous character or the next character
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   140
     * @param secondBias the bias of the second character position, toward the
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   141
     *        previous character or the next character
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    public abstract void damageRange(JTextComponent t, int p0, int p1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                     Position.Bias firstBias,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                     Position.Bias secondBias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Fetches the binding of services that set a policy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * for the type of document being edited.  This contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * things like the commands available, stream readers and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * writers, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   153
     * @param t the text component for which this UI is installed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @return the editor kit binding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    public abstract EditorKit getEditorKit(JTextComponent t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Fetches a View with the allocation of the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * text component (i.e. the root of the hierarchy) that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * can be traversed to determine how the model is being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * represented spatially.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   164
     * @param t the text component for which this UI is installed
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   165
     * @return a {@code View} with the allocation of the associated
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   166
     *         text component
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    public abstract View getRootView(JTextComponent t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * Returns the string to be used as the tooltip at the passed in location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *
26013
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   173
     * @param t  the text component for which this UI is installed
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   174
     * @param pt a {@code Point} specifying location for which to get a tooltip
83b99f14245f 8042284: Add block tags for @return and @param to swing plaf classes
ssides
parents: 22260
diff changeset
   175
     * @return a {@code String} containing the tooltip
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @see javax.swing.text.JTextComponent#getToolTipText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public String getToolTipText(JTextComponent t, Point pt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
}