1 /*
2 * Copyright (c) 1997, 2013, 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
530 // Switch out the old input method
531 Locale savedLocale = inputMethodLocator.getLocale();
532 boolean wasInputMethodActive = isInputMethodActive;
533 boolean wasCompositionEnabledSupported = false;
534 boolean wasCompositionEnabled = false;
535 if (inputMethod != null) {
536 try {
537 wasCompositionEnabled = inputMethod.isCompositionEnabled();
538 wasCompositionEnabledSupported = true;
539 } catch (UnsupportedOperationException e) { }
540
541 if (currentClientComponent != null) {
542 if (!isInputMethodActive) {
543 activateInputMethod(false);
544 }
545 endComposition();
546 deactivateInputMethod(false);
547 if (inputMethod instanceof InputMethodAdapter) {
548 ((InputMethodAdapter) inputMethod).setClientComponent(null);
549 }
550 }
551 savedLocale = inputMethod.getLocale();
552
553 // keep the input method instance around for future use
554 if (usedInputMethods == null) {
555 usedInputMethods = new HashMap<>(5);
556 }
557 if (perInputMethodState == null) {
558 perInputMethodState = new HashMap<>(5);
559 }
560 usedInputMethods.put(inputMethodLocator.deriveLocator(null), inputMethod);
561 perInputMethodState.put(inputMethod,
562 Boolean.valueOf(clientWindowNotificationEnabled));
563 enableClientWindowNotification(inputMethod, false);
564 if (this == inputMethodWindowContext) {
565 inputMethod.hideWindows();
566 inputMethodWindowContext = null;
567 }
568 inputMethodLocator = null;
569 inputMethod = null;
570 inputMethodCreationFailed = false;
571 }
572
573 // Switch in the new input method
574 if (newLocator.getLocale() == null && savedLocale != null &&
575 newLocator.isLocaleAvailable(savedLocale)) {
576 newLocator = newLocator.deriveLocator(savedLocale);
577 }
578 inputMethodLocator = newLocator;
579 inputMethodCreationFailed = false;
580
581 // activate the new input method if the old one was active
582 if (wasInputMethodActive) {
583 inputMethod = getInputMethodInstance();
584 if (inputMethod instanceof InputMethodAdapter) {
585 ((InputMethodAdapter) inputMethod).setAWTFocussedComponent(awtFocussedComponent);
|
1 /*
2 * Copyright (c) 1997, 2019, 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
530 // Switch out the old input method
531 Locale savedLocale = inputMethodLocator.getLocale();
532 boolean wasInputMethodActive = isInputMethodActive;
533 boolean wasCompositionEnabledSupported = false;
534 boolean wasCompositionEnabled = false;
535 if (inputMethod != null) {
536 try {
537 wasCompositionEnabled = inputMethod.isCompositionEnabled();
538 wasCompositionEnabledSupported = true;
539 } catch (UnsupportedOperationException e) { }
540
541 if (currentClientComponent != null) {
542 if (!isInputMethodActive) {
543 activateInputMethod(false);
544 }
545 endComposition();
546 deactivateInputMethod(false);
547 if (inputMethod instanceof InputMethodAdapter) {
548 ((InputMethodAdapter) inputMethod).setClientComponent(null);
549 }
550 if (null == currentClientComponent.getInputMethodRequests())
551 wasCompositionEnabledSupported = false;
552 }
553 savedLocale = inputMethod.getLocale();
554
555 // keep the input method instance around for future use
556 if (usedInputMethods == null) {
557 usedInputMethods = new HashMap<>(5);
558 }
559 if (perInputMethodState == null) {
560 perInputMethodState = new HashMap<>(5);
561 }
562 usedInputMethods.put(inputMethodLocator.deriveLocator(null), inputMethod);
563 perInputMethodState.put(inputMethod,
564 Boolean.valueOf(clientWindowNotificationEnabled));
565 enableClientWindowNotification(inputMethod, false);
566 if (this == inputMethodWindowContext) {
567 inputMethod.hideWindows();
568 inputMethod.removeNotify();
569 inputMethodWindowContext = null;
570 }
571 inputMethodLocator = null;
572 inputMethod = null;
573 inputMethodCreationFailed = false;
574 }
575
576 // Switch in the new input method
577 if (newLocator.getLocale() == null && savedLocale != null &&
578 newLocator.isLocaleAvailable(savedLocale)) {
579 newLocator = newLocator.deriveLocator(savedLocale);
580 }
581 inputMethodLocator = newLocator;
582 inputMethodCreationFailed = false;
583
584 // activate the new input method if the old one was active
585 if (wasInputMethodActive) {
586 inputMethod = getInputMethodInstance();
587 if (inputMethod instanceof InputMethodAdapter) {
588 ((InputMethodAdapter) inputMethod).setAWTFocussedComponent(awtFocussedComponent);
|