home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 166RG7Z (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.2 KB  |  104 lines

  1. package sun.awt.im;
  2.  
  3. import com.ibm.uvm.awt.UvmToolkit;
  4. import java.awt.AWTEvent;
  5. import java.awt.Component;
  6. import java.awt.Toolkit;
  7. import java.util.EventObject;
  8.  
  9. public class InputContext {
  10.    private InputMethod inputMethod;
  11.    private boolean inputMethodCreationFailed;
  12.    private Component currentClientComponent;
  13.  
  14.    protected InputContext() {
  15.    }
  16.  
  17.    synchronized void activate(Component client) {
  18.       this.currentClientComponent = client;
  19.       if (this.inputMethod != null) {
  20.          if (this.inputMethod instanceof InputMethodAdapter) {
  21.             ((InputMethodAdapter)this.inputMethod).setClientComponent(client);
  22.          }
  23.  
  24.          this.inputMethod.activate();
  25.       }
  26.  
  27.    }
  28.  
  29.    synchronized void deactivate(Component client) {
  30.       if (this.inputMethod != null) {
  31.          this.inputMethod.deactivate();
  32.       }
  33.  
  34.       this.currentClientComponent = null;
  35.    }
  36.  
  37.    public synchronized void dispatchEvent(AWTEvent event) {
  38.       InputMethod inputMethod = this.getInputMethod();
  39.       int id = event.getID();
  40.       switch (id) {
  41.          case 103:
  42.             this.dispose();
  43.             this.currentClientComponent = null;
  44.             break;
  45.          case 1004:
  46.             this.activate((Component)((EventObject)event).getSource());
  47.             if (inputMethod != null) {
  48.                inputMethod.dispatchEvent(event);
  49.             }
  50.             break;
  51.          case 1005:
  52.             if (inputMethod != null) {
  53.                inputMethod.dispatchEvent(event);
  54.             }
  55.  
  56.             this.deactivate((Component)((EventObject)event).getSource());
  57.             break;
  58.          default:
  59.             if (inputMethod != null) {
  60.                inputMethod.dispatchEvent(event);
  61.             }
  62.       }
  63.  
  64.    }
  65.  
  66.    public void dispose() {
  67.       if (this.inputMethod != null) {
  68.          this.inputMethod.dispose();
  69.          this.inputMethod = null;
  70.       }
  71.  
  72.    }
  73.  
  74.    Component getClientComponent() {
  75.       Component client = this.currentClientComponent;
  76.       return client;
  77.    }
  78.  
  79.    InputMethod getInputMethod() {
  80.       if (this.inputMethod != null) {
  81.          return this.inputMethod;
  82.       } else if (this.inputMethodCreationFailed) {
  83.          return null;
  84.       } else {
  85.          try {
  86.             Toolkit toolkit = Toolkit.getDefaultToolkit();
  87.             this.inputMethod = ((UvmToolkit)toolkit).getInputMethodAdapter();
  88.          } catch (Exception var2) {
  89.             this.inputMethodCreationFailed = true;
  90.          }
  91.  
  92.          if (this.inputMethod != null) {
  93.             this.inputMethod.setInputContext((InputMethodContext)this);
  94.          }
  95.  
  96.          return this.inputMethod;
  97.       }
  98.    }
  99.  
  100.    public static InputContext getInstance() {
  101.       return new InputMethodContext();
  102.    }
  103. }
  104.