jdk/src/share/classes/com/sun/inputmethods/internal/indicim/IndicInputMethod.java
changeset 5656 4868963e05e0
parent 5655 8dacdb7bb25b
parent 5645 c98f230a6078
child 5657 7e406ebed9a5
equal deleted inserted replaced
5655:8dacdb7bb25b 5656:4868963e05e0
     1 /*
       
     2  * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 /*
       
    27  * (C) Copyright IBM Corp. 2000 - All Rights Reserved
       
    28  *
       
    29  * The original version of this source code and documentation is
       
    30  * copyrighted and owned by IBM. These materials are provided
       
    31  * under terms of a License Agreement between IBM and Sun.
       
    32  * This technology is protected by multiple US and International
       
    33  * patents. This notice and attribution to IBM may not be removed.
       
    34  *
       
    35  */
       
    36 
       
    37 package com.sun.inputmethods.internal.indicim;
       
    38 
       
    39 import java.awt.im.spi.InputMethod;
       
    40 import java.awt.im.spi.InputMethodContext;
       
    41 
       
    42 import java.awt.AWTEvent;
       
    43 import java.awt.Rectangle;
       
    44 
       
    45 import java.awt.event.KeyEvent;
       
    46 import java.awt.event.MouseEvent;
       
    47 
       
    48 import java.lang.Character.Subset;
       
    49 
       
    50 import java.util.Locale;
       
    51 
       
    52 class IndicInputMethod implements InputMethod {
       
    53 
       
    54     private IndicInputMethodImpl impl;
       
    55     private Locale locale;
       
    56 
       
    57     IndicInputMethod(Locale theLocale, IndicInputMethodImpl theImplementation) {
       
    58         locale = theLocale;
       
    59         impl = theImplementation;
       
    60     }
       
    61 
       
    62     /**
       
    63      * Sets the input method context, which is used to dispatch input method
       
    64      * events to the client component and to request information from
       
    65      * the client component.
       
    66      * <p>
       
    67      * This method is called once immediately after instantiating this input
       
    68      * method.
       
    69      *
       
    70      * @param context the input method context for this input method
       
    71      * @exception NullPointerException if <code>context</code> is null
       
    72      */
       
    73     public void setInputMethodContext(InputMethodContext context) {
       
    74 
       
    75         impl.setInputMethodContext(context);
       
    76     }
       
    77 
       
    78     /**
       
    79      * Attempts to set the input locale. If the input method supports the
       
    80      * desired locale, it changes its behavior to support input for the locale
       
    81      * and returns true.
       
    82      * Otherwise, it returns false and does not change its behavior.
       
    83      * <p>
       
    84      * This method is called
       
    85      * <ul>
       
    86      * <li>by {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod},
       
    87      * <li>when switching to this input method through the user interface if the user
       
    88      *     specified a locale or if the previously selected input method's
       
    89      *     {@link java.awt.im.spi.InputMethod#getLocale getLocale} method
       
    90      *     returns a non-null value.
       
    91      * </ul>
       
    92      *
       
    93      * @param locale locale to input
       
    94      * @return whether the specified locale is supported
       
    95      * @exception NullPointerException if <code>locale</code> is null
       
    96      */
       
    97     public boolean setLocale(Locale locale) {
       
    98 
       
    99         if (locale.getLanguage().equals(this.locale.getLanguage())) {
       
   100             //System.out.println("returning true for locale " + locale);
       
   101             return true;
       
   102         }
       
   103         else {
       
   104             //System.out.println("returning false for locale " + locale);
       
   105             return false;
       
   106         }
       
   107     }
       
   108 
       
   109     /**
       
   110      * Returns the current input locale. Might return null in exceptional cases.
       
   111      * <p>
       
   112      * This method is called
       
   113      * <ul>
       
   114      * <li>by {@link java.awt.im.InputContext#getLocale InputContext.getLocale} and
       
   115      * <li>when switching from this input method to a different one through the
       
   116      *     user interface.
       
   117      * </ul>
       
   118      *
       
   119      * @return the current input locale, or null
       
   120      */
       
   121     public Locale getLocale() {
       
   122 
       
   123         return locale;
       
   124     }
       
   125 
       
   126     /**
       
   127      * Sets the subsets of the Unicode character set that this input method
       
   128      * is allowed to input. Null may be passed in to indicate that all
       
   129      * characters are allowed.
       
   130      * <p>
       
   131      * This method is called
       
   132      * <ul>
       
   133      * <li>immediately after instantiating this input method,
       
   134      * <li>when switching to this input method from a different one, and
       
   135      * <li>by {@link java.awt.im.InputContext#setCharacterSubsets InputContext.setCharacterSubsets}.
       
   136      * </ul>
       
   137      *
       
   138      * @param subsets the subsets of the Unicode character set from which
       
   139      * characters may be input
       
   140      */
       
   141     public void setCharacterSubsets(Subset[] subsets) {
       
   142     }
       
   143 
       
   144     /**
       
   145      * Enables or disables this input method for composition,
       
   146      * depending on the value of the parameter <code>enable</code>.
       
   147      * <p>
       
   148      * An input method that is enabled for composition interprets incoming
       
   149      * events for both composition and control purposes, while a
       
   150      * disabled input method does not interpret events for composition.
       
   151      * Note however that events are passed on to the input method regardless
       
   152      * whether it is enabled or not, and that an input method that is disabled
       
   153      * for composition may still interpret events for control purposes,
       
   154      * including to enable or disable itself for composition.
       
   155      * <p>
       
   156      * This method is called
       
   157      * <ul>
       
   158      * <li>by {@link java.awt.im.InputContext#setCompositionEnabled InputContext.setCompositionEnabled},
       
   159      * <li>when switching to this input method from a different one using the
       
   160      *     user interface or
       
   161      *     {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod},
       
   162      *     if the previously selected input method's
       
   163      *     {@link java.awt.im.spi.InputMethod#isCompositionEnabled isCompositionEnabled}
       
   164      *     method returns without throwing an exception.
       
   165      * </ul>
       
   166      *
       
   167      * @param enable whether to enable the input method for composition
       
   168      * @throws UnsupportedOperationException if this input method does not
       
   169      * support the enabling/disabling operation
       
   170      * @see #isCompositionEnabled
       
   171      */
       
   172     public void setCompositionEnabled(boolean enable) {
       
   173 
       
   174         throw new UnsupportedOperationException();
       
   175     }
       
   176 
       
   177     /**
       
   178      * Determines whether this input method is enabled.
       
   179      * An input method that is enabled for composition interprets incoming
       
   180      * events for both composition and control purposes, while a
       
   181      * disabled input method does not interpret events for composition.
       
   182      * <p>
       
   183      * This method is called
       
   184      * <ul>
       
   185      * <li>by {@link java.awt.im.InputContext#isCompositionEnabled InputContext.isCompositionEnabled} and
       
   186      * <li>when switching from this input method to a different one using the
       
   187      *     user interface or
       
   188      *     {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
       
   189      * </ul>
       
   190      *
       
   191      * @return <code>true</code> if this input method is enabled for
       
   192      * composition; <code>false</code> otherwise.
       
   193      * @throws UnsupportedOperationException if this input method does not
       
   194      * support checking whether it is enabled for composition
       
   195      * @see #setCompositionEnabled
       
   196      */
       
   197     public boolean isCompositionEnabled() {
       
   198 
       
   199         return true;
       
   200     }
       
   201 
       
   202     /**
       
   203      * Starts the reconversion operation. The input method obtains the
       
   204      * text to be reconverted from the current client component using the
       
   205      * {@link java.awt.im.InputMethodRequests#getSelectedText InputMethodRequests.getSelectedText}
       
   206      * method. It can use other <code>InputMethodRequests</code>
       
   207      * methods to request additional information required for the
       
   208      * reconversion operation. The composed and committed text
       
   209      * produced by the operation is sent to the client component as a
       
   210      * sequence of <code>InputMethodEvent</code>s. If the given text
       
   211      * cannot be reconverted, the same text should be sent to the
       
   212      * client component as committed text.
       
   213      * <p>
       
   214      * This method is called by
       
   215      * {@link java.awt.im.InputContext#reconvert() InputContext.reconvert}.
       
   216      *
       
   217      * @throws UnsupportedOperationException if the input method does not
       
   218      * support the reconversion operation.
       
   219      */
       
   220     public void reconvert() {
       
   221 
       
   222         throw new UnsupportedOperationException("This input method does not reconvert.");
       
   223     }
       
   224 
       
   225     /**
       
   226      * Dispatches the event to the input method. If input method support is
       
   227      * enabled for the focussed component, incoming events of certain types
       
   228      * are dispatched to the current input method for this component before
       
   229      * they are dispatched to the component's methods or event listeners.
       
   230      * The input method decides whether it needs to handle the event. If it
       
   231      * does, it also calls the event's <code>consume</code> method; this
       
   232      * causes the event to not get dispatched to the component's event
       
   233      * processing methods or event listeners.
       
   234      * <p>
       
   235      * Events are dispatched if they are instances of InputEvent or its
       
   236      * subclasses.
       
   237      * This includes instances of the AWT classes KeyEvent and MouseEvent.
       
   238      * <p>
       
   239      * This method is called by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}.
       
   240      *
       
   241      * @param event the event being dispatched to the input method
       
   242      * @exception NullPointerException if <code>event</code> is null
       
   243      */
       
   244     public void dispatchEvent(AWTEvent event) {
       
   245 
       
   246         if (event instanceof KeyEvent) {
       
   247 
       
   248             KeyEvent keyEvent = (KeyEvent) event;
       
   249             if (event.getID() == KeyEvent.KEY_TYPED) {
       
   250                 impl.handleKeyTyped(keyEvent);
       
   251             }
       
   252             //System.out.println("handled event " + event);
       
   253         }
       
   254         else {
       
   255             //System.out.println("did not handle event " + event);
       
   256         }
       
   257     }
       
   258 
       
   259     /**
       
   260      * Notifies this input method of changes in the client window
       
   261      * location or state. This method is called while this input
       
   262      * method is the current input method of its input context and
       
   263      * notifications for it are enabled (see {@link
       
   264      * InputMethodContext#enableClientWindowNotification
       
   265      * InputMethodContext.enableClientWindowNotification}). Calls
       
   266      * to this method are temporarily suspended if the input context's
       
   267      * {@link java.awt.im.InputContext#removeNotify removeNotify}
       
   268      * method is called, and resume when the input method is activated
       
   269      * for a new client component. It is called in the following
       
   270      * situations:
       
   271      * <ul>
       
   272      * <li>
       
   273      * when the window containing the current client component changes
       
   274      * in location, size, visibility, iconification state, or when the
       
   275      * window is closed.</li>
       
   276      * <li>
       
   277      * from <code> enableClientWindowNotification(inputMethod,
       
   278      * true)</code> if the current client component exists,</li>
       
   279      * <li>
       
   280      * when activating the input method for the first time after it
       
   281      * called
       
   282      * <code>enableClientWindowNotification(inputMethod,
       
   283      * true)</code> if during the call no current client component was
       
   284      * available,</li>
       
   285      * <li>
       
   286      * when activating the input method for a new client component
       
   287      * after the input context's removeNotify method has been
       
   288      * called.</li>
       
   289      * </ul>
       
   290      * @param bounds client window's {@link
       
   291      * java.awt.Component#getBounds bounds} on the screen; or null if
       
   292      * the client window is iconified or invisible
       
   293      */
       
   294     public void notifyClientWindowChange(Rectangle bounds) {
       
   295     }
       
   296 
       
   297     /**
       
   298      * Activates the input method for immediate input processing.
       
   299      * <p>
       
   300      * If an input method provides its own windows, it should make sure
       
   301      * at this point that all necessary windows are open and visible.
       
   302      * <p>
       
   303      * This method is called
       
   304      * <ul>
       
   305      * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
       
   306      *     when a client component receives a FOCUS_GAINED event,
       
   307      * <li>when switching to this input method from a different one using the
       
   308      *     user interface or
       
   309      *     {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
       
   310      * </ul>
       
   311      * The method is only called when the input method is inactive.
       
   312      * A newly instantiated input method is assumed to be inactive.
       
   313      */
       
   314     public void activate() {
       
   315         //System.out.println("activated");
       
   316     }
       
   317 
       
   318     /**
       
   319      * Deactivates the input method.
       
   320      * The isTemporary argument has the same meaning as in
       
   321      * {@link java.awt.event.FocusEvent#isTemporary FocusEvent.isTemporary}.
       
   322      * <p>
       
   323      * If an input method provides its own windows, only windows that relate
       
   324      * to the current composition (such as a lookup choice window) should be
       
   325      * closed at this point.
       
   326      * It is possible that the input method will be immediately activated again
       
   327      * for a different client component, and closing and reopening more
       
   328      * persistent windows (such as a control panel) would create unnecessary
       
   329      * screen flicker.
       
   330      * Before an instance of a different input method class is activated,
       
   331      * {@link #hideWindows} is called on the current input method.
       
   332      * <p>
       
   333      * This method is called
       
   334      * <ul>
       
   335      * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
       
   336      *     when a client component receives a FOCUS_LOST event,
       
   337      * <li>when switching from this input method to a different one using the
       
   338      *     user interface or
       
   339      *     {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod},
       
   340      * <li>before {@link #removeNotify removeNotify} if the current client component is
       
   341      *     removed.
       
   342      * </ul>
       
   343      * The method is only called when the input method is active.
       
   344      *
       
   345      * @param isTemporary whether the focus change is temporary
       
   346      */
       
   347     public void deactivate(boolean isTemporary) {
       
   348         //System.out.println("deactivated");
       
   349     }
       
   350 
       
   351     /**
       
   352      * Closes or hides all windows opened by this input method instance or
       
   353      * its class.
       
   354      * <p>
       
   355      * This method is called
       
   356      * <ul>
       
   357      * <li>before calling {@link #activate activate} on an instance of a different input
       
   358      *     method class,
       
   359      * <li>before calling {@link #dispose dispose} on this input method.
       
   360      * </ul>
       
   361      * The method is only called when the input method is inactive.
       
   362      */
       
   363     public void hideWindows() {
       
   364     }
       
   365 
       
   366     /**
       
   367      * Notifies the input method that a client component has been
       
   368      * removed from its containment hierarchy, or that input method
       
   369      * support has been disabled for the component.
       
   370      * <p>
       
   371      * This method is called by {@link java.awt.im.InputContext#removeNotify InputContext.removeNotify}.
       
   372      * <p>
       
   373      * The method is only called when the input method is inactive.
       
   374      */
       
   375     public void removeNotify() {
       
   376     }
       
   377 
       
   378     /**
       
   379      * Ends any input composition that may currently be going on in this
       
   380      * context. Depending on the platform and possibly user preferences,
       
   381      * this may commit or delete uncommitted text. Any changes to the text
       
   382      * are communicated to the active component using an input method event.
       
   383      *
       
   384      * <p>
       
   385      * A text editing component may call this in a variety of situations,
       
   386      * for example, when the user moves the insertion point within the text
       
   387      * (but outside the composed text), or when the component's text is
       
   388      * saved to a file or copied to the clipboard.
       
   389      * <p>
       
   390      * This method is called
       
   391      * <ul>
       
   392      * <li>by {@link java.awt.im.InputContext#endComposition InputContext.endComposition},
       
   393      * <li>by {@link java.awt.im.InputContext#dispatchEvent InputContext.dispatchEvent}
       
   394      *     when switching to a different client component
       
   395      * <li>when switching from this input method to a different one using the
       
   396      *     user interface or
       
   397      *     {@link java.awt.im.InputContext#selectInputMethod InputContext.selectInputMethod}.
       
   398      * </ul>
       
   399      */
       
   400     public void endComposition() {
       
   401 
       
   402         impl.endComposition();
       
   403     }
       
   404 
       
   405     /**
       
   406      * Disposes of the input method and releases the resources used by it.
       
   407      * In particular, the input method should dispose windows and close files that are no
       
   408      * longer needed.
       
   409      * <p>
       
   410      * This method is called by {@link java.awt.im.InputContext#dispose InputContext.dispose}.
       
   411      * <p>
       
   412      * The method is only called when the input method is inactive.
       
   413      * No method of this interface is called on this instance after dispose.
       
   414      */
       
   415     public void dispose() {
       
   416     }
       
   417 
       
   418     /**
       
   419      * Returns a control object from this input method, or null. A
       
   420      * control object provides methods that control the behavior of the
       
   421      * input method or obtain information from the input method. The type
       
   422      * of the object is an input method specific class. Clients have to
       
   423      * compare the result against known input method control object
       
   424      * classes and cast to the appropriate class to invoke the methods
       
   425      * provided.
       
   426      * <p>
       
   427      * This method is called by
       
   428      * {@link java.awt.im.InputContext#getInputMethodControlObject InputContext.getInputMethodControlObject}.
       
   429      *
       
   430      * @return a control object from this input method, or null
       
   431      */
       
   432     public Object getControlObject() {
       
   433 
       
   434         return null;
       
   435     }
       
   436 }