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