jdk/src/share/classes/javax/swing/text/PlainView.java
author prr
Fri, 23 May 2014 09:05:24 -0700
changeset 24567 a0ebe5fd56ff
parent 23010 6dadb192ad81
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 20158
diff changeset
     2
 * Copyright (c) 1997, 2013, 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.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * Implements View interface for a simple multi-line text view
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * that has text in one font and color.  The view represents each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * child element as a line of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @see     View
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
public class PlainView extends View implements TabExpander {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * Constructs a new PlainView wrapped on an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * @param elem the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public PlainView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        super(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * Returns the tab size set for the document, defaulting to 8.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * @return the tab size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    protected int getTabSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        Integer i = (Integer) getDocument().getProperty(PlainDocument.tabSizeAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        int size = (i != null) ? i.intValue() : 8;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Renders a line of text, suppressing whitespace at the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * and expanding any tabs.  This is implemented to make calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * to the methods <code>drawUnselectedText</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * <code>drawSelectedText</code> so that the way selected and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * unselected text are rendered can be customized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    69
     * @param lineIndex the line to draw &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param g the <code>Graphics</code> context
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    71
     * @param x the starting X position &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
    72
     * @param y the starting Y position &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @see #drawUnselectedText
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * @see #drawSelectedText
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    protected void drawLine(int lineIndex, Graphics g, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        Element line = getElement().getElement(lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        Element elem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            if (line.isLeaf()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                drawElement(lineIndex, line, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                // this line contains the composed text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                int count = line.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                for(int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    elem = line.getElement(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    x = drawElement(lineIndex, elem, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            throw new StateInvariantError("Can't render line: " + lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private int drawElement(int lineIndex, Element elem, Graphics g, int x, int y) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        int p0 = elem.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        int p1 = elem.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        p1 = Math.min(getDocument().getLength(), p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (lineIndex == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            x += firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        AttributeSet attr = elem.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (Utilities.isComposedTextAttributeDefined(attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            g.setColor(unselected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            x = Utilities.drawComposedText(this, attr, g, x, y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                        p0-elem.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                        p1-elem.getStartOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            if (sel0 == sel1 || selected == unselected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                // no selection, or it is invisible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                x = drawUnselectedText(g, x, y, p0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            } else if ((p0 >= sel0 && p0 <= sel1) && (p1 >= sel0 && p1 <= sel1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                x = drawSelectedText(g, x, y, p0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            } else if (sel0 >= p0 && sel0 <= p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                if (sel1 >= p0 && sel1 <= p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    x = drawUnselectedText(g, x, y, p0, sel0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                    x = drawSelectedText(g, x, y, sel0, sel1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    x = drawUnselectedText(g, x, y, sel1, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                    x = drawUnselectedText(g, x, y, p0, sel0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    x = drawSelectedText(g, x, y, sel0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            } else if (sel1 >= p0 && sel1 <= p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                x = drawSelectedText(g, x, y, p0, sel1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                x = drawUnselectedText(g, x, y, sel1, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                x = drawUnselectedText(g, x, y, p0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Renders the given range in the model as normal unselected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * text.  Uses the foreground or disabled color to render the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param g the graphics context
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   141
     * @param x the starting X coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   142
     * @param y the starting Y coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   143
     * @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
   144
     * @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
   145
     * @return the X location of the end of the range &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @exception BadLocationException if the range is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    protected int drawUnselectedText(Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                                     int p0, int p1) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        g.setColor(unselected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        doc.getText(p0, p1 - p0, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        int ret = Utilities.drawTabbedText(this, s, x, y, g, this, p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Renders the given range in the model as selected text.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * is implemented to render the text in the color specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * the hosting component.  It assumes the highlighter will render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * the selected background.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param g the graphics context
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   166
     * @param x the starting X coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   167
     * @param y the starting Y coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   168
     * @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
   169
     * @param p1 the ending position in the model &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @return the location of the end of the range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @exception BadLocationException if the range is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    protected int drawSelectedText(Graphics g, int x,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                                   int y, int p0, int p1) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        g.setColor(selected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        doc.getText(p0, p1 - p0, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        int ret = Utilities.drawTabbedText(this, s, x, y, g, this, p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Gives access to a buffer that can be used to fetch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * text from the associated document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * @return the buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    protected final Segment getLineBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (lineBuffer == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            lineBuffer = new Segment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        return lineBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Checks to see if the font metrics and longest line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * are up-to-date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    protected void updateMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        Component host = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        Font f = host.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (font != f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            // The font changed, we need to recalculate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            // longest line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            calculateLongestLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            tabSize = getTabSize() * metrics.charWidth('m');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    // ---- View methods ----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Determines the preferred span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @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
   221
     * @return   the span the view would like to be rendered into &gt;= 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *           Typically the view is told to render into the span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *           that is returned, although there is no guarantee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *           The parent may choose to resize or break the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @exception IllegalArgumentException for an invalid axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public float getPreferredSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        switch (axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        case View.X_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            return getLineWidth(longLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        case View.Y_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return getElement().getElementCount() * metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            throw new IllegalArgumentException("Invalid axis: " + axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Renders using the given rendering surface and area on that surface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * The view may need to do layout and create child views to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * itself to render into the given allocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param g the rendering surface to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see View#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public void paint(Graphics g, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        Shape originalA = a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        a = adjustPaintRegion(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        Rectangle alloc = (Rectangle) a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        tabBase = alloc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        JTextComponent host = (JTextComponent) getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        Highlighter h = host.getHighlighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        g.setFont(host.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        sel0 = host.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        sel1 = host.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        unselected = (host.isEnabled()) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            host.getForeground() : host.getDisabledTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        Caret c = host.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        selected = c.isSelectionVisible() && h != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                       host.getSelectedTextColor() : unselected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        // If the lines are clipped then we don't expend the effort to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        // try and paint them.  Since all of the lines are the same height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        // with this object, determination of what lines need to be repainted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        // is quick.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        Rectangle clip = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        int heightBelow = (alloc.y + alloc.height) - (clip.y + clip.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        int heightAbove = clip.y - alloc.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        int linesBelow, linesAbove, linesTotal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (fontHeight > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            linesBelow = Math.max(0, heightBelow / fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            linesAbove = Math.max(0, heightAbove / fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            linesTotal = alloc.height / fontHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            if (alloc.height % fontHeight != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                linesTotal++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            linesBelow = linesAbove = linesTotal = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        // update the visible lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        Rectangle lineArea = lineToRect(a, linesAbove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        int y = lineArea.y + metrics.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        int x = lineArea.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        Element map = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        int lineCount = map.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        int endLine = Math.min(lineCount, linesTotal - linesBelow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        lineCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        LayeredHighlighter dh = (h instanceof LayeredHighlighter) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                           (LayeredHighlighter)h : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        for (int line = linesAbove; line < endLine; line++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (dh != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                Element lineElement = map.getElement(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                if (line == lineCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    dh.paintLayeredHighlights(g, lineElement.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                                              lineElement.getEndOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                                              originalA, host, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    dh.paintLayeredHighlights(g, lineElement.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                              lineElement.getEndOffset() - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                              originalA, host, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            drawLine(line, g, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            y += fontHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            if (line == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                // This should never really happen, in so far as if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                // firstLineOffset is non 0, there should only be one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                // line of text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                x -= firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Should return a shape ideal for painting based on the passed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Shape <code>a</code>. This is useful if painting in a different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * region. The default implementation returns <code>a</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    Shape adjustPaintRegion(Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * Provides a mapping from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * to the coordinate space of the view mapped to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   335
     * @param pos the position to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @return the bounding box of the given position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @exception BadLocationException  if the given position does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *   represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @see View#modelToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        // line coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        Element map = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        int lineIndex = map.getElementIndex(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        if (lineIndex < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            return lineToRect(a, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        Rectangle lineArea = lineToRect(a, lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        // determine span from the start of the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        tabBase = lineArea.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        Element line = map.getElement(lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        int p0 = line.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        doc.getText(p0, pos - p0, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        int xOffs = Utilities.getTabbedTextWidth(s, metrics, tabBase, this,p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        // fill in the results and return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        lineArea.x += xOffs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        lineArea.width = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        lineArea.height = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return lineArea;
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
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * coordinate space of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   372
     * @param fx the X coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   373
     * @param fy the Y coordinate &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @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
   376
     *  given point in the view &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        // PENDING(prinz) properly calculate bias
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        bias[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        Rectangle alloc = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        int x = (int) fx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        int y = (int) fy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        if (y < alloc.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            // above the area covered by this icon, so the the position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            // is assumed to be the start of the coverage for this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            return getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        } else if (y > alloc.y + alloc.height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            // below the area covered by this icon, so the the position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            // is assumed to be the end of the coverage for this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            return getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            // positioned within the coverage of this view vertically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            // so we figure out which line the point corresponds to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            // if the line is greater than the number of lines contained, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            // simply use the last line as it represents the last possible place
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            // we can position to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            Element map = doc.getDefaultRootElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            int fontHeight = metrics.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            int lineIndex = (fontHeight > 0 ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                                Math.abs((y - alloc.y) / fontHeight) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                map.getElementCount() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            if (lineIndex >= map.getElementCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                return getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            Element line = map.getElement(lineIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            int dx = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (lineIndex == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                alloc.x += firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                alloc.width -= firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if (x < alloc.x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                // point is to the left of the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                return line.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            } else if (x > alloc.x + alloc.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                // point is to the right of the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                return line.getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                // Determine the offset into the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    int p0 = line.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                    int p1 = line.getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    doc.getText(p0, p1 - p0, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    tabBase = alloc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    int offs = p0 + Utilities.getTabbedTextOffset(s, metrics,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                                                                  tabBase, x, this, p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                    SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    return offs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                    // should not happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Gives notification that something was inserted into the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * @param changes the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see View#insertUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        updateDamage(changes, a, f);
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
     * Gives notification that something was removed from the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @param changes the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @see View#removeUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        updateDamage(changes, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * Gives notification from the document that attributes were changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @param changes the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @see View#changedUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        updateDamage(changes, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Sets the size of the view.  This should cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * layout of the view along the given axis, if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * has any layout duties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   485
     * @param width the width &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   486
     * @param height the height &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public void setSize(float width, float height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        super.setSize(width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    // --- TabExpander methods ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * Returns the next tab stop position after a given reference position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * This implementation does not support things like centering so it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * ignores the tabOffset argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   500
     * @param x the current position &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @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
   502
     *   that the tab occurred at &gt;= 0.
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   503
     * @return the tab stop, measured in points &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public float nextTabStop(float x, int tabOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (tabSize == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        int ntabs = (((int) x) - tabBase) / tabSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        return tabBase + ((ntabs + 1) * tabSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    // --- local methods ------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * Repaint the region of change covered by the given document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * event.  Damages the line that begins the range to cover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * the case when the insert/remove is only on one line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * If lines are added or removed, damages the whole
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * view.  The longest line is checked to see if it has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    protected void updateDamage(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        Component host = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        Element elem = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        DocumentEvent.ElementChange ec = changes.getChange(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        Element[] added = (ec != null) ? ec.getChildrenAdded() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        Element[] removed = (ec != null) ? ec.getChildrenRemoved() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        if (((added != null) && (added.length > 0)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            ((removed != null) && (removed.length > 0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            // lines were added or removed...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            if (added != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                int currWide = getLineWidth(longLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                for (int i = 0; i < added.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    int w = getLineWidth(added[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    if (w > currWide) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                        currWide = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                        longLine = added[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            if (removed != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                for (int i = 0; i < removed.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    if (removed[i] == longLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                        calculateLongestLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            preferenceChanged(null, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            host.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            Element map = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            int line = map.getElementIndex(changes.getOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            damageLineRange(line, line, a, host);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            if (changes.getType() == DocumentEvent.EventType.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                // check to see if the line is longer than current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                // longest line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                int w = getLineWidth(longLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                Element e = map.getElement(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                if (e == longLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    preferenceChanged(null, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                } else if (getLineWidth(e) > w) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    longLine = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    preferenceChanged(null, true, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            } else if (changes.getType() == DocumentEvent.EventType.REMOVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                if (map.getElement(line) == longLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    // removed from longest line... recalc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    calculateLongestLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    preferenceChanged(null, true, false);
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
     * Repaint the given line range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @param host the component hosting the view (used to call repaint)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * @param a  the region allocated for the view to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @param line0 the starting line number to repaint.  This must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *   be a valid line number in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @param line1 the ending line number to repaint.  This must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     *   be a valid line number in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    protected void damageLineRange(int line0, int line1, Shape a, Component host) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            Rectangle area0 = lineToRect(a, line0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            Rectangle area1 = lineToRect(a, line1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            if ((area0 != null) && (area1 != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                Rectangle damage = area0.union(area1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                host.repaint(damage.x, damage.y, damage.width, damage.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                host.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Determine the rectangle that represents the given line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @param a  the region allocated for the view to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @param line the line number to find the region of.  This must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *   be a valid line number in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    protected Rectangle lineToRect(Shape a, int line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        Rectangle r = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        updateMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if (metrics != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            Rectangle alloc = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            if (line == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                alloc.x += firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                alloc.width -= firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            r = new Rectangle(alloc.x, alloc.y + (line * metrics.getHeight()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                              alloc.width, metrics.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * Iterate over the lines represented by the child elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * of the element this view represents, looking for the line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * that is the longest.  The <em>longLine</em> variable is updated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * represent the longest line contained.  The <em>font</em> variable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * is updated to indicate the font used to calculate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * longest line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
    private void calculateLongestLine() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        Component c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        font = c.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        metrics = c.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        Element lines = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        int n = lines.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        int maxWidth = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            Element line = lines.getElement(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            int w = getLineWidth(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            if (w > maxWidth) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                maxWidth = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                longLine = line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * Calculate the width of the line represented by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * the given element.  It is assumed that the font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * and font metrics are up-to-date.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    private int getLineWidth(Element line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        if (line == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        int p0 = line.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
        int p1 = line.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        int w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        Segment s = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            line.getDocument().getText(p0, p1 - p0, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            w = Utilities.getTabbedTextWidth(s, metrics, tabBase, this, p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        } catch (BadLocationException ble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            w = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        SegmentCache.releaseSharedSegment(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
        return w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    // --- member variables -----------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * Font metrics for the current font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
    protected FontMetrics metrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * The current longest line.  This is used to calculate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * the preferred width of the view.  Since the calculation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * is potentially expensive we try to avoid it by stashing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * which line is currently the longest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    Element longLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * Font used to calculate the longest line... if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * changes we need to recalculate the longest line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    Font font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    Segment lineBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    int tabSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    int tabBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    int sel0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    int sel1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    Color unselected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    Color selected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Offset of where to draw the first character on the first line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * This is a hack and temporary until we can better address the problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * of text measuring. This field is actually never set directly in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * PlainView, but by FieldView.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    int firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
}