jdk/src/share/classes/javax/swing/plaf/basic/BasicBorders.java
author darcy
Sun, 23 Mar 2014 13:49:48 -0700
changeset 23697 e556a715949f
parent 23010 6dadb192ad81
child 25765 88051e6ecdc7
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) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.swing.plaf.basic;
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.text.JTextComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Color;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.Graphics;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
/**
20169
d7fa6d7586c9 8025085: [javadoc] some errors in javax/swing
yan
parents: 6510
diff changeset
    41
 * Factory object that can vend Borders appropriate for the basic L & F.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class BasicBorders {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static Border getButtonBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        Border buttonBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
                           new BasicBorders.ButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                                           table.getColor("Button.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                                           table.getColor("Button.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                           table.getColor("Button.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                                           table.getColor("Button.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                                     new MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        return buttonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static Border getRadioButtonBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        Border radioButtonBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                           new BasicBorders.RadioButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                                           table.getColor("RadioButton.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                                           table.getColor("RadioButton.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                           table.getColor("RadioButton.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                           table.getColor("RadioButton.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                     new MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        return radioButtonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    public static Border getToggleButtonBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        Border toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                                     new BasicBorders.ToggleButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                           table.getColor("ToggleButton.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                           table.getColor("ToggleButton.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                           table.getColor("ToggleButton.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                           table.getColor("ToggleButton.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                     new MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        return toggleButtonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public static Border getMenuBarBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        Border menuBarBorder = new BasicBorders.MenuBarBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                                        table.getColor("MenuBar.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                        table.getColor("MenuBar.highlight")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                   );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return menuBarBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    public static Border getSplitPaneBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        Border splitPaneBorder = new BasicBorders.SplitPaneBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                                     table.getColor("SplitPane.highlight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                     table.getColor("SplitPane.darkShadow"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        return splitPaneBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Returns a border instance for a JSplitPane divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public static Border getSplitPaneDividerBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        Border splitPaneBorder = new BasicBorders.SplitPaneDividerBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                                     table.getColor("SplitPane.highlight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                                     table.getColor("SplitPane.darkShadow"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return splitPaneBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public static Border getTextFieldBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        Border textFieldBorder = new BasicBorders.FieldBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                           table.getColor("TextField.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                           table.getColor("TextField.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                           table.getColor("TextField.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                           table.getColor("TextField.highlight"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return textFieldBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public static Border getProgressBarBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        Border progressBarBorder = new BorderUIResource.LineBorderUIResource(Color.green, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return progressBarBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public static Border getInternalFrameBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        Border internalFrameBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                                new BevelBorder(BevelBorder.RAISED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                                        table.getColor("InternalFrame.borderLight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                        table.getColor("InternalFrame.borderHighlight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                        table.getColor("InternalFrame.borderDarkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                        table.getColor("InternalFrame.borderShadow")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                BorderFactory.createLineBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                        table.getColor("InternalFrame.borderColor"), 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return internalFrameBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Special thin border for rollover toolbar buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   147
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public static class RolloverButtonBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        public RolloverButtonBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                  Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            super(shadow, darkShadow, highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            Color shade = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            Component p = b.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            if (p != null && p.getBackground().equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                shade = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            if ((model.isRollover() && !(model.isPressed() && !model.isArmed())) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                if (model.isPressed() && model.isArmed() || model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    // Draw the pressd button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    g.setColor(shade);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    g.drawRect(0, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    g.setColor(lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    g.drawLine(w-1, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    // Draw a rollover button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    g.setColor(lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    g.drawRect(0, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    g.setColor(shade);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    g.drawLine(w-1, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * A border which is like a Margin border but it will only honor the margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * if the margin has been explicitly set by the developer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * Note: This is identical to the package private class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * MetalBorders.RolloverMarginBorder and should probably be consolidated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   200
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    static class RolloverMarginBorder extends EmptyBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        public RolloverMarginBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            super(3,3,3,3); // hardcoded margin for JLF requirements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            Insets margin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                margin = ((AbstractButton)c).getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            if (margin == null || margin instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                // default margin so replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                insets.left = left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                insets.top = top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                insets.right = right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                insets.bottom = bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                // Margin which has been explicitly set by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                insets.left = margin.left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                insets.top = margin.top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                insets.right = margin.right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                insets.bottom = margin.bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   230
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
   public static class ButtonBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        protected Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        protected Color darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        protected Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        protected Color lightHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        public ButtonBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                            Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            this.darkShadow = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            this.lightHighlight = lightHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                            int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            boolean isPressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            boolean isDefault = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                isPressed = model.isPressed() && model.isArmed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                if (c instanceof JButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                    isDefault = ((JButton)c).isDefaultButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            BasicGraphicsUtils.drawBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                   isPressed, isDefault, shadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                                   darkShadow, highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            // leave room for default visual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            insets.set(2, 3, 3, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   273
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public static class ToggleButtonBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        public ToggleButtonBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                                  Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            super(shadow, darkShadow, highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                                int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                BasicGraphicsUtils.drawBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                             false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                                             shadow, darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                                             highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            insets.set(2, 2, 2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   295
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public static class RadioButtonBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        public RadioButtonBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                 Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            super(shadow, darkShadow, highlight, lightHighlight);
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
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                if (model.isArmed() && model.isPressed() || model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                    BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                                                        shadow, darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                                        highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                    BasicGraphicsUtils.drawBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                                               false, b.isFocusPainted() && b.hasFocus(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                                                 shadow, darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                                 highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                             shadow, darkShadow, highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            insets.set(2, 2, 2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   332
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public static class MenuBarBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        private Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        private Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        public MenuBarBorder(Color shadow, Color highlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            g.drawLine(0, height-2, width, height-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            g.drawLine(0, height-1, width, height-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            g.translate(-x,-y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            insets.set(0, 0, 2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   359
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    public static class MarginBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            Insets margin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            // Ideally we'd have an interface defined for classes which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            // support margins (to avoid this hackery), but we've
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            // decided against it for simplicity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
           if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
               AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
               margin = b.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
           } else if (c instanceof JToolBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
               JToolBar t = (JToolBar)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
               margin = t.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
           } else if (c instanceof JTextComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
               JTextComponent t = (JTextComponent)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
               margin = t.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
           insets.top = margin != null? margin.top : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
           insets.left = margin != null? margin.left : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
           insets.bottom = margin != null? margin.bottom : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
           insets.right = margin != null? margin.right : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
           return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23010
diff changeset
   387
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    public static class FieldBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        protected Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        protected Color darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        protected Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        protected Color lightHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        public FieldBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                           Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            this.darkShadow = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            this.lightHighlight = lightHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                            int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                              shadow, darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                                              highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            Insets margin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (c instanceof JTextComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                margin = ((JTextComponent)c).getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            insets.top = margin != null? 2+margin.top : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            insets.left = margin != null? 2+margin.left : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            insets.bottom = margin != null? 2+margin.bottom : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            insets.right = margin != null? 2+margin.right : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Draws the border around the divider in a splitpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * (when BasicSplitPaneUI is used). To get the appropriate effect, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * needs to be used with a SplitPaneBorder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    static class SplitPaneDividerBorder implements Border, UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        SplitPaneDividerBorder(Color highlight, Color shadow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                                int width, int height) {
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   440
            if (!(c instanceof BasicSplitPaneDivider)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   441
                return;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   442
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            Component          child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            Rectangle          cBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            JSplitPane         splitPane = ((BasicSplitPaneDivider)c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                                         getBasicSplitPaneUI().getSplitPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            Dimension          size = c.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            child = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            // This is needed for the space between the divider and end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            // splitpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            g.setColor(c.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            g.drawRect(x, y, width - 1, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    g.drawLine(0, 0, 0, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                child = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    g.drawLine(size.width - 1, 0, size.width - 1, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                    g.drawLine(0, 0, size.width, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
                child = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    g.drawLine(0, size.height - 1, size.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                               size.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        public Insets getBorderInsets(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            Insets insets = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            if (c instanceof BasicSplitPaneDivider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                BasicSplitPaneUI bspui = ((BasicSplitPaneDivider)c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                                         getBasicSplitPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                if (bspui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                    JSplitPane splitPane = bspui.getSplitPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                    if (splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                        if (splitPane.getOrientation() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                            JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                            insets.top = insets.bottom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                            insets.left = insets.right = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                        // VERTICAL_SPLIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                        insets.top = insets.bottom = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                        insets.left = insets.right = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            insets.top = insets.bottom = insets.left = insets.right = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        public boolean isBorderOpaque() { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    /**
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 20169
diff changeset
   508
     * Draws the border around the splitpane. To work correctly you should
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * also install a border on the divider (property SplitPaneDivider.border).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    public static class SplitPaneBorder implements Border, UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        protected Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        protected Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        public SplitPaneBorder(Color highlight, Color shadow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                                int width, int height) {
6510
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   522
            if (!(c instanceof JSplitPane)) {
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   523
                return;
75e8a4664c38 6978482: MetalBorders.ToolBarBorder should specify that its getBorderInsets impl accepts only JToolBar inst
malenkov
parents: 5506
diff changeset
   524
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            // The only tricky part with this border is that the divider is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            // not positioned at the top (for horizontal) or left (for vert),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            // so this border draws to where the divider is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            // -----------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            // |xxxxxxx xxxxxxx|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            // |x     ---     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            // |x     | |     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            // |x     |D|     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            // |x     | |     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            // |x     ---     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            // |xxxxxxx xxxxxxx|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            // -----------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            // The above shows (rather excessively) what this looks like for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            // a horizontal orientation. This border then draws the x's, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            // the SplitPaneDividerBorder drawing its own border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            Component          child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            Rectangle          cBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            JSplitPane splitPane = (JSplitPane)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            child = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            // This is needed for the space between the divider and end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            // splitpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            g.setColor(c.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            g.drawRect(x, y, width - 1, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    cBounds = child.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    g.drawLine(0, 0, cBounds.width + 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                    g.drawLine(0, 1, 0, cBounds.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    g.drawLine(0, cBounds.height + 1, cBounds.width + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                               cBounds.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                child = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                    cBounds = child.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    int             maxX = cBounds.x + cBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    int             maxY = cBounds.y + cBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    g.drawLine(cBounds.x - 1, 0, maxX, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    g.drawLine(cBounds.x - 1, maxY, maxX, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    g.drawLine(maxX, 0, maxX, maxY + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    cBounds = child.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    g.drawLine(0, 0, cBounds.width + 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                    g.drawLine(0, 1, 0, cBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    g.drawLine(1 + cBounds.width, 0, 1 + cBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                               cBounds.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    g.drawLine(0, cBounds.height + 1, 0, cBounds.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                child = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    cBounds = child.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    int             maxX = cBounds.x + cBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    int             maxY = cBounds.y + cBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                    g.drawLine(0, cBounds.y - 1, 0, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                    g.drawLine(maxX, cBounds.y - 1, maxX, cBounds.y - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    g.drawLine(0, maxY, cBounds.width + 1, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                    g.drawLine(maxX, cBounds.y, maxX, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        public Insets getBorderInsets(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            return new Insets(1, 1, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        public boolean isBorderOpaque() { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
}