jdk/src/share/classes/javax/swing/text/Highlighter.java
author gsm
Mon, 07 Sep 2009 12:27:53 +0400
changeset 3750 4195b035138f
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6699856: Creating text in a JTextPane using Chinese text causes undesired behavior 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-1998 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.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * An interface for an object that allows one to mark up the background
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * with colored areas.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
public interface Highlighter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * Called when the UI is being installed into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * interface of a JTextComponent.  This can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     * to gain access to the model that is being navigated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * by the implementation of this interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * @param c the JTextComponent editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public void install(JTextComponent c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Called when the UI is being removed from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * interface of a JTextComponent.  This is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * unregister any listeners that were attached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @param c the JTextComponent editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    public void deinstall(JTextComponent c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * Renders the highlights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @param g the graphics context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public void paint(Graphics g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Adds a highlight to the view.  Returns a tag that can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * to refer to the highlight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param p0 the beginning of the range >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param p1 the end of the range >= p0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * @param p the painter to use for the actual highlighting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * @return an object that refers to the highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @exception BadLocationException for an invalid range specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    public Object addHighlight(int p0, int p1, HighlightPainter p) throws BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * Removes a highlight from the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param tag  which highlight to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public void removeHighlight(Object tag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Removes all highlights this highlighter is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void removeAllHighlights();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * Changes the given highlight to span a different portion of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * the document.  This may be more efficient than a remove/add
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * when a selection is expanding/shrinking (such as a sweep
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * with a mouse) by damaging only what changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param tag  which highlight to change
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @param p0 the beginning of the range >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param p1 the end of the range >= p0
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @exception BadLocationException for an invalid range specification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    public void changeHighlight(Object tag, int p0, int p1) throws BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Fetches the current list of highlights.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @return the highlight list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public Highlight[] getHighlights();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Highlight renderer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public interface HighlightPainter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         * Renders the highlight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         * @param g the graphics context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         * @param p0 the starting offset in the model >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         * @param p1 the ending offset in the model >= p0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         * @param bounds the bounding box for the highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         * @param c the editor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public interface Highlight {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         * Gets the starting model offset for the highlight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
         * @return the starting offset >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        public int getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         * Gets the ending model offset for the highlight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
         * @return the ending offset >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        public int getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * Gets the painter for the highlighter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * @return the painter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        public HighlightPainter getPainter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
};