home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.im;
-
- import com.ibm.uvm.awt.UvmToolkit;
- import java.awt.AWTEvent;
- import java.awt.Component;
- import java.awt.Toolkit;
- import java.util.EventObject;
-
- public class InputContext {
- private InputMethod inputMethod;
- private boolean inputMethodCreationFailed;
- private Component currentClientComponent;
-
- protected InputContext() {
- }
-
- synchronized void activate(Component client) {
- this.currentClientComponent = client;
- if (this.inputMethod != null) {
- if (this.inputMethod instanceof InputMethodAdapter) {
- ((InputMethodAdapter)this.inputMethod).setClientComponent(client);
- }
-
- this.inputMethod.activate();
- }
-
- }
-
- synchronized void deactivate(Component client) {
- if (this.inputMethod != null) {
- this.inputMethod.deactivate();
- }
-
- this.currentClientComponent = null;
- }
-
- public synchronized void dispatchEvent(AWTEvent event) {
- InputMethod inputMethod = this.getInputMethod();
- int id = event.getID();
- switch (id) {
- case 103:
- this.dispose();
- this.currentClientComponent = null;
- break;
- case 1004:
- this.activate((Component)((EventObject)event).getSource());
- if (inputMethod != null) {
- inputMethod.dispatchEvent(event);
- }
- break;
- case 1005:
- if (inputMethod != null) {
- inputMethod.dispatchEvent(event);
- }
-
- this.deactivate((Component)((EventObject)event).getSource());
- break;
- default:
- if (inputMethod != null) {
- inputMethod.dispatchEvent(event);
- }
- }
-
- }
-
- public void dispose() {
- if (this.inputMethod != null) {
- this.inputMethod.dispose();
- this.inputMethod = null;
- }
-
- }
-
- Component getClientComponent() {
- Component client = this.currentClientComponent;
- return client;
- }
-
- InputMethod getInputMethod() {
- if (this.inputMethod != null) {
- return this.inputMethod;
- } else if (this.inputMethodCreationFailed) {
- return null;
- } else {
- try {
- Toolkit toolkit = Toolkit.getDefaultToolkit();
- this.inputMethod = ((UvmToolkit)toolkit).getInputMethodAdapter();
- } catch (Exception var2) {
- this.inputMethodCreationFailed = true;
- }
-
- if (this.inputMethod != null) {
- this.inputMethod.setInputContext((InputMethodContext)this);
- }
-
- return this.inputMethod;
- }
- }
-
- public static InputContext getInstance() {
- return new InputMethodContext();
- }
- }
-