Source Code Cross Referenced for NativeModifierKeyComparator.java in  » IDE-Eclipse » ui-workbench » org » eclipse » ui » internal » keys » 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 Eclipse » ui workbench » org.eclipse.ui.internal.keys 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2006 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         *
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.ui.internal.keys;
011:
012:        import java.util.Comparator;
013:
014:        import org.eclipse.swt.SWT;
015:        import org.eclipse.ui.keys.ModifierKey;
016:
017:        /**
018:         * A comparator that sorts the modifier keys based on the native environment.
019:         * Currently, this is only the windowing toolkit, but in the future it might
020:         * expand to include the window manager.
021:         * 
022:         * @since 3.0
023:         */
024:        class NativeModifierKeyComparator implements  Comparator {
025:
026:            /**
027:             * The sort order value to use when the modifier key is not recognized.
028:             */
029:            private final static int UNKNOWN_KEY = Integer.MAX_VALUE;
030:
031:            /*
032:             * (non-Javadoc)
033:             * 
034:             * @see java.lang.Comparable#compareTo(java.lang.Object)
035:             */
036:            public int compare(Object left, Object right) {
037:                ModifierKey modifierKeyLeft = (ModifierKey) left;
038:                ModifierKey modifierKeyRight = (ModifierKey) right;
039:                int modifierKeyLeftRank = rank(modifierKeyLeft);
040:                int modifierKeyRightRank = rank(modifierKeyRight);
041:
042:                if (modifierKeyLeftRank != modifierKeyRightRank) {
043:                    return modifierKeyLeftRank - modifierKeyRightRank;
044:                } else {
045:                    return modifierKeyLeft.compareTo(modifierKeyRight);
046:                }
047:            }
048:
049:            /**
050:             * Calculates a rank for a given modifier key.
051:             * 
052:             * @param modifierKey
053:             *            The modifier key to rank; may be <code>null</code>.
054:             * @return The rank of this modifier key. This is a non-negative number
055:             *         where a lower number suggests a higher rank.
056:             */
057:            private int rank(ModifierKey modifierKey) {
058:                String platform = SWT.getPlatform();
059:
060:                if ("win32".equals(platform)) { //$NON-NLS-1$
061:                    return rankWindows(modifierKey);
062:                }
063:
064:                if ("gtk".equals(platform)) { //$NON-NLS-1$
065:                    // TODO Do a look-up on window manager.
066:                    return rankGNOME(modifierKey);
067:                }
068:
069:                if ("carbon".equals(platform)) { //$NON-NLS-1$
070:                    return rankMacOSX(modifierKey);
071:                }
072:
073:                if ("motif".equals(platform)) { //$NON-NLS-1$
074:                    // TODO Do a look-up on window manager.
075:                    return rankGNOME(modifierKey);
076:                }
077:
078:                return UNKNOWN_KEY;
079:            }
080:
081:            /**
082:             * Provides a ranking for the modifier key based on the modifier key
083:             * ordering used in the GNOME window manager.
084:             * 
085:             * @param modifierKey
086:             *            The modifier key to rank; may be <code>null</code>.
087:             * @return The rank of this modifier key. This is a non-negative number
088:             *         where a lower number suggests a higher rank.
089:             */
090:            private final int rankGNOME(ModifierKey modifierKey) {
091:                if (ModifierKey.SHIFT.equals(modifierKey)) {
092:                    return 0;
093:                }
094:
095:                if (ModifierKey.CTRL.equals(modifierKey)) {
096:                    return 1;
097:                }
098:
099:                if (ModifierKey.ALT.equals(modifierKey)) {
100:                    return 2;
101:                }
102:
103:                return UNKNOWN_KEY;
104:
105:            }
106:
107:            /**
108:             * Provides a ranking for the modifier key based on the modifier key
109:             * ordering used in the KDE window manager.
110:             * 
111:             * @param modifierKey
112:             *            The modifier key to rank; may be <code>null</code>.
113:             * @return The rank of this modifier key. This is a non-negative number
114:             *         where a lower number suggests a higher rank.
115:             */
116:            //    private final int rankKDE(ModifierKey modifierKey) {
117:            //        if (ModifierKey.ALT.equals(modifierKey)) {
118:            //            return 0;
119:            //        }
120:            //
121:            //        if (ModifierKey.CTRL.equals(modifierKey)) {
122:            //            return 1;
123:            //        }
124:            //
125:            //        if (ModifierKey.SHIFT.equals(modifierKey)) {
126:            //            return 2;
127:            //        }
128:            //
129:            //        return UNKNOWN_KEY;
130:            //    }
131:            /**
132:             * Provides a ranking for the modifier key based on the modifier key
133:             * ordering used in the MacOS X operating system.
134:             * 
135:             * @param modifierKey
136:             *            The modifier key to rank; may be <code>null</code>.
137:             * @return The rank of this modifier key. This is a non-negative number
138:             *         where a lower number suggests a higher rank.
139:             */
140:            private final int rankMacOSX(ModifierKey modifierKey) {
141:                if (ModifierKey.SHIFT.equals(modifierKey)) {
142:                    return 0;
143:                }
144:
145:                if (ModifierKey.CTRL.equals(modifierKey)) {
146:                    return 1;
147:                }
148:
149:                if (ModifierKey.ALT.equals(modifierKey)) {
150:                    return 2;
151:                }
152:
153:                if (ModifierKey.COMMAND.equals(modifierKey)) {
154:                    return 3;
155:                }
156:
157:                return UNKNOWN_KEY;
158:            }
159:
160:            /**
161:             * Provides a ranking for the modifier key based on the modifier key
162:             * ordering used in the Windows operating system.
163:             * 
164:             * @param modifierKey
165:             *            The modifier key to rank; may be <code>null</code>.
166:             * @return The rank of this modifier key. This is a non-negative number
167:             *         where a lower number suggests a higher rank.
168:             */
169:            private final int rankWindows(ModifierKey modifierKey) {
170:                if (ModifierKey.CTRL.equals(modifierKey)) {
171:                    return 0;
172:                }
173:
174:                if (ModifierKey.ALT.equals(modifierKey)) {
175:                    return 1;
176:                }
177:
178:                if (ModifierKey.SHIFT.equals(modifierKey)) {
179:                    return 2;
180:                }
181:
182:                return UNKNOWN_KEY;
183:            }
184:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.