jdk/src/java.desktop/share/classes/javax/swing/text/LabelView.java
author smarks
Tue, 29 Aug 2017 12:16:28 -0700
changeset 47020 2c55106dc37b
parent 30462 507bcb03c954
permissions -rw-r--r--
8186851: fix misspellings of "dependent" and "independent" in the JDK repo Reviewed-by: bpb, psadhukhan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30462
507bcb03c954 8076624: Fix missing doclint warnings in javax.swing.text
darcy
parents: 25859
diff changeset
     2
 * Copyright (c) 1997, 2015, 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.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * A <code>LabelView</code> is a styled chunk of text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * that represents a view mapped over an element in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * text model.  It caches the character level attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * used for rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * @author Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class LabelView extends GlyphView implements TabableView {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * Constructs a new view wrapped on an element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
     * @param elem the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public LabelView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        super(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Synchronize the view's cached values with the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * This causes the font, metrics, color, etc to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * re-cached if the cache has been invalidated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    final void sync() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        if (font == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
            setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Sets whether or not the view is underlined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * Note that this setter is protected and is really
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * only meant if you need to update some additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * state when set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @param u true if the view is underlined, otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *          false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @see #isUnderline
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    protected void setUnderline(boolean u) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        underline = u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Sets whether or not the view has a strike/line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * through it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Note that this setter is protected and is really
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * only meant if you need to update some additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * state when set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param s true if the view has a strike/line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     *          through it, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @see #isStrikeThrough
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    protected void setStrikeThrough(boolean s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        strike = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Sets whether or not the view represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * superscript.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * Note that this setter is protected and is really
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * only meant if you need to update some additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * state when set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param s true if the view represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *          superscript, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see #isSuperscript
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected void setSuperscript(boolean s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        superscript = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Sets whether or not the view represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * subscript.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Note that this setter is protected and is really
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * only meant if you need to update some additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * state when set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @param s true if the view represents a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *          subscript, otherwise false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * @see #isSubscript
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    protected void setSubscript(boolean s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        subscript = s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Sets the background color for the view. This method is typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * invoked as part of configuring this <code>View</code>. If you need
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * to customize the background color you should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * <code>setPropertiesFromAttributes</code> and invoke this method. A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * value of null indicates no background should be rendered, so that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * background of the parent <code>View</code> will show through.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * @param bg background color, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see #setPropertiesFromAttributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    protected void setBackground(Color bg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        this.bg = bg;
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
     * Sets the cached properties from the attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    protected void setPropertiesFromAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        AttributeSet attr = getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            Document d = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (d instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                StyledDocument doc = (StyledDocument) d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                font = doc.getFont(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                fg = doc.getForeground(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                if (attr.isDefined(StyleConstants.Background)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                    bg = doc.getBackground(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                    bg = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                setUnderline(StyleConstants.isUnderline(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                setStrikeThrough(StyleConstants.isStrikeThrough(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                setSuperscript(StyleConstants.isSuperscript(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                setSubscript(StyleConstants.isSubscript(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                throw new StateInvariantError("LabelView needs StyledDocument");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * Fetches the <code>FontMetrics</code> used for this view.
30462
507bcb03c954 8076624: Fix missing doclint warnings in javax.swing.text
darcy
parents: 25859
diff changeset
   164
     * @return the <code>FontMetrics</code> used for this view
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @deprecated FontMetrics are not used for glyph rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *  when running in the JDK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    protected FontMetrics getFontMetrics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        Container c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return (c != null) ? c.getFontMetrics(font) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            Toolkit.getDefaultToolkit().getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * Fetches the background color to use to render the glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * This is implemented to return a cached background color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * which defaults to <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @return the cached background color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public Color getBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Fetches the foreground color to use to render the glyphs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * This is implemented to return a cached foreground color,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * which defaults to <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @return the cached foreground color
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public Color getForeground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Fetches the font that the glyphs should be based upon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * This is implemented to return a cached font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @return the cached font
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     public Font getFont() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return font;
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
     * Determines if the glyphs should be underlined.  If true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * an underline should be drawn through the baseline.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * is implemented to return the cached underline property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * <p>When you request this property, <code>LabelView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * re-syncs its state with the properties of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <code>Element</code>'s <code>AttributeSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * If <code>Element</code>'s <code>AttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * does not have this property set, it will revert to false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @return the value of the cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *     <code>underline</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    public boolean isUnderline() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        return underline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Determines if the glyphs should have a strikethrough
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * line.  If true, a line should be drawn through the center
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * of the glyphs.  This is implemented to return the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * cached <code>strikeThrough</code> property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <p>When you request this property, <code>LabelView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * re-syncs its state with the properties of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <code>Element</code>'s <code>AttributeSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * If <code>Element</code>'s <code>AttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * does not have this property set, it will revert to false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @return the value of the cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *     <code>strikeThrough</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public boolean isStrikeThrough() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return strike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Determines if the glyphs should be rendered as superscript.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @return the value of the cached subscript property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * <p>When you request this property, <code>LabelView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * re-syncs its state with the properties of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * <code>Element</code>'s <code>AttributeSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * If <code>Element</code>'s <code>AttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * does not have this property set, it will revert to false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @return the value of the cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *     <code>subscript</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public boolean isSubscript() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return subscript;
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 if the glyphs should be rendered as subscript.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * <p>When you request this property, <code>LabelView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * re-syncs its state with the properties of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * <code>Element</code>'s <code>AttributeSet</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * If <code>Element</code>'s <code>AttributeSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * does not have this property set, it will revert to false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @return the value of the cached
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *     <code>superscript</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    public boolean isSuperscript() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        sync();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return superscript;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    // --- View methods ---------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * Gives notification from the document that attributes were changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @see View#changedUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        font = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        super.changedUpdate(e, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    // --- variables ------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    private Font font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    private Color fg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    private Color bg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    private boolean underline;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    private boolean strike;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    private boolean superscript;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    private boolean subscript;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}