jdk/src/java.desktop/share/classes/com/sun/java/swing/plaf/motif/MotifBorders.java
author avstepan
Wed, 03 Jun 2015 18:39:26 +0400
changeset 31164 a61c96d50ddd
parent 25859 3317bb8137f4
child 32865 f9cb6e427f9e
permissions -rw-r--r--
8077036: swing docs: fix some tidy warnings Summary: minor fixes for docs Reviewed-by: alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 6510
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.java.swing.plaf.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import sun.swing.SwingUtilities2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.FontMetrics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
/**
31164
a61c96d50ddd 8077036: swing docs: fix some tidy warnings
avstepan
parents: 25859
diff changeset
    44
 * Factory object that can vend Icons appropriate for the basic {@literal L & F}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * future Swing releases.  The current serialization support is appropriate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * for short term storage or RMI between applications running the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * version of Swing.  A future release of Swing will provide support for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * long term persistence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class MotifBorders {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 6510
diff changeset
    57
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static class BevelBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        private Color darkShadow = UIManager.getColor("controlShadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        private Color lightShadow = UIManager.getColor("controlLtHighlight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        private boolean isRaised;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        public BevelBorder(boolean isRaised, Color darkShadow, Color lightShadow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            this.isRaised = isRaised;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            this.darkShadow = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            this.lightShadow = lightShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            g.setColor((isRaised) ? lightShadow : darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            g.drawLine(x, y, x+w-1, y);           // top
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            g.drawLine(x, y+h-1, x, y+1);         // left
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            g.setColor((isRaised) ? darkShadow : lightShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            g.drawLine(x+1, y+h-1, x+w-1, y+h-1); // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            g.drawLine(x+w-1, y+h-1, x+w-1, y+1); // right
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            insets.set(1, 1, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        public boolean isOpaque(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 6510
diff changeset
    91
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public static class FocusBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        private Color focus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        private Color control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        public FocusBorder(Color control, Color focus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            this.control = control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            this.focus = focus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   102
            if (c.hasFocus()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                g.setColor(focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                g.drawRect(x, y, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                g.setColor(control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                g.drawRect(x, y, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            insets.set(1, 1, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 6510
diff changeset
   118
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static class ButtonBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        protected Color focus = UIManager.getColor("activeCaptionBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        protected Color shadow = UIManager.getColor("Button.shadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        protected Color highlight = UIManager.getColor("Button.light");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        protected Color darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        public ButtonBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            this.darkShadow = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            this.focus = focus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            boolean isPressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            boolean hasFocus = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            boolean canBeDefault = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            boolean isDefault = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                isPressed = (model.isArmed() && model.isPressed());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                hasFocus = (model.isArmed() && isPressed) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                           (b.isFocusPainted() && b.hasFocus());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                if (b instanceof JButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    canBeDefault = ((JButton)b).isDefaultCapable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    isDefault = ((JButton)b).isDefaultButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            int bx1 = x+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            int by1 = y+1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            int bx2 = x+w-2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            int by2 = y+h-2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            if (canBeDefault) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                if (isDefault) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    g.drawLine(x+3, y+3, x+3, y+h-4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    g.drawLine(x+3, y+3, x+w-4, y+3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    g.drawLine(x+4, y+h-4, x+w-4, y+h-4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    g.drawLine(x+w-4, y+3, x+w-4, y+h-4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                bx1 +=6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                by1 += 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                bx2 -= 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                by2 -= 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            if (hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                g.setColor(focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                if (isDefault) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    g.drawRect(x, y, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    g.drawRect(bx1-1, by1-1, bx2-bx1+2, by2-by1+2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            g.setColor(isPressed? shadow : highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            g.drawLine(bx1, by1, bx2, by1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            g.drawLine(bx1, by1, bx1, by2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            g.setColor(isPressed? highlight : shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            g.drawLine(bx2, by1+1, bx2, by2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            g.drawLine(bx1+1, by2, bx2, by2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            int thickness = (c instanceof JButton && ((JButton)c).isDefaultCapable())? 8 : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            insets.set(thickness, thickness, thickness, thickness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 6510
diff changeset
   197
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public static class ToggleButtonBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        public ToggleButtonBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
             super(shadow, highlight, darkShadow, focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                            int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                if (model.isArmed() && model.isPressed() || model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                    drawBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                              (model.isPressed() || model.isSelected()),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                              b.isFocusPainted() && b.hasFocus(), shadow, highlight, darkShadow, focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                    drawBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                              false, b.isFocusPainted() && b.hasFocus(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                              shadow, highlight, darkShadow, focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                drawBezel(g, x, y, width, height, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                          shadow, highlight, darkShadow, focus);
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
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            insets.set(2, 2, 3, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 6510
diff changeset
   231
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public static class MenuBarBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        public MenuBarBorder(Color shadow, Color highlight, Color darkShadow, Color focus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            super(shadow, highlight, darkShadow, focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   239
            if (!(c instanceof JMenuBar)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   240
                return;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   241
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            JMenuBar menuBar = (JMenuBar)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            if (menuBar.isBorderPainted() == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                // this draws the MenuBar border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                Dimension size = menuBar.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                drawBezel(g,x,y,size.width,size.height,false,false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                          shadow, highlight, darkShadow, focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            insets.set(6, 6, 6, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 6510
diff changeset
   257
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public static class FrameBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        JComponent jcomp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        Color frameHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        Color frameColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        Color frameShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        // The width of the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        public final static int BORDER_SIZE = 5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        /** Constructs an FrameBorder for the JComponent <b>comp</b>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        public FrameBorder(JComponent comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            jcomp = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        /** Sets the FrameBorder's JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        public void setComponent(JComponent comp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            jcomp = comp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        /** Returns the FrameBorder's JComponent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
          * @see #setComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        public JComponent component() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            return jcomp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        protected Color getFrameHighlight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            return frameHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        protected Color getFrameColor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            return frameColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        protected Color getFrameShadow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            return frameShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            newInsets.set(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
       /** Draws the FrameBorder's top border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        protected boolean drawTopBorder(Component c, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                    int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            Rectangle titleBarRect = new Rectangle(x, y, width, BORDER_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            if (!g.getClipBounds().intersects(titleBarRect)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            int maxX = width - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            int maxY = BORDER_SIZE - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            // Draw frame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            g.setColor(frameColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            g.drawLine(x, y + 2, maxX - 2, y + 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            g.drawLine(x, y + 3, maxX - 2, y + 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            g.drawLine(x, y + 4, maxX - 2, y + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            // Draw highlights
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            g.setColor(frameHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            g.drawLine(x, y, maxX, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            g.drawLine(x, y + 1, maxX, y + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            g.drawLine(x, y + 2, x, y + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            g.drawLine(x + 1, y + 2, x + 1, y + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            // Draw shadows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            g.setColor(frameShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            g.drawLine(x + 4, y + 4, maxX - 4, y + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            g.drawLine(maxX, y + 1, maxX, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            g.drawLine(maxX - 1, y + 2, maxX - 1, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        /** Draws the FrameBorder's left border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        protected boolean drawLeftBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                               int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            Rectangle borderRect =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                new Rectangle(0, 0, getBorderInsets(c).left, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            if (!g.getClipBounds().intersects(borderRect)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            int startY = BORDER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            g.setColor(frameHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            g.drawLine(x, startY, x, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            g.drawLine(x + 1, startY, x + 1, height - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            g.setColor(frameColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            g.fillRect(x + 2, startY, x + 2, height - 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            g.setColor(frameShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            g.drawLine(x + 4, startY, x + 4, height - 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        /** Draws the FrameBorder's right border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        protected boolean drawRightBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            Rectangle borderRect = new Rectangle(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                width - getBorderInsets(c).right, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                getBorderInsets(c).right, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            if (!g.getClipBounds().intersects(borderRect)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            int startX = width - getBorderInsets(c).right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            int startY = BORDER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            g.setColor(frameColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            g.fillRect(startX + 1, startY, 2, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            g.setColor(frameShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            g.fillRect(startX + 3, startY, 2, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            g.setColor(frameHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            g.drawLine(startX, startY, startX, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        /** Draws the FrameBorder's bottom border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        protected boolean drawBottomBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                                 int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            Rectangle    borderRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            int     marginHeight, startY;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            borderRect = new Rectangle(0, height - getBorderInsets(c).bottom,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                  width, getBorderInsets(c).bottom);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if (!g.getClipBounds().intersects(borderRect)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            startY = height - getBorderInsets(c).bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            g.setColor(frameShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            g.drawLine(x + 1, height - 1, width - 1, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            g.drawLine(x + 2, height - 2, width - 2, height - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            g.setColor(frameColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            g.fillRect(x + 2, startY + 1, width - 4, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            g.setColor(frameHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            g.drawLine(x + 5, startY, width - 5, startY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        // Returns true if the associated component has focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        protected boolean isActiveFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return jcomp.hasFocus();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        /** Draws the FrameBorder in the given Rect.  Calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
          * <b>drawTitleBar</b>, <b>drawLeftBorder</b>, <b>drawRightBorder</b> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
          * <b>drawBottomBorder</b>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        public void paintBorder(Component c, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                            int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            if (isActiveFrame()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                frameColor = UIManager.getColor("activeCaptionBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                frameColor = UIManager.getColor("inactiveCaptionBorder");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            frameHighlight = frameColor.brighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            frameShadow = frameColor.darker().darker();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            drawTopBorder(c, g, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            drawLeftBorder(c, g, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            drawRightBorder(c, g, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            drawBottomBorder(c, g, x, y, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 6510
diff changeset
   443
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public static class InternalFrameBorder extends FrameBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        JInternalFrame frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        // The size of the bounding box for Motif frame corners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        public final static int CORNER_SIZE = 24;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        /** Constructs an InternalFrameBorder for the InternalFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
          * <b>aFrame</b>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        public InternalFrameBorder(JInternalFrame aFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            super(aFrame);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            frame = aFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        /** Sets the InternalFrameBorder's InternalFrame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        public void setFrame(JInternalFrame aFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            frame = aFrame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        /** Returns the InternalFrameBorder's InternalFrame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
          * @see #setFrame
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        public JInternalFrame frame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        /** Returns the width of the InternalFrameBorder's resize controls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
          * appearing along the InternalFrameBorder's bottom border.  Clicking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
          * and dragging within these controls lets the user change both the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
          * InternalFrame's width and height, while dragging between the controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
          * constrains resizing to just the vertical dimension.  Override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
          * method if you implement your own bottom border painting and use a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
          * resize control with a different size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        public int resizePartWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            if (!frame.isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            return FrameBorder.BORDER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        /** Draws the InternalFrameBorder's top border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        protected boolean drawTopBorder(Component c, Graphics g,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                                    int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            if (super.drawTopBorder(c, g, x, y, width, height) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                frame.isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                g.setColor(getFrameShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                g.drawLine(CORNER_SIZE - 1, y + 1, CORNER_SIZE - 1, y + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                g.drawLine(width - CORNER_SIZE - 1, y + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                       width - CORNER_SIZE - 1, y + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                g.setColor(getFrameHighlight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                g.drawLine(CORNER_SIZE, y, CORNER_SIZE, y + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                g.drawLine(width - CORNER_SIZE, y, width - CORNER_SIZE, y + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        /** Draws the InternalFrameBorder's left border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        protected boolean drawLeftBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                     int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            if (super.drawLeftBorder(c, g, x, y, width, height) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                frame.isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                g.setColor(getFrameHighlight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                int topY = y + CORNER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                g.drawLine(x, topY, x + 4, topY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                int bottomY = height - CORNER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                g.drawLine(x + 1, bottomY, x + 5, bottomY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                g.setColor(getFrameShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                g.drawLine(x + 1, topY - 1, x + 5, topY - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                g.drawLine(x + 1, bottomY - 1, x + 5, bottomY - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        /** Draws the InternalFrameBorder's right border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        protected boolean drawRightBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                      int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            if (super.drawRightBorder(c, g, x, y, width, height) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                frame.isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                int startX = width - getBorderInsets(c).right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                g.setColor(getFrameHighlight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                int topY = y + CORNER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                g.drawLine(startX, topY, width - 2, topY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                int bottomY = height - CORNER_SIZE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                g.drawLine(startX + 1, bottomY, startX + 3, bottomY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                g.setColor(getFrameShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                g.drawLine(startX + 1, topY - 1, width - 2, topY - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                g.drawLine(startX + 1, bottomY - 1, startX + 3, bottomY - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        /** Draws the InternalFrameBorder's bottom border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        protected boolean drawBottomBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                                       int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            if (super.drawBottomBorder(c, g, x, y, width, height) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                frame.isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                int startY = height - getBorderInsets(c).bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                g.setColor(getFrameShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                g.drawLine(CORNER_SIZE - 1, startY + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                       CORNER_SIZE - 1, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                g.drawLine(width - CORNER_SIZE, startY + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                       width - CORNER_SIZE, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                g.setColor(getFrameHighlight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                g.drawLine(CORNER_SIZE, startY, CORNER_SIZE, height - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                g.drawLine(width - CORNER_SIZE + 1, startY,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                       width - CORNER_SIZE + 1, height - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        // Returns true if the associated internal frame has focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        protected boolean isActiveFrame() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            return frame.isSelected();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    public static void drawBezel(Graphics g, int x, int y, int w, int h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                               boolean isPressed, boolean hasFocus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                               Color shadow, Color highlight,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                               Color darkShadow, Color focus)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if (isPressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            if (hasFocus){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                g.setColor(focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                g.drawRect(0, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            g.setColor(shadow);         // inner border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            g.drawRect(1, 1, w-3, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            g.setColor(highlight);    // inner 3D border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            g.drawLine(2, h-3, w-3, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            g.drawLine(w-3, 2, w-3, h-4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            if (hasFocus) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                g.setColor(focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                g.drawRect(0, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                g.setColor(highlight);   // inner 3D border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                g.drawLine(1, 1, 1, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                g.drawLine(2, 1, w-4, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                g.drawLine(2, h-3, w-3, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                g.drawLine(w-3, 1, w-3, h-4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                g.setColor(darkShadow);        // black drop shadow  __|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                g.drawLine(1, h-2, w-2, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                g.drawLine(w-2, h-2, w-2, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                g.setColor(highlight);    // inner 3D border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                g.drawLine(1,1,1,h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                g.drawLine(2,1,w-4,1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                g.drawLine(2,h-3,w-3,h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                g.drawLine(w-3,1,w-3,h-4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                g.setColor(darkShadow);         // black drop shadow  __|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                g.drawLine(1,h-2,w-2,h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                g.drawLine(w-2,h-2,w-2,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
23632
cd7a34d12e8c 8033908: Fix serial lint warnings in com.sun.java.swing.plaf
darcy
parents: 6510
diff changeset
   628
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    public static class MotifPopupMenuBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        protected Font   font;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        protected Color  background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        protected Color  foreground;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        protected Color  shadowColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        protected Color  highlightColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        // Space between the border and text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        static protected final int TEXT_SPACING = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        // Space for the separator under the title
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        static protected final int GROOVE_HEIGHT = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
         * Creates a MotifPopupMenuBorder instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        public MotifPopupMenuBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                                    Font titleFont,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                                    Color bgColor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                                    Color fgColor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                                    Color shadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                                    Color highlight)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            this.font = titleFont;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            this.background = bgColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            this.foreground = fgColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            this.shadowColor = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            this.highlightColor = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
         * Paints the border for the specified component with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
         * specified position and size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
         * @param c the component for which this border is being painted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
         * @param g the paint graphics
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
         * @param x the x position of the painted border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
         * @param y the y position of the painted border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
         * @param width the width of the painted border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
         * @param height the height of the painted border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   670
            if (!(c instanceof JPopupMenu)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   671
                return;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   672
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            Font origFont = g.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            Color origColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            JPopupMenu popup = (JPopupMenu)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            String title = popup.getLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (title == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            g.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            FontMetrics fm = SwingUtilities2.getFontMetrics(popup, g, font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            int         fontHeight = fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            int         descent = fm.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            int         ascent = fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            Point       textLoc = new Point();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            int         stringWidth = SwingUtilities2.stringWidth(popup, fm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
                                                                  title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            textLoc.y = y + ascent + TEXT_SPACING;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            textLoc.x = x + ((width - stringWidth) / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            g.setColor(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            g.fillRect(textLoc.x - TEXT_SPACING, textLoc.y - (fontHeight-descent),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                       stringWidth + (2 * TEXT_SPACING), fontHeight - descent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            g.setColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            SwingUtilities2.drawString(popup, g, title, textLoc.x, textLoc.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            MotifGraphicsUtils.drawGroove(g, x, textLoc.y + TEXT_SPACING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                                          width, GROOVE_HEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                                          shadowColor, highlightColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            g.setFont(origFont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            g.setColor(origColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
         * Reinitialize the insets parameter with this Border's current Insets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
         * @param c the component for which this border insets value applies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
         * @param insets the object to be reinitialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        public Insets getBorderInsets(Component c, Insets insets) {
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   716
            if (!(c instanceof JPopupMenu)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   717
                return insets;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   718
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            FontMetrics fm;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            int         descent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            int         ascent = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            String title = ((JPopupMenu)c).getLabel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            if (title == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                insets.left = insets.top = insets.right = insets.bottom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            fm = c.getFontMetrics(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            if(fm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                descent = fm.getDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                ascent = fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            insets.top += ascent + descent + TEXT_SPACING + GROOVE_HEIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
}