Source Code Cross Referenced for ConfigurableKeyBinding.java in  » Mail-Clients » pooka » net » suberic » util » gui » 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 » Mail Clients » pooka » net.suberic.util.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.suberic.util.gui;
002:
003:        import java.awt.event.*;
004:        import javax.swing.JComponent;
005:        import javax.swing.KeyStroke;
006:        import javax.swing.Action;
007:        import javax.swing.InputMap;
008:        import javax.swing.ActionMap;
009:        import java.util.Hashtable;
010:        import java.util.Vector;
011:        import java.util.Enumeration;
012:        import net.suberic.util.VariableBundle;
013:
014:        /**
015:         * This class is a KeyBinding controller for a JComponent.
016:         */
017:
018:        public class ConfigurableKeyBinding implements  ConfigurableUI {
019:            private JComponent currentComponent;
020:            private Hashtable commands = new Hashtable();
021:            private Hashtable keyTable = new Hashtable();
022:            private int condition = JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT;
023:
024:            /**
025:             * This creates a new ConfigurableKeyBinding which attaches to component
026:             * newComponent, and defines itself using componentID and vars.
027:             */
028:            public ConfigurableKeyBinding(JComponent newComponent,
029:                    String componentID, VariableBundle vars) {
030:                currentComponent = newComponent;
031:
032:                configureComponent(componentID, vars);
033:            }
034:
035:            /**
036:             * This configures the KeyBindings using the given componentID
037:             * and VariableBundle.
038:             *
039:             * As defined in interface net.suberic.util.gui.ConfigurableUI.
040:             */
041:
042:            public void configureComponent(String componentID,
043:                    VariableBundle vars) {
044:                if (componentID != null
045:                        && vars.getProperty(componentID, "") != "") {
046:                    Vector keys = vars.getPropertyAsVector(componentID, "");
047:                    for (int i = 0; i < keys.size(); i++) {
048:                        String keyID = componentID + "."
049:                                + (String) keys.elementAt(i);
050:                        String keyAction = vars.getProperty(keyID + ".Action",
051:                                "");
052:                        KeyStroke keyStroke = getKeyStroke(keyID, vars);
053:                        if (keyAction != "" && keyStroke != null) {
054:                            putInKeyTable(keyAction, keyStroke);
055:                        }
056:                    }
057:                }
058:            }
059:
060:            /**
061:             * This method returns the key defined by the property keyID in the
062:             * VariableBundle vars.
063:             */
064:            public KeyStroke getKeyStroke(String keyID, VariableBundle vars) {
065:                return KeyStroke.getKeyStroke(vars.getProperty(keyID + ".Key",
066:                        ""));
067:            }
068:
069:            /**
070:             * This method actually binds the configured KeyStrokes to the current
071:             * Actions.
072:             *
073:             * As defined in interface net.suberic.util.gui.ConfigurableUI.
074:             */
075:            public void setActive(Hashtable newCommands) {
076:                commands = newCommands;
077:                Enumeration hashKeys = getKeyTableKeys();
078:                InputMap inputMap = currentComponent
079:                        .getInputMap(getCondition());
080:                ActionMap actionMap = currentComponent.getActionMap();
081:                while (hashKeys.hasMoreElements()) {
082:                    String actionCmd = (String) hashKeys.nextElement();
083:                    Vector keyStrokeVector = getFromKeyTable(actionCmd);
084:                    Action a = getAction(actionCmd);
085:                    for (int i = 0; keyStrokeVector != null
086:                            && i < keyStrokeVector.size(); i++) {
087:                        KeyStroke keyStroke = (KeyStroke) keyStrokeVector
088:                                .elementAt(i);
089:                        inputMap.remove(keyStroke);
090:                        actionMap.remove(actionCmd);
091:                        if (a != null) {
092:                            inputMap.put(keyStroke, actionCmd);
093:                            actionMap.put(actionCmd, a);
094:                        }
095:                        /*
096:                        currentComponent.unregisterKeyboardAction(keyStroke);
097:                        if (a != null) {
098:                          currentComponent.registerKeyboardAction(a, actionCmd, keyStroke, getCondition() );
099:                        }
100:                         */
101:                    }
102:                }
103:            }
104:
105:            /**
106:             * This method actually binds the configured KeyStrokes to the current
107:             * Actions.
108:             *
109:             * As defined in interface net.suberic.util.gui.ConfigurableUI.
110:             */
111:            public void setActive(Action[] newActions) {
112:                Hashtable tmpHash = new Hashtable();
113:                if (newActions != null && newActions.length > 0) {
114:                    for (int i = 0; i < newActions.length; i++) {
115:                        String cmdName = (String) newActions[i]
116:                                .getValue(Action.NAME);
117:                        tmpHash.put(cmdName, newActions[i]);
118:                    }
119:                }
120:                setActive(tmpHash);
121:            }
122:
123:            public void putInKeyTable(Object key, Object value) {
124:                Vector valueList = (Vector) keyTable.get(key);
125:                if (valueList != null) {
126:                    if (!valueList.contains(value))
127:                        valueList.add(value);
128:                } else {
129:                    valueList = new Vector();
130:                    valueList.add(value);
131:                    keyTable.put(key, valueList);
132:                }
133:
134:            }
135:
136:            public Vector getFromKeyTable(Object key) {
137:                return (Vector) keyTable.get(key);
138:            }
139:
140:            public Enumeration getKeyTableKeys() {
141:                return keyTable.keys();
142:            }
143:
144:            private Action getAction(String key) {
145:                try {
146:                    return (Action) commands.get(key);
147:                } catch (ClassCastException cce) {
148:                    return null;
149:                }
150:            }
151:
152:            public void setCondition(int newCondition) {
153:                condition = newCondition;
154:            }
155:
156:            public int getCondition() {
157:                return condition;
158:            }
159:
160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.