Path: blob/master/src/java.desktop/macosx/classes/sun/lwawt/macosx/CInputMethodDescriptor.java
41159 views
/*1* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.lwawt.macosx;2627import java.awt.*;28import java.awt.im.spi.*;29import java.util.*;30import java.util.List;3132/**33* Provides sufficient information about an input method34* to enable selection and loading of that input method.35* The input method itself is only loaded when it is actually used.36*/3738public class CInputMethodDescriptor implements InputMethodDescriptor {3940static {41nativeInit();42}4344public CInputMethodDescriptor() {45}4647/**48* @see java.awt.im.spi.InputMethodDescriptor#getAvailableLocales49*/50public Locale[] getAvailableLocales() {51// returns a copy of internal list for public API52Object[] locales = getAvailableLocalesInternal();53Locale[] tmp = new Locale[locales.length];54System.arraycopy(locales, 0, tmp, 0, locales.length);55return tmp;56}5758static Object[] getAvailableLocalesInternal() {59List<Object> workList = nativeGetAvailableLocales();60Locale currentLocale = CInputMethod.getNativeLocale();6162if (workList == null || workList.isEmpty()) {63return new Object[] {64currentLocale != null ? currentLocale : Locale.getDefault()65};66} else {67if (currentLocale != null && !workList.contains(currentLocale)) {68workList.add(currentLocale);69}70return workList.toArray();71}72}7374/**75* @see java.awt.im.spi.InputMethodDescriptor#hasDynamicLocaleList76*/77public boolean hasDynamicLocaleList() {78return false;79}8081/**82* @see java.awt.im.spi.InputMethodDescriptor#getInputMethodDisplayName83*/84public synchronized String getInputMethodDisplayName(Locale inputLocale, Locale displayLanguage) {85String name = "System Input Methods";86if (Locale.getDefault().equals(displayLanguage)) {87name = Toolkit.getProperty("AWT.HostInputMethodDisplayName", name);88}89return name;90}9192/**93* @see java.awt.im.spi.InputMethodDescriptor#getInputMethodIcon94*/95public Image getInputMethodIcon(Locale inputLocale) {96// This should return the flag icon corresponding to the input Locale.97return null;98}99100/**101* @see java.awt.im.spi.InputMethodDescriptor#createInputMethod102*/103public InputMethod createInputMethod() throws Exception {104return new CInputMethod();105}106107public String toString() {108Locale[] loc = getAvailableLocales();109String locnames = null;110111for (int i = 0; i < loc.length; i++) {112if (locnames == null) {113locnames = loc[i].toString();114} else {115locnames += "," + loc[i];116}117}118return getClass().getName() + "[" +119"locales=" + locnames +120",localelist=" + (hasDynamicLocaleList() ? "dynamic" : "static") +121"]";122}123124private static native void nativeInit();125private static native List<Object> nativeGetAvailableLocales();126}127128129