1 /* 2 * Copyright (c) 2011, 2012, 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 package sun.lwawt.macosx; 27 28 import java.awt.*; 29 import java.awt.im.spi.*; 30 import java.util.*; 31 import java.util.List; 32 33 /** 34 * Provides 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 39 public class CInputMethodDescriptor implements InputMethodDescriptor { 40 41 static { 42 nativeInit(); 43 } 44 45 public CInputMethodDescriptor() { 46 } 47 48 /** 49 * @see java.awt.im.spi.InputMethodDescriptor#getAvailableLocales 50 */ 51 public Locale[] getAvailableLocales() { 52 // returns a copy of internal list for public API 53 Object[] locales = getAvailableLocalesInternal(); 54 Locale[] tmp = new Locale[locales.length]; 55 System.arraycopy(locales, 0, tmp, 0, locales.length); 56 return tmp; 57 } 58 59 static Object[] getAvailableLocalesInternal() { 60 List<?> workList = nativeGetAvailableLocales(); 61 62 if (workList != null) { 63 return workList.toArray(); 64 } 65 66 return new Object[] { 67 Locale.getDefault() 68 }; 69 } 70 71 /** 72 * @see java.awt.im.spi.InputMethodDescriptor#hasDynamicLocaleList 73 */ 74 public boolean hasDynamicLocaleList() { 75 return false; 76 } 77 78 /** 79 * @see java.awt.im.spi.InputMethodDescriptor#getInputMethodDisplayName 80 */ 81 public synchronized String getInputMethodDisplayName(Locale inputLocale, Locale displayLanguage) { 82 String name = "System Input Methods"; 83 if (Locale.getDefault().equals(displayLanguage)) { 84 name = Toolkit.getProperty("AWT.HostInputMethodDisplayName", name); 85 } 86 return name; 87 } 88 89 /** 90 * @see java.awt.im.spi.InputMethodDescriptor#getInputMethodIcon 91 */ 92 public Image getInputMethodIcon(Locale inputLocale) { 93 // This should return the flag icon corresponding to the input Locale. 94 return null; 95 } 96 97 /** 98 * @see java.awt.im.spi.InputMethodDescriptor#createInputMethod 99 */ 100 public InputMethod createInputMethod() throws Exception { 101 return new CInputMethod(); 102 } 103 104 public String toString() { 105 Locale loc[] = getAvailableLocales(); 106 String locnames = null; 107 108 for (int i = 0; i < loc.length; i++) { 109 if (locnames == null) { 110 locnames = loc[i].toString(); 111 } else { 112 locnames += "," + loc[i]; 113 } 114 } 115 return getClass().getName() + "[" + 116 "locales=" + locnames + 117 ",localelist=" + (hasDynamicLocaleList() ? "dynamic" : "static") + 118 "]"; 119 } 120 121 private static native void nativeInit(); 122 private static native List<?> nativeGetAvailableLocales(); 123 }