jdk/src/java.desktop/share/classes/javax/swing/JLabel.java
author aghaisas
Mon, 10 Jul 2017 14:55:29 +0530
changeset 47151 362dcbee0613
parent 33253 78e735319356
permissions -rw-r--r--
6919529: NPE from MultiUIDefaults.getUIError Reviewed-by: aghaisas, psadhukhan, serb Contributed-by: shashidhara.veerabhadraiah@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
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: 2473
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: 2473
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: 2473
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2473
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2473
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Image;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.geom.*;
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    32
import java.beans.JavaBean;
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    33
import java.beans.BeanProperty;
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
    34
import java.beans.Transient;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.plaf.LabelUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.accessibility.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * A display area for a short text string or an image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * or both.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * A label does not react to input events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * As a result, it cannot get the keyboard focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * A label can, however, display a keyboard alternative
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * as a convenience for a nearby component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * that has a keyboard alternative but can't display it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * A <code>JLabel</code> object can display
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * either text, an image, or both.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * You can specify where in the label's display area
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * the label's contents are aligned
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * by setting the vertical and horizontal alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * By default, labels are vertically centered
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * in their display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Text-only labels are leading edge aligned, by default;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * image-only labels are horizontally centered, by default.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * You can also specify the position of the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * relative to the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * By default, text is on the trailing edge of the image,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * with the text and image vertically aligned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * A label's leading and trailing edge are determined from the value of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * {@link java.awt.ComponentOrientation} property.  At present, the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * ComponentOrientation setting maps the leading edge to left and the trailing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * edge to right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * Finally, you can use the <code>setIconTextGap</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * to specify how many pixels
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * should appear between the text and the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * The default is 4 pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * <p>
20455
f6f9a0c2796b 8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents: 19360
diff changeset
    78
 * See <a href="http://docs.oracle.com/javase/tutorial/uiswing/components/label.html">How to Use Labels</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * in <em>The Java Tutorial</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * for further documentation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <strong>Warning:</strong> Swing is not thread safe. For more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * information see <a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * href="package-summary.html#threading">Swing's Threading
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Policy</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
    92
 * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @author Hans Muller
25201
4adc75e0c4e5 8046485: Add missing @since tag under javax.swing.*
henryjen
parents: 22574
diff changeset
    97
 * @since 1.2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
    99
@JavaBean(defaultProperty = "UI", description = "A component that displays a short string and an icon.")
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   100
@SwingContainer(false)
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
   101
@SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
public class JLabel extends JComponent implements SwingConstants, Accessible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see #getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #readObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private static final String uiClassID = "LabelUI";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    private int mnemonic = '\0';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private int mnemonicIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private String text = "";         // "" rather than null, for BeanBox
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private Icon defaultIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    private Icon disabledIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    private boolean disabledIconSet = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private int verticalAlignment = CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    private int horizontalAlignment = LEADING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private int verticalTextPosition = CENTER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    private int horizontalTextPosition = TRAILING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    private int iconTextGap = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   124
    /**
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   125
     * The Component this label is for; null if the label
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   126
     * is not the label for a component
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   127
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    protected Component labelFor = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Client property key used to determine what label is labeling the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * component.  This is generally not used by labels, but is instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * used by components such as text areas that are being labeled by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * labels.  When the labelFor property of a label is set, it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * automatically set the LABELED_BY_PROPERTY of the component being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * labelled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @see #setLabelFor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    static final String LABELED_BY_PROPERTY = "labeledBy";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Creates a <code>JLabel</code> instance with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * text, image, and horizontal alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * The label is centered vertically in its display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * The text is on the trailing edge of the image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param text  The text to be displayed by the label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @param icon  The image to be displayed by the label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param horizontalAlignment  One of the following constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *           defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *           <code>LEFT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *           <code>CENTER</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *           <code>RIGHT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *           <code>LEADING</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *           <code>TRAILING</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public JLabel(String text, Icon icon, int horizontalAlignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        setIcon(icon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        setHorizontalAlignment(horizontalAlignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        updateUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        setAlignmentX(LEFT_ALIGNMENT);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * Creates a <code>JLabel</code> instance with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * text and horizontal alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * The label is centered vertically in its display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param text  The text to be displayed by the label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @param horizontalAlignment  One of the following constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *           defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *           <code>LEFT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *           <code>CENTER</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *           <code>RIGHT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *           <code>LEADING</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *           <code>TRAILING</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public JLabel(String text, int horizontalAlignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        this(text, null, horizontalAlignment);
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
     * Creates a <code>JLabel</code> instance with the specified text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * The label is aligned against the leading edge of its display area,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * and centered vertically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param text  The text to be displayed by the label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    public JLabel(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        this(text, null, LEADING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * Creates a <code>JLabel</code> instance with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * image and horizontal alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * The label is centered vertically in its display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param image  The image to be displayed by the label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param horizontalAlignment  One of the following constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *           defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *           <code>LEFT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *           <code>CENTER</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *           <code>RIGHT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *           <code>LEADING</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *           <code>TRAILING</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public JLabel(Icon image, int horizontalAlignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        this(null, image, horizontalAlignment);
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
     * Creates a <code>JLabel</code> instance with the specified image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * The label is centered vertically and horizontally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * in its display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @param image  The image to be displayed by the label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public JLabel(Icon image) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        this(null, image, CENTER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Creates a <code>JLabel</code> instance with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * no image and with an empty string for the title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * The label is centered vertically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * in its display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * The label's contents, once set, will be displayed on the leading edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * of the label's display area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public JLabel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        this("", null, LEADING);
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
    /**
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   238
     * Returns the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @return LabelUI object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public LabelUI getUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return (LabelUI)ui;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    /**
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   248
     * Sets the L&amp;F object that renders this component.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   250
     * @param ui  the LabelUI L&amp;F object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   253
    @BeanProperty(hidden = true, visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   254
            = "The UI object that implements the Component's LookAndFeel.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public void setUI(LabelUI ui) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        super.setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        // disabled icon is generated by LF so it should be unset here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (!disabledIconSet && disabledIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            setDisabledIcon(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * Resets the UI property to a value from the current look and feel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * @see JComponent#updateUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    public void updateUI() {
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   270
        setUI((LabelUI) UIManager.getUI(this));
2
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
    /**
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   275
     * Returns a string that specifies the name of the l&amp;f class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * that renders this component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * @return String "LabelUI"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @see JComponent#getUIClassID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @see UIDefaults#getUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   283
    @BeanProperty(bound = false)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public String getUIClassID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        return uiClassID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Returns the text string that the label displays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @return a String
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @see #setText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public String getText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        return text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Defines the single line of text this component will display.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * the value of text is null or empty string, nothing is displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * The default value of this property is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * This is a JavaBeans bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   308
     * @param text  the single line of text this component will display
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @see #setVerticalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @see #setHorizontalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @see #setIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   313
    @BeanProperty(preferred = true, visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   314
            = "Defines the single line of text this component will display.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public void setText(String text) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        String oldAccessibleName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (accessibleContext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            oldAccessibleName = accessibleContext.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        String oldValue = this.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        this.text = text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        firePropertyChange("text", oldValue, text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        setDisplayedMnemonicIndex(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                      SwingUtilities.findDisplayedMnemonicIndex(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                                          text, getDisplayedMnemonic()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        if ((accessibleContext != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            && (accessibleContext.getAccessibleName() != oldAccessibleName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                        AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                        oldAccessibleName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                        accessibleContext.getAccessibleName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (text == null || oldValue == null || !text.equals(oldValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Returns the graphic image (glyph, icon) that the label displays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return an Icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @see #setIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    public Icon getIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        return defaultIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Defines the icon this component will display.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * the value of icon is null, nothing is displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * The default value of this property is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * This is a JavaBeans bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   362
     * @param icon  the default icon this component will display
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @see #setVerticalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @see #setHorizontalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @see #getIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   367
    @BeanProperty(preferred = true, visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   368
            = "The icon this component will display.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    public void setIcon(Icon icon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        Icon oldValue = defaultIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        defaultIcon = icon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        /* If the default icon has really changed and we had
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
         * generated the disabled icon for this component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
         * (in other words, setDisabledIcon() was never called), then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
         * clear the disabledIcon field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if ((defaultIcon != oldValue) && !disabledIconSet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            disabledIcon = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        firePropertyChange("icon", oldValue, defaultIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if ((accessibleContext != null) && (oldValue != defaultIcon)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                accessibleContext.firePropertyChange(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                        AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                        oldValue, defaultIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        /* If the default icon has changed and the new one is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         * a different size, then revalidate.   Repaint if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         * default icon has changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (defaultIcon != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            if ((defaultIcon == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                (oldValue == null) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                (defaultIcon.getIconWidth() != oldValue.getIconWidth()) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                (defaultIcon.getIconHeight() != oldValue.getIconHeight())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Returns the icon used by the label when it's disabled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * If no disabled icon has been set this will forward the call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * the look and feel to construct an appropriate disabled Icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Some look and feels might not render the disabled Icon, in which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * case they will ignore this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @return the <code>disabledIcon</code> property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @see #setDisabledIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @see javax.swing.LookAndFeel#getDisabledIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @see ImageIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     */
