Source Code Cross Referenced for MetalBorders.java in  » 6.0-JDK-Core » swing » javax » swing » plaf » metal » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » swing » javax.swing.plaf.metal 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001        /*
0002         * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
0003         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0004         *
0005         * This code is free software; you can redistribute it and/or modify it
0006         * under the terms of the GNU General Public License version 2 only, as
0007         * published by the Free Software Foundation.  Sun designates this
0008         * particular file as subject to the "Classpath" exception as provided
0009         * by Sun in the LICENSE file that accompanied this code.
0010         *
0011         * This code is distributed in the hope that it will be useful, but WITHOUT
0012         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0013         * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0014         * version 2 for more details (a copy is included in the LICENSE file that
0015         * accompanied this code).
0016         *
0017         * You should have received a copy of the GNU General Public License version
0018         * 2 along with this work; if not, write to the Free Software Foundation,
0019         * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0020         *
0021         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
0022         * CA 95054 USA or visit www.sun.com if you need additional information or
0023         * have any questions.
0024         */
0025
0026        package javax.swing.plaf.metal;
0027
0028        import javax.swing.*;
0029        import javax.swing.border.*;
0030        import javax.swing.plaf.*;
0031        import javax.swing.plaf.basic.BasicBorders;
0032        import javax.swing.text.JTextComponent;
0033
0034        import java.awt.Component;
0035        import java.awt.Insets;
0036        import java.awt.Dimension;
0037        import java.awt.Rectangle;
0038        import java.awt.Color;
0039        import java.awt.Dialog;
0040        import java.awt.Frame;
0041        import java.awt.Graphics;
0042        import java.awt.Window;
0043        import java.io.Serializable;
0044
0045        import sun.swing.StringUIClientPropertyKey;
0046
0047        /**
0048         * Factory object that can vend Borders appropriate for the metal L & F.
0049         * @author Steve Wilson
0050         * @version 1.49 05/05/07
0051         */
0052
0053        public class MetalBorders {
0054
0055            /**
0056             * Client property indicating the button shouldn't provide a rollover
0057             * indicator. Only used with the Ocean theme.
0058             */
0059            static Object NO_BUTTON_ROLLOVER = new StringUIClientPropertyKey(
0060                    "NoButtonRollover");
0061
0062            public static class Flush3DBorder extends AbstractBorder implements 
0063                    UIResource {
0064
0065                private static final Insets insets = new Insets(2, 2, 2, 2);
0066
0067                public void paintBorder(Component c, Graphics g, int x, int y,
0068                        int w, int h) {
0069                    if (c.isEnabled()) {
0070                        MetalUtils.drawFlush3DBorder(g, x, y, w, h);
0071                    } else {
0072                        MetalUtils.drawDisabledBorder(g, x, y, w, h);
0073                    }
0074                }
0075
0076                public Insets getBorderInsets(Component c) {
0077                    return insets;
0078                }
0079
0080                public Insets getBorderInsets(Component c, Insets newInsets) {
0081                    newInsets.top = insets.top;
0082                    newInsets.left = insets.left;
0083                    newInsets.bottom = insets.bottom;
0084                    newInsets.right = insets.right;
0085                    return newInsets;
0086                }
0087            }
0088
0089            public static class ButtonBorder extends AbstractBorder implements 
0090                    UIResource {
0091
0092                protected static Insets borderInsets = new Insets(3, 3, 3, 3);
0093
0094                public void paintBorder(Component c, Graphics g, int x, int y,
0095                        int w, int h) {
0096                    if (MetalLookAndFeel.usingOcean()) {
0097                        paintOceanBorder(c, g, x, y, w, h);
0098                        return;
0099                    }
0100                    AbstractButton button = (AbstractButton) c;
0101                    ButtonModel model = button.getModel();
0102
0103                    if (model.isEnabled()) {
0104                        boolean isPressed = model.isPressed()
0105                                && model.isArmed();
0106                        boolean isDefault = (button instanceof  JButton && ((JButton) button)
0107                                .isDefaultButton());
0108
0109                        if (isPressed && isDefault) {
0110                            MetalUtils.drawDefaultButtonPressedBorder(g, x, y,
0111                                    w, h);
0112                        } else if (isPressed) {
0113                            MetalUtils.drawPressed3DBorder(g, x, y, w, h);
0114                        } else if (isDefault) {
0115                            MetalUtils.drawDefaultButtonBorder(g, x, y, w, h,
0116                                    false);
0117                        } else {
0118                            MetalUtils.drawButtonBorder(g, x, y, w, h, false);
0119                        }
0120                    } else { // disabled state
0121                        MetalUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
0122                    }
0123                }
0124
0125                private void paintOceanBorder(Component c, Graphics g, int x,
0126                        int y, int w, int h) {
0127                    AbstractButton button = (AbstractButton) c;
0128                    ButtonModel model = ((AbstractButton) c).getModel();
0129
0130                    g.translate(x, y);
0131                    if (MetalUtils.isToolBarButton(button)) {
0132                        if (model.isEnabled()) {
0133                            if (model.isPressed()) {
0134                                g.setColor(MetalLookAndFeel.getWhite());
0135                                g.fillRect(1, h - 1, w - 1, 1);
0136                                g.fillRect(w - 1, 1, 1, h - 1);
0137                                g.setColor(MetalLookAndFeel
0138                                        .getControlDarkShadow());
0139                                g.drawRect(0, 0, w - 2, h - 2);
0140                                g.fillRect(1, 1, w - 3, 1);
0141                            } else if (model.isSelected() || model.isRollover()) {
0142                                g.setColor(MetalLookAndFeel.getWhite());
0143                                g.fillRect(1, h - 1, w - 1, 1);
0144                                g.fillRect(w - 1, 1, 1, h - 1);
0145                                g.setColor(MetalLookAndFeel
0146                                        .getControlDarkShadow());
0147                                g.drawRect(0, 0, w - 2, h - 2);
0148                            } else {
0149                                g.setColor(MetalLookAndFeel.getWhite());
0150                                g.drawRect(1, 1, w - 2, h - 2);
0151                                g
0152                                        .setColor(UIManager
0153                                                .getColor("Button.toolBarBorderBackground"));
0154                                g.drawRect(0, 0, w - 2, h - 2);
0155                            }
0156                        } else {
0157                            g
0158                                    .setColor(UIManager
0159                                            .getColor("Button.disabledToolBarBorderBackground"));
0160                            g.drawRect(0, 0, w - 2, h - 2);
0161                        }
0162                    } else if (model.isEnabled()) {
0163                        boolean pressed = model.isPressed();
0164                        boolean armed = model.isArmed();
0165
0166                        if ((c instanceof  JButton)
0167                                && ((JButton) c).isDefaultButton()) {
0168                            g.setColor(MetalLookAndFeel.getControlDarkShadow());
0169                            g.drawRect(0, 0, w - 1, h - 1);
0170                            g.drawRect(1, 1, w - 3, h - 3);
0171                        } else if (pressed) {
0172                            g.setColor(MetalLookAndFeel.getControlDarkShadow());
0173                            g.fillRect(0, 0, w, 2);
0174                            g.fillRect(0, 2, 2, h - 2);
0175                            g.fillRect(w - 1, 1, 1, h - 1);
0176                            g.fillRect(1, h - 1, w - 2, 1);
0177                        } else if (model.isRollover()
0178                                && button.getClientProperty(NO_BUTTON_ROLLOVER) == null) {
0179                            g.setColor(MetalLookAndFeel.getPrimaryControl());
0180                            g.drawRect(0, 0, w - 1, h - 1);
0181                            g.drawRect(2, 2, w - 5, h - 5);
0182                            g.setColor(MetalLookAndFeel.getControlDarkShadow());
0183                            g.drawRect(1, 1, w - 3, h - 3);
0184                        } else {
0185                            g.setColor(MetalLookAndFeel.getControlDarkShadow());
0186                            g.drawRect(0, 0, w - 1, h - 1);
0187                        }
0188                    } else {
0189                        g.setColor(MetalLookAndFeel
0190                                .getInactiveControlTextColor());
0191                        g.drawRect(0, 0, w - 1, h - 1);
0192                        if ((c instanceof  JButton)
0193                                && ((JButton) c).isDefaultButton()) {
0194                            g.drawRect(1, 1, w - 3, h - 3);
0195                        }
0196                    }
0197                }
0198
0199                public Insets getBorderInsets(Component c) {
0200                    return borderInsets;
0201                }
0202
0203                public Insets getBorderInsets(Component c, Insets newInsets) {
0204                    newInsets.top = borderInsets.top;
0205                    newInsets.left = borderInsets.left;
0206                    newInsets.bottom = borderInsets.bottom;
0207                    newInsets.right = borderInsets.right;
0208                    return newInsets;
0209                }
0210            }
0211
0212            public static class InternalFrameBorder extends AbstractBorder
0213                    implements  UIResource {
0214
0215                private static final Insets insets = new Insets(5, 5, 5, 5);
0216
0217                private static final int corner = 14;
0218
0219                public void paintBorder(Component c, Graphics g, int x, int y,
0220                        int w, int h) {
0221
0222                    Color background;
0223                    Color highlight;
0224                    Color shadow;
0225
0226                    if (c instanceof  JInternalFrame
0227                            && ((JInternalFrame) c).isSelected()) {
0228                        background = MetalLookAndFeel
0229                                .getPrimaryControlDarkShadow();
0230                        highlight = MetalLookAndFeel.getPrimaryControlShadow();
0231                        shadow = MetalLookAndFeel.getPrimaryControlInfo();
0232                    } else {
0233                        background = MetalLookAndFeel.getControlDarkShadow();
0234                        highlight = MetalLookAndFeel.getControlShadow();
0235                        shadow = MetalLookAndFeel.getControlInfo();
0236                    }
0237
0238                    g.setColor(background);
0239                    // Draw outermost lines
0240                    g.drawLine(1, 0, w - 2, 0);
0241                    g.drawLine(0, 1, 0, h - 2);
0242                    g.drawLine(w - 1, 1, w - 1, h - 2);
0243                    g.drawLine(1, h - 1, w - 2, h - 1);
0244
0245                    // Draw the bulk of the border
0246                    for (int i = 1; i < 5; i++) {
0247                        g.drawRect(x + i, y + i, w - (i * 2) - 1, h - (i * 2)
0248                                - 1);
0249                    }
0250
0251                    if (c instanceof  JInternalFrame
0252                            && ((JInternalFrame) c).isResizable()) {
0253                        g.setColor(highlight);
0254                        // Draw the Long highlight lines
0255                        g.drawLine(corner + 1, 3, w - corner, 3);
0256                        g.drawLine(3, corner + 1, 3, h - corner);
0257                        g.drawLine(w - 2, corner + 1, w - 2, h - corner);
0258                        g.drawLine(corner + 1, h - 2, w - corner, h - 2);
0259
0260                        g.setColor(shadow);
0261                        // Draw the Long shadow lines
0262                        g.drawLine(corner, 2, w - corner - 1, 2);
0263                        g.drawLine(2, corner, 2, h - corner - 1);
0264                        g.drawLine(w - 3, corner, w - 3, h - corner - 1);
0265                        g.drawLine(corner, h - 3, w - corner - 1, h - 3);
0266                    }
0267
0268                }
0269
0270                public Insets getBorderInsets(Component c) {
0271                    return insets;
0272                }
0273
0274                public Insets getBorderInsets(Component c, Insets newInsets) {
0275                    newInsets.top = insets.top;
0276                    newInsets.left = insets.left;
0277                    newInsets.bottom = insets.bottom;
0278                    newInsets.right = insets.right;
0279                    return newInsets;
0280                }
0281            }
0282
0283            /**
0284             * Border for a Frame.
0285             * @since 1.4
0286             */
0287            static class FrameBorder extends AbstractBorder implements 
0288                    UIResource {
0289
0290                private static final Insets insets = new Insets(5, 5, 5, 5);
0291
0292                private static final int corner = 14;
0293
0294                public void paintBorder(Component c, Graphics g, int x, int y,
0295                        int w, int h) {
0296
0297                    Color background;
0298                    Color highlight;
0299                    Color shadow;
0300
0301                    Window window = SwingUtilities.getWindowAncestor(c);
0302                    if (window != null && window.isActive()) {
0303                        background = MetalLookAndFeel
0304                                .getPrimaryControlDarkShadow();
0305                        highlight = MetalLookAndFeel.getPrimaryControlShadow();
0306                        shadow = MetalLookAndFeel.getPrimaryControlInfo();
0307                    } else {
0308                        background = MetalLookAndFeel.getControlDarkShadow();
0309                        highlight = MetalLookAndFeel.getControlShadow();
0310                        shadow = MetalLookAndFeel.getControlInfo();
0311                    }
0312
0313                    g.setColor(background);
0314                    // Draw outermost lines
0315                    g.drawLine(x + 1, y + 0, x + w - 2, y + 0);
0316                    g.drawLine(x + 0, y + 1, x + 0, y + h - 2);
0317                    g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 2);
0318                    g.drawLine(x + 1, y + h - 1, x + w - 2, y + h - 1);
0319
0320                    // Draw the bulk of the border
0321                    for (int i = 1; i < 5; i++) {
0322                        g.drawRect(x + i, y + i, w - (i * 2) - 1, h - (i * 2)
0323                                - 1);
0324                    }
0325
0326                    if ((window instanceof  Frame)
0327                            && ((Frame) window).isResizable()) {
0328                        g.setColor(highlight);
0329                        // Draw the Long highlight lines
0330                        g.drawLine(corner + 1, 3, w - corner, 3);
0331                        g.drawLine(3, corner + 1, 3, h - corner);
0332                        g.drawLine(w - 2, corner + 1, w - 2, h - corner);
0333                        g.drawLine(corner + 1, h - 2, w - corner, h - 2);
0334
0335                        g.setColor(shadow);
0336                        // Draw the Long shadow lines
0337                        g.drawLine(corner, 2, w - corner - 1, 2);
0338                        g.drawLine(2, corner, 2, h - corner - 1);
0339                        g.drawLine(w - 3, corner, w - 3, h - corner - 1);
0340                        g.drawLine(corner, h - 3, w - corner - 1, h - 3);
0341                    }
0342
0343                }
0344
0345                public Insets getBorderInsets(Component c) {
0346                    return insets;
0347                }
0348
0349                public Insets getBorderInsets(Component c, Insets newInsets) {
0350                    newInsets.top = insets.top;
0351                    newInsets.left = insets.left;
0352                    newInsets.bottom = insets.bottom;
0353                    newInsets.right = insets.right;
0354                    return newInsets;
0355                }
0356            }
0357
0358            /**
0359             * Border for a Frame.
0360             * @since 1.4
0361             */
0362            static class DialogBorder extends AbstractBorder implements 
0363                    UIResource {
0364                private static final Insets insets = new Insets(5, 5, 5, 5);
0365                private static final int corner = 14;
0366
0367                protected Color getActiveBackground() {
0368                    return MetalLookAndFeel.getPrimaryControlDarkShadow();
0369                }
0370
0371                protected Color getActiveHighlight() {
0372                    return MetalLookAndFeel.getPrimaryControlShadow();
0373                }
0374
0375                protected Color getActiveShadow() {
0376                    return MetalLookAndFeel.getPrimaryControlInfo();
0377                }
0378
0379                protected Color getInactiveBackground() {
0380                    return MetalLookAndFeel.getControlDarkShadow();
0381                }
0382
0383                protected Color getInactiveHighlight() {
0384                    return MetalLookAndFeel.getControlShadow();
0385                }
0386
0387                protected Color getInactiveShadow() {
0388                    return MetalLookAndFeel.getControlInfo();
0389                }
0390
0391                public void paintBorder(Component c, Graphics g, int x, int y,
0392                        int w, int h) {
0393                    Color background;
0394                    Color highlight;
0395                    Color shadow;
0396
0397                    Window window = SwingUtilities.getWindowAncestor(c);
0398                    if (window != null && window.isActive()) {
0399                        background = getActiveBackground();
0400                        highlight = getActiveHighlight();
0401                        shadow = getActiveShadow();
0402                    } else {
0403                        background = getInactiveBackground();
0404                        highlight = getInactiveHighlight();
0405                        shadow = getInactiveShadow();
0406                    }
0407
0408                    g.setColor(background);
0409                    // Draw outermost lines
0410                    g.drawLine(x + 1, y + 0, x + w - 2, y + 0);
0411                    g.drawLine(x + 0, y + 1, x + 0, y + h - 2);
0412                    g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 2);
0413                    g.drawLine(x + 1, y + h - 1, x + w - 2, y + h - 1);
0414
0415                    // Draw the bulk of the border
0416                    for (int i = 1; i < 5; i++) {
0417                        g.drawRect(x + i, y + i, w - (i * 2) - 1, h - (i * 2)
0418                                - 1);
0419                    }
0420
0421                    if ((window instanceof  Dialog)
0422                            && ((Dialog) window).isResizable()) {
0423                        g.setColor(highlight);
0424                        // Draw the Long highlight lines
0425                        g.drawLine(corner + 1, 3, w - corner, 3);
0426                        g.drawLine(3, corner + 1, 3, h - corner);
0427                        g.drawLine(w - 2, corner + 1, w - 2, h - corner);
0428                        g.drawLine(corner + 1, h - 2, w - corner, h - 2);
0429
0430                        g.setColor(shadow);
0431                        // Draw the Long shadow lines
0432                        g.drawLine(corner, 2, w - corner - 1, 2);
0433                        g.drawLine(2, corner, 2, h - corner - 1);
0434                        g.drawLine(w - 3, corner, w - 3, h - corner - 1);
0435                        g.drawLine(corner, h - 3, w - corner - 1, h - 3);
0436                    }
0437
0438                }
0439
0440                public Insets getBorderInsets(Component c) {
0441                    return insets;
0442                }
0443
0444                public Insets getBorderInsets(Component c, Insets newInsets) {
0445                    newInsets.top = insets.top;
0446                    newInsets.left = insets.left;
0447                    newInsets.bottom = insets.bottom;
0448                    newInsets.right = insets.right;
0449                    return newInsets;
0450                }
0451            }
0452
0453            /**
0454             * Border for an Error Dialog.
0455             * @since 1.4
0456             */
0457            static class ErrorDialogBorder extends DialogBorder implements 
0458                    UIResource {
0459                protected Color getActiveBackground() {
0460                    return UIManager
0461                            .getColor("OptionPane.errorDialog.border.background");
0462                }
0463            }
0464
0465            /**
0466             * Border for a QuestionDialog.  Also used for a JFileChooser and a 
0467             * JColorChooser..
0468             * @since 1.4
0469             */
0470            static class QuestionDialogBorder extends DialogBorder implements 
0471                    UIResource {
0472                protected Color getActiveBackground() {
0473                    return UIManager
0474                            .getColor("OptionPane.questionDialog.border.background");
0475                }
0476            }
0477
0478            /**
0479             * Border for a Warning Dialog.
0480             * @since 1.4
0481             */
0482            static class WarningDialogBorder extends DialogBorder implements 
0483                    UIResource {
0484                protected Color getActiveBackground() {
0485                    return UIManager
0486                            .getColor("OptionPane.warningDialog.border.background");
0487                }
0488            }
0489
0490            /**
0491             * Border for a Palette.
0492             * @since 1.3
0493             */
0494            public static class PaletteBorder extends AbstractBorder implements 
0495                    UIResource {
0496                private static final Insets insets = new Insets(1, 1, 1, 1);
0497                int titleHeight = 0;
0498
0499                public void paintBorder(Component c, Graphics g, int x, int y,
0500                        int w, int h) {
0501
0502                    g.translate(x, y);
0503                    g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
0504                    g.drawLine(0, 1, 0, h - 2);
0505                    g.drawLine(1, h - 1, w - 2, h - 1);
0506                    g.drawLine(w - 1, 1, w - 1, h - 2);
0507                    g.drawLine(1, 0, w - 2, 0);
0508                    g.drawRect(1, 1, w - 3, h - 3);
0509                    g.translate(-x, -y);
0510
0511                }
0512
0513                public Insets getBorderInsets(Component c) {
0514                    return insets;
0515                }
0516
0517                public Insets getBorderInsets(Component c, Insets newInsets) {
0518                    newInsets.top = insets.top;
0519                    newInsets.left = insets.left;
0520                    newInsets.bottom = insets.bottom;
0521                    newInsets.right = insets.right;
0522                    return newInsets;
0523                }
0524            }
0525
0526            public static class OptionDialogBorder extends AbstractBorder
0527                    implements  UIResource {
0528                private static final Insets insets = new Insets(3, 3, 3, 3);
0529                int titleHeight = 0;
0530
0531                public void paintBorder(Component c, Graphics g, int x, int y,
0532                        int w, int h) {
0533
0534                    g.translate(x, y);
0535
0536                    int messageType = JOptionPane.PLAIN_MESSAGE;
0537                    if (c instanceof  JInternalFrame) {
0538                        Object obj = ((JInternalFrame) c)
0539                                .getClientProperty("JInternalFrame.messageType");
0540                        if (obj != null && (obj instanceof  Integer)) {
0541                            messageType = ((Integer) obj).intValue();
0542                        }
0543                    }
0544
0545                    Color borderColor;
0546
0547                    switch (messageType) {
0548                    case (JOptionPane.ERROR_MESSAGE):
0549                        borderColor = UIManager
0550                                .getColor("OptionPane.errorDialog.border.background");
0551                        break;
0552                    case (JOptionPane.QUESTION_MESSAGE):
0553                        borderColor = UIManager
0554                                .getColor("OptionPane.questionDialog.border.background");
0555                        break;
0556                    case (JOptionPane.WARNING_MESSAGE):
0557                        borderColor = UIManager
0558                                .getColor("OptionPane.warningDialog.border.background");
0559                        break;
0560                    case (JOptionPane.INFORMATION_MESSAGE):
0561                    case (JOptionPane.PLAIN_MESSAGE):
0562                    default:
0563                        borderColor = MetalLookAndFeel
0564                                .getPrimaryControlDarkShadow();
0565                        break;
0566                    }
0567
0568                    g.setColor(borderColor);
0569
0570                    // Draw outermost lines
0571                    g.drawLine(1, 0, w - 2, 0);
0572                    g.drawLine(0, 1, 0, h - 2);
0573                    g.drawLine(w - 1, 1, w - 1, h - 2);
0574                    g.drawLine(1, h - 1, w - 2, h - 1);
0575
0576                    // Draw the bulk of the border
0577                    for (int i = 1; i < 3; i++) {
0578                        g.drawRect(i, i, w - (i * 2) - 1, h - (i * 2) - 1);
0579                    }
0580
0581                    g.translate(-x, -y);
0582
0583                }
0584
0585                public Insets getBorderInsets(Component c) {
0586                    return insets;
0587                }
0588
0589                public Insets getBorderInsets(Component c, Insets newInsets) {
0590                    newInsets.top = insets.top;
0591                    newInsets.left = insets.left;
0592                    newInsets.bottom = insets.bottom;
0593                    newInsets.right = insets.right;
0594                    return newInsets;
0595                }
0596            }
0597
0598            public static class MenuBarBorder extends AbstractBorder implements 
0599                    UIResource {
0600                protected static Insets borderInsets = new Insets(1, 0, 1, 0);
0601
0602                public void paintBorder(Component c, Graphics g, int x, int y,
0603                        int w, int h) {
0604                    g.translate(x, y);
0605
0606                    if (MetalLookAndFeel.usingOcean()) {
0607                        // Only paint a border if we're not next to a horizontal
0608                        // toolbar
0609                        if (!MetalToolBarUI
0610                                .doesMenuBarBorderToolBar((JMenuBar) c)) {
0611                            g.setColor(MetalLookAndFeel.getControl());
0612                            g.drawLine(0, h - 2, w, h - 2);
0613                            g.setColor(UIManager
0614                                    .getColor("MenuBar.borderColor"));
0615                            g.drawLine(0, h - 1, w, h - 1);
0616                        }
0617                    } else {
0618                        g.setColor(MetalLookAndFeel.getControlShadow());
0619                        g.drawLine(0, h - 1, w, h - 1);
0620                    }
0621
0622                    g.translate(-x, -y);
0623
0624                }
0625
0626                public Insets getBorderInsets(Component c) {
0627                    return getBorderInsets(c, new Insets(0, 0, 0, 0));
0628                }
0629
0630                public Insets getBorderInsets(Component c, Insets newInsets) {
0631                    if (MetalLookAndFeel.usingOcean()) {
0632                        newInsets.set(0, 0, 2, 0);
0633                    } else {
0634                        newInsets.top = borderInsets.top;
0635                        newInsets.left = borderInsets.left;
0636                        newInsets.bottom = borderInsets.bottom;
0637                        newInsets.right = borderInsets.right;
0638                    }
0639                    return newInsets;
0640                }
0641            }
0642
0643            public static class MenuItemBorder extends AbstractBorder implements 
0644                    UIResource {
0645                protected static Insets borderInsets = new Insets(2, 2, 2, 2);
0646
0647                public void paintBorder(Component c, Graphics g, int x, int y,
0648                        int w, int h) {
0649                    JMenuItem b = (JMenuItem) c;
0650                    ButtonModel model = b.getModel();
0651
0652                    g.translate(x, y);
0653
0654                    if (c.getParent() instanceof  JMenuBar) {
0655                        if (model.isArmed() || model.isSelected()) {
0656                            g.setColor(MetalLookAndFeel.getControlDarkShadow());
0657                            g.drawLine(0, 0, w - 2, 0);
0658                            g.drawLine(0, 0, 0, h - 1);
0659                            g.drawLine(w - 2, 2, w - 2, h - 1);
0660
0661                            g.setColor(MetalLookAndFeel
0662                                    .getPrimaryControlHighlight());
0663                            g.drawLine(w - 1, 1, w - 1, h - 1);
0664
0665                            g.setColor(MetalLookAndFeel.getMenuBackground());
0666                            g.drawLine(w - 1, 0, w - 1, 0);
0667                        }
0668                    } else {
0669                        if (model.isArmed()
0670                                || (c instanceof  JMenu && model.isSelected())) {
0671                            g.setColor(MetalLookAndFeel
0672                                    .getPrimaryControlDarkShadow());
0673                            g.drawLine(0, 0, w - 1, 0);
0674
0675                            g.setColor(MetalLookAndFeel
0676                                    .getPrimaryControlHighlight());
0677                            g.drawLine(0, h - 1, w - 1, h - 1);
0678                        } else {
0679                            g.setColor(MetalLookAndFeel
0680                                    .getPrimaryControlHighlight());
0681                            g.drawLine(0, 0, 0, h - 1);
0682                        }
0683                    }
0684
0685                    g.translate(-x, -y);
0686                }
0687
0688                public Insets getBorderInsets(Component c) {
0689                    return borderInsets;
0690                }
0691
0692                public Insets getBorderInsets(Component c, Insets newInsets) {
0693                    newInsets.top = borderInsets.top;
0694                    newInsets.left = borderInsets.left;
0695                    newInsets.bottom = borderInsets.bottom;
0696                    newInsets.right = borderInsets.right;
0697                    return newInsets;
0698                }
0699            }
0700
0701            public static class PopupMenuBorder extends AbstractBorder
0702                    implements  UIResource {
0703                protected static Insets borderInsets = new Insets(3, 1, 2, 1);
0704
0705                public void paintBorder(Component c, Graphics g, int x, int y,
0706                        int w, int h) {
0707                    g.translate(x, y);
0708
0709                    g.setColor(MetalLookAndFeel.getPrimaryControlDarkShadow());
0710                    g.drawRect(0, 0, w - 1, h - 1);
0711
0712                    g.setColor(MetalLookAndFeel.getPrimaryControlHighlight());
0713                    g.drawLine(1, 1, w - 2, 1);
0714                    g.drawLine(1, 2, 1, 2);
0715                    g.drawLine(1, h - 2, 1, h - 2);
0716
0717                    g.translate(-x, -y);
0718
0719                }
0720
0721                public Insets getBorderInsets(Component c) {
0722                    return borderInsets;
0723                }
0724
0725                public Insets getBorderInsets(Component c, Insets newInsets) {
0726                    newInsets.top = borderInsets.top;
0727                    newInsets.left = borderInsets.left;
0728                    newInsets.bottom = borderInsets.bottom;
0729                    newInsets.right = borderInsets.right;
0730                    return newInsets;
0731                }
0732            }
0733
0734            public static class RolloverButtonBorder extends ButtonBorder {
0735
0736                public void paintBorder(Component c, Graphics g, int x, int y,
0737                        int w, int h) {
0738                    AbstractButton b = (AbstractButton) c;
0739                    ButtonModel model = b.getModel();
0740
0741                    if (model.isRollover()
0742                            && !(model.isPressed() && !model.isArmed())) {
0743                        super .paintBorder(c, g, x, y, w, h);
0744                    }
0745                }
0746
0747            }
0748
0749            /**
0750             * A border which is like a Margin border but it will only honor the margin
0751             * if the margin has been explicitly set by the developer.
0752             * 
0753             * Note: This is identical to the package private class
0754             * BasicBorders.RolloverMarginBorder and should probably be consolidated.
0755             */
0756            static class RolloverMarginBorder extends EmptyBorder {
0757
0758                public RolloverMarginBorder() {
0759                    super (3, 3, 3, 3); // hardcoded margin for JLF requirements.
0760                }
0761
0762                public Insets getBorderInsets(Component c) {
0763                    return getBorderInsets(c, new Insets(0, 0, 0, 0));
0764                }
0765
0766                public Insets getBorderInsets(Component c, Insets insets) {
0767                    Insets margin = null;
0768
0769                    if (c instanceof  AbstractButton) {
0770                        margin = ((AbstractButton) c).getMargin();
0771                    }
0772                    if (margin == null || margin instanceof  UIResource) {
0773                        // default margin so replace
0774                        insets.left = left;
0775                        insets.top = top;
0776                        insets.right = right;
0777                        insets.bottom = bottom;
0778                    } else {
0779                        // Margin which has been explicitly set by the user.
0780                        insets.left = margin.left;
0781                        insets.top = margin.top;
0782                        insets.right = margin.right;
0783                        insets.bottom = margin.bottom;
0784                    }
0785                    return insets;
0786                }
0787            }
0788
0789            public static class ToolBarBorder extends AbstractBorder implements 
0790                    UIResource, SwingConstants {
0791                protected MetalBumps bumps = new MetalBumps(10, 10,
0792                        MetalLookAndFeel.getControlHighlight(),
0793                        MetalLookAndFeel.getControlDarkShadow(), UIManager
0794                                .getColor("ToolBar.background"));
0795
0796                public void paintBorder(Component c, Graphics g, int x, int y,
0797                        int w, int h) {
0798                    g.translate(x, y);
0799
0800                    if (((JToolBar) c).isFloatable()) {
0801                        if (((JToolBar) c).getOrientation() == HORIZONTAL) {
0802                            int shift = MetalLookAndFeel.usingOcean() ? -1 : 0;
0803                            bumps.setBumpArea(10, h - 4);
0804                            if (MetalUtils.isLeftToRight(c)) {
0805                                bumps.paintIcon(c, g, 2, 2 + shift);
0806                            } else {
0807                                bumps.paintIcon(c, g, w - 12, 2 + shift);
0808                            }
0809                        } else // vertical
0810                        {
0811                            bumps.setBumpArea(w - 4, 10);
0812                            bumps.paintIcon(c, g, 2, 2);
0813                        }
0814
0815                    }
0816
0817                    if (((JToolBar) c).getOrientation() == HORIZONTAL
0818                            && MetalLookAndFeel.usingOcean()) {
0819                        g.setColor(MetalLookAndFeel.getControl());
0820                        g.drawLine(0, h - 2, w, h - 2);
0821                        g.setColor(UIManager.getColor("ToolBar.borderColor"));
0822                        g.drawLine(0, h - 1, w, h - 1);
0823                    }
0824
0825                    g.translate(-x, -y);
0826                }
0827
0828                public Insets getBorderInsets(Component c) {
0829                    return getBorderInsets(c, new Insets(0, 0, 0, 0));
0830                }
0831
0832                public Insets getBorderInsets(Component c, Insets newInsets) {
0833                    if (MetalLookAndFeel.usingOcean()) {
0834                        newInsets.set(1, 2, 3, 2);
0835                    } else {
0836                        newInsets.top = newInsets.left = newInsets.bottom = newInsets.right = 2;
0837                    }
0838
0839                    if (((JToolBar) c).isFloatable()) {
0840                        if (((JToolBar) c).getOrientation() == HORIZONTAL) {
0841                            if (c.getComponentOrientation().isLeftToRight()) {
0842                                newInsets.left = 16;
0843                            } else {
0844                                newInsets.right = 16;
0845                            }
0846                        } else {// vertical
0847                            newInsets.top = 16;
0848                        }
0849                    }
0850
0851                    Insets margin = ((JToolBar) c).getMargin();
0852
0853                    if (margin != null) {
0854                        newInsets.left += margin.left;
0855                        newInsets.top += margin.top;
0856                        newInsets.right += margin.right;
0857                        newInsets.bottom += margin.bottom;
0858                    }
0859
0860                    return newInsets;
0861                }
0862            }
0863
0864            private static Border buttonBorder;
0865
0866            /**
0867             * Returns a border instance for a JButton
0868             * @since 1.3
0869             */
0870            public static Border getButtonBorder() {
0871                if (buttonBorder == null) {
0872                    buttonBorder = new BorderUIResource.CompoundBorderUIResource(
0873                            new MetalBorders.ButtonBorder(),
0874                            new BasicBorders.MarginBorder());
0875                }
0876                return buttonBorder;
0877            }
0878
0879            private static Border textBorder;
0880
0881            /**
0882             * Returns a border instance for a text component
0883             * @since 1.3
0884             */
0885            public static Border getTextBorder() {
0886                if (textBorder == null) {
0887                    textBorder = new BorderUIResource.CompoundBorderUIResource(
0888                            new MetalBorders.Flush3DBorder(),
0889                            new BasicBorders.MarginBorder());
0890                }
0891                return textBorder;
0892            }
0893
0894            private static Border textFieldBorder;
0895
0896            /**
0897             * Returns a border instance for a JTextField
0898             * @since 1.3
0899             */
0900            public static Border getTextFieldBorder() {
0901                if (textFieldBorder == null) {
0902                    textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
0903                            new MetalBorders.TextFieldBorder(),
0904                            new BasicBorders.MarginBorder());
0905                }
0906                return textFieldBorder;
0907            }
0908
0909            public static class TextFieldBorder extends Flush3DBorder {
0910
0911                public void paintBorder(Component c, Graphics g, int x, int y,
0912                        int w, int h) {
0913
0914                    if (!(c instanceof  JTextComponent)) {
0915                        // special case for non-text components (bug ID 4144840)
0916                        if (c.isEnabled()) {
0917                            MetalUtils.drawFlush3DBorder(g, x, y, w, h);
0918                        } else {
0919                            MetalUtils.drawDisabledBorder(g, x, y, w, h);
0920                        }
0921                        return;
0922                    }
0923
0924                    if (c.isEnabled() && ((JTextComponent) c).isEditable()) {
0925                        MetalUtils.drawFlush3DBorder(g, x, y, w, h);
0926                    } else {
0927                        MetalUtils.drawDisabledBorder(g, x, y, w, h);
0928                    }
0929
0930                }
0931            }
0932
0933            public static class ScrollPaneBorder extends AbstractBorder
0934                    implements  UIResource {
0935
0936                private static final Insets insets = new Insets(1, 1, 2, 2);
0937
0938                public void paintBorder(Component c, Graphics g, int x, int y,
0939                        int w, int h) {
0940
0941                    JScrollPane scroll = (JScrollPane) c;
0942                    JComponent colHeader = scroll.getColumnHeader();
0943                    int colHeaderHeight = 0;
0944                    if (colHeader != null)
0945                        colHeaderHeight = colHeader.getHeight();
0946
0947                    JComponent rowHeader = scroll.getRowHeader();
0948                    int rowHeaderWidth = 0;
0949                    if (rowHeader != null)
0950                        rowHeaderWidth = rowHeader.getWidth();
0951
0952                    g.translate(x, y);
0953
0954                    g.setColor(MetalLookAndFeel.getControlDarkShadow());
0955                    g.drawRect(0, 0, w - 2, h - 2);
0956                    g.setColor(MetalLookAndFeel.getControlHighlight());
0957
0958                    g.drawLine(w - 1, 1, w - 1, h - 1);
0959                    g.drawLine(1, h - 1, w - 1, h - 1);
0960
0961                    g.setColor(MetalLookAndFeel.getControl());
0962                    g.drawLine(w - 2, 2 + colHeaderHeight, w - 2,
0963                            2 + colHeaderHeight);
0964                    g.drawLine(1 + rowHeaderWidth, h - 2, 1 + rowHeaderWidth,
0965                            h - 2);
0966
0967                    g.translate(-x, -y);
0968
0969                }
0970
0971                public Insets getBorderInsets(Component c) {
0972                    return insets;
0973                }
0974            }
0975
0976            private static Border toggleButtonBorder;
0977
0978            /**
0979             * Returns a border instance for a JToggleButton
0980             * @since 1.3
0981             */
0982            public static Border getToggleButtonBorder() {
0983                if (toggleButtonBorder == null) {
0984                    toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource(
0985                            new MetalBorders.ToggleButtonBorder(),
0986                            new BasicBorders.MarginBorder());
0987                }
0988                return toggleButtonBorder;
0989            }
0990
0991            /**
0992             * @since 1.3
0993             */
0994            public static class ToggleButtonBorder extends ButtonBorder {
0995                public void paintBorder(Component c, Graphics g, int x, int y,
0996                        int w, int h) {
0997                    AbstractButton button = (AbstractButton) c;
0998                    ButtonModel model = button.getModel();
0999                    if (MetalLookAndFeel.usingOcean()) {
1000                        if (model.isArmed() || !button.isEnabled()) {
1001                            super .paintBorder(c, g, x, y, w, h);
1002                        } else {
1003                            g.setColor(MetalLookAndFeel.getControlDarkShadow());
1004                            g.drawRect(0, 0, w - 1, h - 1);
1005                        }
1006                        return;
1007                    }
1008                    if (!c.isEnabled()) {
1009                        MetalUtils.drawDisabledBorder(g, x, y, w - 1, h - 1);
1010                    } else {
1011                        if (model.isPressed() && model.isArmed()) {
1012                            MetalUtils.drawPressed3DBorder(g, x, y, w, h);
1013                        } else if (model.isSelected()) {
1014                            MetalUtils.drawDark3DBorder(g, x, y, w, h);
1015                        } else {
1016                            MetalUtils.drawFlush3DBorder(g, x, y, w, h);
1017                        }
1018                    }
1019                }
1020            }
1021
1022            /**
1023             * Border for a Table Header
1024             * @since 1.3
1025             */
1026            public static class TableHeaderBorder extends
1027                    javax.swing.border.AbstractBorder {
1028                protected Insets editorBorderInsets = new Insets(2, 2, 2, 0);
1029
1030                public void paintBorder(Component c, Graphics g, int x, int y,
1031                        int w, int h) {
1032                    g.translate(x, y);
1033
1034                    g.setColor(MetalLookAndFeel.getControlDarkShadow());
1035                    g.drawLine(w - 1, 0, w - 1, h - 1);
1036                    g.drawLine(1, h - 1, w - 1, h - 1);
1037                    g.setColor(MetalLookAndFeel.getControlHighlight());
1038                    g.drawLine(0, 0, w - 2, 0);
1039                    g.drawLine(0, 0, 0, h - 2);
1040
1041                    g.translate(-x, -y);
1042                }
1043
1044                public Insets getBorderInsets(Component c) {
1045                    return editorBorderInsets;
1046                }
1047            }
1048
1049            /**
1050             * Returns a border instance for a Desktop Icon
1051             * @since 1.3
1052             */
1053            public static Border getDesktopIconBorder() {
1054                return new BorderUIResource.CompoundBorderUIResource(
1055                        new LineBorder(MetalLookAndFeel.getControlDarkShadow(),
1056                                1), new MatteBorder(2, 2, 1, 2,
1057                                MetalLookAndFeel.getControl()));
1058            }
1059
1060            static Border getToolBarRolloverBorder() {
1061                if (MetalLookAndFeel.usingOcean()) {
1062                    return new CompoundBorder(new MetalBorders.ButtonBorder(),
1063                            new MetalBorders.RolloverMarginBorder());
1064                }
1065                return new CompoundBorder(
1066                        new MetalBorders.RolloverButtonBorder(),
1067                        new MetalBorders.RolloverMarginBorder());
1068            }
1069
1070            static Border getToolBarNonrolloverBorder() {
1071                if (MetalLookAndFeel.usingOcean()) {
1072                    new CompoundBorder(new MetalBorders.ButtonBorder(),
1073                            new MetalBorders.RolloverMarginBorder());
1074                }
1075                return new CompoundBorder(new MetalBorders.ButtonBorder(),
1076                        new MetalBorders.RolloverMarginBorder());
1077            }
1078        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.