Source Code Cross Referenced for SmoothGradientBorders.java in  » Database-Client » executequery » org » underworldlabs » swing » plaf » smoothgradient » Java Source Code / Java DocumentationJava Source Code and Java Documentation

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 geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » executequery » org.underworldlabs.swing.plaf.smoothgradient 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * SmoothGradientBorders.java
0003:         *
0004:         * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
0005:         *
0006:         * This program is free software; you can redistribute it and/or
0007:         * modify it under the terms of the GNU General Public License
0008:         * as published by the Free Software Foundation; either version 2
0009:         * of the License, or any later version.
0010:         *
0011:         * This program is distributed in the hope that it will be useful,
0012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014:         * GNU General Public License for more details.
0015:         *
0016:         * You should have received a copy of the GNU General Public License
0017:         * along with this program; if not, write to the Free Software
0018:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
0019:         *
0020:         */
0021:
0022:        package org.underworldlabs.swing.plaf.smoothgradient;
0023:
0024:        import java.awt.Color;
0025:        import java.awt.Component;
0026:        import java.awt.Dialog;
0027:        import java.awt.Graphics;
0028:        import java.awt.Insets;
0029:        import java.awt.Window;
0030:
0031:        import javax.swing.AbstractButton;
0032:        import javax.swing.ButtonModel;
0033:        import javax.swing.JButton;
0034:        import javax.swing.JInternalFrame;
0035:        import javax.swing.JMenuItem;
0036:        import javax.swing.JOptionPane;
0037:        import javax.swing.JToggleButton;
0038:        import javax.swing.SwingUtilities;
0039:        import javax.swing.UIManager;
0040:        import javax.swing.border.AbstractBorder;
0041:        import javax.swing.border.Border;
0042:        import javax.swing.border.CompoundBorder;
0043:        import javax.swing.plaf.BorderUIResource;
0044:        import javax.swing.plaf.UIResource;
0045:        import javax.swing.plaf.basic.BasicBorders;
0046:        import javax.swing.plaf.metal.MetalBorders;
0047:        import javax.swing.plaf.metal.MetalLookAndFeel;
0048:        import javax.swing.text.JTextComponent;
0049:
0050:        /* ----------------------------------------------------------
0051:         * CVS NOTE: Changes to the CVS repository prior to the 
0052:         *           release of version 3.0.0beta1 has meant a 
0053:         *           resetting of CVS revision numbers.
0054:         * ----------------------------------------------------------
0055:         */
0056:
0057:        /**
0058:         *
0059:         * @author   Takis Diakoumis
0060:         * @version  $Revision: 1.4 $
0061:         * @date     $Date: 2006/05/14 06:56:07 $
0062:         */
0063:        final class SmoothGradientBorders {
0064:
0065:            // Accessing and Creating Borders ***************************************
0066:
0067:            private static Border buttonBorder;
0068:            private static Border comboBoxEditorBorder;
0069:            private static Border comboBoxArrowButtonBorder;
0070:            private static Border etchedBorder;
0071:            private static Border flush3DBorder;
0072:            private static Border menuBarHeaderBorder;
0073:            private static Border menuBorder;
0074:            private static Border menuItemBorder;
0075:            private static Border popupMenuBorder;
0076:            private static Border rolloverButtonBorder;
0077:            private static Border scrollPaneBorder;
0078:            private static Border separatorBorder;
0079:            private static Border textFieldBorder;
0080:            private static Border thinLoweredBorder;
0081:            private static Border thinRaisedBorder;
0082:            private static Border toggleButtonBorder;
0083:            private static Border toolBarHeaderBorder;
0084:
0085:            /**
0086:             * Returns a border instance for a <code>JButton</code>.
0087:             */
0088:            static Border getButtonBorder() {
0089:                if (buttonBorder == null) {
0090:                    buttonBorder = new BorderUIResource.CompoundBorderUIResource(
0091:                            new ButtonBorder(), new BasicBorders.MarginBorder());
0092:                }
0093:                return buttonBorder;
0094:            }
0095:
0096:            /**
0097:             * Returns a border for a <code>JComboBox</code>'s editor.
0098:             */
0099:            static Border getComboBoxEditorBorder() {
0100:                if (comboBoxEditorBorder == null) {
0101:                    comboBoxEditorBorder = new CompoundBorder(
0102:                            // No UIResource
0103:                            new ComboBoxEditorBorder(),
0104:                            new BasicBorders.MarginBorder());
0105:                }
0106:                return comboBoxEditorBorder;
0107:            }
0108:
0109:            /**
0110:             * Returns a border for a <code>JComboBox</code>'s button.
0111:             */
0112:            static Border getComboBoxArrowButtonBorder() {
0113:                if (comboBoxArrowButtonBorder == null) {
0114:                    comboBoxArrowButtonBorder = new CompoundBorder(
0115:                            // No UIResource
0116:                            new ComboBoxArrowButtonBorder(),
0117:                            new BasicBorders.MarginBorder());
0118:                }
0119:                return comboBoxArrowButtonBorder;
0120:            }
0121:
0122:            /**
0123:             * Returns an etched border instance for <code>JMenuBar</code> or
0124:             * <code>JToolBar</code>.
0125:             */
0126:            static Border getEtchedBorder() {
0127:                if (etchedBorder == null) {
0128:                    etchedBorder = new BorderUIResource.CompoundBorderUIResource(
0129:                            new EtchedBorder(), new BasicBorders.MarginBorder());
0130:                }
0131:                return etchedBorder;
0132:            }
0133:
0134:            /**
0135:             * Returns a flushed 3D border.
0136:             */
0137:            static Border getFlush3DBorder() {
0138:                if (flush3DBorder == null) {
0139:                    flush3DBorder = new Flush3DBorder();
0140:                }
0141:                return flush3DBorder;
0142:            }
0143:
0144:            /**
0145:             * Returns a border for a <code>JInternalFrame</code>.
0146:             */
0147:            static Border getInternalFrameBorder() {
0148:                return new InternalFrameBorder();
0149:            }
0150:
0151:            /**
0152:             * Returns a special border for a <code>JMenuBar</code> that
0153:             * is used in a header just above a <code>JToolBar</code>.
0154:             */
0155:            static Border getMenuBarHeaderBorder() {
0156:                if (menuBarHeaderBorder == null) {
0157:                    menuBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource(
0158:                            new MenuBarHeaderBorder(),
0159:                            new BasicBorders.MarginBorder());
0160:                }
0161:                return menuBarHeaderBorder;
0162:            }
0163:
0164:            /**
0165:             * Returns a border instance for a <code>JMenu</code>.
0166:             */
0167:            static Border getMenuBorder() {
0168:                if (menuBorder == null) {
0169:                    menuBorder = new BorderUIResource.CompoundBorderUIResource(
0170:                            new MenuBorder(), new BasicBorders.MarginBorder());
0171:                }
0172:                return menuBorder;
0173:            }
0174:
0175:            /**
0176:             * Returns a border instance for a <code>JMenuItem</code>.
0177:             */
0178:            static Border getMenuItemBorder() {
0179:                if (menuItemBorder == null) {
0180:                    menuItemBorder = new BorderUIResource(
0181:                            new BasicBorders.MarginBorder());
0182:                }
0183:                return menuItemBorder;
0184:            }
0185:
0186:            /**
0187:             * Returns a border instance for a <code>JPopupMenu</code>.
0188:             */
0189:            static Border getPopupMenuBorder() {
0190:                if (popupMenuBorder == null) {
0191:                    popupMenuBorder = new PopupMenuBorder();
0192:                }
0193:                return popupMenuBorder;
0194:            }
0195:
0196:            /**
0197:             * Returns a border for a <code>JInternalFrame</code>'s palette.
0198:             */
0199:            static Border getPaletteBorder() {
0200:                return new PaletteBorder();
0201:            }
0202:
0203:            /**
0204:             * Returns a rollover border for buttons in a <code>JToolBar</code>.
0205:             */
0206:            static Border getRolloverButtonBorder() {
0207:                if (rolloverButtonBorder == null) {
0208:                    rolloverButtonBorder = new BorderUIResource.CompoundBorderUIResource(
0209:                            new RolloverButtonBorder(),
0210:                            new BasicBorders.MarginBorder());
0211:                }
0212:                return rolloverButtonBorder;
0213:            }
0214:
0215:            /**
0216:             * Returns a separator border instance for <code>JScrollPane</code>.
0217:             */
0218:            static Border getScrollPaneBorder() {
0219:                if (scrollPaneBorder == null) {
0220:                    scrollPaneBorder = new ScrollPaneBorder();
0221:                }
0222:                return scrollPaneBorder;
0223:            }
0224:
0225:            /**
0226:             * Returns a separator border instance for <code>JMenuBar</code> or
0227:             * <code>JToolBar</code>.
0228:             */
0229:            static Border getSeparatorBorder() {
0230:                if (separatorBorder == null) {
0231:                    separatorBorder = new BorderUIResource.CompoundBorderUIResource(
0232:                            new SeparatorBorder(),
0233:                            new BasicBorders.MarginBorder());
0234:                }
0235:                return separatorBorder;
0236:            }
0237:
0238:            /**
0239:             * Returns a border instance for a JTextField.
0240:             */
0241:            static Border getTextFieldBorder() {
0242:                if (textFieldBorder == null) {
0243:                    textFieldBorder = new BorderUIResource.CompoundBorderUIResource(
0244:                            new TextFieldBorder(),
0245:                            new BasicBorders.MarginBorder());
0246:                }
0247:                return textFieldBorder;
0248:            }
0249:
0250:            /**
0251:             * Returns a thin lowered border.
0252:             */
0253:            static Border getThinLoweredBorder() {
0254:                if (thinLoweredBorder == null) {
0255:                    thinLoweredBorder = new ThinLoweredBorder();
0256:                }
0257:                return thinLoweredBorder;
0258:            }
0259:
0260:            /**
0261:             * Returns a thin raised border.
0262:             */
0263:            static Border getThinRaisedBorder() {
0264:                if (thinRaisedBorder == null) {
0265:                    thinRaisedBorder = new ThinRaisedBorder();
0266:                }
0267:                return thinRaisedBorder;
0268:            }
0269:
0270:            /**
0271:             * Returns a border instance for a JToggleButton.
0272:             */
0273:            static Border getToggleButtonBorder() {
0274:                if (toggleButtonBorder == null) {
0275:                    toggleButtonBorder = new BorderUIResource.CompoundBorderUIResource(
0276:                            new ToggleButtonBorder(),
0277:                            new BasicBorders.MarginBorder());
0278:                }
0279:                return toggleButtonBorder;
0280:            }
0281:
0282:            /**
0283:             * Returns a special border for a <code>JToolBar</code> that
0284:             * is used in a header just below a <code>JMenuBar</code>.
0285:             */
0286:            static Border getToolBarHeaderBorder() {
0287:                if (toolBarHeaderBorder == null) {
0288:                    toolBarHeaderBorder = new BorderUIResource.CompoundBorderUIResource(
0289:                            new ToolBarHeaderBorder(),
0290:                            new BasicBorders.MarginBorder());
0291:                }
0292:                return toolBarHeaderBorder;
0293:            }
0294:
0295:            private static Border optionDialogBorder;
0296:
0297:            static Border getOptionDialogBorder() {
0298:                if (optionDialogBorder == null) {
0299:                    optionDialogBorder = new OptionDialogBorder();
0300:                }
0301:                return optionDialogBorder;
0302:            }
0303:
0304:            private static class OptionDialogBorder extends AbstractBorder
0305:                    implements  UIResource {
0306:                private static final Insets insets = new Insets(3, 3, 3, 3);
0307:                int titleHeight = 0;
0308:
0309:                public void paintBorder(Component c, Graphics g, int x, int y,
0310:                        int w, int h) {
0311:
0312:                    g.translate(x, y);
0313:
0314:                    int messageType = JOptionPane.PLAIN_MESSAGE;
0315:                    if (c instanceof  JInternalFrame) {
0316:                        Object obj = ((JInternalFrame) c)
0317:                                .getClientProperty("JInternalFrame.messageType");
0318:                        if (obj != null && (obj instanceof  Integer)) {
0319:                            messageType = ((Integer) obj).intValue();
0320:                        }
0321:                    }
0322:
0323:                    Color borderColor;
0324:
0325:                    switch (messageType) {
0326:                    case (JOptionPane.ERROR_MESSAGE):
0327:                        borderColor = UIManager
0328:                                .getColor("OptionPane.errorDialog.border.background");
0329:                        break;
0330:                    case (JOptionPane.QUESTION_MESSAGE):
0331:                        borderColor = UIManager
0332:                                .getColor("OptionPane.questionDialog.border.background");
0333:                        break;
0334:                    case (JOptionPane.WARNING_MESSAGE):
0335:                        borderColor = UIManager
0336:                                .getColor("OptionPane.warningDialog.border.background");
0337:                        break;
0338:                    case (JOptionPane.INFORMATION_MESSAGE):
0339:                    case (JOptionPane.PLAIN_MESSAGE):
0340:                    default:
0341:                        borderColor = MetalLookAndFeel
0342:                                .getPrimaryControlDarkShadow();
0343:                        break;
0344:                    }
0345:
0346:                    g.setColor(borderColor);
0347:
0348:                    // Draw outermost lines
0349:                    g.drawLine(1, 0, w - 2, 0);
0350:                    g.drawLine(0, 1, 0, h - 2);
0351:                    g.drawLine(w - 1, 1, w - 1, h - 2);
0352:                    g.drawLine(1, h - 1, w - 2, h - 1);
0353:
0354:                    // Draw the bulk of the border
0355:                    for (int i = 1; i < 3; i++) {
0356:                        g.drawRect(i, i, w - (i * 2) - 1, h - (i * 2) - 1);
0357:                    }
0358:
0359:                    g.translate(-x, -y);
0360:
0361:                }
0362:
0363:                public Insets getBorderInsets(Component c) {
0364:                    return insets;
0365:                }
0366:
0367:                public Insets getBorderInsets(Component c, Insets newInsets) {
0368:                    newInsets.top = insets.top;
0369:                    newInsets.left = insets.left;
0370:                    newInsets.bottom = insets.bottom;
0371:                    newInsets.right = insets.right;
0372:                    return newInsets;
0373:                }
0374:            }
0375:
0376:            private static Border dialogBorder;
0377:
0378:            static Border getDialogBorder() {
0379:                if (dialogBorder == null) {
0380:                    dialogBorder = new DialogBorder();
0381:                }
0382:                return dialogBorder;
0383:            }
0384:
0385:            private static class DialogBorder extends AbstractBorder implements 
0386:                    UIResource {
0387:                private static final Insets insets = new Insets(2, 2, 2, 2);
0388:                private static final int corner = 14;
0389:
0390:                protected Color getActiveBackground() {
0391:                    return SmoothGradientLookAndFeel
0392:                            .getPrimaryControlDarkShadow();
0393:                }
0394:
0395:                protected Color getActiveHighlight() {
0396:                    return SmoothGradientLookAndFeel.getPrimaryControlShadow();
0397:                }
0398:
0399:                protected Color getActiveShadow() {
0400:                    return SmoothGradientLookAndFeel.getPrimaryControlInfo();
0401:                }
0402:
0403:                protected Color getInactiveBackground() {
0404:                    return SmoothGradientLookAndFeel.getControlDarkShadow();
0405:                }
0406:
0407:                protected Color getInactiveHighlight() {
0408:                    return SmoothGradientLookAndFeel.getControlShadow();
0409:                }
0410:
0411:                protected Color getInactiveShadow() {
0412:                    return SmoothGradientLookAndFeel.getControlInfo();
0413:                }
0414:
0415:                public void paintBorder(Component c, Graphics g, int x, int y,
0416:                        int w, int h) {
0417:                    Color background;
0418:                    Color highlight;
0419:                    Color shadow;
0420:
0421:                    Window window = SwingUtilities.getWindowAncestor(c);
0422:                    if (window != null && window.isActive()) {
0423:                        background = getActiveBackground();
0424:                        highlight = getActiveHighlight();
0425:                        shadow = getActiveShadow();
0426:                    } else {
0427:                        background = getInactiveBackground();
0428:                        highlight = getInactiveHighlight();
0429:                        shadow = getInactiveShadow();
0430:                    }
0431:
0432:                    g.setColor(background);
0433:                    // Draw outermost lines
0434:                    g.drawLine(x + 1, y + 0, x + w - 2, y + 0);
0435:                    g.drawLine(x + 0, y + 1, x + 0, y + h - 2);
0436:                    g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 2);
0437:                    g.drawLine(x + 1, y + h - 1, x + w - 2, y + h - 1);
0438:
0439:                    // Draw the bulk of the border
0440:                    for (int i = 1; i < 5; i++) {
0441:                        g.drawRect(x + i, y + i, w - (i * 2) - 1, h - (i * 2)
0442:                                - 1);
0443:                    }
0444:
0445:                    if ((window instanceof  Dialog)
0446:                            && ((Dialog) window).isResizable()) {
0447:                        g.setColor(highlight);
0448:                        // Draw the Long highlight lines
0449:                        g.drawLine(corner + 1, 3, w - corner, 3);
0450:                        g.drawLine(3, corner + 1, 3, h - corner);
0451:                        g.drawLine(w - 2, corner + 1, w - 2, h - corner);
0452:                        g.drawLine(corner + 1, h - 2, w - corner, h - 2);
0453:
0454:                        g.setColor(shadow);
0455:                        // Draw the Long shadow lines
0456:                        g.drawLine(corner, 2, w - corner - 1, 2);
0457:                        g.drawLine(2, corner, 2, h - corner - 1);
0458:                        g.drawLine(w - 3, corner, w - 3, h - corner - 1);
0459:                        g.drawLine(corner, h - 3, w - corner - 1, h - 3);
0460:                    }
0461:
0462:                }
0463:
0464:                public Insets getBorderInsets(Component c) {
0465:                    return insets;
0466:                }
0467:
0468:                public Insets getBorderInsets(Component c, Insets newInsets) {
0469:                    newInsets.top = insets.top;
0470:                    newInsets.left = insets.left;
0471:                    newInsets.bottom = insets.bottom;
0472:                    newInsets.right = insets.right;
0473:                    return newInsets;
0474:                }
0475:            }
0476:
0477:            private static Border errorDialogBorder;
0478:
0479:            static Border getErrorDialogBorder() {
0480:                if (errorDialogBorder == null) {
0481:                    errorDialogBorder = new ErrorDialogBorder();
0482:                }
0483:                return errorDialogBorder;
0484:            }
0485:
0486:            private static class ErrorDialogBorder extends DialogBorder
0487:                    implements  UIResource {
0488:                protected Color getActiveBackground() {
0489:                    return UIManager
0490:                            .getColor("OptionPane.errorDialog.border.background");
0491:                }
0492:            }
0493:
0494:            private static Border questionDialogBorder;
0495:
0496:            static Border getQuestionDialogBorder() {
0497:                if (questionDialogBorder == null) {
0498:                    questionDialogBorder = new QuestionDialogBorder();
0499:                }
0500:                return questionDialogBorder;
0501:            }
0502:
0503:            private static class QuestionDialogBorder extends DialogBorder
0504:                    implements  UIResource {
0505:                protected Color getActiveBackground() {
0506:                    return UIManager
0507:                            .getColor("OptionPane.questionDialog.border.background");
0508:                }
0509:            }
0510:
0511:            private static Border warningDialogBorder;
0512:
0513:            static Border getWarningDialogBorder() {
0514:                if (warningDialogBorder == null) {
0515:                    warningDialogBorder = new WarningDialogBorder();
0516:                }
0517:                return warningDialogBorder;
0518:            }
0519:
0520:            private static class WarningDialogBorder extends DialogBorder
0521:                    implements  UIResource {
0522:                protected Color getActiveBackground() {
0523:                    return UIManager
0524:                            .getColor("OptionPane.warningDialog.border.background");
0525:                }
0526:            }
0527:
0528:            private static class Flush3DBorder extends AbstractBorder implements 
0529:                    UIResource {
0530:
0531:                private static final Insets INSETS = new Insets(2, 2, 2, 2);
0532:
0533:                public void paintBorder(Component c, Graphics g, int x, int y,
0534:                        int w, int h) {
0535:                    if (c.isEnabled())
0536:                        SmoothGradientUtils.drawFlush3DBorder(g, x, y, w, h);
0537:                    else
0538:                        SmoothGradientUtils.drawDisabledBorder(g, x, y, w, h);
0539:                }
0540:
0541:                public Insets getBorderInsets(Component c) {
0542:                    return INSETS;
0543:                }
0544:
0545:                public Insets getBorderInsets(Component c, Insets newInsets) {
0546:                    newInsets.top = INSETS.top;
0547:                    newInsets.left = INSETS.left;
0548:                    newInsets.bottom = INSETS.bottom;
0549:                    newInsets.right = INSETS.right;
0550:                    return newInsets;
0551:                }
0552:            }
0553:
0554:            private static class ButtonBorder extends AbstractBorder implements 
0555:                    UIResource {
0556:
0557:                protected static final Insets INSETS = new Insets(2, 3, 2, 3);
0558:
0559:                public void paintBorder(Component c, Graphics g, int x, int y,
0560:                        int w, int h) {
0561:                    AbstractButton button = (AbstractButton) c;
0562:                    ButtonModel model = button.getModel();
0563:
0564:                    if (model.isEnabled()) {
0565:                        boolean isPressed = model.isPressed()
0566:                                && model.isArmed();
0567:                        boolean isDefault = button instanceof  JButton
0568:                                && ((JButton) button).isDefaultButton();
0569:
0570:                        if (isPressed && isDefault)
0571:                            SmoothGradientUtils.drawDefaultButtonPressedBorder(
0572:                                    g, x, y, w, h);
0573:                        else if (isPressed)
0574:                            SmoothGradientUtils.drawPressed3DBorder(g, x, y, w,
0575:                                    h);
0576:                        else if (isDefault)
0577:                            SmoothGradientUtils.drawDefaultButtonBorder(g, x,
0578:                                    y, w, h, false);
0579:                        else
0580:                            SmoothGradientUtils.drawButtonBorder(g, x, y, w, h,
0581:                                    false);
0582:                    } else { // disabled state
0583:                        SmoothGradientUtils.drawDisabledBorder(g, x, y, w - 1,
0584:                                h - 1);
0585:                    }
0586:                }
0587:
0588:                public Insets getBorderInsets(Component c) {
0589:                    return INSETS;
0590:                }
0591:
0592:                public Insets getBorderInsets(Component c, Insets newInsets) {
0593:                    newInsets.top = INSETS.top;
0594:                    newInsets.left = INSETS.left;
0595:                    newInsets.bottom = INSETS.bottom;
0596:                    newInsets.right = INSETS.right;
0597:                    return newInsets;
0598:                }
0599:            }
0600:
0601:            private static class ComboBoxEditorBorder extends AbstractBorder {
0602:
0603:                private static final Insets INSETS = new Insets(2, 2, 2, 0);
0604:
0605:                public void paintBorder(Component c, Graphics g, int x, int y,
0606:                        int w, int h) {
0607:                    if (c.isEnabled())
0608:                        SmoothGradientUtils
0609:                                .drawFlush3DBorder(g, x, y, w + 2, h);
0610:                    else {
0611:                        SmoothGradientUtils.drawDisabledBorder(g, x, y, w + 2,
0612:                                h - 1);
0613:                        g.setColor(UIManager.getColor("control"));
0614:                        g.drawLine(x, y + h - 1, x + w, y + h - 1);
0615:                    }
0616:                }
0617:
0618:                public Insets getBorderInsets(Component c) {
0619:                    return INSETS;
0620:                }
0621:            }
0622:
0623:            private static class ComboBoxArrowButtonBorder extends
0624:                    AbstractBorder implements  UIResource {
0625:
0626:                protected static final Insets INSETS = new Insets(2, 2, 2, 2);
0627:
0628:                public void paintBorder(Component c, Graphics g, int x, int y,
0629:                        int w, int h) {
0630:                    AbstractButton button = (AbstractButton) c;
0631:                    ButtonModel model = button.getModel();
0632:
0633:                    if (model.isEnabled()) {
0634:                        boolean isPressed = model.isPressed()
0635:                                && model.isArmed();
0636:
0637:                        if (isPressed)
0638:                            SmoothGradientUtils.drawPressed3DBorder(g, x, y, w,
0639:                                    h);
0640:                        else
0641:                            SmoothGradientUtils.drawButtonBorder(g, x, y, w, h,
0642:                                    false);
0643:                    } else {
0644:                        SmoothGradientUtils.drawDisabledBorder(g, x, y, w - 1,
0645:                                h - 1);
0646:                    }
0647:                }
0648:
0649:                public Insets getBorderInsets(Component c) {
0650:                    return INSETS;
0651:                }
0652:            }
0653:
0654:            /**
0655:             * A border used for <code>JInternalFrame</code>s.
0656:             */
0657:            private static class InternalFrameBorder extends AbstractBorder
0658:                    implements  UIResource {
0659:
0660:                private static final Insets NORMAL_INSETS = new Insets(3, 3, 3,
0661:                        3);
0662:
0663:                private static final int corner = 14;
0664:
0665:                private static final Insets MAXIMIZED_INSETS = new Insets(2, 2,
0666:                        2, 2);
0667:                static final int ALPHA1 = 150;
0668:                static final int ALPHA2 = 50;
0669:
0670:                public void paintBorder(Component c, Graphics g, int x, int y,
0671:                        int w, int h) {
0672:
0673:                    Color background;
0674:                    Color highlight;
0675:                    Color shadow;
0676:
0677:                    if (c instanceof  JInternalFrame
0678:                            && ((JInternalFrame) c).isSelected()) {
0679:                        background = SmoothGradientLookAndFeel
0680:                                .getPrimaryControlDarkShadow();
0681:                        highlight = SmoothGradientLookAndFeel
0682:                                .getPrimaryControlShadow();
0683:                        shadow = SmoothGradientLookAndFeel
0684:                                .getPrimaryControlInfo();
0685:                    } else {
0686:                        background = SmoothGradientLookAndFeel
0687:                                .getControlDarkShadow();
0688:                        highlight = SmoothGradientLookAndFeel
0689:                                .getControlShadow();
0690:                        shadow = SmoothGradientLookAndFeel.getControlInfo();
0691:                    }
0692:
0693:                    g.setColor(background);
0694:                    // Draw outermost lines
0695:                    g.drawLine(1, 0, w - 2, 0);
0696:                    g.drawLine(0, 1, 0, h - 2);
0697:                    g.drawLine(w - 1, 1, w - 1, h - 2);
0698:                    g.drawLine(1, h - 1, w - 2, h - 1);
0699:
0700:                    // Draw the bulk of the border
0701:                    for (int i = 1; i < 5; i++) {
0702:                        g.drawRect(x + i, y + i, w - (i * 2) - 1, h - (i * 2)
0703:                                - 1);
0704:                    }
0705:
0706:                    if (c instanceof  JInternalFrame
0707:                            && ((JInternalFrame) c).isResizable()) {
0708:                        g.setColor(highlight);
0709:                        // Draw the Long highlight lines
0710:                        g.drawLine(corner + 1, 3, w - corner, 3);
0711:                        g.drawLine(3, corner + 1, 3, h - corner);
0712:                        g.drawLine(w - 2, corner + 1, w - 2, h - corner);
0713:                        g.drawLine(corner + 1, h - 2, w - corner, h - 2);
0714:
0715:                        g.setColor(shadow);
0716:                        // Draw the Long shadow lines
0717:                        g.drawLine(corner, 2, w - corner - 1, 2);
0718:                        g.drawLine(2, corner, 2, h - corner - 1);
0719:                        g.drawLine(w - 3, corner, w - 3, h - corner - 1);
0720:                        g.drawLine(corner, h - 3, w - corner - 1, h - 3);
0721:                    }
0722:                    /*
0723:                     JInternalFrame frame = (JInternalFrame) c;
0724:                     if (frame.isMaximum())
0725:                     SmoothGradientUtils.drawFlush3DBorder(g, x, y, w, h);
0726:                     else
0727:                     paintShadowedBorder(g, x, y, w, h);
0728:                     */
0729:                }
0730:
0731:                private void paintShadowedBorder(Graphics g, int x, int y,
0732:                        int w, int h) {
0733:
0734:                    /*
0735:                    Color background	= UIManager.getColor("desktop");
0736:                    Color highlight		= UIManager.getColor("controlLtHighlight");
0737:                    Color darkShadow    = UIManager.getColor("controlDkShadow");
0738:                    Color lightShadow   = new Color(darkShadow.getRed(),
0739:                                                    darkShadow.getGreen(),
0740:                                                    darkShadow.getBlue(),
0741:                                                    ALPHA1);
0742:                    Color lighterShadow = new Color(darkShadow.getRed(),
0743:                                                    darkShadow.getGreen(),
0744:                                                    darkShadow.getBlue(),
0745:                                                    ALPHA2);
0746:                    g.translate(x, y);
0747:                    // Dark border
0748:                    g.setColor(darkShadow);
0749:                    g.drawRect(0,   0, w-3, h-3);
0750:                    // Highlight top and left
0751:                    g.setColor(highlight);
0752:                    g.drawLine(1, 1, w - 4, 1);
0753:                    g.drawLine(1, 1, 1, h - 4);
0754:                    // Paint background before painting the shadow
0755:                    g.setColor(background);
0756:                    g.fillRect(w - 2, 0, 2, h);
0757:                    g.fillRect(0, h-2, w, 2);
0758:                    // Shadow line 1
0759:                    g.setColor(lightShadow);
0760:                    g.drawLine(w - 2, 1, w - 2, h - 2);
0761:                    g.drawLine(1, h - 2, w - 3, h - 2);
0762:                    // Shadow line2
0763:                    g.setColor(lighterShadow);
0764:                    g.drawLine(w - 1, 2, w - 1, h - 2);
0765:                    g.drawLine(2, h - 1, w - 2, h - 1);
0766:                    g.translate(-x, -y);
0767:                     **/
0768:                }
0769:
0770:                public Insets getBorderInsets(Component c) {
0771:                    return ((JInternalFrame) c).isMaximum() ? MAXIMIZED_INSETS
0772:                            : NORMAL_INSETS;
0773:                }
0774:            }
0775:
0776:            /**
0777:             * A border used for the palette of <code>JInternalFrame</code>s.
0778:             */
0779:            private static class PaletteBorder extends AbstractBorder implements 
0780:                    UIResource {
0781:
0782:                private static final Insets INSETS = new Insets(1, 1, 1, 1);
0783:
0784:                public void paintBorder(Component c, Graphics g, int x, int y,
0785:                        int w, int h) {
0786:                    g.translate(x, y);
0787:                    g
0788:                            .setColor(SmoothGradientLookAndFeel
0789:                                    .getControlDarkShadow());
0790:                    g.drawRect(0, 0, w - 1, h - 1);
0791:                    g.translate(-x, -y);
0792:                }
0793:
0794:                public Insets getBorderInsets(Component c) {
0795:                    return INSETS;
0796:                }
0797:            }
0798:
0799:            /**
0800:             * A border that looks like a separator line; used for menu bars
0801:             * and tool bars.
0802:             */
0803:            private static class SeparatorBorder extends AbstractBorder
0804:                    implements  UIResource {
0805:
0806:                private static final Insets INSETS = new Insets(0, 0, 2, 1);
0807:
0808:                public void paintBorder(Component c, Graphics g, int x, int y,
0809:                        int w, int h) {
0810:                    g.translate(x, y);
0811:                    g.setColor(UIManager.getColor("Separator.foreground"));
0812:                    g.drawLine(0, h - 2, w - 1, h - 2);
0813:
0814:                    g.setColor(UIManager.getColor("Separator.background"));
0815:                    g.drawLine(0, h - 1, w - 1, h - 1);
0816:                    g.translate(-x, -y);
0817:                }
0818:
0819:                public Insets getBorderInsets(Component c) {
0820:                    return INSETS;
0821:                }
0822:            }
0823:
0824:            private static class ThinRaisedBorder extends AbstractBorder
0825:                    implements  UIResource {
0826:                private static final Insets INSETS = new Insets(2, 2, 2, 2);
0827:
0828:                public void paintBorder(Component c, Graphics g, int x, int y,
0829:                        int w, int h) {
0830:                    SmoothGradientUtils.drawThinFlush3DBorder(g, x, y, w, h);
0831:                }
0832:
0833:                public Insets getBorderInsets(Component c) {
0834:                    return INSETS;
0835:                }
0836:            }
0837:
0838:            private static class ThinLoweredBorder extends AbstractBorder
0839:                    implements  UIResource {
0840:                private static final Insets INSETS = new Insets(2, 2, 2, 2);
0841:
0842:                public void paintBorder(Component c, Graphics g, int x, int y,
0843:                        int w, int h) {
0844:                    SmoothGradientUtils.drawThinPressed3DBorder(g, x, y, w, h);
0845:                }
0846:
0847:                public Insets getBorderInsets(Component c) {
0848:                    return INSETS;
0849:                }
0850:            }
0851:
0852:            /**
0853:             * A border used for menu bars and tool bars in
0854:             * <code>HeaderStyle.SINGLE</code>. The bar is wrapped by an inner thin
0855:             * raised border, which in turn is wrapped by an outer thin lowered
0856:             * border.
0857:             */
0858:            private static class EtchedBorder extends AbstractBorder implements 
0859:                    UIResource {
0860:
0861:                private static final Insets INSETS = new Insets(2, 2, 2, 2);
0862:
0863:                public void paintBorder(Component c, Graphics g, int x, int y,
0864:                        int w, int h) {
0865:                    SmoothGradientUtils.drawThinPressed3DBorder(g, x, y, w, h);
0866:                    SmoothGradientUtils.drawThinFlush3DBorder(g, x + 1, y + 1,
0867:                            w - 2, h - 2);
0868:                }
0869:
0870:                public Insets getBorderInsets(Component c) {
0871:                    return INSETS;
0872:                }
0873:            }
0874:
0875:            /**
0876:             * A border used for menu bars in <code>HeaderStyle.BOTH</code>.
0877:             * The menu bar and tool bar are wrapped by a thin raised border,
0878:             * both together are wrapped by a thin lowered border.
0879:             */
0880:            private static class MenuBarHeaderBorder extends AbstractBorder
0881:                    implements  UIResource {
0882:
0883:                private static final Insets INSETS = new Insets(2, 2, 1, 2);
0884:
0885:                public void paintBorder(Component c, Graphics g, int x, int y,
0886:                        int w, int h) {
0887:                    SmoothGradientUtils.drawThinPressed3DBorder(g, x, y, w,
0888:                            h + 1);
0889:                    SmoothGradientUtils.drawThinFlush3DBorder(g, x + 1, y + 1,
0890:                            w - 2, h - 1);
0891:                }
0892:
0893:                public Insets getBorderInsets(Component c) {
0894:                    return INSETS;
0895:                }
0896:            }
0897:
0898:            /**
0899:             * A border used for tool bars in <code>HeaderStyle.BOTH</code>.
0900:             * The menu bar and tool bar are wrapped by a thin raised border,
0901:             * both together are wrapped by a thin lowered border.
0902:             */
0903:            private static class ToolBarHeaderBorder extends AbstractBorder
0904:                    implements  UIResource {
0905:
0906:                private static final Insets INSETS = new Insets(1, 2, 2, 2);
0907:
0908:                public void paintBorder(Component c, Graphics g, int x, int y,
0909:                        int w, int h) {
0910:                    SmoothGradientUtils.drawThinPressed3DBorder(g, x, y - 1, w,
0911:                            h + 1);
0912:                    SmoothGradientUtils.drawThinFlush3DBorder(g, x + 1, y,
0913:                            w - 2, h - 1);
0914:                }
0915:
0916:                public Insets getBorderInsets(Component c) {
0917:                    return INSETS;
0918:                }
0919:            }
0920:
0921:            private static class MenuBorder extends AbstractBorder implements 
0922:                    UIResource {
0923:                private static final Insets INSETS = new Insets(2, 2, 2, 2);
0924:
0925:                public void paintBorder(Component c, Graphics g, int x, int y,
0926:                        int w, int h) {
0927:                    JMenuItem b = (JMenuItem) c;
0928:                    ButtonModel model = b.getModel();
0929:
0930:                    if (model.isArmed() || model.isSelected()) {
0931:                        g.setColor(SmoothGradientLookAndFeel
0932:                                .getControlDarkShadow());
0933:                        g.drawLine(0, 0, w - 2, 0);
0934:                        g.drawLine(0, 0, 0, h - 1);
0935:                        //g.drawLine(w - 2, 2, w - 2, h - 1 );
0936:
0937:                        g.setColor(SmoothGradientLookAndFeel
0938:                                .getPrimaryControlHighlight());
0939:                        g.drawLine(w - 1, 0, w - 1, h - 1);
0940:                    } else if (model.isRollover()) {
0941:                        g.translate(x, y);
0942:                        SmoothGradientUtils.drawFlush3DBorder(g, x, y, w, h);
0943:                        g.translate(-x, -y);
0944:                    }
0945:                }
0946:
0947:                public Insets getBorderInsets(Component c) {
0948:                    return INSETS;
0949:                }
0950:
0951:                public Insets getBorderInsets(Component c, Insets newInsets) {
0952:                    newInsets.top = INSETS.top;
0953:                    newInsets.left = INSETS.left;
0954:                    newInsets.bottom = INSETS.bottom;
0955:                    newInsets.right = INSETS.right;
0956:                    return newInsets;
0957:                }
0958:            }
0959:
0960:            private static class PopupMenuBorder extends AbstractBorder
0961:                    implements  UIResource {
0962:                private static final Insets INSETS = new Insets(3, 3, 3, 3);
0963:
0964:                public void paintBorder(Component c, Graphics g, int x, int y,
0965:                        int w, int h) {
0966:                    g.translate(x, y);
0967:                    g
0968:                            .setColor(SmoothGradientLookAndFeel
0969:                                    .getControlDarkShadow());
0970:                    g.drawRect(0, 0, w - 1, h - 1);
0971:                    g.setColor(SmoothGradientLookAndFeel
0972:                            .getPrimaryControlHighlight());
0973:                    g.drawLine(1, 1, w - 2, 1);
0974:                    g.drawLine(1, 1, 1, h - 2);
0975:                    g.setColor(SmoothGradientLookAndFeel.getMenuBackground());
0976:                    g.drawRect(2, 2, w - 5, h - 5);
0977:                    g.translate(-x, -y);
0978:                }
0979:
0980:                public Insets getBorderInsets(Component c) {
0981:                    return INSETS;
0982:                }
0983:            }
0984:
0985:            private static class RolloverButtonBorder extends ButtonBorder {
0986:                private static final Insets INSETS_3 = new Insets(3, 3, 3, 3);
0987:
0988:                public void paintBorder(Component c, Graphics g, int x, int y,
0989:                        int w, int h) {
0990:                    AbstractButton b = (AbstractButton) c;
0991:                    ButtonModel model = b.getModel();
0992:
0993:                    if (!model.isEnabled())
0994:                        return;
0995:
0996:                    if (!(c instanceof  JToggleButton)) {
0997:                        if (model.isRollover()
0998:                                && !(model.isPressed() && !model.isArmed())) {
0999:                            super .paintBorder(c, g, x, y, w, h);
1000:                        }
1001:                        return;
1002:                    }
1003:
1004:                    //if ( model.isRollover() && !( model.isPressed() && !model.isArmed() ) ) {
1005:                    //super.paintBorder( c, g, x, y, w, h );
1006:                    //}
1007:
1008:                    if (model.isRollover()) {
1009:                        if (model.isPressed() && model.isArmed()) {
1010:                            SmoothGradientUtils.drawPressed3DBorder(g, x, y, w,
1011:                                    h);
1012:                        } else {
1013:                            SmoothGradientUtils
1014:                                    .drawFlush3DBorder(g, x, y, w, h);
1015:                        }
1016:                    } else if (model.isSelected())
1017:                        SmoothGradientUtils.drawDark3DBorder(g, x, y, w, h);
1018:                }
1019:
1020:                public Insets getBorderInsets(Component c) {
1021:                    return INSETS_3;
1022:                }
1023:            }
1024:
1025:            /**
1026:             * Unlike Metal we don't paint the (misplaced) control color edges.
1027:             * Being a subclass of MetalBorders.ScrollPaneBorders ensures that
1028:             * the ScrollPaneUI will update the ScrollbarsFreeStanding property.
1029:             */
1030:            private static class ScrollPaneBorder extends
1031:                    MetalBorders.ScrollPaneBorder {
1032:
1033:                public void paintBorder(Component c, Graphics g, int x, int y,
1034:                        int w, int h) {
1035:                    g.translate(x, y);
1036:
1037:                    g
1038:                            .setColor(SmoothGradientLookAndFeel
1039:                                    .getControlDarkShadow());
1040:                    g.drawRect(0, 0, w - 2, h - 2);
1041:                    g.setColor(SmoothGradientLookAndFeel.getControlHighlight());
1042:                    g.drawLine(w - 1, 0, w - 1, h - 1);
1043:                    g.drawLine(0, h - 1, w - 1, h - 1);
1044:
1045:                    g.translate(-x, -y);
1046:                }
1047:            }
1048:
1049:            private static class TextFieldBorder extends Flush3DBorder {
1050:                public void paintBorder(Component c, Graphics g, int x, int y,
1051:                        int w, int h) {
1052:
1053:                    if (!(c instanceof  JTextComponent)) {
1054:                        // special case for non-text components (bug ID 4144840)
1055:                        if (c.isEnabled()) {
1056:                            SmoothGradientUtils
1057:                                    .drawFlush3DBorder(g, x, y, w, h);
1058:                        } else {
1059:                            SmoothGradientUtils.drawDisabledBorder(g, x, y, w,
1060:                                    h);
1061:                        }
1062:                        return;
1063:                    }
1064:
1065:                    if (c.isEnabled() && ((JTextComponent) c).isEditable())
1066:                        SmoothGradientUtils.drawFlush3DBorder(g, x, y, w, h);
1067:                    else
1068:                        SmoothGradientUtils.drawDisabledBorder(g, x, y, w, h);
1069:                }
1070:            }
1071:
1072:            private static class ToggleButtonBorder extends ButtonBorder {
1073:                public void paintBorder(Component c, Graphics g, int x, int y,
1074:                        int w, int h) {
1075:                    if (!c.isEnabled()) {
1076:                        SmoothGradientUtils.drawDisabledBorder(g, x, y, w - 1,
1077:                                h - 1);
1078:                    } else {
1079:                        AbstractButton button = (AbstractButton) c;
1080:                        ButtonModel model = button.getModel();
1081:                        if (model.isPressed() && model.isArmed())
1082:                            SmoothGradientUtils.drawPressed3DBorder(g, x, y, w,
1083:                                    h);
1084:                        else if (model.isSelected())
1085:                            SmoothGradientUtils.drawDark3DBorder(g, x, y, w, h);
1086:                        else
1087:                            SmoothGradientUtils
1088:                                    .drawFlush3DBorder(g, x, y, w, h);
1089:                    }
1090:                }
1091:            }
1092:
1093:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.