jdk/src/share/classes/javax/swing/plaf/metal/MetalBorders.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 23010 6dadb192ad81
child 25178 dbab904451e9
permissions -rw-r--r--
8034169: Fix serial lint warnings in javax.swing Reviewed-by: alanb, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
     2
 * Copyright (c) 1998, 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 javax.swing.plaf.metal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.border.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.plaf.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.plaf.basic.BasicBorders;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.text.JTextComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Dialog;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Frame;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import sun.swing.StringUIClientPropertyKey;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 6510
diff changeset
    46
 * Factory object that can vend Borders appropriate for the metal L & F.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author Steve Wilson
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class MetalBorders {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Client property indicating the button shouldn't provide a rollover
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * indicator. Only used with the Ocean theme.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static Object NO_BUTTON_ROLLOVER =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        new StringUIClientPropertyKey("NoButtonRollover");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    59
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static class Flush3DBorder extends AbstractBorder implements UIResource{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                          int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            if (c.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                MetalUtils.drawFlush3DBorder(g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                MetalUtils.drawDisabledBorder(g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            newInsets.set(2, 2, 2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
    76
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public static class ButtonBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        protected static Insets borderInsets = new Insets( 3, 3, 3, 3 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        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
    82
            if (!(c instanceof AbstractButton)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
    83
                return;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
    84
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                paintOceanBorder(c, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            AbstractButton button = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            ButtonModel model = button.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if ( model.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                boolean isPressed = model.isPressed() && model.isArmed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                boolean isDefault = (button instanceof JButton && ((JButton)button).isDefaultButton());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                if (isPressed && isDefault) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    MetalUtils.drawDefaultButtonPressedBorder(g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                } else if (isPressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    MetalUtils.drawPressed3DBorder( g, x, y, w, h );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                } else if (isDefault) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    MetalUtils.drawDefaultButtonBorder( g, x, y, w, h, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    MetalUtils.drawButtonBorder( g, x, y, w, h, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            } else { // disabled state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        private void paintOceanBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                      int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            AbstractButton button = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            ButtonModel model = ((AbstractButton)c).getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            if (MetalUtils.isToolBarButton(button)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                if (model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                    if (model.isPressed()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                        g.setColor(MetalLookAndFeel.getWhite());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                        g.fillRect(1, h - 1, w - 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                        g.fillRect(w - 1, 1, 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                        g.setColor(MetalLookAndFeel.getControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                        g.drawRect(0, 0, w - 2, h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                        g.fillRect(1, 1, w - 3, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                    else if (model.isSelected() || model.isRollover()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                        g.setColor(MetalLookAndFeel.getWhite());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                        g.fillRect(1, h - 1, w - 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        g.fillRect(w - 1, 1, 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                        g.setColor(MetalLookAndFeel.getControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                        g.drawRect(0, 0, w - 2, h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                        g.setColor(MetalLookAndFeel.getWhite());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                        g.drawRect(1, 1, w - 2, h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                        g.setColor(UIManager.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                "Button.toolBarBorderBackground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                        g.drawRect(0, 0, w - 2, h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                   g.setColor(UIManager.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                           "Button.disabledToolBarBorderBackground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                   g.drawRect(0, 0, w - 2, h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            else if (model.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                boolean pressed = model.isPressed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                boolean armed = model.isArmed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                    g.setColor(MetalLookAndFeel.getControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    g.drawRect(0, 0, w - 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    g.drawRect(1, 1, w - 3, h - 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                else if (pressed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    g.setColor(MetalLookAndFeel.getControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                    g.fillRect(0, 0, w, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    g.fillRect(0, 2, 2, h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                    g.fillRect(w - 1, 1, 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    g.fillRect(1, h - 1, w - 2, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                else if (model.isRollover() && button.getClientProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                               NO_BUTTON_ROLLOVER) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    g.setColor(MetalLookAndFeel.getPrimaryControl());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                    g.drawRect(0, 0, w - 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    g.drawRect(2, 2, w - 5, h - 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                    g.setColor(MetalLookAndFeel.getControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                    g.drawRect(1, 1, w - 3, h - 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    g.setColor(MetalLookAndFeel.getControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    g.drawRect(0, 0, w - 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                g.drawRect(0, 0, w - 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                if ((c instanceof JButton) && ((JButton)c).isDefaultButton()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    g.drawRect(1, 1, w - 3, h - 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            newInsets.set(3, 3, 3, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   191
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public static class InternalFrameBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        private static final int corner = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                          int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            Color background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if (c instanceof JInternalFrame && ((JInternalFrame)c).isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                background = MetalLookAndFeel.getPrimaryControlDarkShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                highlight = MetalLookAndFeel.getPrimaryControlShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                shadow = MetalLookAndFeel.getPrimaryControlInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                background = MetalLookAndFeel.getControlDarkShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                highlight = MetalLookAndFeel.getControlShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                shadow = MetalLookAndFeel.getControlInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
              g.setColor(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
              // Draw outermost lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
              g.drawLine( 1, 0, w-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
              g.drawLine( 0, 1, 0, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
              g.drawLine( w-1, 1, w-1, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
              g.drawLine( 1, h-1, w-2, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
              // Draw the bulk of the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
              for (int i = 1; i < 5; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                  g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
              if (c instanceof JInternalFrame &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                               ((JInternalFrame)c).isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                  g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                  // Draw the Long highlight lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                  g.drawLine( corner+1, 3, w-corner, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                  g.drawLine( 3, corner+1, 3, h-corner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                  g.drawLine( w-2, corner+1, w-2, h-corner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                  g.drawLine( corner+1, h-2, w-corner, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                  g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                  // Draw the Long shadow lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                  g.drawLine( corner, 2, w-corner-1, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                  g.drawLine( 2, corner, 2, h-corner-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                  g.drawLine( w-3, corner, w-3, h-corner-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                  g.drawLine( corner, h-3, w-corner-1, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
          public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
              newInsets.set(5, 5, 5, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
              return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * Border for a Frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   253
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    static class FrameBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        private static final int corner = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            Color background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            Window window = SwingUtilities.getWindowAncestor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            if (window != null && window.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                background = MetalLookAndFeel.getPrimaryControlDarkShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                highlight = MetalLookAndFeel.getPrimaryControlShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                shadow = MetalLookAndFeel.getPrimaryControlInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                background = MetalLookAndFeel.getControlDarkShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                highlight = MetalLookAndFeel.getControlShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                shadow = MetalLookAndFeel.getControlInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            g.setColor(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            // Draw outermost lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            g.drawLine( x+1, y+0, x+w-2, y+0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            g.drawLine( x+0, y+1, x+0, y +h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            g.drawLine( x+w-1, y+1, x+w-1, y+h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            g.drawLine( x+1, y+h-1, x+w-2, y+h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            // Draw the bulk of the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            for (int i = 1; i < 5; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            if ((window instanceof Frame) && ((Frame) window).isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                // Draw the Long highlight lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                g.drawLine( corner+1, 3, w-corner, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                g.drawLine( 3, corner+1, 3, h-corner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                g.drawLine( w-2, corner+1, w-2, h-corner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                g.drawLine( corner+1, h-2, w-corner, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                // Draw the Long shadow lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                g.drawLine( corner, 2, w-corner-1, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                g.drawLine( 2, corner, 2, h-corner-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                g.drawLine( w-3, corner, w-3, h-corner-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                g.drawLine( corner, h-3, w-corner-1, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        public Insets getBorderInsets(Component c, Insets newInsets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            newInsets.set(5, 5, 5, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * Border for a Frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   316
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    static class DialogBorder extends AbstractBorder implements UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        private static final int corner = 14;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        protected Color getActiveBackground()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            return MetalLookAndFeel.getPrimaryControlDarkShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        protected Color getActiveHighlight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            return MetalLookAndFeel.getPrimaryControlShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        protected Color getActiveShadow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            return MetalLookAndFeel.getPrimaryControlInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        protected Color getInactiveBackground()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            return MetalLookAndFeel.getControlDarkShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        protected Color getInactiveHighlight()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            return MetalLookAndFeel.getControlShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        protected Color getInactiveShadow()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            return MetalLookAndFeel.getControlInfo();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            Color background;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            Window window = SwingUtilities.getWindowAncestor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            if (window != null && window.isActive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                background = getActiveBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                highlight = getActiveHighlight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                shadow = getActiveShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                background = getInactiveBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                highlight = getInactiveHighlight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                shadow = getInactiveShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            g.setColor(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            // Draw outermost lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            g.drawLine( x + 1, y + 0, x + w-2, y + 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            g.drawLine( x + 0, y + 1, x + 0, y + h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            g.drawLine( x + w - 1, y + 1, x + w - 1, y + h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            g.drawLine( x + 1, y + h - 1, x + w - 2, y + h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            // Draw the bulk of the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            for (int i = 1; i < 5; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                g.drawRect(x+i,y+i,w-(i*2)-1, h-(i*2)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            if ((window instanceof Dialog) && ((Dialog) window).isResizable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
                // Draw the Long highlight lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
                g.drawLine( corner+1, 3, w-corner, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                g.drawLine( 3, corner+1, 3, h-corner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                g.drawLine( w-2, corner+1, w-2, h-corner);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                g.drawLine( corner+1, h-2, w-corner, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                // Draw the Long shadow lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                g.drawLine( corner, 2, w-corner-1, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                g.drawLine( 2, corner, 2, h-corner-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                g.drawLine( w-3, corner, w-3, h-corner-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                g.drawLine( corner, h-3, w-corner-1, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        public Insets getBorderInsets(Component c, Insets newInsets)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            newInsets.set(5, 5, 5, 5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Border for an Error Dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   410
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    static class ErrorDialogBorder extends DialogBorder implements UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        protected Color getActiveBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            return UIManager.getColor("OptionPane.errorDialog.border.background");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Border for a QuestionDialog.  Also used for a JFileChooser and a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * JColorChooser..
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   424
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    static class QuestionDialogBorder extends DialogBorder implements UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        protected Color getActiveBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return UIManager.getColor("OptionPane.questionDialog.border.background");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Border for a Warning Dialog.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   437
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    static class WarningDialogBorder extends DialogBorder implements UIResource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        protected Color getActiveBackground() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            return UIManager.getColor("OptionPane.warningDialog.border.background");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * Border for a Palette.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   450
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public static class PaletteBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        int titleHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            g.translate(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            g.drawLine(0, 1, 0, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            g.drawLine(1, h-1, w-2, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            g.drawLine(w-1,  1, w-1, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            g.drawLine( 1, 0, w-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            g.drawRect(1,1, w-3, h-3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            g.translate(-x,-y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            newInsets.set(1, 1, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   473
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
    public static class OptionDialogBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        int titleHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            g.translate(x,y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            int messageType = JOptionPane.PLAIN_MESSAGE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if (c instanceof JInternalFrame) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                Object obj = ((JInternalFrame) c).getClientProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                              "JInternalFrame.messageType");
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   485
                if (obj instanceof Integer) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   486
                    messageType = (Integer) obj;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            Color borderColor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            switch (messageType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            case(JOptionPane.ERROR_MESSAGE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                borderColor = UIManager.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    "OptionPane.errorDialog.border.background");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            case(JOptionPane.QUESTION_MESSAGE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                borderColor = UIManager.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    "OptionPane.questionDialog.border.background");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            case(JOptionPane.WARNING_MESSAGE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                borderColor = UIManager.getColor(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                    "OptionPane.warningDialog.border.background");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            case(JOptionPane.INFORMATION_MESSAGE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            case(JOptionPane.PLAIN_MESSAGE):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                borderColor = MetalLookAndFeel.getPrimaryControlDarkShadow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            g.setColor(borderColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
              // Draw outermost lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
              g.drawLine( 1, 0, w-2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
              g.drawLine( 0, 1, 0, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
              g.drawLine( w-1, 1, w-1, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
              g.drawLine( 1, h-1, w-2, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
              // Draw the bulk of the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
              for (int i = 1; i < 3; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                  g.drawRect(i, i, w-(i*2)-1, h-(i*2)-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            g.translate(-x,-y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            newInsets.set(3, 3, 3, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   535
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    public static class MenuBarBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        protected static Insets borderInsets = new Insets( 1, 0, 1, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            g.translate( x, y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                // Only paint a border if we're not next to a horizontal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                // toolbar
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   545
                if ((c instanceof JMenuBar) && !MetalToolBarUI.doesMenuBarBorderToolBar((JMenuBar)c)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    g.setColor(MetalLookAndFeel.getControl());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    g.drawLine(0, h - 2, w, h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    g.setColor(UIManager.getColor("MenuBar.borderColor"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    g.drawLine(0, h - 1, w, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                g.setColor( MetalLookAndFeel.getControlShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                g.drawLine( 0, h-1, w, h-1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            g.translate( -x, -y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                newInsets.set(0, 0, 2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                newInsets.set(1, 0, 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   572
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    public static class MenuItemBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        protected static Insets borderInsets = new Insets( 2, 2, 2, 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        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
   577
            if (!(c instanceof JMenuItem)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   578
                return;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   579
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            JMenuItem b = (JMenuItem) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            g.translate( x, y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            if ( c.getParent() instanceof JMenuBar ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                if ( model.isArmed() || model.isSelected() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    g.setColor( MetalLookAndFeel.getControlDarkShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    g.drawLine( 0, 0, w - 2, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    g.drawLine( 0, 0, 0, h - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    g.drawLine( w - 2, 2, w - 2, h - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    g.drawLine( w - 1, 1, w - 1, h - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    g.setColor( MetalLookAndFeel.getMenuBackground() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    g.drawLine( w - 1, 0, w - 1, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                if (  model.isArmed() || ( c instanceof JMenu && model.isSelected() ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    g.drawLine( 0, 0, w - 1, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                    g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    g.drawLine( 0, h - 1, w - 1, h - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                    g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                    g.drawLine( 0, 0, 0, h - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            g.translate( -x, -y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            newInsets.set(2, 2, 2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   620
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public static class PopupMenuBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        protected static Insets borderInsets = new Insets( 3, 1, 2, 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            g.translate( x, y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            g.setColor( MetalLookAndFeel.getPrimaryControlDarkShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            g.drawRect( 0, 0, w - 1, h - 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            g.setColor( MetalLookAndFeel.getPrimaryControlHighlight() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            g.drawLine( 1, 1, w - 2, 1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
            g.drawLine( 1, 2, 1, 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            g.drawLine( 1, h - 2, 1, h - 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            g.translate( -x, -y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            newInsets.set(3, 1, 2, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   645
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    public static class RolloverButtonBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                super.paintBorder( c, g, x, y, w, h );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * A border which is like a Margin border but it will only honor the margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * if the margin has been explicitly set by the developer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * Note: This is identical to the package private class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * BasicBorders.RolloverMarginBorder and should probably be consolidated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   666
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    static class RolloverMarginBorder extends EmptyBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
        public RolloverMarginBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            super(3,3,3,3); // hardcoded margin for JLF requirements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            Insets margin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                margin = ((AbstractButton)c).getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (margin == null || margin instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                // default margin so replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                insets.left = left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                insets.top = top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                insets.right = right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                insets.bottom = bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                // Margin which has been explicitly set by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                insets.left = margin.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                insets.top = margin.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                insets.right = margin.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                insets.bottom = margin.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   696
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    public static class ToolBarBorder extends AbstractBorder implements UIResource, SwingConstants
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        protected MetalBumps bumps = new MetalBumps( 10, 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
                                      MetalLookAndFeel.getControlHighlight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                                      MetalLookAndFeel.getControlDarkShadow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
                                     UIManager.getColor("ToolBar.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        public void paintBorder( Component c, Graphics g, int x, int y, int w, int h )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        {
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   706
            if (!(c instanceof JToolBar)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   707
                return;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   708
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            g.translate( x, y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            if ( ((JToolBar) c).isFloatable() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                if ( ((JToolBar) c).getOrientation() == HORIZONTAL )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    int shift = MetalLookAndFeel.usingOcean() ? -1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    bumps.setBumpArea( 10, h - 4 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    if( MetalUtils.isLeftToRight(c) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                        bumps.paintIcon( c, g, 2, 2 + shift );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                        bumps.paintIcon( c, g, w-12,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                                         2 + shift );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                else // vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                    bumps.setBumpArea( w - 4, 10 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                    bumps.paintIcon( c, g, 2, 2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            if (((JToolBar) c).getOrientation() == HORIZONTAL &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                               MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                g.setColor(MetalLookAndFeel.getControl());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                g.drawLine(0, h - 2, w, h - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                g.setColor(UIManager.getColor("ToolBar.borderColor"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                g.drawLine(0, h - 1, w, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            g.translate( -x, -y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        public Insets getBorderInsets(Component c, Insets newInsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                newInsets.set(1, 2, 3, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                newInsets.top = newInsets.left = newInsets.bottom = newInsets.right = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   751
            if (!(c instanceof JToolBar)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   752
                return newInsets;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   753
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            if ( ((JToolBar) c).isFloatable() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                if ( ((JToolBar) c).getOrientation() == HORIZONTAL ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                    if (c.getComponentOrientation().isLeftToRight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
                        newInsets.left = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                        newInsets.right = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                } else {// vertical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                    newInsets.top = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            Insets margin = ((JToolBar) c).getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            if ( margin != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                newInsets.left   += margin.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                newInsets.top    += margin.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                newInsets.right  += margin.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                newInsets.bottom += margin.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            return newInsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
    private static Border buttonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * Returns a border instance for a JButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    public static Border getButtonBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        if (buttonBorder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            buttonBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                                                   new MetalBorders.ButtonBorder(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                                                   new BasicBorders.MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        return buttonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    private static Border textBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * Returns a border instance for a text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    public static Border getTextBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        if (textBorder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
            textBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                                                   new MetalBorders.Flush3DBorder(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                                                   new BasicBorders.MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        return textBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
    private static Border textFieldBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * Returns a border instance for a JTextField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    public static Border getTextFieldBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        if (textFieldBorder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                                                   new MetalBorders.TextFieldBorder(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                                                   new BasicBorders.MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
        return textFieldBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   824
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
    public static class TextFieldBorder extends Flush3DBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
                                int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
          if (!(c instanceof JTextComponent)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                // special case for non-text components (bug ID 4144840)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                if (c.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    MetalUtils.drawFlush3DBorder(g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    MetalUtils.drawDisabledBorder(g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            if (c.isEnabled() && ((JTextComponent)c).isEditable()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                MetalUtils.drawFlush3DBorder(g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                MetalUtils.drawDisabledBorder(g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   849
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    public static class ScrollPaneBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                          int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   854
            if (!(c instanceof JScrollPane)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   855
                return;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   856
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            JScrollPane scroll = (JScrollPane)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            JComponent colHeader = scroll.getColumnHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
            int colHeaderHeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            if (colHeader != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
               colHeaderHeight = colHeader.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
            JComponent rowHeader = scroll.getRowHeader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
            int rowHeaderWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            if (rowHeader != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
               rowHeaderWidth = rowHeader.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
            g.translate( x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            g.setColor( MetalLookAndFeel.getControlDarkShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            g.drawRect( 0, 0, w-2, h-2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
            g.setColor( MetalLookAndFeel.getControlHighlight() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            g.drawLine( w-1, 1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            g.drawLine( 1, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
            g.setColor( MetalLookAndFeel.getControl() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            g.drawLine( w-2, 2+colHeaderHeight, w-2, 2+colHeaderHeight );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            g.drawLine( 1+rowHeaderWidth, h-2, 1+rowHeaderWidth, h-2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            g.translate( -x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            insets.set(1, 1, 2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    private static Border toggleButtonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * Returns a border instance for a JToggleButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    public static Border getToggleButtonBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        if (toggleButtonBorder == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                                                   new MetalBorders.ToggleButtonBorder(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                                                   new BasicBorders.MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        return toggleButtonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   910
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
    public static class ToggleButtonBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            AbstractButton button = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
            ButtonModel model = button.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                if(model.isArmed() || !button.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                    super.paintBorder(c, g, x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                 g.setColor(MetalLookAndFeel.getControlDarkShadow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                 g.drawRect(0, 0, w - 1, h - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            if (! c.isEnabled() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                MetalUtils.drawDisabledBorder( g, x, y, w-1, h-1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                if ( model.isPressed() && model.isArmed() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                   MetalUtils.drawPressed3DBorder( g, x, y, w, h );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                } else if ( model.isSelected() ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                    MetalUtils.drawDark3DBorder( g, x, y, w, h );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
                    MetalUtils.drawFlush3DBorder( g, x, y, w, h );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * Border for a Table Header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   943
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
    public static class TableHeaderBorder extends javax.swing.border.AbstractBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        protected Insets editorBorderInsets = new Insets( 2, 2, 2, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            g.translate( x, y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            g.setColor( MetalLookAndFeel.getControlDarkShadow() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            g.drawLine( w-1, 0, w-1, h-1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            g.drawLine( 1, h-1, w-1, h-1 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            g.setColor( MetalLookAndFeel.getControlHighlight() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            g.drawLine( 0, 0, w-2, 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            g.drawLine( 0, 0, 0, h-2 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            g.translate( -x, -y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            insets.set(2, 2, 2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * Returns a border instance for a Desktop Icon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
    public static Border getDesktopIconBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        return new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                                          new LineBorder(MetalLookAndFeel.getControlDarkShadow(), 1),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                                          new MatteBorder (2,2,1,2, MetalLookAndFeel.getControl()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    static Border getToolBarRolloverBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            return new CompoundBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
                new MetalBorders.ButtonBorder(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                new MetalBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        return new CompoundBorder(new MetalBorders.RolloverButtonBorder(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                                  new MetalBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
    static Border getToolBarNonrolloverBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        if (MetalLookAndFeel.usingOcean()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
            new CompoundBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
                new MetalBorders.ButtonBorder(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
                new MetalBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        return new CompoundBorder(new MetalBorders.ButtonBorder(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
                                  new MetalBorders.RolloverMarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
}