Source Code Cross Referenced for NativeKeyFormatter.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, 2005 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:        import java.util.HashMap;
014:        import java.util.ResourceBundle;
015:
016:        import org.eclipse.swt.SWT;
017:        import org.eclipse.ui.internal.util.Util;
018:        import org.eclipse.ui.keys.CharacterKey;
019:        import org.eclipse.ui.keys.Key;
020:        import org.eclipse.ui.keys.KeySequence;
021:        import org.eclipse.ui.keys.KeyStroke;
022:        import org.eclipse.ui.keys.ModifierKey;
023:        import org.eclipse.ui.keys.SpecialKey;
024:
025:        /**
026:         * Formats the key sequences and key strokes into the native human-readable
027:         * format. This is typically what you would see on the menus for the given
028:         * platform and locale.
029:         * 
030:         * @since 3.0
031:         */
032:        public class NativeKeyFormatter extends AbstractKeyFormatter {
033:
034:            /**
035:             * The key into the internationalization resource bundle for the delimiter
036:             * to use between keys (on the Carbon platform).
037:             */
038:            private final static String CARBON_KEY_DELIMITER_KEY = "CARBON_KEY_DELIMITER"; //$NON-NLS-1$
039:
040:            /**
041:             * A look-up table for the string representations of various carbon keys.
042:             */
043:            private final static HashMap CARBON_KEY_LOOK_UP = new HashMap();
044:
045:            /**
046:             * A comparator to sort modifier keys in the order that they would be
047:             * displayed to a user. This comparator is platform-specific.
048:             */
049:            private final static Comparator MODIFIER_KEY_COMPARATOR = new NativeModifierKeyComparator();
050:
051:            /**
052:             * The resource bundle used by <code>format()</code> to translate formal
053:             * string representations by locale.
054:             */
055:            private final static ResourceBundle RESOURCE_BUNDLE;
056:
057:            /**
058:             * The key into the internationalization resource bundle for the delimiter
059:             * to use between key strokes (on the Win32 platform).
060:             */
061:            private final static String WIN32_KEY_STROKE_DELIMITER_KEY = "WIN32_KEY_STROKE_DELIMITER"; //$NON-NLS-1$
062:
063:            static {
064:                RESOURCE_BUNDLE = ResourceBundle
065:                        .getBundle(NativeKeyFormatter.class.getName());
066:
067:                CARBON_KEY_LOOK_UP.put(CharacterKey.BS.toString(), "\u232B"); //$NON-NLS-1$
068:                CARBON_KEY_LOOK_UP.put(CharacterKey.CR.toString(), "\u21A9"); //$NON-NLS-1$
069:                CARBON_KEY_LOOK_UP.put(CharacterKey.DEL.toString(), "\u2326"); //$NON-NLS-1$
070:                CARBON_KEY_LOOK_UP.put(CharacterKey.SPACE.toString(), "\u2423"); //$NON-NLS-1$
071:                CARBON_KEY_LOOK_UP.put(ModifierKey.ALT.toString(), "\u2325"); //$NON-NLS-1$
072:                CARBON_KEY_LOOK_UP
073:                        .put(ModifierKey.COMMAND.toString(), "\u2318"); //$NON-NLS-1$
074:                CARBON_KEY_LOOK_UP.put(ModifierKey.CTRL.toString(), "\u2303"); //$NON-NLS-1$
075:                CARBON_KEY_LOOK_UP.put(ModifierKey.SHIFT.toString(), "\u21E7"); //$NON-NLS-1$
076:                CARBON_KEY_LOOK_UP.put(SpecialKey.ARROW_DOWN.toString(),
077:                        "\u2193"); //$NON-NLS-1$
078:                CARBON_KEY_LOOK_UP.put(SpecialKey.ARROW_LEFT.toString(),
079:                        "\u2190"); //$NON-NLS-1$
080:                CARBON_KEY_LOOK_UP.put(SpecialKey.ARROW_RIGHT.toString(),
081:                        "\u2192"); //$NON-NLS-1$
082:                CARBON_KEY_LOOK_UP
083:                        .put(SpecialKey.ARROW_UP.toString(), "\u2191"); //$NON-NLS-1$
084:                CARBON_KEY_LOOK_UP.put(SpecialKey.END.toString(), "\u2198"); //$NON-NLS-1$
085:                CARBON_KEY_LOOK_UP.put(SpecialKey.NUMPAD_ENTER.toString(),
086:                        "\u2324"); //$NON-NLS-1$
087:                CARBON_KEY_LOOK_UP.put(SpecialKey.HOME.toString(), "\u2196"); //$NON-NLS-1$
088:                CARBON_KEY_LOOK_UP.put(SpecialKey.PAGE_DOWN.toString(),
089:                        "\u21DF"); //$NON-NLS-1$
090:                CARBON_KEY_LOOK_UP.put(SpecialKey.PAGE_UP.toString(), "\u21DE"); //$NON-NLS-1$
091:            }
092:
093:            /**
094:             * Formats an individual key into a human readable format. This uses an
095:             * internationalization resource bundle to look up the key. This does the
096:             * platform-specific formatting for Carbon.
097:             * 
098:             * @param key
099:             *            The key to format; must not be <code>null</code>.
100:             * @return The key formatted as a string; should not be <code>null</code>.
101:             */
102:            public String format(Key key) {
103:                String name = key.toString();
104:
105:                // TODO consider platform-specific resource bundles
106:                if ("carbon".equals(SWT.getPlatform())) { //$NON-NLS-1$    	
107:                    String formattedName = (String) CARBON_KEY_LOOK_UP
108:                            .get(name);
109:                    if (formattedName != null) {
110:                        return formattedName;
111:                    }
112:                }
113:
114:                return super .format(key);
115:            }
116:
117:            /*
118:             * (non-Javadoc)
119:             * 
120:             * @see org.eclipse.ui.keys.AbstractKeyFormatter#getKeyDelimiter()
121:             */
122:            protected String getKeyDelimiter() {
123:                // We must do the look up every time, as our locale might change.
124:                if ("carbon".equals(SWT.getPlatform())) { //$NON-NLS-1$
125:                    return Util.translateString(RESOURCE_BUNDLE,
126:                            CARBON_KEY_DELIMITER_KEY, Util.ZERO_LENGTH_STRING,
127:                            false, false);
128:                } else {
129:                    return Util.translateString(RESOURCE_BUNDLE,
130:                            KEY_DELIMITER_KEY, KeyStroke.KEY_DELIMITER, false,
131:                            false);
132:                }
133:            }
134:
135:            /*
136:             * (non-Javadoc)
137:             * 
138:             * @see org.eclipse.ui.keys.AbstractKeyFormatter#getKeyStrokeDelimiter()
139:             */
140:            protected String getKeyStrokeDelimiter() {
141:                // We must do the look up every time, as our locale might change.
142:                if ("win32".equals(SWT.getPlatform())) { //$NON-NLS-1$
143:                    return Util.translateString(RESOURCE_BUNDLE,
144:                            WIN32_KEY_STROKE_DELIMITER_KEY,
145:                            KeySequence.KEY_STROKE_DELIMITER, false, false);
146:                } else {
147:                    return Util.translateString(RESOURCE_BUNDLE,
148:                            KEY_STROKE_DELIMITER_KEY,
149:                            KeySequence.KEY_STROKE_DELIMITER, false, false);
150:                }
151:            }
152:
153:            /*
154:             * (non-Javadoc)
155:             * 
156:             * @see org.eclipse.ui.keys.AbstractKeyFormatter#getModifierKeyComparator()
157:             */
158:            protected Comparator getModifierKeyComparator() {
159:                return MODIFIER_KEY_COMPARATOR;
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.