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
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
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 }
|
1 /*
2 * Copyright (c) 2011, 2017, 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
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<Object> workList = nativeGetAvailableLocales();
61 Locale currentLocale = CInputMethod.getNativeLocale();
62
63 if (workList == null || (workList != null && workList.isEmpty())) {
64 return new Object[] {
65 currentLocale != null ? currentLocale : Locale.getDefault()
66 };
67 } else {
68 if (currentLocale != null && !workList.contains(currentLocale)) {
69 workList.add(currentLocale);
70 }
71 return workList.toArray();
72 }
73 }
74
75 /**
76 * @see java.awt.im.spi.InputMethodDescriptor#hasDynamicLocaleList
77 */
78 public boolean hasDynamicLocaleList() {
79 return false;
80 }
81
82 /**
83 * @see java.awt.im.spi.InputMethodDescriptor#getInputMethodDisplayName
84 */
85 public synchronized String getInputMethodDisplayName(Locale inputLocale, Locale displayLanguage) {
86 String name = "System Input Methods";
87 if (Locale.getDefault().equals(displayLanguage)) {
88 name = Toolkit.getProperty("AWT.HostInputMethodDisplayName", name);
89 }
90 return name;
91 }
92
106 }
107
108 public String toString() {
109 Locale loc[] = getAvailableLocales();
110 String locnames = null;
111
112 for (int i = 0; i < loc.length; i++) {
113 if (locnames == null) {
114 locnames = loc[i].toString();
115 } else {
116 locnames += "," + loc[i];
117 }
118 }
119 return getClass().getName() + "[" +
120 "locales=" + locnames +
121 ",localelist=" + (hasDynamicLocaleList() ? "dynamic" : "static") +
122 "]";
123 }
124
125 private static native void nativeInit();
126 private static native List<Object> nativeGetAvailableLocales();
127 }
|