Source Code Cross Referenced for EnhancedMenuItem.java in  » Swing-Library » jEdit » org » gjt » sp » jedit » menu » 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 » jEdit » org.gjt.sp.jedit.menu 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * EnhancedMenuItem.java - Menu item with user-specified accelerator string
003:         * :tabSize=8:indentSize=8:noTabs=false:
004:         * :folding=explicit:collapseFolds=1:
005:         *
006:         * Copyright (C) 1999, 2003 Slava Pestov
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:
023:        package org.gjt.sp.jedit.menu;
024:
025:        //{{{ Imports
026:        import javax.swing.*;
027:        import java.awt.event.*;
028:        import java.awt.*;
029:        import org.gjt.sp.jedit.*;
030:
031:        //}}}
032:
033:        /**
034:         * jEdit's custom menu item. It adds support for multi-key shortcuts.
035:         */
036:        public class EnhancedMenuItem extends JMenuItem {
037:            //{{{ EnhancedMenuItem constructor
038:            /**
039:             * Creates a new menu item. Most plugins should call
040:             * GUIUtilities.loadMenuItem() instead.
041:             * @param label The menu item label
042:             * @param action The edit action
043:             * @param context An action context
044:             * @since jEdit 4.2pre1
045:             */
046:            public EnhancedMenuItem(String label, String action,
047:                    ActionContext context) {
048:                this .action = action;
049:                this .shortcut = GUIUtilities.getShortcutLabel(action);
050:                if (OperatingSystem.hasScreenMenuBar() && shortcut != null) {
051:                    setText(label + " (" + shortcut + ")");
052:                    shortcut = null;
053:                } else
054:                    setText(label);
055:
056:                if (action != null) {
057:                    setEnabled(true);
058:                    addActionListener(new EditAction.Wrapper(context, action));
059:                    addMouseListener(new MouseHandler());
060:                } else
061:                    setEnabled(false);
062:            } //}}}
063:
064:            //{{{ getPreferredSize() method
065:            public Dimension getPreferredSize() {
066:                Dimension d = super .getPreferredSize();
067:
068:                if (shortcut != null) {
069:                    d.width += (getFontMetrics(acceleratorFont).stringWidth(
070:                            shortcut) + 15);
071:                }
072:                return d;
073:            } //}}}
074:
075:            //{{{ paint() method
076:            public void paint(Graphics g) {
077:                super .paint(g);
078:
079:                if (shortcut != null) {
080:                    g.setFont(acceleratorFont);
081:                    g
082:                            .setColor(getModel().isArmed() ? acceleratorSelectionForeground
083:                                    : acceleratorForeground);
084:                    FontMetrics fm = g.getFontMetrics();
085:                    Insets insets = getInsets();
086:                    g.drawString(shortcut, getWidth()
087:                            - (fm.stringWidth(shortcut) + insets.right
088:                                    + insets.left + 5), getFont().getSize()
089:                            + (insets.top - (OperatingSystem.isMacOSLF() ? 0
090:                                    : 1))
091:                    /* XXX magic number */);
092:                }
093:            } //}}}
094:
095:            //{{{ Package-private members
096:            static Font acceleratorFont;
097:            static Color acceleratorForeground;
098:            static Color acceleratorSelectionForeground;
099:            //}}}
100:
101:            //{{{ Private members
102:
103:            //{{{ Instance variables
104:            private String shortcut;
105:            private String action;
106:            //}}}
107:
108:            //{{{ Class initializer
109:            static {
110:                String shortcutFont;
111:                if (OperatingSystem.isMacOSLF()) {
112:                    shortcutFont = "Lucida Grande";
113:                } else {
114:                    shortcutFont = "Monospaced";
115:                }
116:
117:                acceleratorFont = UIManager.getFont("MenuItem.acceleratorFont");
118:                if (acceleratorFont == null) {
119:                    acceleratorFont = new Font(shortcutFont, Font.PLAIN, 12);
120:                }
121:                acceleratorForeground = UIManager
122:                        .getColor("MenuItem.acceleratorForeground");
123:                if (acceleratorForeground == null) {
124:                    acceleratorForeground = Color.black;
125:                }
126:
127:                acceleratorSelectionForeground = UIManager
128:                        .getColor("MenuItem.acceleratorSelectionForeground");
129:                if (acceleratorSelectionForeground == null) {
130:                    acceleratorSelectionForeground = Color.black;
131:                }
132:            } //}}}
133:
134:            //}}}
135:
136:            //{{{ MouseHandler class
137:            class MouseHandler extends MouseAdapter {
138:                boolean msgSet = false;
139:
140:                public void mouseReleased(MouseEvent evt) {
141:                    if (msgSet) {
142:                        GUIUtilities.getView((Component) evt.getSource())
143:                                .getStatus().setMessage(null);
144:                        msgSet = false;
145:                    }
146:                }
147:
148:                public void mouseEntered(MouseEvent evt) {
149:                    String msg = jEdit.getProperty(action + ".mouse-over");
150:                    if (msg != null) {
151:                        GUIUtilities.getView((Component) evt.getSource())
152:                                .getStatus().setMessage(msg);
153:                        msgSet = true;
154:                    }
155:                }
156:
157:                public void mouseExited(MouseEvent evt) {
158:                    if (msgSet) {
159:                        GUIUtilities.getView((Component) evt.getSource())
160:                                .getStatus().setMessage(null);
161:                        msgSet = false;
162:                    }
163:                }
164:            } //}}}
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.