jdk/src/share/classes/javax/swing/border/TitledBorder.java
author malenkov
Thu, 01 Jul 2010 18:09:45 +0400
changeset 5953 33ad0303d717
parent 5506 202f599c92aa
child 7263 3da4189127ac
permissions -rw-r--r--
4129681: Cannot get a title border to display its label as disabled Reviewed-by: alexp, rupashka
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2010, 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: 2658
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: 2658
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: 2658
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2658
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    27
import java.awt.Color;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    28
import java.awt.Component;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    29
import java.awt.Dimension;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    30
import java.awt.Font;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Graphics;
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    32
import java.awt.Graphics2D;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Rectangle;
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    35
import java.awt.geom.Path2D;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.beans.ConstructorProperties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.JComponent;
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    38
import javax.swing.JLabel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.UIManager;
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    40
import javax.swing.plaf.basic.BasicHTML;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * A class which implements an arbitrary border
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * with the addition of a String title in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * specified position and justification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * If the border, font, or color property values are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * specified in the constuctor or by invoking the appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * set methods, the property values will be defined by the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * look and feel, using the following property names in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Defaults Table:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <li>&quot;TitledBorder.border&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <li>&quot;TitledBorder.font&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <li>&quot;TitledBorder.titleColor&quot;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author David Kloba
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public class TitledBorder extends AbstractBorder
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    protected String title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    protected Border border;
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    74
    protected int titlePosition;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    75
    protected int titleJustification;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    76
    protected Font titleFont;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    77
    protected Color titleColor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    79
    private final JLabel label;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Use the default vertical orientation for the title text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    static public final int     DEFAULT_POSITION        = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /** Position the title above the border's top line. */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    86
    static public final int     ABOVE_TOP               = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    /** Position the title in the middle of the border's top line. */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    88
    static public final int     TOP                     = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /** Position the title below the border's top line. */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    90
    static public final int     BELOW_TOP               = 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /** Position the title above the border's bottom line. */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    92
    static public final int     ABOVE_BOTTOM            = 4;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /** Position the title in the middle of the border's bottom line. */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    94
    static public final int     BOTTOM                  = 5;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /** Position the title below the border's bottom line. */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
    96
    static public final int     BELOW_BOTTOM            = 6;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * Use the default justification for the title text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    static public final int     DEFAULT_JUSTIFICATION   = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /** Position title text at the left side of the border line. */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   103
    static public final int     LEFT                    = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /** Position title text in the center of the border line. */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   105
    static public final int     CENTER                  = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    /** Position title text at the right side of the border line. */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   107
    static public final int     RIGHT                   = 3;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /** Position title text at the left side of the border line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *  for left to right orientation, at the right side of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *  border line for right to left orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    static public final int     LEADING = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /** Position title text at the right side of the border line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *  for left to right orientation, at the left side of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *  border line for right to left orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    static public final int     TRAILING = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    // Space between the border and the component's edge
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    static protected final int EDGE_SPACING = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // Space between the border and text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    static protected final int TEXT_SPACING = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // Horizontal inset of text that is left or right justified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    static protected final int TEXT_INSET_H = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Creates a TitledBorder instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @param title  the title the border should display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   133
    public TitledBorder(String title) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 463
diff changeset
   134
        this(null, title, LEADING, DEFAULT_POSITION, null, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Creates a TitledBorder instance with the specified border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * and an empty title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param border  the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   143
    public TitledBorder(Border border) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 463
diff changeset
   144
        this(border, "", LEADING, DEFAULT_POSITION, null, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * Creates a TitledBorder instance with the specified border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * and title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @param border  the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param title  the title the border should display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public TitledBorder(Border border, String title) {
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 463
diff changeset
   155
        this(border, title, LEADING, DEFAULT_POSITION, null, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * Creates a TitledBorder instance with the specified border,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * title, title-justification, and title-position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @param border  the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * @param title  the title the border should display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @param titleJustification the justification for the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * @param titlePosition the position for the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public TitledBorder(Border border,
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   168
                         String title,
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   169
                         int titleJustification,
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   170
                         int titlePosition) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        this(border, title, titleJustification,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                        titlePosition, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Creates a TitledBorder instance with the specified border,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * title, title-justification, title-position, and title-font.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param border  the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @param title  the title the border should display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param titleJustification the justification for the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param titlePosition the position for the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param titleFont the font for rendering the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public TitledBorder(Border border,
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   186
                         String title,
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   187
                         int titleJustification,
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   188
                         int titlePosition,
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   189
                         Font titleFont) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        this(border, title, titleJustification,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        titlePosition, titleFont, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Creates a TitledBorder instance with the specified border,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * title, title-justification, title-position, title-font, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * title-color.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param border  the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @param title  the title the border should display
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param titleJustification the justification for the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * @param titlePosition the position for the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @param titleFont the font of the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param titleColor the color of the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    @ConstructorProperties({"border", "title", "titleJustification", "titlePosition", "titleFont", "titleColor"})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    public TitledBorder(Border border,
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   208
                         String title,
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   209
                         int titleJustification,
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   210
                         int titlePosition,
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   211
                         Font titleFont,
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   212
                         Color titleColor) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        this.title = title;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        this.border = border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        this.titleFont = titleFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        this.titleColor = titleColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        setTitleJustification(titleJustification);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        setTitlePosition(titlePosition);
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   220
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   221
        this.label = new JLabel();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   222
        this.label.setOpaque(false);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   223
        this.label.putClientProperty(BasicHTML.propertyKey, null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Paints the border for the specified component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * specified position and size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @param c the component for which this border is being painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param g the paint graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @param x the x position of the painted border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param y the y position of the painted border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @param width the width of the painted border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param height the height of the painted border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   237
        Border border = getBorderUI();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   238
        String title = getTitle();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   239
        if ((title != null) && !title.isEmpty()) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   240
            int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   241
            JLabel label = getLabel(c);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   242
            Dimension size = label.getPreferredSize();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   243
            Insets insets = (border != null)
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   244
                    ? border.getBorderInsets(c)
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   245
                    : new Insets(0, 0, 0, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   247
            int borderX = x + edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   248
            int borderY = y + edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   249
            int borderW = width - edge - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   250
            int borderH = height - edge - edge;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   252
            int labelY = y;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   253
            int labelH = size.height;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   254
            int position = getPosition();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   255
            switch (position) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   256
                case ABOVE_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   257
                    insets.left = 0;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   258
                    insets.right = 0;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   259
                    borderY += labelH - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   260
                    borderH -= labelH - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   261
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   262
                case TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   263
                    insets.top = edge + insets.top/2 - labelH/2;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   264
                    if (insets.top < edge) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   265
                        borderY -= insets.top;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   266
                        borderH += insets.top;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   267
                    }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   268
                    else {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   269
                        labelY += insets.top;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   270
                    }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   271
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   272
                case BELOW_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   273
                    labelY += insets.top + edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   274
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   275
                case ABOVE_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   276
                    labelY += height - labelH - insets.bottom - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   277
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   278
                case BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   279
                    labelY += height - labelH;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   280
                    insets.bottom = edge + (insets.bottom - labelH) / 2;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   281
                    if (insets.bottom < edge) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   282
                        borderH += insets.bottom;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   283
                    }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   284
                    else {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   285
                        labelY -= insets.bottom;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   286
                    }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   287
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   288
                case BELOW_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   289
                    insets.left = 0;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   290
                    insets.right = 0;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   291
                    labelY += height - labelH;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   292
                    borderH -= labelH - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   293
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   295
            insets.left += edge + TEXT_INSET_H;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   296
            insets.right += edge + TEXT_INSET_H;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   298
            int labelX = x;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   299
            int labelW = width - insets.left - insets.right;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   300
            if (labelW > size.width) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   301
                labelW = size.width;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   302
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   303
            switch (getJustification(c)) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   304
                case LEFT:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   305
                    labelX += insets.left;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   306
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   307
                case RIGHT:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   308
                    labelX += width - insets.right - labelW;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   309
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   310
                case CENTER:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   311
                    labelX += (width - labelW) / 2;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   312
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   313
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   315
            if (border != null) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   316
                if ((position != TOP) && (position != BOTTOM)) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   317
                    border.paintBorder(c, g, borderX, borderY, borderW, borderH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                }
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   319
                else {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   320
                    Graphics g2 = g.create();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   321
                    if (g2 instanceof Graphics2D) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   322
                        Graphics2D g2d = (Graphics2D) g2;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   323
                        Path2D path = new Path2D.Float();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   324
                        path.append(new Rectangle(borderX, borderY, borderW, labelY - borderY), false);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   325
                        path.append(new Rectangle(borderX, labelY, labelX - borderX - TEXT_SPACING, labelH), false);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   326
                        path.append(new Rectangle(labelX + labelW + TEXT_SPACING, labelY, borderX - labelX + borderW - labelW - TEXT_SPACING, labelH), false);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   327
                        path.append(new Rectangle(borderX, labelY + labelH, borderW, borderY - labelY + borderH - labelH), false);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   328
                        g2d.clip(path);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                    }
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   330
                    border.paintBorder(c, g2, borderX, borderY, borderW, borderH);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   331
                    g2.dispose();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   334
            g.translate(labelX, labelY);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   335
            label.setSize(labelW, labelH);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   336
            label.paint(g);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   337
            g.translate(-labelX, -labelY);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        }
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   339
        else if (border != null) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   340
            border.paintBorder(c, g, x, y, width, height);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   341
        }
2
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
     * Reinitialize the insets parameter with this Border's current Insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * @param c the component for which this border insets value applies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @param insets the object to be reinitialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public Insets getBorderInsets(Component c, Insets insets) {
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   350
        Border border = getBorderUI();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   351
        if (border == null) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   352
            insets.set(0, 0, 0, 0);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   353
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   354
        else if (border instanceof AbstractBorder) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   355
            AbstractBorder ab = (AbstractBorder) border;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   356
            insets = ab.getBorderInsets(c, insets);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   358
        else {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   359
            Insets i = border.getBorderInsets(c);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   360
            insets.set(i.top, i.left, i.bottom, i.right);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   362
        String title = getTitle();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   363
        if ((title != null) && !title.isEmpty()) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   364
            int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   365
            JLabel label = getLabel(c);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   366
            Dimension size = label.getPreferredSize();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   368
            switch (getPosition()) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   369
                case ABOVE_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   370
                    insets.top += size.height - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   371
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   372
                case TOP: {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   373
                    if (insets.top < size.height) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   374
                        insets.top = size.height - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   375
                    }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   376
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   377
                }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   378
                case BELOW_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   379
                    insets.top += size.height;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   380
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   381
                case ABOVE_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   382
                    insets.bottom += size.height;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   383
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   384
                case BOTTOM: {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   385
                    if (insets.bottom < size.height) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   386
                        insets.bottom = size.height - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   387
                    }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   388
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   389
                }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   390
                case BELOW_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   391
                    insets.bottom += size.height - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   392
                    break;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   393
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   394
            insets.top += edge + TEXT_SPACING;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   395
            insets.left += edge + TEXT_SPACING;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   396
            insets.right += edge + TEXT_SPACING;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   397
            insets.bottom += edge + TEXT_SPACING;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Returns whether or not the border is opaque.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    public boolean isBorderOpaque() { return false; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Returns the title of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public String getTitle()        {       return title;   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Returns the border of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   415
    public Border getBorder() {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   416
        return border;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Returns the title-position of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
2658
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 463
diff changeset
   422
    public int getTitlePosition() {
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 463
diff changeset
   423
        return titlePosition;
43e06bc950ec 6591875: Nimbus Swing Look and Feel
peterz
parents: 463
diff changeset
   424
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * Returns the title-justification of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public int getTitleJustification()      {       return titleJustification;      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Returns the title-font of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public Font getTitleFont()      {
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   435
        return titleFont;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Returns the title-color of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public Color getTitleColor()    {
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   442
        return titleColor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    // REMIND(aim): remove all or some of these set methods?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * Sets the title of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * param title the title for the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public void setTitle(String title)      {       this.title = title;     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Sets the border of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @param border the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public void setBorder(Border border)    {       this.border = border;   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * Sets the title-position of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @param titlePosition the position for the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public void setTitlePosition(int titlePosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        switch (titlePosition) {
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   466
            case ABOVE_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   467
            case TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   468
            case BELOW_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   469
            case ABOVE_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   470
            case BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   471
            case BELOW_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   472
            case DEFAULT_POSITION:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                this.titlePosition = titlePosition;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                break;
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   475
            default:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   476
                throw new IllegalArgumentException(titlePosition +
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   477
                        " is not a valid title position.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Sets the title-justification of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param titleJustification the justification for the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    public void setTitleJustification(int titleJustification)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        switch (titleJustification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
          case DEFAULT_JUSTIFICATION:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
          case LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
          case CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
          case RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
          case LEADING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
          case TRAILING:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            this.titleJustification = titleJustification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
          default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            throw new IllegalArgumentException(titleJustification +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                        " is not a valid title justification.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * Sets the title-font of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @param titleFont the font for the border title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    public void setTitleFont(Font titleFont) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        this.titleFont = titleFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * Sets the title-color of the titled border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * @param titleColor the color for the border title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    public void setTitleColor(Color titleColor) {
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   514
        this.titleColor = titleColor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * Returns the minimum dimensions this border requires
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * in order to fully display the border and title.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * @param c the component where this border will be drawn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    public Dimension getMinimumSize(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        Insets insets = getBorderInsets(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        Dimension minSize = new Dimension(insets.right+insets.left,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                                          insets.top+insets.bottom);
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   526
        String title = getTitle();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   527
        if ((title != null) && !title.isEmpty()) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   528
            JLabel label = getLabel(c);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   529
            Dimension size = label.getPreferredSize();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   530
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   531
            int position = getPosition();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   532
            if ((position != ABOVE_TOP) && (position != BELOW_BOTTOM)) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   533
                minSize.width += size.width;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   534
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   535
            else if (minSize.width < size.width) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   536
                minSize.width += size.width;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   537
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        return minSize;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * Returns the baseline.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @throws IllegalArgumentException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    public int getBaseline(Component c, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        if (c == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            throw new NullPointerException("Must supply non-null component");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        }
463
435cd1cc42b6 6625450: javax.swing.border.TitledBorder.getBaseline() doesn't throw IAE when width is < 0
malenkov
parents: 2
diff changeset
   554
        if (width < 0) {
435cd1cc42b6 6625450: javax.swing.border.TitledBorder.getBaseline() doesn't throw IAE when width is < 0
malenkov
parents: 2
diff changeset
   555
            throw new IllegalArgumentException("Width must be >= 0");
435cd1cc42b6 6625450: javax.swing.border.TitledBorder.getBaseline() doesn't throw IAE when width is < 0
malenkov
parents: 2
diff changeset
   556
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        if (height < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            throw new IllegalArgumentException("Height must be >= 0");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   560
        Border border = getBorderUI();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        String title = getTitle();
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   562
        if ((title != null) && !title.isEmpty()) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   563
            int edge = (border instanceof TitledBorder) ? 0 : EDGE_SPACING;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   564
            JLabel label = getLabel(c);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   565
            Dimension size = label.getPreferredSize();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   566
            Insets insets = (border != null)
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   567
                    ? border.getBorderInsets(c)
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   568
                    : new Insets(0, 0, 0, 0);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   569
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   570
            int baseline = label.getBaseline(size.width, size.height);
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   571
            switch (getPosition()) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   572
                case ABOVE_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   573
                    return baseline;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   574
                case TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   575
                    insets.top = edge + (insets.top - size.height) / 2;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   576
                    return (insets.top < edge)
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   577
                            ? baseline
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   578
                            : baseline + insets.top;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   579
                case BELOW_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   580
                    return baseline + insets.top + edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   581
                case ABOVE_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   582
                    return baseline + height - size.height - insets.bottom - edge;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   583
                case BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   584
                    insets.bottom = edge + (insets.bottom - size.height) / 2;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   585
                    return (insets.bottom < edge)
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   586
                            ? baseline + height - size.height
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   587
                            : baseline + height - size.height + insets.bottom;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   588
                case BELOW_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   589
                    return baseline + height - size.height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * Returns an enum indicating how the baseline of the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * changes as the size changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @throws NullPointerException {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * @see javax.swing.JComponent#getBaseline(int, int)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    public Component.BaselineResizeBehavior getBaselineResizeBehavior(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        super.getBaselineResizeBehavior(c);
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   606
        switch (getPosition()) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   607
            case TitledBorder.ABOVE_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   608
            case TitledBorder.TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   609
            case TitledBorder.BELOW_TOP:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   610
                return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   611
            case TitledBorder.ABOVE_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   612
            case TitledBorder.BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   613
            case TitledBorder.BELOW_BOTTOM:
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   614
                return JComponent.BaselineResizeBehavior.CONSTANT_DESCENT;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        return Component.BaselineResizeBehavior.OTHER;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   619
    private Border getBorderUI() {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   620
        Border border = getBorder();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   621
        return border != null
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   622
                ? border
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   623
                : UIManager.getBorder("TitledBorder.border");
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   624
    }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   625
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   626
    private int getPosition() {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   627
        int position = getTitlePosition();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   628
        if (position != DEFAULT_POSITION) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   629
            return position;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   630
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   631
        Object value = UIManager.get("TitledBorder.position");
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   632
        if (value instanceof Integer) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   633
            int i = (Integer) value;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   634
            if ((0 < i) && (i <= 6)) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   635
                return i;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   636
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   637
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   638
        else if (value instanceof String) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   639
            String s = (String) value;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   640
            if (s.equalsIgnoreCase("ABOVE_TOP")) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   641
                return ABOVE_TOP;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   642
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   643
            if (s.equalsIgnoreCase("TOP")) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   644
                return TOP;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   645
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   646
            if (s.equalsIgnoreCase("BELOW_TOP")) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   647
                return BELOW_TOP;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   648
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   649
            if (s.equalsIgnoreCase("ABOVE_BOTTOM")) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   650
                return ABOVE_BOTTOM;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   651
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   652
            if (s.equalsIgnoreCase("BOTTOM")) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   653
                return BOTTOM;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   654
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   655
            if (s.equalsIgnoreCase("BELOW_BOTTOM")) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   656
                return BELOW_BOTTOM;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   657
            }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   658
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   659
        return TOP;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   660
    }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   661
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   662
    private int getJustification(Component c) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   663
        int justification = getTitleJustification();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   664
        if ((justification == LEADING) || (justification == DEFAULT_JUSTIFICATION)) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   665
            return c.getComponentOrientation().isLeftToRight() ? LEFT : RIGHT;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   666
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   667
        if (justification == TRAILING) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   668
            return c.getComponentOrientation().isLeftToRight() ? RIGHT : LEFT;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   669
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   670
        return justification;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   671
    }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   672
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    protected Font getFont(Component c) {
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   674
        Font font = getTitleFont();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   675
        if (font != null) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   676
            return font;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   677
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   678
        font = UIManager.getFont("TitledBorder.font");
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   679
        if (font != null) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
            return font;
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   681
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   682
        if (c != null) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   683
            font = c.getFont();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   684
            if (font != null) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   685
                return font;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   686
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        return new Font(Font.DIALOG, Font.PLAIN, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   691
    private Color getColor(Component c) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   692
        Color color = getTitleColor();
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   693
        if (color != null) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   694
            return color;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   695
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   696
        color = UIManager.getColor("TitledBorder.titleColor");
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   697
        if (color != null) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   698
            return color;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   699
        }
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   700
        return (c != null)
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   701
                ? c.getForeground()
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   702
                : null;
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   703
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
5953
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   705
    private JLabel getLabel(Component c) {
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   706
        this.label.setText(getTitle());
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   707
        this.label.setFont(getFont(c));
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   708
        this.label.setForeground(getColor(c));
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   709
        this.label.setComponentOrientation(c.getComponentOrientation());
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   710
        this.label.setEnabled(c.isEnabled());
33ad0303d717 4129681: Cannot get a title border to display its label as disabled
malenkov
parents: 5506
diff changeset
   711
        return this.label;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
}