jdk/src/share/classes/javax/swing/plaf/basic/BasicBorders.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 6510 75e8a4664c38
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2006, 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
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Factory object that can vend Borders appropriate for the basic L & F.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author Georges Saab
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author Amy Fowler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public class BasicBorders {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static Border getButtonBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        Border buttonBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                           new BasicBorders.ButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                                           table.getColor("Button.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
                                           table.getColor("Button.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                                           table.getColor("Button.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                                           table.getColor("Button.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                                     new MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return buttonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static Border getRadioButtonBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        Border radioButtonBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                           new BasicBorders.RadioButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                                           table.getColor("RadioButton.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                                           table.getColor("RadioButton.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                                           table.getColor("RadioButton.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                                           table.getColor("RadioButton.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                                     new MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return radioButtonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public static Border getToggleButtonBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        Border toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                                     new BasicBorders.ToggleButtonBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
                                           table.getColor("ToggleButton.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                                           table.getColor("ToggleButton.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                           table.getColor("ToggleButton.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                                           table.getColor("ToggleButton.highlight")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                                     new MarginBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        return toggleButtonBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static Border getMenuBarBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Border menuBarBorder = new BasicBorders.MenuBarBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                                        table.getColor("MenuBar.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                        table.getColor("MenuBar.highlight")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                   );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        return menuBarBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public static Border getSplitPaneBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        Border splitPaneBorder = new BasicBorders.SplitPaneBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                                     table.getColor("SplitPane.highlight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                                     table.getColor("SplitPane.darkShadow"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        return splitPaneBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Returns a border instance for a JSplitPane divider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static Border getSplitPaneDividerBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        Border splitPaneBorder = new BasicBorders.SplitPaneDividerBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                                     table.getColor("SplitPane.highlight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                     table.getColor("SplitPane.darkShadow"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        return splitPaneBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public static Border getTextFieldBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        Border textFieldBorder = new BasicBorders.FieldBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                           table.getColor("TextField.shadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                                           table.getColor("TextField.darkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
                                           table.getColor("TextField.light"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                                           table.getColor("TextField.highlight"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        return textFieldBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public static Border getProgressBarBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        Border progressBarBorder = new BorderUIResource.LineBorderUIResource(Color.green, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        return progressBarBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public static Border getInternalFrameBorder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        UIDefaults table = UIManager.getLookAndFeelDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        Border internalFrameBorder = new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                                new BevelBorder(BevelBorder.RAISED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                                        table.getColor("InternalFrame.borderLight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                                        table.getColor("InternalFrame.borderHighlight"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                                        table.getColor("InternalFrame.borderDarkShadow"),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                                        table.getColor("InternalFrame.borderShadow")),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                                BorderFactory.createLineBorder(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                                        table.getColor("InternalFrame.borderColor"), 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        return internalFrameBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * Special thin border for rollover toolbar buttons.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public static class RolloverButtonBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        public RolloverButtonBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                  Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            super(shadow, darkShadow, highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        public void paintBorder( Component c, Graphics g, int x, int y, int w, int h ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            AbstractButton b = (AbstractButton) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            Color shade = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            Component p = b.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            if (p != null && p.getBackground().equals(shadow)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                shade = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            if ((model.isRollover() && !(model.isPressed() && !model.isArmed())) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                if (model.isPressed() && model.isArmed() || model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    // Draw the pressd button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    g.setColor(shade);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    g.drawRect(0, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    g.setColor(lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    g.drawLine(w-1, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    // Draw a rollover button
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    g.setColor(lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                    g.drawRect(0, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                    g.setColor(shade);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    g.drawLine(w-1, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                    g.drawLine(0, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                g.translate(-x, -y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                g.setColor(oldColor);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * A border which is like a Margin border but it will only honor the margin
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * if the margin has been explicitly set by the developer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Note: This is identical to the package private class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * MetalBorders.RolloverMarginBorder and should probably be consolidated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
   public static class ButtonBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        protected Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        protected Color darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        protected Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        protected Color lightHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        public ButtonBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                            Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            this.darkShadow = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            this.lightHighlight = lightHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                            int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            boolean isPressed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            boolean isDefault = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                isPressed = model.isPressed() && model.isArmed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                if (c instanceof JButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                    isDefault = ((JButton)c).isDefaultButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            BasicGraphicsUtils.drawBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                   isPressed, isDefault, shadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                   darkShadow, highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            // leave room for default visual
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            insets.set(2, 3, 3, 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
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
    public static class ToggleButtonBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        public ToggleButtonBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                  Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            super(shadow, darkShadow, highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                                int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                BasicGraphicsUtils.drawBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                                             false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                             shadow, darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                                             highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            insets.set(2, 2, 2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public static class RadioButtonBorder extends ButtonBorder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        public RadioButtonBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                                 Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            super(shadow, darkShadow, highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                ButtonModel model = b.getModel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                if (model.isArmed() && model.isPressed() || model.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    BasicGraphicsUtils.drawLoweredBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                                        shadow, darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                                        highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    BasicGraphicsUtils.drawBezel(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                                               false, b.isFocusPainted() && b.hasFocus(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                                                 shadow, darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                                                 highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                BasicGraphicsUtils.drawBezel(g, x, y, width, height, false, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                             shadow, darkShadow, highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            insets.set(2, 2, 2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public static class MenuBarBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        private Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        private Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        public MenuBarBorder(Color shadow, Color highlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            Color oldColor = g.getColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            g.translate(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            g.drawLine(0, height-2, width, height-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            g.drawLine(0, height-1, width, height-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            g.translate(-x,-y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            g.setColor(oldColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            insets.set(0, 0, 2, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public static class MarginBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        public Insets getBorderInsets(Component c, Insets insets)       {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            Insets margin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            // Ideally we'd have an interface defined for classes which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            // support margins (to avoid this hackery), but we've
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            // decided against it for simplicity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
           if (c instanceof AbstractButton) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
               AbstractButton b = (AbstractButton)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
               margin = b.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
           } else if (c instanceof JToolBar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
               JToolBar t = (JToolBar)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
               margin = t.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
           } else if (c instanceof JTextComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
               JTextComponent t = (JTextComponent)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
               margin = t.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
           }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
           insets.top = margin != null? margin.top : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
           insets.left = margin != null? margin.left : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
           insets.bottom = margin != null? margin.bottom : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
           insets.right = margin != null? margin.right : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
           return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    public static class FieldBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        protected Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        protected Color darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        protected Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        protected Color lightHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        public FieldBorder(Color shadow, Color darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                           Color highlight, Color lightHighlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            this.darkShadow = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            this.lightHighlight = lightHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                            int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            BasicGraphicsUtils.drawEtchedRect(g, x, y, width, height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                              shadow, darkShadow,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                              highlight, lightHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            Insets margin = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            if (c instanceof JTextComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                margin = ((JTextComponent)c).getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            insets.top = margin != null? 2+margin.top : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            insets.left = margin != null? 2+margin.left : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            insets.bottom = margin != null? 2+margin.bottom : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            insets.right = margin != null? 2+margin.right : 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        }
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
     * Draws the border around the divider in a splitpane
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * (when BasicSplitPaneUI is used). To get the appropriate effect, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * needs to be used with a SplitPaneBorder.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    static class SplitPaneDividerBorder implements Border, UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        SplitPaneDividerBorder(Color highlight, Color shadow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                                int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            Component          child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            Rectangle          cBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            JSplitPane         splitPane = ((BasicSplitPaneDivider)c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                                         getBasicSplitPaneUI().getSplitPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            Dimension          size = c.getSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            child = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            // This is needed for the space between the divider and end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            // splitpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            g.setColor(c.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            g.drawRect(x, y, width - 1, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    g.drawLine(0, 0, 0, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                child = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
                    g.drawLine(size.width - 1, 0, size.width - 1, size.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    g.drawLine(0, 0, size.width, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                child = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                    g.drawLine(0, size.height - 1, size.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                               size.height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        public Insets getBorderInsets(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            Insets insets = new Insets(0,0,0,0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            if (c instanceof BasicSplitPaneDivider) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                BasicSplitPaneUI bspui = ((BasicSplitPaneDivider)c).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                                         getBasicSplitPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                if (bspui != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    JSplitPane splitPane = bspui.getSplitPane();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                    if (splitPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                        if (splitPane.getOrientation() ==
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                            JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                            insets.top = insets.bottom = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                            insets.left = insets.right = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                        // VERTICAL_SPLIT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                        insets.top = insets.bottom = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                        insets.left = insets.right = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                        return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            insets.top = insets.bottom = insets.left = insets.right = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        public boolean isBorderOpaque() { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * Draws the border around the splitpane. To work correctly you shoudl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * also install a border on the divider (property SplitPaneDivider.border).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    public static class SplitPaneBorder implements Border, UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        protected Color highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        protected Color shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        public SplitPaneBorder(Color highlight, Color shadow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            this.highlight = highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            this.shadow = shadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        public void paintBorder(Component c, Graphics g, int x, int y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                                int width, int height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            // The only tricky part with this border is that the divider is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            // not positioned at the top (for horizontal) or left (for vert),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            // so this border draws to where the divider is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            // -----------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            // |xxxxxxx xxxxxxx|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            // |x     ---     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            // |x     | |     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            // |x     |D|     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            // |x     | |     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            // |x     ---     x|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            // |xxxxxxx xxxxxxx|
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            // -----------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            // The above shows (rather excessively) what this looks like for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            // a horizontal orientation. This border then draws the x's, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            // the SplitPaneDividerBorder drawing its own border.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            Component          child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            Rectangle          cBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            JSplitPane splitPane = (JSplitPane)c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            child = splitPane.getLeftComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            // This is needed for the space between the divider and end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            // splitpane.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            g.setColor(c.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            g.drawRect(x, y, width - 1, height - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            if(splitPane.getOrientation() == JSplitPane.HORIZONTAL_SPLIT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                    cBounds = child.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    g.drawLine(0, 0, cBounds.width + 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    g.drawLine(0, 1, 0, cBounds.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    g.drawLine(0, cBounds.height + 1, cBounds.width + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                               cBounds.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                child = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    cBounds = child.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    int             maxX = cBounds.x + cBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                    int             maxY = cBounds.y + cBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    g.drawLine(cBounds.x - 1, 0, maxX, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                    g.drawLine(cBounds.x - 1, maxY, maxX, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                    g.drawLine(maxX, 0, maxX, maxY + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    cBounds = child.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                    g.drawLine(0, 0, cBounds.width + 1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                    g.drawLine(0, 1, 0, cBounds.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                    g.drawLine(1 + cBounds.width, 0, 1 + cBounds.width,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                               cBounds.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    g.drawLine(0, cBounds.height + 1, 0, cBounds.height + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                child = splitPane.getRightComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                if(child != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    cBounds = child.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                    int             maxX = cBounds.x + cBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    int             maxY = cBounds.y + cBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                    g.setColor(shadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    g.drawLine(0, cBounds.y - 1, 0, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    g.drawLine(maxX, cBounds.y - 1, maxX, cBounds.y - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                    g.drawLine(0, maxY, cBounds.width + 1, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    g.drawLine(maxX, cBounds.y, maxX, maxY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        public Insets getBorderInsets(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            return new Insets(1, 1, 1, 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        public boolean isBorderOpaque() { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
}