jdk/src/share/classes/javax/swing/text/html/ParagraphView.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 7959 2e05332a8f5c
child 21278 ef8a3a2a72f2
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 7959
diff changeset
     2
 * Copyright (c) 1998, 2011, 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: 3709
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: 3709
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: 3709
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3709
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3709
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.html;
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.SizeRequirements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.DocumentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.text.Document;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.text.Element;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.text.AttributeSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.text.StyleConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.text.View;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.text.ViewFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.text.BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.text.JTextComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * Displays the a paragraph, and uses css attributes for its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * configuration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class ParagraphView extends javax.swing.text.ParagraphView {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * Constructs a ParagraphView for the given element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @param elem the element that this view is responsible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public ParagraphView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        super(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Establishes the parent view for this view.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * guaranteed to be called before any other methods if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * parent view is functioning properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * This is implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * to forward to the superclass as well as call the
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
    64
     * {@link #setPropertiesFromAttributes setPropertiesFromAttributes}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * method to set the paragraph properties from the css
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * attributes.  The call is made at this time to ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * the ability to resolve upward through the parents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * view attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * @param parent the new parent, or null if the view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *  being removed from a parent it was previously added
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *  to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public void setParent(View parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        super.setParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Fetches the attributes to use when rendering.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * implemented to multiplex the attributes specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * model with a StyleSheet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public AttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            StyleSheet sheet = getStyleSheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            attr = sheet.getViewAttributes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        return attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Sets up the paragraph from css attributes instead of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * the values found in StyleConstants (i.e. which are used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * by the superclass).  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    protected void setPropertiesFromAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        StyleSheet sheet = getStyleSheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        attr = sheet.getViewAttributes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        painter = sheet.getBoxPainter(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            super.setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            setInsets((short) painter.getInset(TOP, this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                      (short) painter.getInset(LEFT, this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                      (short) painter.getInset(BOTTOM, this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                      (short) painter.getInset(RIGHT, this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            Object o = attr.getAttribute(CSS.Attribute.TEXT_ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                // set horizontal alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                String ta = o.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                if (ta.equals("left")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    setJustification(StyleConstants.ALIGN_LEFT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                } else if (ta.equals("center")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                    setJustification(StyleConstants.ALIGN_CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                } else if (ta.equals("right")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    setJustification(StyleConstants.ALIGN_RIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                } else if (ta.equals("justify")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                    setJustification(StyleConstants.ALIGN_JUSTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            // Get the width/height
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            cssWidth = (CSS.LengthValue)attr.getAttribute(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                                        CSS.Attribute.WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            cssHeight = (CSS.LengthValue)attr.getAttribute(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                                         CSS.Attribute.HEIGHT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    protected StyleSheet getStyleSheet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        HTMLDocument doc = (HTMLDocument) getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return doc.getStyleSheet();
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Calculate the needs for the paragraph along the minor axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * <p>If size requirements are explicitly specified for the paragraph,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * use that requirements.  Otherwise, use the requirements of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * superclass {@link javax.swing.text.ParagraphView}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <p>If the {@code axis} parameter is neither {@code View.X_AXIS} nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * {@code View.Y_AXIS}, {@link IllegalArgumentException} is thrown.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * {@code r} parameter is {@code null,} a new {@code SizeRequirements}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * object is created, otherwise the supplied {@code SizeRequirements}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * object is returned.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param axis  the minor axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param r     the input {@code SizeRequirements} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @return      the new or adjusted {@code SizeRequirements} object
3709
e7cf22d025bb 6876628: @throw instead of @throws in two ParagraphView classes
darcy
parents: 2
diff changeset
   153
     * @throws IllegalArgumentException  if the {@code axis} parameter is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    protected SizeRequirements calculateMinorAxisRequirements(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                                int axis, SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        r = super.calculateMinorAxisRequirements(axis, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (BlockView.spanSetFromAttributes(axis, r, cssWidth, cssHeight)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // Offset by the margins so that pref/min/max return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            // right value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            int margin = (axis == X_AXIS) ? getLeftInset() + getRightInset() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                                            getTopInset() + getBottomInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            r.minimum -= margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            r.preferred -= margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            r.maximum -= margin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
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
     * Indicates whether or not this view should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * displayed.  If none of the children wish to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * displayed and the only visible child is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * break that ends the paragraph, the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * will not be considered visible.  Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * it will be considered visible and return true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @return true if the paragraph should be displayed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        int n = getLayoutViewCount() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            View v = getLayoutView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (v.isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            View v = getLayoutView(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            if ((v.getEndOffset() - v.getStartOffset()) == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // If it's the last paragraph and not editable, it shouldn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // be visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (getStartOffset() == getDocument().getLength()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            boolean editable = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            Component c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (c instanceof JTextComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                editable = ((JTextComponent)c).isEditable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            if (!editable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Renders using the given rendering surface and area on that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * surface.  This is implemented to delgate to the superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * after stashing the base coordinate for tab calculations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * @param g the rendering surface to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see View#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public void paint(Graphics g, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (a == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        Rectangle r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (a instanceof Rectangle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            r = (Rectangle) a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            r = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        painter.paint(g, r.x, r.y, r.width, r.height, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        super.paint(g, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Determines the preferred span for this view.  Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * 0 if the view is not visible, otherwise it calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * superclass method to get the preferred span.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param axis may be either View.X_AXIS or View.Y_AXIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @return   the span the view would like to be rendered into;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *           typically the view is told to render into the span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *           that is returned, although there is no guarantee;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *           the parent may choose to resize or break the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see javax.swing.text.ParagraphView#getPreferredSpan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public float getPreferredSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (!isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        return super.getPreferredSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Determines the minimum span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * axis.  Returns 0 if the view is not visible, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * it calls the superclass method to get the minimum span.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *  <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @return  the minimum span the view can be rendered into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see javax.swing.text.ParagraphView#getMinimumSpan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public float getMinimumSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (!isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return super.getMinimumSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * Determines the maximum span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * axis.  Returns 0 if the view is not visible, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * it calls the superclass method ot get the maximum span.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *  <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @return  the maximum span the view can be rendered into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @see javax.swing.text.ParagraphView#getMaximumSpan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public float getMaximumSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        if (!isVisible()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        return super.getMaximumSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    private AttributeSet attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    private StyleSheet.BoxPainter painter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    private CSS.LengthValue cssWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    private CSS.LengthValue cssHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
}