466
6acd5ec503a8 4935607: RFE: LTP: Should be possible to set the TRANSIENT attribute of propertiies to FALSE
malenkov
parents: 2
diff changeset
   419
    @Transient
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public Icon getDisabledIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        if (!disabledIconSet && disabledIcon == null && defaultIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, defaultIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            if (disabledIcon != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                firePropertyChange("disabledIcon", null, disabledIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        return disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Set the icon to be displayed if this JLabel is "disabled"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * (JLabel.setEnabled(false)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * The default value of this property is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * @param disabledIcon the Icon to display when the component is disabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @see #getDisabledIcon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @see #setEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   441
    @BeanProperty(visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   442
            = "The icon to display if the label is disabled.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    public void setDisabledIcon(Icon disabledIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        Icon oldValue = this.disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        this.disabledIcon = disabledIcon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        disabledIconSet = (disabledIcon != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        firePropertyChange("disabledIcon", oldValue, disabledIcon);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        if (disabledIcon != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            if (disabledIcon == null || oldValue == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                disabledIcon.getIconWidth() != oldValue.getIconWidth() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                disabledIcon.getIconHeight() != oldValue.getIconHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if (!isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * Specify a keycode that indicates a mnemonic key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * This property is used when the label is part of a larger component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * If the labelFor property of the label is not null, the label will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * call the requestFocus method of the component specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * labelFor property when the mnemonic is activated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   468
     * @param key  a keycode that indicates a mnemonic key
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @see #getLabelFor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @see #setLabelFor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   472
    @BeanProperty(visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   473
            = "The mnemonic keycode.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public void setDisplayedMnemonic(int key) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        int oldKey = mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        mnemonic = key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        firePropertyChange("displayedMnemonic", oldKey, mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        setDisplayedMnemonicIndex(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            SwingUtilities.findDisplayedMnemonicIndex(getText(), mnemonic));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        if (key != oldKey) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Specifies the displayedMnemonic as a char value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @param aChar  a char specifying the mnemonic to display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @see #setDisplayedMnemonic(int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    public void setDisplayedMnemonic(char aChar) {
2473
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 466
diff changeset
   496
        int vk = java.awt.event.KeyEvent.getExtendedKeyCodeForChar(aChar);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 466
diff changeset
   497
        if (vk != java.awt.event.KeyEvent.VK_UNDEFINED) {
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 466
diff changeset
   498
            setDisplayedMnemonic(vk);
3f4bbd3be2f1 6680988: KeyEvent is still missing VK values for many keyboards
yan
parents: 466
diff changeset
   499
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Return the keycode that indicates a mnemonic key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * This property is used when the label is part of a larger component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * If the labelFor property of the label is not null, the label will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * call the requestFocus method of the component specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * labelFor property when the mnemonic is activated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @return int value for the mnemonic key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * @see #getLabelFor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @see #setLabelFor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    public int getDisplayedMnemonic() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * Provides a hint to the look and feel as to which character in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * text should be decorated to represent the mnemonic. Not all look and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * feels may support this. A value of -1 indicates either there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * mnemonic, the mnemonic character is not contained in the string, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * the developer does not wish the mnemonic to be displayed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * The value of this is updated as the properties relating to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * mnemonic change (such as the mnemonic itself, the text...).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * You should only ever have to call this if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * you do not wish the default character to be underlined. For example, if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * the text was 'Save As', with a mnemonic of 'a', and you wanted the 'A'
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * to be decorated, as 'Save <u>A</u>s', you would have to invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * <code>setDisplayedMnemonicIndex(5)</code> after invoking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <code>setDisplayedMnemonic(KeyEvent.VK_A)</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @param index Index into the String to underline
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   537
     * @exception IllegalArgumentException will be thrown if <code>index</code>
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
   538
     *            is &gt;= length of the text, or &lt; -1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   540
    @BeanProperty(visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   541
            = "the index into the String to draw the keyboard character mnemonic at")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public void setDisplayedMnemonicIndex(int index)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                             throws IllegalArgumentException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        int oldValue = mnemonicIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        if (index == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            mnemonicIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            String text = getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            int textLength = (text == null) ? 0 : text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            if (index < -1 || index >= textLength) {  // index out of range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                throw new IllegalArgumentException("index == " + index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        mnemonicIndex = index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        firePropertyChange("displayedMnemonicIndex", oldValue, index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        if (index != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Returns the character, as an index, that the look and feel should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     * provide decoration for as representing the mnemonic character.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @return index representing mnemonic character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * @see #setDisplayedMnemonicIndex
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    public int getDisplayedMnemonicIndex() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        return mnemonicIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Verify that key is a legal value for the horizontalAlignment properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @param key the property value to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @param message the IllegalArgumentException detail message
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   579
     * @return the key value if {@code key} is a a legal value for the
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   580
     *         horizontalAlignment properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @exception IllegalArgumentException if key isn't LEFT, CENTER, RIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * LEADING or TRAILING.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * @see #setHorizontalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @see #setHorizontalAlignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    protected int checkHorizontalKey(int key, String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if ((key == LEFT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            (key == CENTER) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            (key == RIGHT) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            (key == LEADING) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            (key == TRAILING)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            throw new IllegalArgumentException(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Verify that key is a legal value for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * verticalAlignment or verticalTextPosition properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * @param key the property value to check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @param message the IllegalArgumentException detail message
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   606
     * @return the key value if {@code key} is a legal value for the
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   607
     *         verticalAlignment or verticalTextPosition properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * @exception IllegalArgumentException if key isn't TOP, CENTER, or BOTTOM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @see #setVerticalAlignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * @see #setVerticalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    protected int checkVerticalKey(int key, String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        if ((key == TOP) || (key == CENTER) || (key == BOTTOM)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            return key;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            throw new IllegalArgumentException(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * Returns the amount of space between the text and the icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * displayed in this label.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @return an int equal to the number of pixels between the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *         and the icon.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * @see #setIconTextGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    public int getIconTextGap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return iconTextGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * If both the icon and text properties are set, this property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * defines the space between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * The default value of this property is 4 pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     * This is a JavaBeans bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *
25760
7955db32d6b0 8046597: fix doclint issues in swing classes, part 4 of 4
ssides
parents: 25201
diff changeset
   643
     * @param iconTextGap  the space between the icon and text properties
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @see #getIconTextGap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   646
    @BeanProperty(visualUpdate = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   647
            = "If both the icon and text properties are set, this property defines the space between them.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public void setIconTextGap(int iconTextGap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        int oldValue = this.iconTextGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        this.iconTextGap = iconTextGap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        firePropertyChange("iconTextGap", oldValue, iconTextGap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (iconTextGap != oldValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * Returns the alignment of the label's contents along the Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * @return   The value of the verticalAlignment property, one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *           following constants defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *           <code>TOP</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *           <code>CENTER</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *           <code>BOTTOM</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * @see SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * @see #setVerticalAlignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    public int getVerticalAlignment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        return verticalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * Sets the alignment of the label's contents along the Y axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * The default value of this property is CENTER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @param alignment One of the following constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     *           defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *           <code>TOP</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     *           <code>CENTER</code> (the default), or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     *           <code>BOTTOM</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @see SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @see #getVerticalAlignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   691
    @BeanProperty(visualUpdate = true, enumerationValues = {
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   692
            "SwingConstants.TOP",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   693
            "SwingConstants.CENTER",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   694
            "SwingConstants.BOTTOM"},
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   695
            description = "The alignment of the label's contents along the Y axis.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    public void setVerticalAlignment(int alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        if (alignment == verticalAlignment) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        int oldValue = verticalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        verticalAlignment = checkVerticalKey(alignment, "verticalAlignment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        firePropertyChange("verticalAlignment", oldValue, verticalAlignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Returns the alignment of the label's contents along the X axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @return   The value of the horizontalAlignment property, one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *           following constants defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *           <code>LEFT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *           <code>CENTER</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *           <code>RIGHT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *           <code>LEADING</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     *           <code>TRAILING</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @see #setHorizontalAlignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @see SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    public int getHorizontalAlignment() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        return horizontalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * Sets the alignment of the label's contents along the X axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * This is a JavaBeans bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @param alignment  One of the following constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     *           defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *           <code>LEFT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     *           <code>CENTER</code> (the default for image-only labels),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     *           <code>RIGHT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *           <code>LEADING</code> (the default for text-only labels) or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     *           <code>TRAILING</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * @see SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @see #getHorizontalAlignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   739
    @BeanProperty(visualUpdate = true, enumerationValues = {
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   740
            "SwingConstants.LEFT",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   741
            "SwingConstants.CENTER",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   742
            "SwingConstants.RIGHT",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   743
            "SwingConstants.LEADING",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   744
            "SwingConstants.TRAILING"}, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   745
            = "The alignment of the label's content along the X axis.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    public void setHorizontalAlignment(int alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        if (alignment == horizontalAlignment) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        int oldValue = horizontalAlignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        horizontalAlignment = checkHorizontalKey(alignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                                                 "horizontalAlignment");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        firePropertyChange("horizontalAlignment",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                           oldValue, horizontalAlignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * Returns the vertical position of the label's text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * relative to its image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @return   One of the following constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     *           defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     *           <code>TOP</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     *           <code>CENTER</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     *           <code>BOTTOM</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * @see #setVerticalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * @see SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    public int getVerticalTextPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        return verticalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * Sets the vertical position of the label's text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * relative to its image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * The default value of this property is CENTER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * This is a JavaBeans bound property.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * @param textPosition  One of the following constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *           defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *           <code>TOP</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     *           <code>CENTER</code> (the default), or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     *           <code>BOTTOM</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @see SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * @see #getVerticalTextPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   792
    @BeanProperty(expert = true, visualUpdate = true, enumerationValues = {
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   793
            "SwingConstants.TOP",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   794
            "SwingConstants.CENTER",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   795
            "SwingConstants.BOTTOM"},
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   796
            description = "The vertical position of the text relative to it's image.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    public void setVerticalTextPosition(int textPosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        if (textPosition == verticalTextPosition) return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        int old = verticalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        verticalTextPosition = checkVerticalKey(textPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
                                                "verticalTextPosition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        firePropertyChange("verticalTextPosition", old, verticalTextPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * Returns the horizontal position of the label's text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * relative to its image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @return   One of the following constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *           defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     *           <code>LEFT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     *           <code>CENTER</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     *           <code>RIGHT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     *           <code>LEADING</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     *           <code>TRAILING</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * @see SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    public int getHorizontalTextPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
        return horizontalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * Sets the horizontal position of the label's text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * relative to its image.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @param textPosition  One of the following constants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *           defined in <code>SwingConstants</code>:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     *           <code>LEFT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     *           <code>CENTER</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     *           <code>RIGHT</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     *           <code>LEADING</code>, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     *           <code>TRAILING</code> (the default).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * @see SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   841
    @BeanProperty(expert = true, visualUpdate = true, enumerationValues = {
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   842
            "SwingConstants.LEFT",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   843
            "SwingConstants.CENTER",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   844
            "SwingConstants.RIGHT",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   845
            "SwingConstants.LEADING",
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   846
            "SwingConstants.TRAILING"}, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
   847
            = "The horizontal position of the label's text, relative to its image.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
    public void setHorizontalTextPosition(int textPosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        int old = horizontalTextPosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        this.horizontalTextPosition = checkHorizontalKey(textPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                                                "horizontalTextPosition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        firePropertyChange("horizontalTextPosition",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
                           old, horizontalTextPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
        revalidate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * This is overridden to return false if the current Icon's Image is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * not equal to the passed in Image <code>img</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * @see     java.awt.image.ImageObserver
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * @see     java.awt.Component#imageUpdate(java.awt.Image, int, int, int, int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
    public boolean imageUpdate(Image img, int infoflags,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                               int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        // Don't use getDisabledIcon, will trigger creation of icon if icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        // not set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        if (!isShowing() ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            !SwingUtilities.doesIconReferenceImage(getIcon(), img) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            !SwingUtilities.doesIconReferenceImage(disabledIcon, img)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
        return super.imageUpdate(img, infoflags, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * See readObject() and writeObject() in JComponent for more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * information about serialization in Swing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
    private void writeObject(ObjectOutputStream s) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        if (getUIClassID().equals(uiClassID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            byte count = JComponent.getWriteObjCounter(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            JComponent.setWriteObjCounter(this, --count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
            if (count == 0 && ui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
                ui.installUI(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * Returns a string representation of this JLabel. This method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * is intended to be used only for debugging purposes, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     * content and format of the returned string may vary between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     * implementations. The returned string may be empty but may not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     * be <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * @return  a string representation of this JLabel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    protected String paramString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        String textString = (text != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
                             text : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        String defaultIconString = ((defaultIcon != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
                                    && (defaultIcon != this)  ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                                    defaultIcon.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        String disabledIconString = ((disabledIcon != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                                     && (disabledIcon != this) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
                                     disabledIcon.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        String labelForString = (labelFor  != null ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
                                 labelFor.toString() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        String verticalAlignmentString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        if (verticalAlignment == TOP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            verticalAlignmentString = "TOP";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
        } else if (verticalAlignment == CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            verticalAlignmentString = "CENTER";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
        } else if (verticalAlignment == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            verticalAlignmentString = "BOTTOM";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
        } else verticalAlignmentString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        String horizontalAlignmentString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        if (horizontalAlignment == LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            horizontalAlignmentString = "LEFT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        } else if (horizontalAlignment == CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            horizontalAlignmentString = "CENTER";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        } else if (horizontalAlignment == RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            horizontalAlignmentString = "RIGHT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
        } else if (horizontalAlignment == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            horizontalAlignmentString = "LEADING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        } else if (horizontalAlignment == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            horizontalAlignmentString = "TRAILING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
        } else horizontalAlignmentString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        String verticalTextPositionString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        if (verticalTextPosition == TOP) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            verticalTextPositionString = "TOP";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        } else if (verticalTextPosition == CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            verticalTextPositionString = "CENTER";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        } else if (verticalTextPosition == BOTTOM) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            verticalTextPositionString = "BOTTOM";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        } else verticalTextPositionString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        String horizontalTextPositionString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        if (horizontalTextPosition == LEFT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            horizontalTextPositionString = "LEFT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        } else if (horizontalTextPosition == CENTER) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            horizontalTextPositionString = "CENTER";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        } else if (horizontalTextPosition == RIGHT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            horizontalTextPositionString = "RIGHT";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
        } else if (horizontalTextPosition == LEADING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            horizontalTextPositionString = "LEADING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        } else if (horizontalTextPosition == TRAILING) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            horizontalTextPositionString = "TRAILING";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        } else horizontalTextPositionString = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        return super.paramString() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        ",defaultIcon=" + defaultIconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        ",disabledIcon=" + disabledIconString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        ",horizontalAlignment=" + horizontalAlignmentString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
        ",horizontalTextPosition=" + horizontalTextPositionString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        ",iconTextGap=" + iconTextGap +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        ",labelFor=" + labelForString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        ",text=" + textString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        ",verticalAlignment=" + verticalAlignmentString +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        ",verticalTextPosition=" + verticalTextPositionString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * --- Accessibility Support ---
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * Get the component this is labelling.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * @return the Component this is labelling.  Can be null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * does not label a Component.  If the displayedMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * property is set and the labelFor property is also set, the label
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * will call the requestFocus method of the component specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * labelFor property when the mnemonic is activated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * @see #getDisplayedMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @see #setDisplayedMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    public Component getLabelFor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        return labelFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * Set the component this is labelling.  Can be null if this does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     * label a Component.  If the displayedMnemonic property is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * and the labelFor property is also set, the label will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * call the requestFocus method of the component specified by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * labelFor property when the mnemonic is activated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * @param c  the Component this label is for, or null if the label is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     *           not the label for a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * @see #getDisplayedMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * @see #setDisplayedMnemonic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
  1002
    @BeanProperty(description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
  1003
            = "The component this is labelling.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
    public void setLabelFor(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        Component oldC = labelFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
        labelFor = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        firePropertyChange("labelFor", oldC, c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        if (oldC instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            ((JComponent)oldC).putClientProperty(LABELED_BY_PROPERTY, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        if (c instanceof JComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            ((JComponent)c).putClientProperty(LABELED_BY_PROPERTY, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * Get the AccessibleContext of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @return the AccessibleContext of this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     */
33253
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
  1022
    @BeanProperty(bound = false, expert = true, description
78e735319356 4763438: Replace uses of @beaninfo with meta facility in core j2se
serb
parents: 25859
diff changeset
  1023
            = "The AccessibleContext associated with this Label.")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    public AccessibleContext getAccessibleContext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        if (accessibleContext == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            accessibleContext = new AccessibleJLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        return accessibleContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * The class used to obtain the accessible role for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * the same version of Swing.  As of 1.4, support for long term storage
20458
f2423fb3fd19 8025840: Fix all the doclint warnings about trademark
cl
parents: 20455
diff changeset
  1039
     * of all JavaBeans&trade;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     */
11268
f0e59c4852de 7116950: Reduce number of warnings in swing
alexsch
parents: 5506
diff changeset
  1043
    @SuppressWarnings("serial")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    protected class AccessibleJLabel extends AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        implements AccessibleText, AccessibleExtendedComponent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
         * Get the accessible name of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         * @return the localized name of the object -- can be null if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
         * object does not have a name
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
         * @see AccessibleContext#setAccessibleName
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        public String getAccessibleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            String name = accessibleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                name = (String)getClientProperty(AccessibleContext.ACCESSIBLE_NAME_PROPERTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                name = JLabel.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            if (name == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                name = super.getAccessibleName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            return name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
         * Get the role of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
         * @return an instance of AccessibleRole describing the role of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
         * object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
         * @see AccessibleRole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
        public AccessibleRole getAccessibleRole() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            return AccessibleRole.LABEL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
         * Get the AccessibleIcons associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
         * or more exist.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        public AccessibleIcon [] getAccessibleIcon() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            Icon icon = getIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            if (icon instanceof Accessible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                AccessibleContext ac =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                ((Accessible)icon).getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                if (ac != null && ac instanceof AccessibleIcon) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                    return new AccessibleIcon[] { (AccessibleIcon)ac };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
         * Get the AccessibleRelationSet associated with this object if one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
         * exists.  Otherwise return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
         * @see AccessibleRelation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        public AccessibleRelationSet getAccessibleRelationSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            // Check where the AccessibleContext's relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            // set already contains a LABEL_FOR relation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            AccessibleRelationSet relationSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
                = super.getAccessibleRelationSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            if (!relationSet.contains(AccessibleRelation.LABEL_FOR)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                Component c = JLabel.this.getLabelFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                    AccessibleRelation relation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                        = new AccessibleRelation(AccessibleRelation.LABEL_FOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                    relation.setTarget(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                    relationSet.add(relation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            return relationSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        /* AccessibleText ---------- */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        public AccessibleText getAccessibleText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            View view = (View)JLabel.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
         * Given a point in local coordinates, return the zero-based index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
         * of the character under that Point.  If the point is invalid,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
         * this method returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
         * @param p the Point in local coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
         * @return the zero-based index of the character under Point p; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
         * Point is invalid returns -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        public int getIndexAtPoint(Point p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            View view = (View) JLabel.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                Rectangle r = getTextRectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                Rectangle2D.Float shape =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                    new Rectangle2D.Float(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                Position.Bias bias[] = new Position.Bias[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                return view.viewToModel(p.x, p.y, shape, bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        /**
19360
0fd3028166c5 7121409: Two conformance tests for AccessibleText.getCharacterBounds(int i) fail
alexsch
parents: 11268
diff changeset
  1160
         * Returns the bounding box of the character at the given
0fd3028166c5 7121409: Two conformance tests for AccessibleText.getCharacterBounds(int i) fail
alexsch
parents: 11268
diff changeset
  1161
         * index in the string.  The bounds are returned in local
0fd3028166c5 7121409: Two conformance tests for AccessibleText.getCharacterBounds(int i) fail
alexsch
parents: 11268
diff changeset
  1162
         * coordinates. If the index is invalid, <code>null</code> is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
         * @param i the index into the String
19360
0fd3028166c5 7121409: Two conformance tests for AccessibleText.getCharacterBounds(int i) fail
alexsch
parents: 11268
diff changeset
  1165
         * @return the screen coordinates of the character's bounding box.
0fd3028166c5 7121409: Two conformance tests for AccessibleText.getCharacterBounds(int i) fail
alexsch
parents: 11268
diff changeset
  1166
         * If the index is invalid, <code>null</code> is returned.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        public Rectangle getCharacterBounds(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
            View view = (View) JLabel.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                Rectangle r = getTextRectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                Rectangle2D.Float shape =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                    new Rectangle2D.Float(r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                    Shape charShape =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                        view.modelToView(i, shape, Position.Bias.Forward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    return charShape.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
         * Return the number of characters (valid indicies)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
         * @return the number of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        public int getCharCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            View view = (View) JLabel.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                Document d = view.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                if (d instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                    StyledDocument doc = (StyledDocument)d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                    return doc.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            return accessibleContext.getAccessibleName().length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
         * Return the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
         * Note: That to the right of the caret will have the same index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
         * value as the offset (the caret is between two characters).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
         * @return the zero-based offset of the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
        public int getCaretPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            // There is no caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
         * Returns the String at a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
         * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
         * or AccessibleText.SENTENCE to retrieve
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
  1226
         * @param index an index within the text &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
         * @return the letter, word, or sentence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
         *   null for an invalid index or part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
        public String getAtIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            if (index < 0 || index >= getCharCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
            switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                    return getText(index, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            case AccessibleText.WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                    BreakIterator words = BreakIterator.getWordInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                    words.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                    int end = words.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                    return s.substring(words.previous(), end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            case AccessibleText.SENTENCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    BreakIterator sentence =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                        BreakIterator.getSentenceInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                    sentence.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                    int end = sentence.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                    return s.substring(sentence.previous(), end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
         * Returns the String after a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
         * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
         * or AccessibleText.SENTENCE to retrieve
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
  1273
         * @param index an index within the text &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
         * @return the letter, word, or sentence, null for an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
         *  index or part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        public String getAfterIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            if (index < 0 || index >= getCharCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                if (index+1 >= getCharCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                   return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                    return getText(index+1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            case AccessibleText.WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                    BreakIterator words = BreakIterator.getWordInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                    words.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                    int start = words.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                    if (start == BreakIterator.DONE || start >= s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    int end = words.following(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                    if (end == BreakIterator.DONE || end >= s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
            case AccessibleText.SENTENCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                    BreakIterator sentence =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                        BreakIterator.getSentenceInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                    sentence.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                    int start = sentence.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                    if (start == BreakIterator.DONE || start > s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                    int end = sentence.following(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                    if (end == BreakIterator.DONE || end > s.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
         * Returns the String before a given index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
         * @param part the AccessibleText.CHARACTER, AccessibleText.WORD,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
         *   or AccessibleText.SENTENCE to retrieve
21592
da6abe91602a 8025234: [javadoc] fix some errors in javax.swing.**
yan
parents: 21278
diff changeset
  1337
         * @param index an index within the text &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
         * @return the letter, word, or sentence, null for an invalid index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
         *  or part
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        public String getBeforeIndex(int part, int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            if (index < 0 || index > getCharCount()-1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
            switch (part) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            case AccessibleText.CHARACTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                if (index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                    return getText(index-1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
            case AccessibleText.WORD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                    BreakIterator words = BreakIterator.getWordInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
                    words.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                    int end = words.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                    end = words.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                    int start = words.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                    if (start == BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            case AccessibleText.SENTENCE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                    String s = getText(0, getCharCount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                    BreakIterator sentence =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                        BreakIterator.getSentenceInstance(getLocale());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                    sentence.setText(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
                    int end = sentence.following(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
                    end = sentence.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
                    int start = sentence.previous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
                    if (start == BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                    return s.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                } catch (BadLocationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
         * Return the AttributeSet for a given character at a given index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
         * @param i the zero-based index into the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
         * @return the AttributeSet of the character
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        public AttributeSet getCharacterAttribute(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            View view = (View) JLabel.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                Document d = view.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                if (d instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                    StyledDocument doc = (StyledDocument)d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                    Element elem = doc.getCharacterElement(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                    if (elem != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                        return elem.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
         * Returns the start offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
         * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
         * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
         * @return the index into the text of the start of the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
        public int getSelectionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            // Text cannot be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
         * Returns the end offset within the selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
         * If there is no selection, but there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
         * a caret, the start and end offsets will be the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
         *
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20458
diff changeset
  1432
         * @return the index into the text of the end of the selection
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        public int getSelectionEnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            // Text cannot be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
         * Returns the portion of the text that is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
         * @return the String portion of the text that is selected
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
         * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
        public String getSelectedText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            // Text cannot be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
         * Returns the text substring starting at the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
         * offset with the specified length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
        private String getText(int offset, int length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            View view = (View) JLabel.this.getClientProperty("html");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            if (view != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                Document d = view.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                if (d instanceof StyledDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                    StyledDocument doc = (StyledDocument)d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                    return doc.getText(offset, length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
         * Returns the bounding rectangle for the component text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        private Rectangle getTextRectangle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            String text = JLabel.this.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            Icon icon = (JLabel.this.isEnabled()) ? JLabel.this.getIcon() : JLabel.this.getDisabledIcon();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            if ((icon == null) && (text == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            Rectangle paintIconR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            Rectangle paintTextR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            Rectangle paintViewR = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            Insets paintViewInsets = new Insets(0, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            paintViewInsets = JLabel.this.getInsets(paintViewInsets);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            paintViewR.x = paintViewInsets.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            paintViewR.y = paintViewInsets.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            paintViewR.width = JLabel.this.getWidth() - (paintViewInsets.left + paintViewInsets.right);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            paintViewR.height = JLabel.this.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            String clippedText = SwingUtilities.layoutCompoundLabel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                (JComponent)JLabel.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                getFontMetrics(getFont()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                icon,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                JLabel.this.getVerticalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                JLabel.this.getHorizontalAlignment(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                JLabel.this.getVerticalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                JLabel.this.getHorizontalTextPosition(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                paintViewR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                paintIconR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                paintTextR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                JLabel.this.getIconTextGap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
            return paintTextR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
        // ----- AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
         * Returns the AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
         * @return the AccessibleExtendedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        AccessibleExtendedComponent getAccessibleExtendedComponent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
         * Returns the tool tip text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
         * @return the tool tip text, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
        public String getToolTipText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
            return JLabel.this.getToolTipText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
         * Returns the titled border text
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
         * @return the titled border text, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
        public String getTitledBorderText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            return super.getTitledBorderText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
         * Returns key bindings associated with this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
         * @return the key bindings, if supported, of the object;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
         * otherwise, null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
         * @see AccessibleKeyBinding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
         * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
        public AccessibleKeyBinding getAccessibleKeyBinding() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
            int mnemonic = JLabel.this.getDisplayedMnemonic();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
            if (mnemonic == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
            return new LabelKeyBinding(mnemonic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
        class LabelKeyBinding implements AccessibleKeyBinding {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
            int mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
            LabelKeyBinding(int mnemonic) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
                this.mnemonic = mnemonic;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
             * Returns the number of key bindings for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
             * @return the zero-based number of key bindings for this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            public int getAccessibleKeyBindingCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
                return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
             * Returns a key binding for this object.  The value returned is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
             * java.lang.Object which must be cast to appropriate type depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
             * on the underlying implementation of the key.  For example, if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
             * Object returned is a javax.swing.KeyStroke, the user of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
             * method should do the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
             * <nf><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
             * Component c = <get the component that has the key bindings>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
             * AccessibleContext ac = c.getAccessibleContext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
             * AccessibleKeyBinding akb = ac.getAccessibleKeyBinding();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
             * for (int i = 0; i < akb.getAccessibleKeyBindingCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
             *     Object o = akb.getAccessibleKeyBinding(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
             *     if (o instanceof javax.swing.KeyStroke) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
             *         javax.swing.KeyStroke keyStroke = (javax.swing.KeyStroke)o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
             *         <do something with the key binding>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
             *     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
             * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
             * </code></nf>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
             *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
             * @param i zero-based index of the key bindings
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
             * @return a javax.lang.Object which specifies the key binding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
             * @exception IllegalArgumentException if the index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
             * out of bounds
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
             * @see #getAccessibleKeyBindingCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
            public java.lang.Object getAccessibleKeyBinding(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                if (i != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                    throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                return KeyStroke.getKeyStroke(mnemonic, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
    }  // AccessibleJComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
}