Source Code Cross Referenced for BasicJideSplitButtonUI.java in  » Swing-Library » jide-common » com » jidesoft » plaf » basic » 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 » Swing Library » jide common » com.jidesoft.plaf.basic 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * @(#)VsnetMenuUI.java
0003:         *
0004:         * Copyright 2002 JIDE Software Inc. All rights reserved.
0005:         */
0006:
0007:        package com.jidesoft.plaf.basic;
0008:
0009:        import com.jidesoft.icons.IconsFactory;
0010:        import com.jidesoft.plaf.UIDefaultsLookup;
0011:        import com.jidesoft.plaf.vsnet.VsnetMenuUI;
0012:        import com.jidesoft.swing.*;
0013:        import com.jidesoft.utils.SecurityUtils;
0014:        import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
0015:
0016:        import javax.swing.*;
0017:        import javax.swing.event.MouseInputListener;
0018:        import javax.swing.plaf.ComponentUI;
0019:        import javax.swing.plaf.UIResource;
0020:        import javax.swing.plaf.basic.BasicGraphicsUtils;
0021:        import javax.swing.plaf.basic.BasicHTML;
0022:        import javax.swing.text.View;
0023:        import java.awt.*;
0024:        import java.awt.event.ActionEvent;
0025:        import java.awt.event.FocusEvent;
0026:        import java.awt.event.FocusListener;
0027:        import java.awt.event.MouseEvent;
0028:        import java.util.ArrayList;
0029:
0030:        /**
0031:         * SplitButtonUI implementation
0032:         */
0033:        public class BasicJideSplitButtonUI extends VsnetMenuUI {
0034:
0035:            protected ThemePainter _painter;
0036:
0037:            protected Color _shadowColor;
0038:            protected Color _darkShadowColor;
0039:            protected Color _highlight;
0040:            protected Color _lightHighlightColor;
0041:
0042:            protected int _splitButtonMargin = 12;
0043:            protected int _splitButtonMarginOnMenu = 20;
0044:
0045:            protected boolean _isFloatingIcon = false;
0046:
0047:            private FocusListener _focusListener;
0048:
0049:            private final static String propertyPrefix = "JideSplitButton";
0050:
0051:            public static ComponentUI createUI(JComponent x) {
0052:                return new BasicJideSplitButtonUI();
0053:            }
0054:
0055:            @Override
0056:            protected String getPropertyPrefix() {
0057:                return propertyPrefix;
0058:            }
0059:
0060:            @Override
0061:            protected void installDefaults() {
0062:                _painter = (ThemePainter) UIDefaultsLookup.get("Theme.painter");
0063:                _isFloatingIcon = UIDefaultsLookup.getBoolean("Icon.floating");
0064:
0065:                _shadowColor = UIDefaultsLookup.getColor("controlShadow");
0066:                _darkShadowColor = UIDefaultsLookup.getColor("controlDkShadow");
0067:                _highlight = UIDefaultsLookup.getColor("controlHighlight");
0068:                _lightHighlightColor = UIDefaultsLookup
0069:                        .getColor("controlLtHighlight");
0070:
0071:                super .installDefaults();
0072:            }
0073:
0074:            @Override
0075:            protected void uninstallDefaults() {
0076:                _painter = null;
0077:
0078:                _shadowColor = null;
0079:                _highlight = null;
0080:                _lightHighlightColor = null;
0081:                _darkShadowColor = null;
0082:
0083:                super .uninstallDefaults();
0084:            }
0085:
0086:            @Override
0087:            protected void installListeners() {
0088:                super .installListeners();
0089:                if (_focusListener == null) {
0090:                    _focusListener = new FocusListener() {
0091:                        public void focusGained(FocusEvent e) {
0092:                            menuItem.repaint();
0093:                        }
0094:
0095:                        public void focusLost(FocusEvent e) {
0096:                            menuItem.repaint();
0097:                        }
0098:                    };
0099:                }
0100:                menuItem.addFocusListener(_focusListener);
0101:            }
0102:
0103:            @Override
0104:            protected void uninstallListeners() {
0105:                super .uninstallListeners();
0106:                if (_focusListener != null) {
0107:                    menuItem.removeFocusListener(_focusListener);
0108:                }
0109:            }
0110:
0111:            /**
0112:             * Returns the ui that is of type <code>klass</code>, or null if
0113:             * one can not be found.
0114:             */
0115:            static Object getUIOfType(ComponentUI ui, Class klass) {
0116:                if (klass.isInstance(ui)) {
0117:                    return ui;
0118:                }
0119:                return null;
0120:            }
0121:
0122:            /**
0123:             * Returns the InputMap for condition <code>condition</code>. Called as
0124:             * part of <code>installKeyboardActions</code>.
0125:             */
0126:            public InputMap getInputMap(int condition, JComponent c) {
0127:                if (condition == JComponent.WHEN_FOCUSED) {
0128:                    BasicJideSplitButtonUI ui = (BasicJideSplitButtonUI) getUIOfType(
0129:                            ((JideSplitButton) c).getUI(),
0130:                            BasicJideSplitButtonUI.class);
0131:                    if (ui != null) {
0132:                        return (InputMap) UIDefaultsLookup.get(ui
0133:                                .getPropertyPrefix()
0134:                                + ".focusInputMap");
0135:                    }
0136:                }
0137:                return null;
0138:            }
0139:
0140:            @Override
0141:            protected void installKeyboardActions() {
0142:                super .installKeyboardActions();
0143:                AbstractButton b = menuItem;
0144:
0145:                LazyActionMap.installLazyActionMap(b,
0146:                        BasicJideSplitButtonUI.class,
0147:                        "JideSplitButton.actionMap");
0148:
0149:                InputMap km = getInputMap(JComponent.WHEN_FOCUSED, b);
0150:
0151:                SwingUtilities
0152:                        .replaceUIInputMap(b, JComponent.WHEN_FOCUSED, km);
0153:            }
0154:
0155:            @Override
0156:            protected void uninstallKeyboardActions() {
0157:                AbstractButton b = menuItem;
0158:                SwingUtilities.replaceUIInputMap(b,
0159:                        JComponent.WHEN_IN_FOCUSED_WINDOW, null);
0160:                SwingUtilities.replaceUIInputMap(b, JComponent.WHEN_FOCUSED,
0161:                        null);
0162:                SwingUtilities.replaceUIActionMap(b, null);
0163:                super .uninstallKeyboardActions();
0164:            }
0165:
0166:            @Override
0167:            protected MouseInputListener createMouseInputListener(JComponent c) {
0168:                return new MouseInputHandler();
0169:            }
0170:
0171:            @Override
0172:            protected void paintBackground(Graphics g, JMenuItem menuItem,
0173:                    Color bgColor) {
0174:                ButtonModel model = menuItem.getModel();
0175:                int menuWidth = 0;
0176:                int menuHeight = 0;
0177:                if (JideSwingUtilities.getOrientationOf(menuItem) == SwingConstants.HORIZONTAL) {
0178:                    menuWidth = menuItem.getWidth();
0179:                    menuHeight = menuItem.getHeight();
0180:                } else {
0181:                    menuWidth = menuItem.getHeight();
0182:                    menuHeight = menuItem.getWidth();
0183:                }
0184:
0185:                if (!((JMenu) menuItem).isTopLevelMenu()) {
0186:                    super .paintBackground(g, menuItem, bgColor);
0187:                    if (menuItem.isEnabled()) {
0188:                        if (model.isArmed() || model.isPressed()
0189:                                || isMouseOver()) {
0190:                            g.setColor(selectionForeground);
0191:                            g.drawLine(menuWidth - _splitButtonMarginOnMenu, 0,
0192:                                    menuWidth - _splitButtonMarginOnMenu,
0193:                                    menuHeight - 2);
0194:                            JideSwingUtilities.paintArrow(g,
0195:                                    selectionForeground, menuWidth
0196:                                            - _splitButtonMarginOnMenu / 2 - 2,
0197:                                    menuHeight / 2 - 3, 7,
0198:                                    SwingConstants.VERTICAL);
0199:                        } else {
0200:                            g.setColor(menuItem.getForeground());
0201:                            g.drawLine(menuWidth - _splitButtonMarginOnMenu, 0,
0202:                                    menuWidth - _splitButtonMarginOnMenu,
0203:                                    menuHeight - 2);
0204:                            JideSwingUtilities.paintArrow(g, menuItem
0205:                                    .getForeground(), menuWidth
0206:                                    - _splitButtonMarginOnMenu / 2 - 2,
0207:                                    menuHeight / 2 - 3, 7,
0208:                                    SwingConstants.VERTICAL);
0209:                        }
0210:                    } else {
0211:                        g
0212:                                .setColor(UIDefaultsLookup
0213:                                        .getColor("controlDkShadow"));
0214:                        g.drawLine(menuWidth - _splitButtonMarginOnMenu, 0,
0215:                                menuWidth - _splitButtonMarginOnMenu,
0216:                                menuHeight - 2);
0217:                        JideSwingUtilities.paintArrow(g, UIDefaultsLookup
0218:                                .getColor("controlDkShadow"), menuWidth
0219:                                - _splitButtonMarginOnMenu / 2 - 2,
0220:                                menuHeight / 2 - 3, 7, SwingConstants.VERTICAL);
0221:                    }
0222:                    return;
0223:                }
0224:
0225:                if (menuItem.isOpaque()) {
0226:                    if (menuItem.getParent() != null) {
0227:                        g.setColor(menuItem.getParent().getBackground());
0228:                    } else {
0229:                        g.setColor(menuItem.getBackground());
0230:                    }
0231:                    g.fillRect(0, 0, menuWidth, menuHeight);
0232:                }
0233:
0234:                JideSplitButton b = (JideSplitButton) menuItem;
0235:                if (menuItem instanceof  ButtonStyle
0236:                        && ((ButtonStyle) menuItem).getButtonStyle() == ButtonStyle.TOOLBAR_STYLE) {
0237:                    if ((menuItem instanceof  JMenu && model.isSelected())) {
0238:                        // Draw a dark shadow border without bottom
0239:                        getPainter().paintSelectedMenu(menuItem, g,
0240:                                new Rectangle(0, 0, menuWidth, menuHeight),
0241:                                JideSwingUtilities.getOrientationOf(menuItem),
0242:                                ThemePainter.STATE_SELECTED);
0243:                    } else if (model.isArmed() || model.isPressed()) {
0244:                        Rectangle rect = new Rectangle(0, 0, menuWidth
0245:                                - _splitButtonMargin, menuHeight);
0246:                        if (((JideSplitButton) menuItem).isButtonEnabled()) {
0247:                            getPainter().paintButtonBackground(
0248:                                    menuItem,
0249:                                    g,
0250:                                    rect,
0251:                                    JideSwingUtilities
0252:                                            .getOrientationOf(menuItem),
0253:                                    ThemePainter.STATE_PRESSED);
0254:                        }
0255:                        rect = new Rectangle(menuWidth - _splitButtonMargin - 1
0256:                                + getOffset(), 0, _splitButtonMargin
0257:                                - getOffset(), menuHeight);
0258:                        getPainter().paintButtonBackground(menuItem, g, rect,
0259:                                JideSwingUtilities.getOrientationOf(menuItem),
0260:                                ThemePainter.STATE_ROLLOVER);
0261:                    } else if (model instanceof  SplitButtonModel
0262:                            && ((DefaultSplitButtonModel) model)
0263:                                    .isButtonSelected()) {
0264:                        if ((isMouseOver() || b.hasFocus())
0265:                                && model.isEnabled()) {
0266:                            Rectangle rect = new Rectangle(menuWidth
0267:                                    - _splitButtonMargin - 1 + getOffset(), 0,
0268:                                    _splitButtonMargin - getOffset(),
0269:                                    menuHeight);
0270:                            getPainter().paintButtonBackground(
0271:                                    menuItem,
0272:                                    g,
0273:                                    rect,
0274:                                    JideSwingUtilities
0275:                                            .getOrientationOf(menuItem),
0276:                                    ThemePainter.STATE_ROLLOVER);
0277:                            rect = new Rectangle(0, 0, menuWidth
0278:                                    - _splitButtonMargin, menuHeight);
0279:                            if (((JideSplitButton) menuItem).isButtonEnabled()) {
0280:                                getPainter().paintButtonBackground(
0281:                                        menuItem,
0282:                                        g,
0283:                                        rect,
0284:                                        JideSwingUtilities
0285:                                                .getOrientationOf(menuItem),
0286:                                        ThemePainter.STATE_PRESSED);
0287:                            }
0288:                        } else {
0289:                            Rectangle rect = new Rectangle(menuWidth
0290:                                    - _splitButtonMargin - 1 + getOffset(), 0,
0291:                                    _splitButtonMargin - getOffset(),
0292:                                    menuHeight);
0293:                            getPainter().paintButtonBackground(
0294:                                    menuItem,
0295:                                    g,
0296:                                    rect,
0297:                                    JideSwingUtilities
0298:                                            .getOrientationOf(menuItem),
0299:                                    ThemePainter.STATE_DEFAULT);
0300:                            rect = new Rectangle(0, 0, menuWidth
0301:                                    - _splitButtonMargin, menuHeight);
0302:                            getPainter().paintButtonBackground(
0303:                                    menuItem,
0304:                                    g,
0305:                                    rect,
0306:                                    JideSwingUtilities
0307:                                            .getOrientationOf(menuItem),
0308:                                    ThemePainter.STATE_SELECTED);
0309:                        }
0310:                    } else {
0311:                        if ((isMouseOver() || b.hasFocus())
0312:                                && model.isEnabled()) {
0313:                            if (isAlwaysDropdown(menuItem)) {
0314:                                Rectangle rect = new Rectangle(0, 0, menuWidth,
0315:                                        menuHeight);
0316:                                getPainter().paintButtonBackground(
0317:                                        menuItem,
0318:                                        g,
0319:                                        rect,
0320:                                        JideSwingUtilities
0321:                                                .getOrientationOf(menuItem),
0322:                                        ThemePainter.STATE_ROLLOVER);
0323:                            } else {
0324:                                // Draw a line border with background
0325:                                Rectangle rect = new Rectangle(0, 0, menuWidth
0326:                                        - _splitButtonMargin, menuHeight);
0327:                                if (((JideSplitButton) menuItem)
0328:                                        .isButtonEnabled()) {
0329:                                    getPainter()
0330:                                            .paintButtonBackground(
0331:                                                    menuItem,
0332:                                                    g,
0333:                                                    rect,
0334:                                                    JideSwingUtilities
0335:                                                            .getOrientationOf(menuItem),
0336:                                                    ThemePainter.STATE_ROLLOVER);
0337:                                }
0338:                                rect = new Rectangle(menuWidth
0339:                                        - _splitButtonMargin - 1 + getOffset(),
0340:                                        0, _splitButtonMargin - getOffset(),
0341:                                        menuHeight);
0342:                                getPainter().paintButtonBackground(
0343:                                        menuItem,
0344:                                        g,
0345:                                        rect,
0346:                                        JideSwingUtilities
0347:                                                .getOrientationOf(menuItem),
0348:                                        ThemePainter.STATE_ROLLOVER);
0349:                            }
0350:                        }
0351:                    }
0352:                } else if (menuItem instanceof  ButtonStyle
0353:                        && ((ButtonStyle) menuItem).getButtonStyle() == ButtonStyle.FLAT_STYLE) {
0354:                    if ((menuItem instanceof  JMenu && model.isSelected())) {
0355:                        // Draw a dark shadow border without bottom
0356:                        getPainter().paintSelectedMenu(menuItem, g,
0357:                                new Rectangle(0, 0, menuWidth, menuHeight),
0358:                                JideSwingUtilities.getOrientationOf(menuItem),
0359:                                ThemePainter.STATE_SELECTED);
0360:                    } else if (model.isArmed() || model.isPressed()) {
0361:                        Rectangle rect = new Rectangle(0, 0, menuWidth
0362:                                - _splitButtonMargin, menuHeight);
0363:                        if (((JideSplitButton) menuItem).isButtonEnabled()) {
0364:                            JideSwingUtilities.paintBackground(g, rect,
0365:                                    _highlight, _highlight);
0366:                        }
0367:                        rect = new Rectangle(menuWidth - _splitButtonMargin
0368:                                + getOffset(), 0, _splitButtonMargin
0369:                                - getOffset(), menuHeight);
0370:                        JideSwingUtilities.paintBackground(g, rect, _highlight,
0371:                                _highlight);
0372:
0373:                        if (!b.isOpaque()) {
0374:                            rect = new Rectangle(0, 0, menuWidth
0375:                                    - _splitButtonMargin, menuHeight);
0376:                            paintSunkenBorder(g, rect);
0377:                            rect = new Rectangle(menuWidth - _splitButtonMargin
0378:                                    + getOffset(), 0, _splitButtonMargin
0379:                                    - getOffset(), menuHeight);
0380:                            paintRaisedBorder(g, rect);
0381:                        }
0382:                    } else if (model instanceof  SplitButtonModel
0383:                            && ((DefaultSplitButtonModel) model)
0384:                                    .isButtonSelected()) {
0385:                        if ((isMouseOver() || b.hasFocus())
0386:                                && model.isEnabled()) {
0387:                            Rectangle rect = new Rectangle(menuWidth
0388:                                    - _splitButtonMargin + getOffset(), 0,
0389:                                    _splitButtonMargin - getOffset(),
0390:                                    menuHeight);
0391:                            JideSwingUtilities.paintBackground(g, rect,
0392:                                    _highlight, _highlight);
0393:                            rect = new Rectangle(0, 0, menuWidth
0394:                                    - _splitButtonMargin, menuHeight);
0395:                            if (((JideSplitButton) menuItem).isButtonEnabled()) {
0396:                                JideSwingUtilities.paintBackground(g, rect,
0397:                                        _highlight, _highlight);
0398:                            }
0399:                            if (!b.isOpaque()) {
0400:                                rect = new Rectangle(0, 0, menuWidth
0401:                                        - _splitButtonMargin, menuHeight);
0402:                                paintSunkenBorder(g, rect);
0403:                                rect = new Rectangle(menuWidth
0404:                                        - _splitButtonMargin + getOffset(), 0,
0405:                                        _splitButtonMargin - getOffset(),
0406:                                        menuHeight);
0407:                                paintRaisedBorder(g, rect);
0408:                            }
0409:                        } else {
0410:                            Rectangle rect = null;
0411:                            if (b.isOpaque()) {
0412:                                rect = new Rectangle(menuWidth
0413:                                        - _splitButtonMargin + getOffset(), 0,
0414:                                        _splitButtonMargin - getOffset(),
0415:                                        menuHeight);
0416:                                JideSwingUtilities.paintBackground(g, rect,
0417:                                        _highlight, _highlight);
0418:                            }
0419:                            rect = new Rectangle(0, 0, menuWidth
0420:                                    - _splitButtonMargin, menuHeight);
0421:                            JideSwingUtilities.paintBackground(g, rect,
0422:                                    _highlight, _highlight);
0423:
0424:                            if (!b.isOpaque()) {
0425:                                rect = new Rectangle(0, 0, menuWidth
0426:                                        - _splitButtonMargin, menuHeight);
0427:                                paintSunkenBorder(g, rect);
0428:                                //                        rect = new Rectangle(menuWidth - _splitButtonMargin + getOffset(), 0, _splitButtonMargin - getOffset(), menuHeight);
0429:                                //                        paintRaisedBorder(g, rect);
0430:                            }
0431:                        }
0432:
0433:                    } else {
0434:                        if ((isMouseOver() || b.hasFocus())
0435:                                && model.isEnabled()) {
0436:                            // Draw a line border with background
0437:                            Rectangle rect = new Rectangle(0, 0, menuWidth
0438:                                    - _splitButtonMargin, menuHeight);
0439:                            if (((JideSplitButton) menuItem).isButtonEnabled()) {
0440:                                JideSwingUtilities.paintBackground(g, rect,
0441:                                        _highlight, _highlight);
0442:                            }
0443:                            rect = new Rectangle(menuWidth - _splitButtonMargin
0444:                                    - getOffset(), 0, _splitButtonMargin
0445:                                    - getOffset(), menuHeight);
0446:                            JideSwingUtilities.paintBackground(g, rect,
0447:                                    _highlight, _highlight);
0448:
0449:                            rect = new Rectangle(0, 0, menuWidth
0450:                                    - _splitButtonMargin, menuHeight);
0451:                            paintRaisedBorder(g, rect);
0452:                            rect = new Rectangle(menuWidth - _splitButtonMargin
0453:                                    + getOffset(), 0, _splitButtonMargin
0454:                                    - getOffset(), menuHeight);
0455:                            paintRaisedBorder(g, rect);
0456:                        } else {
0457:                            if (b.isOpaque()) {
0458:                                Rectangle rect = new Rectangle(0, 0, menuWidth
0459:                                        - _splitButtonMargin, menuHeight);
0460:                                if (((JideSplitButton) menuItem)
0461:                                        .isButtonEnabled()) {
0462:                                    getPainter()
0463:                                            .paintButtonBackground(
0464:                                                    menuItem,
0465:                                                    g,
0466:                                                    rect,
0467:                                                    JideSwingUtilities
0468:                                                            .getOrientationOf(menuItem),
0469:                                                    ThemePainter.STATE_DEFAULT);
0470:                                }
0471:                                rect = new Rectangle(menuWidth
0472:                                        - _splitButtonMargin - 1 + getOffset(),
0473:                                        0, _splitButtonMargin - getOffset(),
0474:                                        menuHeight);
0475:                                getPainter().paintButtonBackground(
0476:                                        menuItem,
0477:                                        g,
0478:                                        rect,
0479:                                        JideSwingUtilities
0480:                                                .getOrientationOf(menuItem),
0481:                                        ThemePainter.STATE_DEFAULT);
0482:                            }
0483:                        }
0484:                    }
0485:                } else if (menuItem instanceof  ButtonStyle
0486:                        && ((ButtonStyle) menuItem).getButtonStyle() == ButtonStyle.TOOLBOX_STYLE) {
0487:                    if ((menuItem instanceof  JMenu && model.isSelected())) {
0488:                        // Draw a dark shadow border without bottom
0489:                        getPainter().paintSelectedMenu(menuItem, g,
0490:                                new Rectangle(0, 0, menuWidth, menuHeight),
0491:                                JideSwingUtilities.getOrientationOf(menuItem),
0492:                                ThemePainter.STATE_SELECTED);
0493:                    } else if (model.isArmed() || model.isPressed()) {
0494:                        Rectangle rect = new Rectangle(0, 0, menuWidth
0495:                                - _splitButtonMargin, menuHeight);
0496:                        if (((JideSplitButton) menuItem).isButtonEnabled()) {
0497:                            getPainter().paintButtonBackground(
0498:                                    menuItem,
0499:                                    g,
0500:                                    rect,
0501:                                    JideSwingUtilities
0502:                                            .getOrientationOf(menuItem),
0503:                                    ThemePainter.STATE_PRESSED);
0504:                        }
0505:                        rect = new Rectangle(menuWidth - _splitButtonMargin
0506:                                + getOffset(), 0, _splitButtonMargin
0507:                                - getOffset(), menuHeight);
0508:                        getPainter().paintButtonBackground(menuItem, g, rect,
0509:                                JideSwingUtilities.getOrientationOf(menuItem),
0510:                                ThemePainter.STATE_ROLLOVER);
0511:
0512:                        if (!b.isOpaque()) {
0513:                            rect = new Rectangle(0, 0, menuWidth
0514:                                    - _splitButtonMargin, menuHeight);
0515:                            paintSunken2Border(g, rect);
0516:                            rect = new Rectangle(menuWidth - _splitButtonMargin
0517:                                    + getOffset(), 0, _splitButtonMargin
0518:                                    - getOffset(), menuHeight);
0519:                            paintRaisedBorder(g, rect);
0520:                        }
0521:                    } else if (model instanceof  SplitButtonModel
0522:                            && ((DefaultSplitButtonModel) model)
0523:                                    .isButtonSelected()) {
0524:                        if (isMouseOver() && model.isEnabled()) {
0525:                            Rectangle rect = new Rectangle(menuWidth
0526:                                    - _splitButtonMargin + getOffset(), 0,
0527:                                    _splitButtonMargin - getOffset(),
0528:                                    menuHeight);
0529:                            getPainter().paintButtonBackground(
0530:                                    menuItem,
0531:                                    g,
0532:                                    rect,
0533:                                    JideSwingUtilities
0534:                                            .getOrientationOf(menuItem),
0535:                                    ThemePainter.STATE_ROLLOVER);
0536:                            rect = new Rectangle(0, 0, menuWidth
0537:                                    - _splitButtonMargin, menuHeight);
0538:                            if (((JideSplitButton) menuItem).isButtonEnabled()) {
0539:                                getPainter().paintButtonBackground(
0540:                                        menuItem,
0541:                                        g,
0542:                                        rect,
0543:                                        JideSwingUtilities
0544:                                                .getOrientationOf(menuItem),
0545:                                        ThemePainter.STATE_PRESSED);
0546:                            }
0547:                            if (!b.isOpaque()) {
0548:                                rect = new Rectangle(0, 0, menuWidth
0549:                                        - _splitButtonMargin, menuHeight);
0550:                                paintSunken2Border(g, rect);
0551:                                rect = new Rectangle(menuWidth
0552:                                        - _splitButtonMargin + getOffset(), 0,
0553:                                        _splitButtonMargin - getOffset(),
0554:                                        menuHeight);
0555:                                paintRaisedBorder(g, rect);
0556:                            }
0557:                        } else {
0558:                            Rectangle rect = null;
0559:                            if (b.isOpaque()) {
0560:                                rect = new Rectangle(menuWidth
0561:                                        - _splitButtonMargin + getOffset(), 0,
0562:                                        _splitButtonMargin - getOffset(),
0563:                                        menuHeight);
0564:                                getPainter().paintButtonBackground(
0565:                                        menuItem,
0566:                                        g,
0567:                                        rect,
0568:                                        JideSwingUtilities
0569:                                                .getOrientationOf(menuItem),
0570:                                        ThemePainter.STATE_DEFAULT);
0571:                            }
0572:                            rect = new Rectangle(0, 0, menuWidth
0573:                                    - _splitButtonMargin, menuHeight);
0574:                            getPainter().paintButtonBackground(
0575:                                    menuItem,
0576:                                    g,
0577:                                    rect,
0578:                                    JideSwingUtilities
0579:                                            .getOrientationOf(menuItem),
0580:                                    ThemePainter.STATE_SELECTED);
0581:
0582:                            if (!b.isOpaque()) {
0583:                                rect = new Rectangle(0, 0, menuWidth
0584:                                        - _splitButtonMargin, menuHeight);
0585:                                paintSunken2Border(g, rect);
0586:                                rect = new Rectangle(menuWidth
0587:                                        - _splitButtonMargin + getOffset(), 0,
0588:                                        _splitButtonMargin - getOffset(),
0589:                                        menuHeight);
0590:                                paintRaisedBorder(g, rect);
0591:                            }
0592:                        }
0593:
0594:                    } else {
0595:                        if (isMouseOver() && model.isEnabled()) {
0596:                            // Draw a line border with background
0597:                            Rectangle rect = new Rectangle(0, 0, menuWidth
0598:                                    - _splitButtonMargin, menuHeight);
0599:                            if (((JideSplitButton) menuItem).isButtonEnabled()) {
0600:                                getPainter().paintButtonBackground(
0601:                                        menuItem,
0602:                                        g,
0603:                                        rect,
0604:                                        JideSwingUtilities
0605:                                                .getOrientationOf(menuItem),
0606:                                        ThemePainter.STATE_ROLLOVER);
0607:                            }
0608:                            rect = new Rectangle(menuWidth - _splitButtonMargin
0609:                                    - getOffset(), 0, _splitButtonMargin
0610:                                    - getOffset(), menuHeight);
0611:                            getPainter().paintButtonBackground(
0612:                                    menuItem,
0613:                                    g,
0614:                                    rect,
0615:                                    JideSwingUtilities
0616:                                            .getOrientationOf(menuItem),
0617:                                    ThemePainter.STATE_ROLLOVER);
0618:
0619:                            rect = new Rectangle(0, 0, menuWidth
0620:                                    - _splitButtonMargin, menuHeight);
0621:                            paintRaised2Border(g, rect);
0622:                            rect = new Rectangle(menuWidth - _splitButtonMargin
0623:                                    + getOffset(), 0, _splitButtonMargin
0624:                                    - getOffset(), menuHeight);
0625:                            paintRaised2Border(g, rect);
0626:                        } else {
0627:                            if (b.isOpaque()) {
0628:                                Rectangle rect = new Rectangle(0, 0, menuWidth
0629:                                        - _splitButtonMargin, menuHeight);
0630:                                if (((JideSplitButton) menuItem)
0631:                                        .isButtonEnabled()) {
0632:                                    getPainter()
0633:                                            .paintButtonBackground(
0634:                                                    menuItem,
0635:                                                    g,
0636:                                                    rect,
0637:                                                    JideSwingUtilities
0638:                                                            .getOrientationOf(menuItem),
0639:                                                    ThemePainter.STATE_DEFAULT);
0640:                                }
0641:                                rect = new Rectangle(menuWidth
0642:                                        - _splitButtonMargin - 1 + getOffset(),
0643:                                        0, _splitButtonMargin - getOffset(),
0644:                                        menuHeight);
0645:                                getPainter().paintButtonBackground(
0646:                                        menuItem,
0647:                                        g,
0648:                                        rect,
0649:                                        JideSwingUtilities
0650:                                                .getOrientationOf(menuItem),
0651:                                        ThemePainter.STATE_DEFAULT);
0652:                            } else {
0653:                                Rectangle rect = new Rectangle(0, 0, menuWidth
0654:                                        - _splitButtonMargin, menuHeight);
0655:                                paintRaisedBorder(g, rect);
0656:                                rect = new Rectangle(menuWidth
0657:                                        - _splitButtonMargin + getOffset(), 0,
0658:                                        _splitButtonMargin - getOffset(),
0659:                                        menuHeight);
0660:                                paintRaisedBorder(g, rect);
0661:                            }
0662:                        }
0663:                    }
0664:                }
0665:
0666:                if (menuItem.isEnabled()) {
0667:                    JideSwingUtilities.paintArrow(g, menuItem.getForeground(),
0668:                            menuWidth - 9, menuHeight / 2 - 1, 5,
0669:                            SwingConstants.HORIZONTAL);
0670:                } else {
0671:                    JideSwingUtilities.paintArrow(g, UIDefaultsLookup
0672:                            .getColor("controlShadow"), menuWidth - 9,
0673:                            menuHeight / 2 - 1, 5, SwingConstants.HORIZONTAL);
0674:                }
0675:            }
0676:
0677:            protected void paintSunkenBorder(Graphics g, Rectangle b) {
0678:                Color old = g.getColor();
0679:                g.setColor(_shadowColor); // inner 3D border
0680:                g.drawLine(b.x, b.y, b.x + b.width - 1, b.y);
0681:                g.drawLine(b.x, b.y, b.x, b.y + b.height - 1);
0682:
0683:                g.setColor(_lightHighlightColor); // black drop shadow  __|
0684:                g.drawLine(b.x, b.y + b.height - 1, b.x + b.width - 1, b.y
0685:                        + b.height - 1);
0686:                g.drawLine(b.x + b.width - 1, b.y, b.x + b.width - 1, b.y
0687:                        + b.height - 1);
0688:                g.setColor(old);
0689:            }
0690:
0691:            protected void paintSunken2Border(Graphics g, Rectangle b) {
0692:                Color old = g.getColor();
0693:                g.setColor(_darkShadowColor); // inner 3D border
0694:                g.drawLine(b.x, b.y, b.x + b.width - 2, b.y);
0695:                g.drawLine(b.x, b.y, b.x, b.y + b.height - 2);
0696:
0697:                g.setColor(_shadowColor); // inner 3D border
0698:                g.drawLine(b.x + 1, b.y + 1, b.x + b.width - 3, b.y + 1);
0699:                g.drawLine(b.x + 1, b.y + 1, b.x + 1, b.y + b.height - 3);
0700:
0701:                g.setColor(_lightHighlightColor); // black drop shadow  __|
0702:                g.drawLine(b.x, b.y + b.height - 1, b.x + b.width - 1, b.y
0703:                        + b.height - 1);
0704:                g.drawLine(b.x + b.width - 1, b.x, b.x + b.width - 1, b.y
0705:                        + b.height - 1);
0706:                g.setColor(old);
0707:            }
0708:
0709:            protected void paintRaised2Border(Graphics g, Rectangle b) {
0710:                Color old = g.getColor();
0711:                g.setColor(_lightHighlightColor); // inner 3D border
0712:                g.drawLine(b.x, b.y, b.x + b.width - 1, b.y);
0713:                g.drawLine(b.x, b.y, b.x, b.y + b.height - 1);
0714:
0715:                g.setColor(_shadowColor); // gray drop shadow  __|
0716:                g.drawLine(b.x + 1, b.y + b.height - 2, b.x + b.width - 2, b.y
0717:                        + b.height - 2);
0718:                g.drawLine(b.x + b.width - 2, 1, b.x + b.width - 2, b.y
0719:                        + b.height - 2);
0720:
0721:                g.setColor(_darkShadowColor); // black drop shadow  __|
0722:                g.drawLine(b.x, b.y + b.height - 1, b.x + b.width - 1, b.y
0723:                        + b.height - 1);
0724:                g.drawLine(b.x + b.width - 1, b.y, b.x + b.width - 1, b.y
0725:                        + b.height - 1);
0726:                g.setColor(old);
0727:            }
0728:
0729:            protected void paintRaisedBorder(Graphics g, Rectangle b) {
0730:                Color old = g.getColor();
0731:                g.setColor(_lightHighlightColor); // inner 3D border
0732:                g.drawLine(b.x, b.y, b.x + b.width - 1, b.y);
0733:                g.drawLine(b.x, b.y, b.x, b.y + b.height - 1);
0734:
0735:                g.setColor(_shadowColor); // black drop shadow  __|
0736:                g.drawLine(b.x, b.y + b.height - 1, b.x + b.width - 1, b.y
0737:                        + b.height - 1);
0738:                g.drawLine(b.x + b.width - 1, b.y, b.x + b.width - 1, b.y
0739:                        + b.height - 1);
0740:                g.setColor(old);
0741:            }
0742:
0743:            protected class MouseInputHandler implements  MouseInputListener {
0744:                public void mouseClicked(MouseEvent e) {
0745:                    cancelMenuIfNecessary(e);
0746:                }
0747:
0748:                /**
0749:                 * Invoked when the mouse has been clicked on the menu. This
0750:                 * method clears or sets the selection path of the
0751:                 * MenuSelectionManager.
0752:                 *
0753:                 * @param e the mouse event
0754:                 */
0755:                public void mousePressed(MouseEvent e) {
0756:                    JMenu menu = (JMenu) menuItem;
0757:                    if (!menu.isEnabled())
0758:                        return;
0759:
0760:                    setMouseOver(true);
0761:
0762:                    if (!SwingUtilities.isLeftMouseButton(e)) {
0763:                        return;
0764:                    }
0765:                    if (isClickOnButton(e, menu)) {
0766:                        if (((JideSplitButton) menuItem).isButtonEnabled()) {
0767:                            // click button
0768:                            menu.getModel().setArmed(true);
0769:                            menu.getModel().setPressed(true);
0770:                        }
0771:                        if (!menu.hasFocus() && menu.isRequestFocusEnabled()) {
0772:                            menu.requestFocus();
0773:                        }
0774:                    } else {
0775:                        downButtonPressed(menu);
0776:                    }
0777:                }
0778:
0779:                private boolean isClickOnButton(MouseEvent e, JMenu menu) {
0780:                    if (((JideSplitButton) menu).isAlwaysDropdown()) {
0781:                        return false;
0782:                    }
0783:
0784:                    boolean clickOnDropDown = false;
0785:                    int size = ((JMenu) menuItem).isTopLevelMenu() ? _splitButtonMargin
0786:                            : _splitButtonMarginOnMenu;
0787:                    if (JideSwingUtilities.getOrientationOf(menuItem) == SwingConstants.HORIZONTAL) {
0788:                        if (e.getPoint().getX() < menu.getWidth() - size) {
0789:                            clickOnDropDown = true;
0790:                        }
0791:                    } else {
0792:                        if (e.getPoint().getY() < menu.getHeight() - size) {
0793:                            clickOnDropDown = true;
0794:                        }
0795:                    }
0796:                    return clickOnDropDown;
0797:                }
0798:
0799:                /**
0800:                 * Invoked when the mouse has been released on the menu. Delegates the
0801:                 * mouse event to the MenuSelectionManager.
0802:                 *
0803:                 * @param e the mouse event
0804:                 */
0805:                public void mouseReleased(MouseEvent e) {
0806:                    if (!isMouseOver()) {
0807:                        // these two lines order matters. In this order, it would not trigger actionPerformed.
0808:                        menuItem.getModel().setArmed(false);
0809:                        menuItem.getModel().setPressed(false);
0810:                    }
0811:                    cancelMenuIfNecessary(e);
0812:                }
0813:
0814:                private void cancelMenuIfNecessary(MouseEvent e) {
0815:                    JMenu menu = (JMenu) menuItem;
0816:                    if (!menu.isEnabled())
0817:                        return;
0818:                    if (isClickOnButton(e, menu)) {
0819:                        if (((JideSplitButton) menuItem).isButtonEnabled()) {
0820:                            // click button
0821:                            // these two lines order matters. In this order, it would trigger actionPerformed.
0822:                            if (SwingUtilities.isLeftMouseButton(e)) {
0823:                                menu.getModel().setPressed(false);
0824:                                menu.getModel().setArmed(false);
0825:                            } else {
0826:                                menu.getModel().setArmed(false);
0827:                                menu.getModel().setPressed(false);
0828:                            }
0829:
0830:                            MenuSelectionManager manager = MenuSelectionManager
0831:                                    .defaultManager();
0832:                            MenuElement[] menuElements = manager
0833:                                    .getSelectedPath();
0834:                            for (int i = menuElements.length - 1; i >= 0; i--) {
0835:                                MenuElement menuElement = menuElements[i];
0836:                                if (menuElement instanceof  JPopupMenu
0837:                                        && ((JPopupMenu) menuElement)
0838:                                                .isAncestorOf(menu)) {
0839:                                    menu.getModel().setRollover(false);
0840:                                    setMouseOver(false);
0841:                                    manager.clearSelectedPath();
0842:                                }
0843:                            }
0844:                        }
0845:                    } else {
0846:                        //                MenuSelectionManager manager =
0847:                        //                        MenuSelectionManager.defaultManager();
0848:                        //                manager.processMouseEvent(e);
0849:                        //                if (!e.isConsumed())
0850:                        //                    manager.clearSelectedPath();
0851:                    }
0852:                }
0853:
0854:                /**
0855:                 * Invoked when the cursor enters the menu. This method sets the selected
0856:                 * path for the MenuSelectionManager and handles the case
0857:                 * in which a menu item is used to pop up an additional menu, as in a
0858:                 * hierarchical menu system.
0859:                 *
0860:                 * @param e the mouse event; not used
0861:                 */
0862:                public void mouseEntered(MouseEvent e) {
0863:                    JMenu menu = (JMenu) menuItem;
0864:                    if (!menu.isEnabled())
0865:                        return;
0866:
0867:                    MenuSelectionManager manager = MenuSelectionManager
0868:                            .defaultManager();
0869:                    MenuElement selectedPath[] = manager.getSelectedPath();
0870:                    if (!menu.isTopLevelMenu()) {
0871:                        if (!(selectedPath.length > 0 && selectedPath[selectedPath.length - 1] == menu
0872:                                .getPopupMenu())) {
0873:                            if (menu.getDelay() == 0) {
0874:                                appendPath(getPath(), menu.getPopupMenu());
0875:                            } else {
0876:                                manager.setSelectedPath(getPath());
0877:                                setupPostTimer(menu);
0878:                            }
0879:                        }
0880:                    } else {
0881:                        if (selectedPath.length > 0
0882:                                && selectedPath[0] == menu.getParent()) {
0883:                            MenuElement newPath[] = new MenuElement[3];
0884:                            // A top level menu's parent is by definition
0885:                            // a JMenuBar
0886:                            newPath[0] = (MenuElement) menu.getParent();
0887:                            newPath[1] = menu;
0888:                            newPath[2] = menu.getPopupMenu();
0889:                            manager.setSelectedPath(newPath);
0890:                        }
0891:                    }
0892:
0893:                    if (!SwingUtilities.isLeftMouseButton(e)) {
0894:                        setMouseOver(true);
0895:                    }
0896:                    menuItem.repaint();
0897:                }
0898:
0899:                public void mouseExited(MouseEvent e) {
0900:                    setMouseOver(false);
0901:                    menuItem.repaint();
0902:                }
0903:
0904:                /**
0905:                 * Invoked when a mouse button is pressed on the menu and then dragged.
0906:                 * Delegates the mouse event to the MenuSelectionManager.
0907:                 *
0908:                 * @param e the mouse event
0909:                 * @see java.awt.event.MouseMotionListener#mouseDragged
0910:                 */
0911:                public void mouseDragged(MouseEvent e) {
0912:                    JMenu menu = (JMenu) menuItem;
0913:                    if (!menu.isEnabled())
0914:                        return;
0915:                    MenuSelectionManager.defaultManager().processMouseEvent(e);
0916:                }
0917:
0918:                public void mouseMoved(MouseEvent e) {
0919:                }
0920:            }
0921:
0922:            @Override
0923:            public Dimension getPreferredSize(JComponent c) {
0924:                if (!(c instanceof  JMenu) || !((JMenu) c).isTopLevelMenu()) {
0925:                    return super .getPreferredSize(c);
0926:                }
0927:
0928:                AbstractButton b = (AbstractButton) c;
0929:
0930:                boolean isHorizontal = true;
0931:                if (JideSwingUtilities.getOrientationOf(c) == SwingConstants.VERTICAL) {
0932:                    isHorizontal = false;
0933:                }
0934:
0935:                // JDK PORTING HINT
0936:                // JDK1.3: No getIconTextGap, use defaultTextIconGap
0937:                Dimension d = BasicGraphicsUtils.getPreferredButtonSize(b,
0938:                        defaultTextIconGap);
0939:                //        d.width += b.getMargin().left + b.getMargin().right;
0940:                //        d.height += b.getMargin().bottom + b.getMargin().top;
0941:
0942:                int size = ((JMenu) menuItem).isTopLevelMenu() ? _splitButtonMargin
0943:                        : _splitButtonMarginOnMenu;
0944:                d.width += size;
0945:
0946:                if (isHorizontal)
0947:                    return d;
0948:                else
0949:                    return new Dimension(d.height, d.width); // swap width and height
0950:            }
0951:
0952:            @Override
0953:            public Dimension getMinimumSize(JComponent c) {
0954:                if (!(c instanceof  JMenu) || !((JMenu) c).isTopLevelMenu()) {
0955:                    return super .getMinimumSize(c);
0956:                }
0957:
0958:                Dimension d = getPreferredSize(c);
0959:                View v = (View) c.getClientProperty(BasicHTML.propertyKey);
0960:                if (v != null) {
0961:                    if (JideSwingUtilities.getOrientationOf(c) == SwingConstants.HORIZONTAL)
0962:                        d.width -= v.getPreferredSpan(View.X_AXIS)
0963:                                - v.getMinimumSpan(View.X_AXIS);
0964:                    else
0965:                        // TODO: not sure if this is correct
0966:                        d.height -= v.getPreferredSpan(View.X_AXIS)
0967:                                - v.getMinimumSpan(View.X_AXIS);
0968:                }
0969:
0970:                return d;
0971:            }
0972:
0973:            @Override
0974:            public Dimension getMaximumSize(JComponent c) {
0975:                if (!(c instanceof  JMenu) || !((JMenu) c).isTopLevelMenu()) {
0976:                    return super .getMaximumSize(c);
0977:                }
0978:
0979:                Dimension d = getPreferredSize(c);
0980:                View v = (View) c.getClientProperty(BasicHTML.propertyKey);
0981:                if (v != null) {
0982:                    if (JideSwingUtilities.getOrientationOf(c) == SwingConstants.HORIZONTAL)
0983:                        d.width += v.getMaximumSpan(View.X_AXIS)
0984:                                - v.getPreferredSpan(View.X_AXIS);
0985:                    else
0986:                        // TODO: not sure if this is correct
0987:                        d.height += v.getMaximumSpan(View.X_AXIS)
0988:                                - v.getPreferredSpan(View.X_AXIS);
0989:                }
0990:
0991:                return d;
0992:            }
0993:
0994:            @Override
0995:            protected void paintText(Graphics g, JMenuItem menuItem,
0996:                    Rectangle textRect, String text) {
0997:                // Note: This method is almost identical to the same method in WindowsMenuItemUI
0998:                ButtonModel model = menuItem.getModel();
0999:
1000:                if (!(menuItem instanceof  JMenu)
1001:                        || !((JMenu) menuItem).isTopLevelMenu()) {
1002:                    if (menuItem.getComponentOrientation().isLeftToRight()) {
1003:                        int defaultTextIconGap = UIDefaultsLookup
1004:                                .getInt("MenuItem.textIconGap");
1005:                        int defaultShadowWidth = UIDefaultsLookup
1006:                                .getInt("MenuItem.shadowWidth");
1007:                        textRect.x = defaultShadowWidth + defaultTextIconGap;
1008:                    } else {
1009:                        // isLeftToRight is false
1010:                    }
1011:                }
1012:
1013:                FontMetrics fm = g.getFontMetrics();
1014:                int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
1015:                // W2K Feature: Check to see if the Underscore should be rendered.
1016:                if (WindowsLookAndFeel.isMnemonicHidden()) {
1017:                    mnemonicIndex = -1;
1018:                }
1019:
1020:                Color oldColor = g.getColor();
1021:
1022:                if (!model.isEnabled()
1023:                        || !((JideSplitButton) menuItem).isButtonEnabled()) {
1024:                    // *** paint the text disabled
1025:                    g.setColor(menuItem.getBackground().brighter());
1026:
1027:                    // JDK PORTING HINT
1028:                    // JDK1.3: No drawStringUnderlineCharAt, draw the string then draw the underline
1029:                    JideSwingUtilities.drawStringUnderlineCharAt(menuItem, g,
1030:                            text, mnemonicIndex, textRect.x, textRect.y
1031:                                    + fm.getAscent());
1032:                    g.setColor(menuItem.getBackground().darker());
1033:
1034:                    // JDK PORTING HINT
1035:                    // JDK1.3: No drawStringUnderlineCharAt, draw the string then draw the underline
1036:                    JideSwingUtilities.drawStringUnderlineCharAt(menuItem, g,
1037:                            text, mnemonicIndex, textRect.x - 1, textRect.y
1038:                                    + fm.getAscent() - 1);
1039:                } else {
1040:                    // For Win95, the selected text color is the selection forground color
1041:                    if (model.isSelected()) {
1042:                        g.setColor(selectionForeground); // Uses protected field.
1043:                    } else {
1044:                        int state = JideSwingUtilities.getButtonState(menuItem);
1045:                        Color foreground = null;
1046:                        if (menuItem instanceof  ComponentStateSupport) {
1047:                            foreground = ((ComponentStateSupport) menuItem)
1048:                                    .getForegroundOfState(state);
1049:                        }
1050:                        if (foreground == null
1051:                                || foreground instanceof  UIResource) {
1052:                            foreground = menuItem.getForeground();
1053:                        }
1054:                        g.setColor(foreground);
1055:                    }
1056:                    JideSwingUtilities.drawStringUnderlineCharAt(menuItem, g,
1057:                            text, mnemonicIndex, textRect.x, textRect.y
1058:                                    + fm.getAscent());
1059:                }
1060:                g.setColor(oldColor);
1061:            }
1062:
1063:            @Override
1064:            protected void paintIcon(JMenuItem b, Graphics g) {
1065:                ButtonModel model = b.getModel();
1066:
1067:                // Paint the Icon
1068:                if (b.getIcon() != null) {
1069:                    //            if (JideSwingUtilities.getOrientationOf(b) == SwingConstants.VERTICAL) {
1070:                    //                ((Graphics2D) g).translate(0, b.getWidth() - 1);
1071:                    //                ((Graphics2D) g).rotate(-Math.PI / 2);
1072:                    //            }
1073:
1074:                    Icon icon = getIcon(b);
1075:
1076:                    if (icon != null) {
1077:                        boolean enabled = model.isEnabled()
1078:                                && (model instanceof  SplitButtonModel ? ((SplitButtonModel) model)
1079:                                        .isButtonEnabled()
1080:                                        : true);
1081:                        if (isFloatingIcon() && enabled) {
1082:                            if (model.isRollover() && !model.isPressed()
1083:                                    && !model.isSelected()) {
1084:                                if (!"true".equals(SecurityUtils.getProperty(
1085:                                        "shadingtheme", "false"))) {
1086:                                    if (icon instanceof  ImageIcon) {
1087:                                        ImageIcon shadow = IconsFactory
1088:                                                .createGrayImage(((ImageIcon) icon)
1089:                                                        .getImage());
1090:                                        shadow.paintIcon(b, g, iconRect.x + 1,
1091:                                                iconRect.y + 1);
1092:                                    } else {
1093:                                        ImageIcon shadow = IconsFactory
1094:                                                .createGrayImage(b, icon);
1095:                                        shadow.paintIcon(b, g, iconRect.x + 1,
1096:                                                iconRect.y + 1);
1097:                                    }
1098:                                    icon.paintIcon(b, g, iconRect.x - 1,
1099:                                            iconRect.y - 1);
1100:                                } else {
1101:                                    icon
1102:                                            .paintIcon(b, g, iconRect.x,
1103:                                                    iconRect.y);
1104:                                }
1105:                            } else {
1106:                                icon.paintIcon(b, g, iconRect.x, iconRect.y);
1107:                            }
1108:                        } else {
1109:                            icon.paintIcon(b, g, iconRect.x, iconRect.y);
1110:                        }
1111:                    }
1112:
1113:                    //            if (JideSwingUtilities.getOrientationOf(b) == SwingConstants.VERTICAL) {
1114:                    //                ((Graphics2D) g).rotate(Math.PI / 2);
1115:                    //                ((Graphics2D) g).translate(0, -b.getHeight() + 1);
1116:                    //            }
1117:                }
1118:            }
1119:
1120:            @Override
1121:            protected boolean isFloatingIcon() {
1122:                return _isFloatingIcon;
1123:            }
1124:
1125:            @Override
1126:            protected Icon getIcon(AbstractButton b) {
1127:                ButtonModel model = b.getModel();
1128:                Icon icon = b.getIcon();
1129:                Icon tmpIcon = null;
1130:                if (!model.isEnabled()
1131:                        || !((JideSplitButton) menuItem).isButtonEnabled()) {
1132:                    if (model.isSelected()) {
1133:                        tmpIcon = (Icon) b.getDisabledSelectedIcon();
1134:                    } else {
1135:                        tmpIcon = (Icon) b.getDisabledIcon();
1136:                    }
1137:
1138:                    // create default diabled icon
1139:                    if (tmpIcon == null) {
1140:                        if (icon instanceof  ImageIcon) {
1141:                            icon = IconsFactory
1142:                                    .createGrayImage(((ImageIcon) icon)
1143:                                            .getImage());
1144:                        } else {
1145:                            icon = IconsFactory.createGrayImage(b, icon);
1146:                        }
1147:                    }
1148:                } else if (model.isPressed() && model.isArmed()) {
1149:                    tmpIcon = (Icon) b.getPressedIcon();
1150:                    if (tmpIcon != null) {
1151:                        // revert back to 0 offset
1152:                        // clearTextShiftOffset();
1153:                    }
1154:                } else if (b.isRolloverEnabled() && model.isRollover()) {
1155:                    if (model.isSelected()) {
1156:                        tmpIcon = (Icon) b.getRolloverSelectedIcon();
1157:                    } else {
1158:                        tmpIcon = (Icon) b.getRolloverIcon();
1159:                    }
1160:                } else if (model.isSelected()) {
1161:                    tmpIcon = (Icon) b.getSelectedIcon();
1162:                }
1163:
1164:                if (tmpIcon != null) {
1165:                    icon = tmpIcon;
1166:                }
1167:                return icon;
1168:            }
1169:
1170:            /**
1171:             * The gap between the button part and the drop down menu part.
1172:             *
1173:             * @return the gap.
1174:             */
1175:            protected int getOffset() {
1176:                return 0;
1177:            }
1178:
1179:            protected boolean isAlwaysDropdown(JMenuItem menuItem) {
1180:                if (menuItem instanceof  JideSplitButton) {
1181:                    return ((JideSplitButton) menuItem).isAlwaysDropdown();
1182:                } else {
1183:                    return false;
1184:                }
1185:            }
1186:
1187:            @Override
1188:            protected int getRightMargin() {
1189:                return _splitButtonMargin - 1;
1190:            }
1191:
1192:            /**
1193:             * Actions for Buttons. Two type of action are supported:
1194:             * pressed: Moves the button to a pressed state
1195:             * released: Disarms the button.
1196:             */
1197:            private static class Actions extends UIAction {
1198:                private static final String PRESS = "pressed";
1199:                private static final String RELEASE = "released";
1200:                private static final String DOWN_PRESS = "downPressed";
1201:                private static final String DOWN_RELEASE = "downReleased";
1202:
1203:                Actions(String name) {
1204:                    super (name);
1205:                }
1206:
1207:                public void actionPerformed(ActionEvent e) {
1208:                    AbstractButton b = (AbstractButton) e.getSource();
1209:                    String key = getName();
1210:
1211:                    // if isAlwaysDropDown it true, treat PRESS as DOWN_PRESS
1212:                    if (PRESS.equals(key)
1213:                            && ((JideSplitButton) b).isAlwaysDropdown()) {
1214:                        key = DOWN_PRESS;
1215:                    }
1216:
1217:                    if (PRESS.equals(key)) {
1218:                        ButtonModel model = b.getModel();
1219:                        model.setArmed(true);
1220:                        model.setPressed(true);
1221:                        if (!b.hasFocus()) {
1222:                            b.requestFocus();
1223:                        }
1224:                    } else if (RELEASE.equals(key)) {
1225:                        ButtonModel model = b.getModel();
1226:                        model.setPressed(false);
1227:                        model.setArmed(false);
1228:                    } else if (DOWN_PRESS.equals(key)) {
1229:                        downButtonPressed((JMenu) b);
1230:                    } else if (DOWN_RELEASE.equals(key)) {
1231:                    }
1232:                }
1233:
1234:                @Override
1235:                public boolean isEnabled(Object sender) {
1236:                    if (sender != null
1237:                            && (sender instanceof  AbstractButton)
1238:                            && !((AbstractButton) sender).getModel()
1239:                                    .isEnabled()) {
1240:                        return false;
1241:                    } else {
1242:                        return true;
1243:                    }
1244:                }
1245:            }
1246:
1247:            /**
1248:             * Populates Buttons actions.
1249:             */
1250:            public static void loadActionMap(LazyActionMap map) {
1251:                map.put(new Actions(Actions.PRESS));
1252:                map.put(new Actions(Actions.RELEASE));
1253:                map.put(new Actions(Actions.DOWN_PRESS));
1254:                map.put(new Actions(Actions.DOWN_RELEASE));
1255:            }
1256:
1257:            protected static void downButtonPressed(JMenu menu) {
1258:                MenuSelectionManager manager = MenuSelectionManager
1259:                        .defaultManager();
1260:                if (menu.isTopLevelMenu()) {
1261:                    if (menu.isSelected()) {
1262:                        manager.clearSelectedPath();
1263:                    } else {
1264:                        Container cnt = menu.getParent();
1265:                        if (cnt != null && cnt instanceof  MenuElement) {
1266:                            ArrayList parents = new ArrayList();
1267:                            while (cnt instanceof  MenuElement) {
1268:                                parents.add(0, cnt);
1269:                                if (cnt instanceof  JPopupMenu) {
1270:                                    cnt = (Container) ((JPopupMenu) cnt)
1271:                                            .getInvoker();
1272:                                } else {
1273:                                    cnt = cnt.getParent();
1274:                                }
1275:                            }
1276:
1277:                            MenuElement me[] = new MenuElement[parents.size() + 1];
1278:                            for (int i = 0; i < parents.size(); i++) {
1279:                                Container container = (Container) parents
1280:                                        .get(i);
1281:                                me[i] = (MenuElement) container;
1282:                            }
1283:                            me[parents.size()] = menu;
1284:                            manager.setSelectedPath(me);
1285:                        } else {
1286:                            MenuElement me[] = new MenuElement[1];
1287:                            me[0] = menu;
1288:                            manager.setSelectedPath(me);
1289:                        }
1290:                    }
1291:                }
1292:
1293:                MenuElement selectedPath[] = manager.getSelectedPath();
1294:                if (selectedPath.length > 0
1295:                        && selectedPath[selectedPath.length - 1] != menu
1296:                                .getPopupMenu()) {
1297:                    if (menu.isTopLevelMenu() || menu.getDelay() == 0) {
1298:                        appendPath(selectedPath, menu.getPopupMenu());
1299:                    } else {
1300:                        setupPostTimer(menu);
1301:                    }
1302:                }
1303:            }
1304:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.