home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / im / InputContext.java next >
Encoding:
Java Source  |  1998-03-20  |  5.8 KB  |  158 lines

  1. /*
  2.  * @(#)InputContext.java    1.12 98/03/18
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.im;
  16.  
  17. import java.awt.Component;
  18. import java.util.Locale;
  19. import java.awt.AWTEvent;
  20. import java.lang.Character.Subset;
  21. import sun.awt.im.InputMethod;
  22. import sun.awt.im.InputMethodContext;
  23.  
  24. /**
  25.  * An InputContext object manages the communication between text editing
  26.  * components and input methods. It dispatches events between them, and
  27.  * forwards requests for information from the input method to the text
  28.  * editing component. It also lets text editing components select input
  29.  * methods by locale.
  30.  *
  31.  * <p>
  32.  * By default, one InputContext instance is created per Window instance,
  33.  * and this input context is shared by all components within the window's
  34.  * container hierarchy. However, this means that only one text input
  35.  * operation is possible at any one time within a window, and that the
  36.  * text needs to be committed when moving the focus from one text component
  37.  * to another. If this is not desired, text components can create their
  38.  * own input context instances.
  39.  *
  40.  * <p>
  41.  * Not all platforms and locales support input methods. Where input methods are
  42.  * unavailable, input contexts can still be created and used; the
  43.  * InputContext instance methods return without doing anything (selectLocale
  44.  * returns false).
  45.  *
  46.  * @see java.awt.Component#getInputContext
  47.  * @see java.awt.Component#enableInputMethods
  48.  * @version 1.12 03/18/98
  49.  * @author JavaSoft Asia/Pacific
  50.  */
  51.  
  52. public class InputContext {
  53.  
  54.     /**
  55.      * Constructs an InputContext.
  56.      */
  57.     protected InputContext() {
  58.         // real implementation is in sun.awt.im.InputContext
  59.     }
  60.  
  61.     /**
  62.      * Returns a new InputContext instance.
  63.      */
  64.     public static InputContext getInstance() {
  65.     return new InputMethodContext();
  66.     }
  67.  
  68.     /**
  69.      * Selects an input method that supports the given locale.
  70.      * If the currently selected input method supports the desired locale
  71.      * or if there's no input method available that supports the desired
  72.      * locale, the current input method remains active. Otherwise, an input
  73.      * method is selected that supports text input for the desired locale.
  74.      * Before switching to a different input method, any currently uncommitted
  75.      * text is committed.
  76.      *
  77.      * <p>
  78.      * A text editing component may call this method, for example, when
  79.      * the user changes the insertion point, so that the user can
  80.      * immediately continue typing in the language of the surrounding text.
  81.      *
  82.      * @param locale The desired new locale.
  83.      * @return Whether the input method that's active after this call
  84.      *         supports the desired locale.
  85.      */
  86.     public boolean selectInputMethod(Locale locale) {
  87.         // real implementation is in sun.awt.im.InputContext
  88.         return false;
  89.     }
  90.  
  91.     /**
  92.      * Sets the subsets of the Unicode character set that input methods of this input
  93.      * context should be allowed to input. Null may be passed in to
  94.      * indicate that all characters are allowed. The initial value
  95.      * is null. The setting applies to the current input method as well
  96.      * as input methods selected after this call is made. However,
  97.      * applications cannot rely on this call having the desired effect,
  98.      * since this setting cannot be passed on to all host input methods -
  99.      * applications still need to apply their own character validation.
  100.      *
  101.      * @param subsets The subsets of the Unicode character set from which characters may be input
  102.      */
  103.     public void setCharacterSubsets(Subset[] subsets) {
  104.         // real implementation is in sun.awt.im.InputContext
  105.     }
  106.     
  107.     /**
  108.      * Dispatches an event to the active input method. Called by AWT.
  109.      *
  110.      * @param event The event
  111.      */
  112.     public synchronized void dispatchEvent(AWTEvent event) {
  113.         // real implementation is in sun.awt.im.InputContext
  114.     }
  115.  
  116.     /**
  117.      * Ends any input composition that may currently be going on in this
  118.      * context. Depending on the platform and possibly user preferences,
  119.      * this may commit or delete uncommitted text. Any changes to the text
  120.      * are communicated to the active component using an input method event.
  121.      *
  122.      * <p>
  123.      * A text editing component may call this in a variety of situations,
  124.      * for example, when the user moves the insertion point within the text
  125.      * (but outside the composed text), or when the component's text is
  126.      * saved to a file or copied to the clipboard.
  127.      *
  128.      */
  129.     public synchronized void endComposition() {
  130.         // real implementation is in sun.awt.im.InputContext
  131.     }
  132.  
  133.     /**
  134.      * Disposes of the input context and release the resources used by it.
  135.      * Called by AWT.
  136.      */
  137.     public void dispose() {
  138.         // real implementation is in sun.awt.im.InputContext
  139.     }
  140.  
  141.     /**
  142.      * Returns a control object from the current input method, or null. A
  143.      * control object provides methods that control the behavior of the
  144.      * input method or obtain information from the input method. The type
  145.      * of the object is an input method specific class. Clients have to
  146.      * compare the result against known input method control object
  147.      * classes and cast to the appropriate class to invoke the methods
  148.      * provided.
  149.      *
  150.      * @return A control object from the current input method, or null.
  151.      */
  152.     public Object getInputMethodControlObject() {
  153.         // real implementation is in sun.awt.im.InputContext
  154.         return null;
  155.     }
  156.  
  157. }
  158.