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