1 /*
   2  * Copyright (c) 1998, 2014, 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 package java.awt.im.spi;
  28 
  29 import java.awt.AWTException;
  30 import java.awt.Image;
  31 import java.util.Locale;
  32 
  33 /**
  34  * Defines methods that provide sufficient information about an input method
  35  * to enable selection and loading of that input method.
  36  * The input method itself is only loaded when it is actually used.
  37  *
  38  * @since 1.3
  39  */
  40 
  41 public interface InputMethodDescriptor {
  42 
  43     /**
  44      * Returns the locales supported by the corresponding input method.
  45      * The locale may describe just the language, or may also include
  46      * country and variant information if needed.
  47      * The information is used to select input methods by locale
  48      * ({@link java.awt.im.InputContext#selectInputMethod(Locale)}). It may also
  49      * be used to sort input methods by locale in a user-visible
  50      * list of input methods.
  51      * <p>
  52      * Only the input method's primary locales should be returned.
  53      * For example, if a Japanese input method also has a pass-through
  54      * mode for Roman characters, typically still only Japanese would
  55      * be returned. Thus, the list of locales returned is typically
  56      * a subset of the locales for which the corresponding input method's
  57      * implementation of {@link java.awt.im.spi.InputMethod#setLocale} returns true.
  58      * <p>
  59      * If {@link #hasDynamicLocaleList} returns true, this method is
  60      * called each time the information is needed. This
  61      * gives input methods that depend on network resources the chance
  62      * to add or remove locales as resources become available or
  63      * unavailable.
  64      *
  65      * @return the locales supported by the input method
  66      * @exception AWTException if it can be determined that the input method
  67      * is inoperable, for example, because of incomplete installation.
  68      */
  69     Locale[] getAvailableLocales() throws AWTException;
  70 
  71     /**
  72      * Returns whether the list of available locales can change
  73      * at runtime. This may be the case, for example, for adapters
  74      * that access real input methods over the network.
  75      * @return whether the list of available locales can change at
  76      * runtime
  77      */
  78     boolean hasDynamicLocaleList();
  79 
  80     /**
  81      * Returns the user-visible name of the corresponding
  82      * input method for the given input locale in the language in which
  83      * the name will be displayed.
  84      * <p>
  85      * The inputLocale parameter specifies the locale for which text
  86      * is input.
  87      * This parameter can only take values obtained from this descriptor's
  88      * {@link #getAvailableLocales} method or null. If it is null, an
  89      * input locale independent name for the input method should be
  90      * returned.
  91      * <p>
  92      * If a name for the desired display language is not available, the
  93      * method may fall back to some other language.
  94      *
  95      * @param inputLocale the locale for which text input is supported, or null
  96      * @param displayLanguage the language in which the name will be displayed
  97      * @return the user-visible name of the corresponding input method
  98      * for the given input locale in the language in which the name
  99      * will be displayed
 100      */
 101     String getInputMethodDisplayName(Locale inputLocale, Locale displayLanguage);
 102 
 103     /**
 104      * Returns an icon for the corresponding input method.
 105      * The icon may be used by a user interface for selecting input methods.
 106      * <p>
 107      * The inputLocale parameter specifies the locale for which text
 108      * is input.
 109      * This parameter can only take values obtained from this descriptor's
 110      * {@link #getAvailableLocales} method or null. If it is null, an
 111      * input locale independent icon for the input method should be
 112      * returned.
 113      * <p>
 114      * The icon's size should be 16&times;16 pixels.
 115      *
 116      * @param inputLocale the locale for which text input is supported, or null
 117      * @return an icon for the corresponding input method, or null
 118      */
 119     Image getInputMethodIcon(Locale inputLocale);
 120 
 121     /**
 122      * Creates a new instance of the corresponding input method.
 123      *
 124      * @return a new instance of the corresponding input method
 125      * @exception Exception any exception that may occur while creating the
 126      * input method instance
 127      */
 128     InputMethod createInputMethod() throws Exception;
 129 }