Source Code Cross Referenced for AbstractContextMenuFactory.java in  » IDE-Netbeans » performance » org » netbeans » actions » engine » spi » 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 » IDE Netbeans » performance » org.netbeans.actions.engine.spi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * AbstractContextMenuFactory.java
003:         *
004:         * Created on January 31, 2004, 9:22 PM
005:         */
006:
007:        package org.netbeans.actions.engine.spi;
008:
009:        import java.awt.event.ActionEvent;
010:        import java.awt.event.ActionListener;
011:        import java.beans.BeanInfo;
012:        import java.util.Map;
013:        import javax.swing.Action;
014:        import javax.swing.JMenu;
015:        import javax.swing.JMenuItem;
016:        import javax.swing.JPopupMenu;
017:        import org.netbeans.actions.spi.ActionProvider;
018:        import org.netbeans.actions.spi.ContainerProvider;
019:
020:        /**
021:         *
022:         * @author  tim
023:         */
024:        public abstract class AbstractContextMenuFactory implements 
025:                ContextMenuFactory {
026:            private static final String KEY_CREATOR = "creator";
027:            private static final String KEY_ACTION = "action";
028:            private static final String KEY_CONTAINERCONTEXT = "containercontext";
029:            private AbstractEngine engine;
030:
031:            /** Creates a new instance of AbstractContextMenuFactory */
032:            protected AbstractContextMenuFactory(AbstractEngine engine) {
033:                this .engine = engine;
034:            }
035:
036:            protected final AbstractEngine getEngine() {
037:                return engine;
038:            }
039:
040:            public JPopupMenu createMenu(Map context) {
041:                JPopupMenu result = new JPopupMenu();
042:                populateMenu(result, context);
043:                return result;
044:            }
045:
046:            private JMenuItem getOrCreateMenuItem(int type) {
047:                JMenuItem result = type == ActionProvider.ACTION_TYPE_ITEM ? new JMenuItem()
048:                        : type == ActionProvider.ACTION_TYPE_SUBCONTEXT ? new JMenu()
049:                                : null;
050:                if (type == ActionProvider.ACTION_TYPE_ITEM) {
051:                    result.addActionListener(getItemListener());
052:                } else if (type == ActionProvider.ACTION_TYPE_SUBCONTEXT) {
053:                    //attachToMenu ((JMenu) result);
054:                }
055:                result.putClientProperty(KEY_CREATOR, this );
056:                return result;
057:            }
058:
059:            protected void populateMenu(JPopupMenu menu, Map context) {
060:                ActionProvider provider = getEngine().getActionProvider();
061:                String[] names = provider
062:                        .getActionNames(ContainerProvider.CONTEXTMENU_CONTEXT);
063:                for (int i = 0; i < names.length; i++) {
064:                    JMenuItem item = getOrCreateMenuItem(provider
065:                            .getActionType(names[i],
066:                                    ContainerProvider.CONTEXTMENU_CONTEXT));
067:                    configureMenuItem(item,
068:                            ContainerProvider.CONTEXTMENU_CONTEXT, names[i],
069:                            provider, context);
070:                    menu.add(item);
071:                }
072:                //        getEngine().notifyMenuShown(ContainerProvider.CONTEXTMENU_CONTEXT, menu); //XXX listener should do this
073:                //        addMapping (ContainerProvider.CONTEXTMENU_CONTEXT, menu, ContainerProvider.TYPE_MENU); //XXX handle popup
074:            }
075:
076:            private void configureMenuItem(JMenuItem item, String containerCtx,
077:                    String action, ActionProvider provider, Map context) {
078:                //        System.err.println("ConfigureMenuItem: " + containerCtx + "/" + action);
079:                item.setName(action);
080:                item.putClientProperty(KEY_ACTION, action);
081:                item.putClientProperty(KEY_CONTAINERCONTEXT, containerCtx);
082:                item.putClientProperty(KEY_CREATOR, this );
083:                item.setText(provider.getDisplayName(action, containerCtx));
084:                item.setToolTipText(provider.getDescription(action,
085:                        containerCtx));
086:                int state = context == null ? ActionProvider.STATE_ENABLED
087:                        | ActionProvider.STATE_VISIBLE : provider.getState(
088:                        action, containerCtx, context);
089:                boolean enabled = (state & ActionProvider.STATE_ENABLED) != 0;
090:                item.setEnabled(enabled);
091:                boolean visible = (state & ActionProvider.STATE_VISIBLE) != 0;
092:                //Intentionally use enabled property
093:                item.setVisible(enabled);
094:                item.setMnemonic(provider.getMnemonic(action, containerCtx));
095:                item.setDisplayedMnemonicIndex(provider.getMnemonicIndex(
096:                        action, containerCtx));
097:                item.setIcon(provider.getIcon(action, containerCtx,
098:                        BeanInfo.ICON_COLOR_16x16));
099:            }
100:
101:            private MenuItemListener itemListener = null;
102:
103:            private MenuItemListener getItemListener() {
104:                if (itemListener == null) {
105:                    itemListener = new MenuItemListener();
106:                }
107:                return itemListener;
108:            }
109:
110:            private class MenuItemListener implements  ActionListener {
111:                public void actionPerformed(java.awt.event.ActionEvent e) {
112:                    JMenuItem item = (JMenuItem) e.getSource();
113:                    String actionCommand = (String) item
114:                            .getClientProperty(KEY_ACTION);
115:                    String context = (String) item
116:                            .getClientProperty(KEY_CONTAINERCONTEXT);
117:
118:                    getEngine().notifyWillPerform(actionCommand, context);
119:
120:                    Action action = getEngine().getAction(context,
121:                            actionCommand);
122:
123:                    if (action.isEnabled()) {
124:                        ActionEvent event = new ActionEvent(item,
125:                                ActionEvent.ACTION_PERFORMED, actionCommand);
126:                        action.actionPerformed(event);
127:                    }
128:
129:                    getEngine().notifyPerformed(actionCommand, context);
130:                }
131:            }
132:
133:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.