Source Code Cross Referenced for InputContext.java in  » 6.0-JDK-Modules » j2me » sun » awt » im » 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 » 6.0 JDK Modules » j2me » sun.awt.im 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * @(#)InputContext.java	1.15 06/10/10
003:         *
004:         * Copyright  1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation. 
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt). 
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA 
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions. 
025:         *
026:         */
027:
028:        package sun.awt.im;
029:
030:        import java.awt.Component;
031:        import java.util.Locale;
032:        import java.awt.AWTEvent;
033:        import java.awt.Toolkit;
034:        import java.awt.event.FocusEvent;
035:        import java.awt.event.ComponentEvent;
036:
037:        //import sun.awt.SunToolkit;
038:
039:        /**
040:         * An InputContext object manages the communication between text editing
041:         * components and input methods. It dispatches events between them, and
042:         * forwards requests for information from the input method to the text
043:         * editing component.
044:         *
045:         * <p>
046:         * By default, one InputContext instance is created per Window instance,
047:         * and this input context is shared by all components within the window's
048:         * container hierarchy. However, this means that only one text input
049:         * operation is possible at any one time within a window, and that the
050:         * text needs to be committed when moving the focus from one text component
051:         * to another. If this is not desired, text components can create their
052:         * own input context instances.
053:         *
054:         * @see java.awt.Component#getInputContext
055:         * @version 1.10, 08/19/02
056:         * @author Sun Microsystems, Inc.
057:         */
058:
059:        public class InputContext extends java.awt.im.InputContext {
060:            private InputMethod inputMethod;
061:            private boolean inputMethodCreationFailed;
062:            private Component currentClientComponent;
063:
064:            /**
065:             * Constructs an InputContext.
066:             */
067:            protected InputContext() {
068:            }
069:
070:            /**
071:             * Dispatches an event to the active input method. Called by AWT.
072:             *
073:             * @param event The event
074:             */
075:            public synchronized void dispatchEvent(AWTEvent event) {
076:                InputMethod inputMethod = getInputMethod();
077:                int id = event.getID();
078:                switch (id) {
079:                case ComponentEvent.COMPONENT_HIDDEN:
080:                    dispose();
081:                    currentClientComponent = null;
082:                    break;
083:
084:                case FocusEvent.FOCUS_GAINED:
085:                    activate((Component) event.getSource());
086:                    if (inputMethod != null)
087:                        inputMethod.dispatchEvent(event);
088:                    break;
089:
090:                case FocusEvent.FOCUS_LOST:
091:                    if (inputMethod != null)
092:                        inputMethod.dispatchEvent(event);
093:                    deactivate((Component) event.getSource());
094:                    break;
095:
096:                default:
097:                    if (inputMethod != null)
098:                        inputMethod.dispatchEvent(event);
099:                }
100:            }
101:
102:            /**
103:             * Activates input context for the given component. If the input
104:             * context previously was active for a different component and there
105:             * is uncommitted text for that component, the text is committed.
106:             * Called by AWT when the keyboard focus moves to the component.
107:             *
108:             * @param client The client component into which text is entered.
109:             */
110:            synchronized void activate(Component client) {
111:                currentClientComponent = client;
112:                if (inputMethod != null) {
113:                    if (inputMethod instanceof  InputMethodAdapter) {
114:                        ((InputMethodAdapter) inputMethod)
115:                                .setClientComponent(client);
116:                    }
117:                    inputMethod.activate();
118:                }
119:            }
120:
121:            /**
122:             * Deactivates input context for the given component. Called by AWT
123:             * when the keyboard focus moves away from the component.
124:             *
125:             * @param target The component into which text was entered.
126:             */
127:            synchronized void deactivate(Component client) {
128:                if (inputMethod != null) {
129:                    inputMethod.deactivate();
130:                }
131:                currentClientComponent = null;
132:            }
133:
134:            /**
135:             * Returns the client component.
136:             */
137:            Component getClientComponent() {
138:                Component client = currentClientComponent;
139:                return client;
140:            }
141:
142:            /**
143:             * Disposes of the input context and release the resources used by it.
144:             * Called by AWT.
145:             */
146:            public void dispose() {
147:                if (inputMethod != null) {
148:                    inputMethod.dispose();
149:                    inputMethod = null;
150:                }
151:            }
152:
153:            InputMethod getInputMethod() {
154:                if (inputMethod != null) {
155:                    return inputMethod;
156:                }
157:                if (inputMethodCreationFailed) {
158:                    return null;
159:                }
160:                inputMethodCreationFailed = true;
161:                /***
162:                 **        try {
163:                 **            Toolkit toolkit = Toolkit.getDefaultToolkit();
164:                 **            inputMethod = ((SunToolkit) toolkit).getInputMethodAdapter();
165:                 **        } catch (Exception e) {
166:                 **            // there are a number of bad things that can happen while creating
167:                 **            // the input method. In any case, we just continue without an
168:                 **            // input method.
169:                 **            inputMethodCreationFailed = true;
170:                 **        }
171:                 **        if (inputMethod != null) {
172:                 **            inputMethod.setInputContext((InputMethodContext)this);
173:                 **        }
174:                 ***/
175:                return inputMethod;
176:            }
177:
178:            public boolean selectInputMethod(Locale locale) {
179:                if (locale == null)
180:                    throw new NullPointerException("Locale is null");
181:                return false;
182:            }
183:
184:            boolean compositionEnabled = false;
185:
186:            public void setCompositionEnabled(boolean enable) {
187:                compositionEnabled = enable;
188:            }
189:
190:            public boolean isCompositionEnabled() {
191:                return compositionEnabled;
192:            }
193:
194:            public void removeNotify(Component client) {
195:                if (client == null)
196:                    throw new NullPointerException("Component is null");
197:            }
198:
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.