Source Code Cross Referenced for ShortcutDefinition.java in  » Database-Client » SQL-Workbench » workbench » resource » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » SQL Workbench » workbench.resource 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ShortcutDefinition.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.resource;
013:
014:        import javax.swing.KeyStroke;
015:
016:        /**
017:         * @author support@sql-workbench.net
018:         *
019:         */
020:        public class ShortcutDefinition {
021:            private String actionClass;
022:            private StoreableKeyStroke currentKey;
023:            private StoreableKeyStroke defaultKey;
024:            private StoreableKeyStroke alternateKey;
025:            private boolean shortcutRemoved;
026:
027:            public ShortcutDefinition() {
028:            }
029:
030:            public boolean isMappedTo(KeyStroke key) {
031:                if (key == null)
032:                    return false;
033:                KeyStroke mykey = this .getActiveKeyStroke();
034:                if (mykey != null) {
035:                    return mykey.equals(key);
036:                }
037:                return false;
038:            }
039:
040:            public ShortcutDefinition(String aClass) {
041:                this .setActionClass(aClass);
042:            }
043:
044:            public void setShortcutRemoved(boolean aFlag) {
045:                this .shortcutRemoved = aFlag;
046:                if (aFlag) {
047:                    this .clearKeyStroke();
048:                }
049:            }
050:
051:            public boolean getShortcutRemoved() {
052:                return this .shortcutRemoved;
053:            }
054:
055:            /**
056:             *	Clears the currently defined shortcut.
057:             *	If a default shortcut is defined, this will make this Definition "customized"
058:             *  as the default shortcut is "overwritten" with nothing
059:             */
060:            public void clearKeyStroke() {
061:                this .currentKey = null;
062:            }
063:
064:            /**
065:             * Get the default (storeable) KeyStroke. 
066:             * This is only here to statisfy the XMLEncoder, so that the whole thing can be saved 
067:             */
068:            public KeyStroke getDefaultKeyStroke() {
069:                if (this .defaultKey != null)
070:                    return this .defaultKey.getKeyStroke();
071:                return null;
072:            }
073:
074:            /**
075:             * Set the default (storeable) alternate KeyStroke. 
076:             * This is only here to statisfy the XMLEncoder, so that the whole thing can be saved 
077:             * @param aKey
078:             */
079:            public void setAlternateKey(StoreableKeyStroke aKey) {
080:                this .alternateKey = aKey;
081:            }
082:
083:            /**
084:             * Get the default (storeable) alternate KeyStroke. 
085:             * This is only here to statisfy the XMLEncoder, so that the whole thing can be saved 
086:             */
087:            public KeyStroke getAlternateKeyStroke() {
088:                if (this .alternateKey != null)
089:                    return this .alternateKey.getKeyStroke();
090:                return null;
091:            }
092:
093:            /**
094:             * Set the current/active (storeable) KeyStroke. 
095:             * This is only here to statisfy the XMLEncoder, so that the whole thing can be saved 
096:             * @param aKey
097:             */
098:            public void setCurrentKey(StoreableKeyStroke aKey) {
099:                this .currentKey = aKey;
100:            }
101:
102:            /**
103:             * Get the current/active (storeable) KeyStroke. 
104:             * This is only here to statisfy the XMLEncoder, so that the whole thing can be saved 
105:             */
106:            public StoreableKeyStroke getCurrentKey() {
107:                return currentKey;
108:            }
109:
110:            public KeyStroke getCurrentKeyStroke() {
111:                if (this .currentKey == null)
112:                    return null;
113:                return this .currentKey.getKeyStroke();
114:            }
115:
116:            /**
117:             * Assign a KeyStroke to this action.
118:             * @param aKey
119:             */
120:            public void assignKey(KeyStroke aKey) {
121:                this .assignKey(new StoreableKeyStroke(aKey));
122:            }
123:
124:            public void assignKey(StoreableKeyStroke aKey) {
125:                this .currentKey = aKey;
126:                this .shortcutRemoved = false;
127:            }
128:
129:            /**
130:             * Assign a default key for this action class.
131:             * This method is called assign so that the XMLEncoder does not consider
132:             * reading or writing this "property" as KeyStrokes cannot be serialized 
133:             * to XML
134:             * @param aKey
135:             */
136:            public void assignDefaultKey(KeyStroke aKey) {
137:                this .defaultKey = new StoreableKeyStroke(aKey);
138:                //if (this.currentKey == null) this.currentKey = this.defaultKey;
139:            }
140:
141:            /**
142:             * Return the current default key. This is the "matching" 
143:             * getter for the assignDefaultKey() method.
144:             * @return KeyStroke
145:             */
146:            public StoreableKeyStroke getDefaultKey() {
147:                return this .defaultKey;
148:            }
149:
150:            /**
151:             * Assign an alternate key for this action class.
152:             * This method is called assign so that the XMLEncoder does not consider
153:             * reading or writing this "property" as KeyStrokes cannot be serialized 
154:             * to XML
155:             * @param aKey
156:             */
157:            public void assignAlternateKey(KeyStroke aKey) {
158:                this .alternateKey = new StoreableKeyStroke(aKey);
159:            }
160:
161:            /**
162:             * Return the defined alternate key as a KeyStroke.
163:             * If no alternate key is define null is returned
164:             * @return the alternate keystroke
165:             */
166:            public StoreableKeyStroke getAlternateKey() {
167:                return this .alternateKey;
168:            }
169:
170:            public boolean hasDefault() {
171:                return this .defaultKey != null;
172:            }
173:
174:            /**
175:             * Return if the this shortcut definition is customized.
176:             * It's customized if a default exists, and currently no shortcut is defined.
177:             * Or if a shortcut is defined, that is different to the default.
178:             * @return true if this shortcut definition differs from the default.
179:             */
180:            public boolean isCustomized() {
181:                if (this .defaultKey == null && this .currentKey == null)
182:                    return false;
183:                if (this .defaultKey == null && this .currentKey != null)
184:                    return true;
185:                if (this .defaultKey != null && this .currentKey == null)
186:                    return this .shortcutRemoved;
187:
188:                return (!this .currentKey.equals(this .defaultKey));
189:            }
190:
191:            /**
192:             * Restores the default mapping for this shortcut.
193:             * After a call to resetToDefault() isCustomized() will return false
194:             */
195:            public void resetToDefault() {
196:                this .shortcutRemoved = false;
197:                this .currentKey = null;
198:            }
199:
200:            /**
201:             * 	Returns the active KeyStroke.
202:             * 	This is either the current or the default, or null if the shortcut 
203:             *  has been removed completely. 
204:             * @return the keystroke that is active
205:             */
206:            public KeyStroke getActiveKeyStroke() {
207:                if (this .shortcutRemoved)
208:                    return null;
209:                if (this .currentKey != null)
210:                    return this .currentKey.getKeyStroke();
211:                if (this .defaultKey != null)
212:                    return this .defaultKey.getKeyStroke();
213:                return null;
214:            }
215:
216:            public StoreableKeyStroke getActiveKey() {
217:                if (this .shortcutRemoved)
218:                    return null;
219:                if (this .currentKey != null)
220:                    return this .currentKey;
221:                return this .defaultKey;
222:            }
223:
224:            public String getActionClass() {
225:                return this .actionClass;
226:            }
227:
228:            public void setActionClass(String aClass) {
229:                if (aClass == null)
230:                    throw new IllegalArgumentException(
231:                            "ClassName cannot be null");
232:                this .actionClass = aClass;
233:            }
234:
235:            public String toString() {
236:                StringBuilder result = new StringBuilder(50);
237:                result.append(this .actionClass);
238:                StoreableKeyStroke active = (this .currentKey != null) ? this .currentKey
239:                        : this .defaultKey;
240:                if (active != null) {
241:                    result.append(" [");
242:                    result.append(active.toString());
243:                    result.append(']');
244:                } else {
245:                    result.append("[no shortcut]");
246:                }
247:                if (isCustomized())
248:                    result.append(" (customized)");
249:
250:                return result.toString();
251:            }
252:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.