src/java.desktop/share/classes/javax/swing/text/PlainView.java
author psadhukhan
Tue, 14 Nov 2017 10:32:31 +0530
changeset 47835 dde53d789c3d
parent 47216 71c04702a3d5
permissions -rw-r--r--
8187957: Tab Size does not work correctly in JTextArea Reviewed-by: ssadetsky, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43075
diff changeset
     2
 * Copyright (c) 1997, 2017, 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.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    28
import java.awt.font.FontRenderContext;
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    29
import java.awt.geom.Rectangle2D;
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    30
import java.security.AccessController;
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    31
import java.security.PrivilegedAction;
39554
12687019f2b9 8142966: Wrong cursor position in text components on HiDPI display
alexsch
parents: 39553
diff changeset
    32
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.event.*;
43075
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
    34
import java.lang.ref.SoftReference;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
    35
import java.util.HashMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Implements View interface for a simple multi-line text view
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * that has text in one font and color.  The view represents each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * child element as a line of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @see     View
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class PlainView extends View implements TabExpander {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Constructs a new PlainView wrapped on an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * @param elem the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public PlainView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        super(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Returns the tab size set for the document, defaulting to 8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * @return the tab size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    protected int getTabSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        Integer i = (Integer) getDocument().getProperty(PlainDocument.tabSizeAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        int size = (i != null) ? i.intValue() : 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * Renders a line of text, suppressing whitespace at the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * and expanding any tabs.  This is implemented to make calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * to the methods <code>drawUnselectedText</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <code>drawSelectedText</code> so that the way selected and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * unselected text are rendered can be customized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    74
     * @param lineIndex the line to draw &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param g the <code>Graphics</code> context
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    76
     * @param x the starting X position &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    77
     * @param y the starting Y position &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @see #drawUnselectedText
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @see #drawSelectedText
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    80
     *
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    81
     * @deprecated replaced by
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    82
     *     {@link #drawLine(int, Graphics2D, float, float)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    84
    @Deprecated(since = "9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected void drawLine(int lineIndex, Graphics g, int x, int y) {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    86
        drawLineImpl(lineIndex, g, x, y);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    87
    }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    88
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
    89
    private void drawLineImpl(int lineIndex, Graphics g, float x, float y) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        Element line = getElement().getElement(lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        Element elem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if (line.isLeaf()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                drawElement(lineIndex, line, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                // this line contains the composed text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                int count = line.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                for(int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    elem = line.getElement(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    x = drawElement(lineIndex, elem, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            throw new StateInvariantError("Can't render line: " + lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
39553
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   109
    /**
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   110
     * Renders a line of text, suppressing whitespace at the end
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   111
     * and expanding any tabs.  This is implemented to make calls
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   112
     * to the methods {@code drawUnselectedText} and
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   113
     * {@code drawSelectedText} so that the way selected and
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   114
     * unselected text are rendered can be customized.
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   115
     *
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   116
     * @param lineIndex the line to draw {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   117
     * @param g the {@code Graphics} context
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   118
     * @param x the starting X position {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   119
     * @param y the starting Y position {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   120
     * @see #drawUnselectedText
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   121
     * @see #drawSelectedText
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   122
     *
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   123
     * @since 9
39553
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   124
     */
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   125
    protected void drawLine(int lineIndex, Graphics2D g, float x, float y) {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   126
        drawLineImpl(lineIndex, g, x, y);
39553
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   127
    }
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   128
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   129
    private float drawElement(int lineIndex, Element elem, Graphics g,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   130
                              float x, float y)
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   131
                              throws BadLocationException
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   132
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        int p0 = elem.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        int p1 = elem.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        p1 = Math.min(getDocument().getLength(), p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (lineIndex == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            x += firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        AttributeSet attr = elem.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (Utilities.isComposedTextAttributeDefined(attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            g.setColor(unselected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            x = Utilities.drawComposedText(this, attr, g, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                        p0-elem.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                        p1-elem.getStartOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            if (sel0 == sel1 || selected == unselected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                // no selection, or it is invisible
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   149
                x = callDrawUnselectedText(g, x, y, p0, p1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            } else if ((p0 >= sel0 && p0 <= sel1) && (p1 >= sel0 && p1 <= sel1)) {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   151
                x = callDrawSelectedText(g, x, y, p0, p1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            } else if (sel0 >= p0 && sel0 <= p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                if (sel1 >= p0 && sel1 <= p1) {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   154
                    x = callDrawUnselectedText(g, x, y, p0, sel0);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   155
                    x = callDrawSelectedText(g, x, y, sel0, sel1);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   156
                    x = callDrawUnselectedText(g, x, y, sel1, p1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                } else {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   158
                    x = callDrawUnselectedText(g, x, y, p0, sel0);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   159
                    x = callDrawSelectedText(g, x, y, sel0, p1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            } else if (sel1 >= p0 && sel1 <= p1) {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   162
                x = callDrawSelectedText(g, x, y, p0, sel1);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   163
                x = callDrawUnselectedText(g, x, y, sel1, p1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            } else {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   165
                x = callDrawUnselectedText(g, x, y, p0, p1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Renders the given range in the model as normal unselected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * text.  Uses the foreground or disabled color to render the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param g the graphics context
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   177
     * @param x the starting X coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   178
     * @param y the starting Y coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   179
     * @param p0 the beginning position in the model &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   180
     * @param p1 the ending position in the model &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   181
     * @return the X location of the end of the range &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception BadLocationException if the range is invalid
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   183
     *
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   184
     * @deprecated replaced by
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   185
     *     {@link #drawUnselectedText(Graphics2D, float, float, int, int)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     */
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   187
    @Deprecated(since = "9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    protected int drawUnselectedText(Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                     int p0, int p1) throws BadLocationException {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   190
        return (int) drawUnselectedTextImpl(g, x, y, p0, p1, false);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   191
    }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   192
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   193
    private float callDrawUnselectedText(Graphics g, float x, float y,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   194
                                         int p0, int p1)
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   195
                                         throws BadLocationException
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   196
    {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   197
        return drawUnselectedTextOverridden && (g instanceof Graphics2D)
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   198
                ? drawUnselectedText((Graphics2D) g, x, y, p0, p1)
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   199
                : drawUnselectedText(g, (int) x, (int) y, p0, p1);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   200
    }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   201
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   202
    private float drawUnselectedTextImpl(Graphics g, float x, float y,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   203
                                         int p0, int p1,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   204
                                         boolean useFPAPI)
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   205
            throws BadLocationException
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   206
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        g.setColor(unselected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        doc.getText(p0, p1 - p0, s);
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   211
        float ret = Utilities.drawTabbedText(this, s, x, y, g, this, p0, null,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   212
                                             useFPAPI);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
39553
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   218
     * Renders the given range in the model as normal unselected
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   219
     * text.  Uses the foreground or disabled color to render the text.
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   220
     *
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   221
     * @param g the graphics context
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   222
     * @param x the starting X coordinate {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   223
     * @param y the starting Y coordinate {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   224
     * @param p0 the beginning position in the model {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   225
     * @param p1 the ending position in the model {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   226
     * @return the X location of the end of the range {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   227
     * @exception BadLocationException if the range is invalid
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   228
     *
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   229
     * @since 9
39553
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   230
     */
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   231
    protected float drawUnselectedText(Graphics2D g, float x, float y,
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   232
                                       int p0, int p1) throws BadLocationException {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   233
        return drawUnselectedTextImpl(g, x, y, p0, p1, true);
39553
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   234
    }
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   235
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   236
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Renders the given range in the model as selected text.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * is implemented to render the text in the color specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * the hosting component.  It assumes the highlighter will render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * the selected background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param g the graphics context
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   243
     * @param x the starting X coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   244
     * @param y the starting Y coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   245
     * @param p0 the beginning position in the model &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   246
     * @param p1 the ending position in the model &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @return the location of the end of the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @exception BadLocationException if the range is invalid
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   249
     *
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   250
     * @deprecated replaced by
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   251
     *     {@link #drawSelectedText(Graphics2D, float, float, int, int)}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   253
    @Deprecated(since = "9")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    protected int drawSelectedText(Graphics g, int x,
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   255
                                   int y, int p0, int p1)
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   256
                                   throws BadLocationException
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   257
    {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   258
        return (int) drawSelectedTextImpl(g, x, y, p0, p1, false);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   259
    }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   260
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   261
    float callDrawSelectedText(Graphics g, float x, float y,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   262
                               int p0, int p1)
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   263
                               throws BadLocationException
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   264
    {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   265
        return drawSelectedTextOverridden && g instanceof Graphics2D
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   266
                ? drawSelectedText((Graphics2D) g, x, y, p0, p1)
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   267
                : drawSelectedText(g, (int) x, (int) y, p0, p1);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   268
    }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   269
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   270
    private float drawSelectedTextImpl(Graphics g, float x, float y,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   271
                                       int p0, int p1,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   272
                                       boolean useFPAPI)
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   273
            throws BadLocationException
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   274
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        g.setColor(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        doc.getText(p0, p1 - p0, s);
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   279
        float ret = Utilities.drawTabbedText(this, s, x, y, g, this, p0, null,
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   280
                                             useFPAPI);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    /**
39553
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   286
     * Renders the given range in the model as selected text.  This
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   287
     * is implemented to render the text in the color specified in
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   288
     * the hosting component.  It assumes the highlighter will render
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   289
     * the selected background.
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   290
     *
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   291
     * @param g the graphics context
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   292
     * @param x the starting X coordinate {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   293
     * @param y the starting Y coordinate {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   294
     * @param p0 the beginning position in the model {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   295
     * @param p1 the ending position in the model {@code >= 0}
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   296
     * @return the location of the end of the range
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   297
     * @exception BadLocationException if the range is invalid
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   298
     *
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   299
     * @since 9
39553
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   300
     */
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   301
    protected float drawSelectedText(Graphics2D g, float x,
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   302
                                     float y, int p0, int p1) throws BadLocationException {
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   303
        return drawSelectedTextImpl(g, x, y, p0, p1, true);
39553
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   304
    }
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   305
965a62655c4c 8132119: Provide public API for text related methods in SwingUtilities2
alexsch
parents: 30462
diff changeset
   306
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Gives access to a buffer that can be used to fetch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * text from the associated document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @return the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    protected final Segment getLineBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (lineBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            lineBuffer = new Segment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return lineBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Checks to see if the font metrics and longest line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * are up-to-date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    protected void updateMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        Component host = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        Font f = host.getFont();
39554
12687019f2b9 8142966: Wrong cursor position in text components on HiDPI display
alexsch
parents: 39553
diff changeset
   328
        FontMetrics fm = (font == null) ? null : host.getFontMetrics(font);
12687019f2b9 8142966: Wrong cursor position in text components on HiDPI display
alexsch
parents: 39553
diff changeset
   329
        if (font != f || !Objects.equals(metrics, fm)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // The font changed, we need to recalculate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // longest line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            calculateLongestLine();
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   333
            if (useFloatingPointAPI) {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   334
                FontRenderContext frc = metrics.getFontRenderContext();
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   335
                float tabWidth = (float) font.getStringBounds("m", frc).getWidth();
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   336
                tabSize = getTabSize() * tabWidth;
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   337
            } else {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   338
                tabSize = getTabSize() * metrics.charWidth('m');
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   339
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    // ---- View methods ----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Determines the preferred span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * @param axis may be either View.X_AXIS or View.Y_AXIS
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   350
     * @return   the span the view would like to be rendered into &gt;= 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *           Typically the view is told to render into the span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *           that is returned, although there is no guarantee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *           The parent may choose to resize or break the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @exception IllegalArgumentException for an invalid axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public float getPreferredSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        switch (axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        case View.X_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return getLineWidth(longLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        case View.Y_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            return getElement().getElementCount() * metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            throw new IllegalArgumentException("Invalid axis: " + axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Renders using the given rendering surface and area on that surface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * The view may need to do layout and create child views to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * itself to render into the given allocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param g the rendering surface to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @see View#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public void paint(Graphics g, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        Shape originalA = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        a = adjustPaintRegion(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        Rectangle alloc = (Rectangle) a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        tabBase = alloc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        JTextComponent host = (JTextComponent) getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        Highlighter h = host.getHighlighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        g.setFont(host.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        sel0 = host.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        sel1 = host.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        unselected = (host.isEnabled()) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            host.getForeground() : host.getDisabledTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        Caret c = host.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        selected = c.isSelectionVisible() && h != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                       host.getSelectedTextColor() : unselected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        // If the lines are clipped then we don't expend the effort to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        // try and paint them.  Since all of the lines are the same height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        // with this object, determination of what lines need to be repainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        // is quick.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        Rectangle clip = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        int heightBelow = (alloc.y + alloc.height) - (clip.y + clip.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        int heightAbove = clip.y - alloc.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        int linesBelow, linesAbove, linesTotal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        if (fontHeight > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            linesBelow = Math.max(0, heightBelow / fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            linesAbove = Math.max(0, heightAbove / fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            linesTotal = alloc.height / fontHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (alloc.height % fontHeight != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                linesTotal++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            linesBelow = linesAbove = linesTotal = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        // update the visible lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        Rectangle lineArea = lineToRect(a, linesAbove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        int y = lineArea.y + metrics.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        int x = lineArea.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        Element map = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        int lineCount = map.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        int endLine = Math.min(lineCount, linesTotal - linesBelow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        lineCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        LayeredHighlighter dh = (h instanceof LayeredHighlighter) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                           (LayeredHighlighter)h : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        for (int line = linesAbove; line < endLine; line++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            if (dh != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                Element lineElement = map.getElement(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                if (line == lineCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                    dh.paintLayeredHighlights(g, lineElement.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                                              lineElement.getEndOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                              originalA, host, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    dh.paintLayeredHighlights(g, lineElement.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                                              lineElement.getEndOffset() - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                              originalA, host, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            }
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   440
            if (drawLineOverridden && (g instanceof Graphics2D)) {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   441
                drawLine(line, (Graphics2D) g, (float) x, (float) y);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   442
            } else {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   443
                drawLine(line, g, x, y);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   444
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            y += fontHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            if (line == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                // This should never really happen, in so far as if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                // firstLineOffset is non 0, there should only be one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                // line of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                x -= firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Should return a shape ideal for painting based on the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Shape <code>a</code>. This is useful if painting in a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * region. The default implementation returns <code>a</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    Shape adjustPaintRegion(Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * Provides a mapping from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * to the coordinate space of the view mapped to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   468
     * @param pos the position to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @return the bounding box of the given position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @exception BadLocationException  if the given position does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     *   represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @see View#modelToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     */
42216
621af0ebf6c4 8169518: Suppress Deprecation warnings for deprecated Swing APIs
prr
parents: 41807
diff changeset
   475
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        // line coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        Element map = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        int lineIndex = map.getElementIndex(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        if (lineIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            return lineToRect(a, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        Rectangle lineArea = lineToRect(a, lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        // determine span from the start of the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        tabBase = lineArea.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        Element line = map.getElement(lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        int p0 = line.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        doc.getText(p0, pos - p0, s);
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   492
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   493
        if (useFloatingPointAPI) {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   494
            float xOffs = Utilities.getTabbedTextWidth(s, metrics, (float) tabBase, this, p0);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   495
            SegmentCache.releaseSharedSegment(s);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   496
            return new Rectangle2D.Float(lineArea.x + xOffs, lineArea.y, 1, metrics.getHeight());
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   497
        }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   498
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        int xOffs = Utilities.getTabbedTextWidth(s, metrics, tabBase, this,p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        // fill in the results and return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        lineArea.x += xOffs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        lineArea.width = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        lineArea.height = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return lineArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * coordinate space of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43075
diff changeset
   513
     * @param x the X coordinate &gt;= 0
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 43075
diff changeset
   514
     * @param y the Y coordinate &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * @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
   517
     *  given point in the view &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     */
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   520
    public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        // PENDING(prinz) properly calculate bias
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        bias[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        Rectangle alloc = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        Document doc = getDocument();
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   526
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        if (y < alloc.y) {
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   528
            // above the area covered by this icon, so the position
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            // is assumed to be the start of the coverage for this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            return getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        } else if (y > alloc.y + alloc.height) {
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   532
            // below the area covered by this icon, so the position
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            // is assumed to be the end of the coverage for this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            return getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            // positioned within the coverage of this view vertically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            // so we figure out which line the point corresponds to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            // if the line is greater than the number of lines contained, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            // simply use the last line as it represents the last possible place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            // we can position to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            Element map = doc.getDefaultRootElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            int lineIndex = (fontHeight > 0 ?
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   544
                                (int)Math.abs((y - alloc.y) / fontHeight) :
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                map.getElementCount() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            if (lineIndex >= map.getElementCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                return getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            Element line = map.getElement(lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            int dx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if (lineIndex == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                alloc.x += firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                alloc.width -= firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            if (x < alloc.x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                // point is to the left of the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                return line.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            } else if (x > alloc.x + alloc.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                // point is to the right of the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                return line.getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                // Determine the offset into the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    int p0 = line.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    int p1 = line.getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    doc.getText(p0, p1 - p0, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    tabBase = alloc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    int offs = p0 + Utilities.getTabbedTextOffset(s, metrics,
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   570
                                                                  tabBase, x, this, p0, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                    SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    return offs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    // should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Gives notification that something was inserted into the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @param changes the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @see View#insertUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        updateDamage(changes, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * Gives notification that something was removed from the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @param changes the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @see View#removeUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        updateDamage(changes, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Gives notification from the document that attributes were changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @param changes the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @see View#changedUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        updateDamage(changes, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * Sets the size of the view.  This should cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * layout of the view along the given axis, if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * has any layout duties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   625
     * @param width the width &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   626
     * @param height the height &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    public void setSize(float width, float height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
        super.setSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    // --- TabExpander methods ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * Returns the next tab stop position after a given reference position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * This implementation does not support things like centering so it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * ignores the tabOffset argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   640
     * @param x the current position &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * @param tabOffset the position within the text stream
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   642
     *   that the tab occurred at &gt;= 0.
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   643
     * @return the tab stop, measured in points &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    public float nextTabStop(float x, int tabOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        if (tabSize == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
47835
dde53d789c3d 8187957: Tab Size does not work correctly in JTextArea
psadhukhan
parents: 47216
diff changeset
   649
        int ntabs = (int) ((x - tabBase) / tabSize);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        return tabBase + ((ntabs + 1) * tabSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    // --- local methods ------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * Repaint the region of change covered by the given document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * event.  Damages the line that begins the range to cover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * the case when the insert/remove is only on one line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * If lines are added or removed, damages the whole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * view.  The longest line is checked to see if it has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *
30462
507bcb03c954 8076624: Fix missing doclint warnings in javax.swing.text
darcy
parents: 28059
diff changeset
   663
     * @param changes the change information from the associated document
507bcb03c954 8076624: Fix missing doclint warnings in javax.swing.text
darcy
parents: 28059
diff changeset
   664
     * @param a the current allocation of the view
507bcb03c954 8076624: Fix missing doclint warnings in javax.swing.text
darcy
parents: 28059
diff changeset
   665
     * @param f the factory to use to rebuild if the view has children
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        Component host = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        Element elem = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        DocumentEvent.ElementChange ec = changes.getChange(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        Element[] added = (ec != null) ? ec.getChildrenAdded() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        Element[] removed = (ec != null) ? ec.getChildrenRemoved() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        if (((added != null) && (added.length > 0)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
            ((removed != null) && (removed.length > 0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            // lines were added or removed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (added != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                int currWide = getLineWidth(longLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                for (int i = 0; i < added.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    int w = getLineWidth(added[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    if (w > currWide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                        currWide = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                        longLine = added[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            if (removed != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                for (int i = 0; i < removed.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                    if (removed[i] == longLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                        calculateLongestLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            preferenceChanged(null, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            host.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            Element map = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            int line = map.getElementIndex(changes.getOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            damageLineRange(line, line, a, host);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            if (changes.getType() == DocumentEvent.EventType.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                // check to see if the line is longer than current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                // longest line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                int w = getLineWidth(longLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                Element e = map.getElement(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                if (e == longLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    preferenceChanged(null, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                } else if (getLineWidth(e) > w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    longLine = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    preferenceChanged(null, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            } else if (changes.getType() == DocumentEvent.EventType.REMOVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                if (map.getElement(line) == longLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    // removed from longest line... recalc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    calculateLongestLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                    preferenceChanged(null, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * Repaint the given line range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * @param host the component hosting the view (used to call repaint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @param a  the region allocated for the view to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * @param line0 the starting line number to repaint.  This must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *   be a valid line number in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @param line1 the ending line number to repaint.  This must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *   be a valid line number in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    protected void damageLineRange(int line0, int line1, Shape a, Component host) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
        if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            Rectangle area0 = lineToRect(a, line0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            Rectangle area1 = lineToRect(a, line1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            if ((area0 != null) && (area1 != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                Rectangle damage = area0.union(area1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                host.repaint(damage.x, damage.y, damage.width, damage.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                host.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * Determine the rectangle that represents the given line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * @param a  the region allocated for the view to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @param line the line number to find the region of.  This must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     *   be a valid line number in the model.
30462
507bcb03c954 8076624: Fix missing doclint warnings in javax.swing.text
darcy
parents: 28059
diff changeset
   754
     * @return the rectangle that represents the given line
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    protected Rectangle lineToRect(Shape a, int line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        Rectangle r = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        if (metrics != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            Rectangle alloc = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            if (line == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                alloc.x += firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                alloc.width -= firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            r = new Rectangle(alloc.x, alloc.y + (line * metrics.getHeight()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                              alloc.width, metrics.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * Iterate over the lines represented by the child elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * of the element this view represents, looking for the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * that is the longest.  The <em>longLine</em> variable is updated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * represent the longest line contained.  The <em>font</em> variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * is updated to indicate the font used to calculate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * longest line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    private void calculateLongestLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        Component c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        font = c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        metrics = c.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        Element lines = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        int n = lines.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        int maxWidth = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            Element line = lines.getElement(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            int w = getLineWidth(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            if (w > maxWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                maxWidth = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                longLine = line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * Calculate the width of the line represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * the given element.  It is assumed that the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * and font metrics are up-to-date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     */
42216
621af0ebf6c4 8169518: Suppress Deprecation warnings for deprecated Swing APIs
prr
parents: 41807
diff changeset
   803
    @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    private int getLineWidth(Element line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        if (line == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        int p0 = line.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        int p1 = line.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        int w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            line.getDocument().getText(p0, p1 - p0, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            w = Utilities.getTabbedTextWidth(s, metrics, tabBase, this, p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        } catch (BadLocationException ble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            w = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
        return w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
43075
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   822
    static boolean getFPMethodOverridden(Class<?> cls, String method,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   823
                                         FPMethodArgs methodArgs) {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   824
        HashMap<FPMethodItem, Boolean> map = null;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   825
        boolean initialized = methodsOverriddenMapRef != null
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   826
                              && (map = methodsOverriddenMapRef.get()) != null;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   827
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   828
        if (!initialized) {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   829
            map = new HashMap<>();
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   830
            methodsOverriddenMapRef = new SoftReference<>(map);
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   831
        }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   832
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   833
        FPMethodItem key = new FPMethodItem(cls, method);
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   834
        Boolean isFPMethodOverridden = map.get(key);
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   835
        if (isFPMethodOverridden == null) {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   836
            isFPMethodOverridden = checkFPMethodOverridden(cls, method, methodArgs);
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   837
            map.put(key, isFPMethodOverridden);
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   838
        }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   839
        return isFPMethodOverridden;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   840
    }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   841
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   842
    private static boolean checkFPMethodOverridden(final Class<?> className,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   843
                                                   final String methodName,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   844
                                                   final FPMethodArgs methodArgs) {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   845
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   846
        return AccessController
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   847
                .doPrivileged(new PrivilegedAction<Boolean>() {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   848
                    @Override
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   849
                    public Boolean run() {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   850
                        return isFPMethodOverridden(methodName, className,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   851
                                                    methodArgs.getMethodArguments(false),
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   852
                                                    methodArgs.getMethodArguments(true));
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   853
                    }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   854
                });
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   855
    }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   856
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   857
    private static boolean isFPMethodOverridden(String method,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   858
                                                Class<?> cls,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   859
                                                Class<?>[] intTypes,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   860
                                                Class<?>[] fpTypes)
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   861
    {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   862
        Module thisModule = PlainView.class.getModule();
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   863
        while (!thisModule.equals(cls.getModule())) {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   864
            try {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   865
                cls.getDeclaredMethod(method, fpTypes);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   866
                return true;
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   867
            } catch (Exception e1) {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   868
                try {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   869
                    cls.getDeclaredMethod(method, intTypes);
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   870
                    return false;
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   871
                } catch (Exception e2) {
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   872
                    cls = cls.getSuperclass();
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   873
                }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   874
            }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   875
        }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   876
        return true;
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   877
    }
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   878
43075
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   879
    enum FPMethodArgs {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   880
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   881
        IGNN,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   882
        IIGNN,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   883
        GNNII,
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   884
        GNNC;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   885
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   886
        public Class<?>[] getMethodArguments(boolean isFPType) {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   887
            Class<?> N = (isFPType) ? Float.TYPE : Integer.TYPE;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   888
            Class<?> G = (isFPType) ? Graphics2D.class : Graphics.class;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   889
            switch (this) {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   890
                case IGNN:
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   891
                    return new Class<?>[]{Integer.TYPE, G, N, N};
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   892
                case IIGNN:
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   893
                    return new Class<?>[]{Integer.TYPE, Integer.TYPE, G, N, N};
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   894
                case GNNII:
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   895
                    return new Class<?>[]{G, N, N, Integer.TYPE, Integer.TYPE};
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   896
                case GNNC:
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   897
                    return new Class<?>[]{G, N, N, Character.TYPE};
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   898
                default:
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   899
                    throw new RuntimeException("Unknown method arguments!");
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   900
            }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   901
        }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   902
    }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   903
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   904
     private static class FPMethodItem {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   905
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   906
        final Class<?> className;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   907
        final String methodName;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   908
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   909
        public FPMethodItem(Class<?> className, String methodName) {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   910
            this.className = className;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   911
            this.methodName = methodName;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   912
        }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   913
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   914
        @Override
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   915
        public boolean equals(Object obj) {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   916
            if (obj instanceof FPMethodItem) {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   917
                FPMethodItem that = (FPMethodItem) obj;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   918
                return this.className.equals(that.className)
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   919
                        && this.methodName.equals(that.methodName);
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   920
            }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   921
            return false;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   922
        }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   923
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   924
        @Override
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   925
        public int hashCode() {
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   926
            return 31 * methodName.hashCode() + className.hashCode();
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   927
        }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   928
    }
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   929
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
    // --- member variables -----------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * Font metrics for the current font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    protected FontMetrics metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * The current longest line.  This is used to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * the preferred width of the view.  Since the calculation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * is potentially expensive we try to avoid it by stashing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * which line is currently the longest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    Element longLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * Font used to calculate the longest line... if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * changes we need to recalculate the longest line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    Font font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    Segment lineBuffer;
41807
f9eb6cb54fed 8156217: Selected text is shifted on HiDPI display
alexsch
parents: 39554
diff changeset
   952
    float tabSize;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    int tabBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    int sel0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    int sel1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    Color unselected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    Color selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * Offset of where to draw the first character on the first line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * This is a hack and temporary until we can better address the problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * of text measuring. This field is actually never set directly in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * PlainView, but by FieldView.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    int firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
43075
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   968
    private static SoftReference<HashMap<FPMethodItem, Boolean>> methodsOverriddenMapRef;
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   969
    final boolean drawLineOverridden =
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   970
            getFPMethodOverridden(getClass(), "drawLine", FPMethodArgs.IGNN);
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   971
    final boolean drawSelectedTextOverridden =
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   972
            getFPMethodOverridden(getClass(), "drawSelectedText", FPMethodArgs.GNNII);
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   973
    final boolean drawUnselectedTextOverridden =
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   974
            getFPMethodOverridden(getClass(), "drawUnselectedText", FPMethodArgs.GNNII);
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   975
    final boolean useFloatingPointAPI =
668b6d00cc79 8169922: SwingMark/TextArea: 2-7% regression on Linux, Mac, Windows in 9-b143
alexsch
parents: 42216
diff changeset
   976
            drawUnselectedTextOverridden || drawSelectedTextOverridden;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
}