jdk/src/share/classes/javax/swing/text/FieldView.java
author malenkov
Wed, 30 Apr 2014 19:28:05 +0400
changeset 24544 c0133e7c7162
parent 23010 6dadb192ad81
permissions -rw-r--r--
8041917: unexcepted behavior of LineBorder while using Boolean variable true Reviewed-by: alexsch, serb
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.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * Extends the multi-line plain text view to be suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * for a single-line editor view.  If the view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * allocated extra space, the field must adjust for it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * If the hosting component is a JTextField, this view
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * will manage the ranges of the associated BoundedRangeModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * and will adjust the horizontal allocation to match the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * current visibility settings of the JTextField.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * @see     View
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class FieldView extends PlainView {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * Constructs a new FieldView wrapped on an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * @param elem the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public FieldView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        super(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Fetches the font metrics associated with the component hosting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @return the metrics
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected FontMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Component c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        return c.getFontMetrics(c.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * Adjusts the allocation given to the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * to be a suitable allocation for a text field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * If the view has been allocated more than the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * preferred span vertically, the allocation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * changed to be centered vertically.  Horizontally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * the view is adjusted according to the horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * alignment property set on the associated JTextField
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * (if that is the type of the hosting component).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @param a the allocation given to the view, which may need
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     *  to be adjusted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @return the allocation that the superclass should use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    protected Shape adjustAllocation(Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            Rectangle bounds = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            int vspan = (int) getPreferredSpan(Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            int hspan = (int) getPreferredSpan(X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (bounds.height != vspan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                int slop = bounds.height - vspan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                bounds.y += slop / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                bounds.height -= slop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            // horizontal adjustments
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            Component c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (c instanceof JTextField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                JTextField field = (JTextField) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                BoundedRangeModel vis = field.getHorizontalVisibility();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                int max = Math.max(hspan, bounds.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                int value = vis.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                int extent = Math.min(max, bounds.width - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                if ((value + extent) > max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    value = max - extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                vis.setRangeProperties(value, extent, vis.getMinimum(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                                       max, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                if (hspan < bounds.width) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    // horizontally align the interior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    int slop = bounds.width - 1 - hspan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                    int align = ((JTextField)c).getHorizontalAlignment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                    if(Utilities.isLeftToRight(c)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                        if(align==LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                            align = LEFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                        else if(align==TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                            align = RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                        if(align==LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                            align = RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                        else if(align==TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                            align = LEFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    switch (align) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    case SwingConstants.CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        bounds.x += slop / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        bounds.width -= slop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    case SwingConstants.RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        bounds.x += slop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                        bounds.width -= slop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    // adjust the allocation to match the bounded range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                    bounds.width = hspan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    bounds.x -= vis.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return bounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * Update the visibility model with the associated JTextField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * (if there is one) to reflect the current visibility as a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * result of changes to the document model.  The bounded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * range properties are updated.  If the view hasn't yet been
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * shown the extent will be zero and we just set it to be full
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * until determined otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    void updateVisibilityModel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        Component c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (c instanceof JTextField) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            JTextField field = (JTextField) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            BoundedRangeModel vis = field.getHorizontalVisibility();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            int hspan = (int) getPreferredSpan(X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            int extent = vis.getExtent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            int maximum = Math.max(hspan, extent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            extent = (extent == 0) ? maximum : extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            int value = maximum - extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            int oldValue = vis.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if ((oldValue + extent) > maximum) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                oldValue = maximum - extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            value = Math.max(0, Math.min(value, oldValue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            vis.setRangeProperties(value, extent, 0, maximum, false);
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
    // --- View methods -------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Renders using the given rendering surface and area on that surface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * The view may need to do layout and create child views to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * itself to render into the given allocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param g the rendering surface to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see View#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public void paint(Graphics g, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        Rectangle r = (Rectangle) a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        g.clipRect(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        super.paint(g, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Adjusts <code>a</code> based on the visible region and returns it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    Shape adjustPaintRegion(Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return adjustAllocation(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Determines the preferred span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @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
   203
     * @return   the span the view would like to be rendered into &gt;= 0.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *           Typically the view is told to render into the span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *           that is returned, although there is no guarantee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *           The parent may choose to resize or break the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public float getPreferredSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        switch (axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        case View.X_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            Segment buff = SegmentCache.getSharedSegment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            int width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                FontMetrics fm = getFontMetrics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                doc.getText(0, doc.getLength(), buff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                width = Utilities.getTabbedTextWidth(buff, fm, 0, this, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                if (buff.count > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    Component c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    firstLineOffset = sun.swing.SwingUtilities2.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        getLeftSideBearing((c instanceof JComponent) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                                           (JComponent)c : null, fm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                                           buff.array[buff.offset]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    firstLineOffset = Math.max(0, -firstLineOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                    firstLineOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            SegmentCache.releaseSharedSegment(buff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return width + firstLineOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            return super.getPreferredSpan(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
     * Determines the resizability of the view along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * given axis.  A value of 0 or less is not resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param axis View.X_AXIS or View.Y_AXIS
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   244
     * @return the weight -&gt; 1 for View.X_AXIS, else 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public int getResizeWeight(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (axis == View.X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Provides a mapping from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * to the coordinate space of the view mapped to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   257
     * @param pos the position to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @return the bounding box of the given position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @exception BadLocationException  if the given position does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *   represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @see View#modelToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        return super.modelToView(pos, adjustAllocation(a), b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * coordinate space of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   272
     * @param fx the X coordinate &gt;= 0.0f
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   273
     * @param fy the Y coordinate &gt;= 0.0f
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return the location within the model that best represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *  given point in the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public int viewToModel(float fx, float fy, Shape a, Position.Bias[] bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return super.viewToModel(fx, fy, adjustAllocation(a), bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Gives notification that something was inserted into the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @param changes the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @see View#insertUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        super.insertUpdate(changes, adjustAllocation(a), f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        updateVisibilityModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Gives notification that something was removed from the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param changes the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @see View#removeUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        super.removeUpdate(changes, adjustAllocation(a), f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        updateVisibilityModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}