jdk/src/java.desktop/share/classes/sun/awt/im/ExecutableInputMethodManager.java
author serb
Fri, 22 May 2015 23:26:00 +0300
changeset 30948 0a0972d3b58d
parent 28093 270b6925cbc8
child 35667 ed476aba94de
permissions -rw-r--r--
6587235: Incorrect javadoc: "no parameter" in 2d source code Reviewed-by: azvegint, prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 14330
diff changeset
     2
 * Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved.
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     4
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    10
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    15
 * accompanied this code).
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    16
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    20
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    23
 * questions.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    24
 */
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    25
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    26
package sun.awt.im;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    27
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    28
import java.awt.AWTException;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    29
import java.awt.CheckboxMenuItem;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    30
import java.awt.Component;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    31
import java.awt.Dialog;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    32
import java.awt.EventQueue;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    33
import java.awt.Frame;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    34
import java.awt.PopupMenu;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    35
import java.awt.Menu;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    36
import java.awt.MenuItem;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    37
import java.awt.Toolkit;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    38
import sun.awt.AppContext;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    39
import java.awt.event.ActionEvent;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    40
import java.awt.event.ActionListener;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    41
import java.awt.event.InvocationEvent;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    42
import java.awt.im.spi.InputMethodDescriptor;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    43
import java.lang.reflect.InvocationTargetException;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    44
import java.security.AccessController;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    45
import java.security.PrivilegedAction;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    46
import java.security.PrivilegedActionException;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    47
import java.security.PrivilegedExceptionAction;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    48
import java.util.Hashtable;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    49
import java.util.Iterator;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    50
import java.util.Locale;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    51
import java.util.ServiceLoader;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    52
import java.util.Vector;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    53
import java.util.Set;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    54
import java.util.prefs.BackingStoreException;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    55
import java.util.prefs.Preferences;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    56
import sun.awt.InputMethodSupport;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    57
import sun.awt.SunToolkit;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    58
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    59
/**
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    60
 * <code>ExecutableInputMethodManager</code> is the implementation of the
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    61
 * <code>InputMethodManager</code> class. It is runnable as a separate
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    62
 * thread in the AWT environment.&nbsp;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    63
 * <code>InputMethodManager.getInstance()</code> creates an instance of
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    64
 * <code>ExecutableInputMethodManager</code> and executes it as a deamon
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    65
 * thread.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    66
 *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    67
 * @see InputMethodManager
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    68
 */
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    69
class ExecutableInputMethodManager extends InputMethodManager
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    70
                                   implements Runnable
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    71
{
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    72
    // the input context that's informed about selections from the user interface
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    73
    private InputContext currentInputContext;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    74
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    75
    // Menu item string for the trigger menu.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    76
    private String triggerMenuString;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    77
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    78
    // popup menu for selecting an input method
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    79
    private InputMethodPopupMenu selectionMenu;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    80
    private static String selectInputMethodMenuTitle;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    81
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    82
    // locator and name of host adapter
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    83
    private InputMethodLocator hostAdapterLocator;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    84
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    85
    // locators for Java input methods
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    86
    private int javaInputMethodCount;         // number of Java input methods found
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    87
    private Vector<InputMethodLocator> javaInputMethodLocatorList;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    88
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    89
    // component that is requesting input method switch
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    90
    // must be Frame or Dialog
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    91
    private Component requestComponent;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    92
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    93
    // input context that is requesting input method switch
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    94
    private InputContext requestInputContext;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    95
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    96
    // IM preference stuff
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    97
    private static final String preferredIMNode = "/sun/awt/im/preferredInputMethod";
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    98
    private static final String descriptorKey = "descriptor";
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
    99
    private Hashtable<String, InputMethodLocator> preferredLocatorCache = new Hashtable<>();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   100
    private Preferences userRoot;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   101
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   102
    ExecutableInputMethodManager() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   103
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   104
        // set up host adapter locator
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   105
        Toolkit toolkit = Toolkit.getDefaultToolkit();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   106
        try {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   107
            if (toolkit instanceof InputMethodSupport) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   108
                InputMethodDescriptor hostAdapterDescriptor =
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   109
                    ((InputMethodSupport)toolkit)
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   110
                    .getInputMethodAdapterDescriptor();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   111
                if (hostAdapterDescriptor != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   112
                    hostAdapterLocator = new InputMethodLocator(hostAdapterDescriptor, null, null);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   113
                }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   114
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   115
        } catch (AWTException e) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   116
            // if we can't get a descriptor, we'll just have to do without native input methods
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   117
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   118
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   119
        javaInputMethodLocatorList = new Vector<InputMethodLocator>();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   120
        initializeInputMethodLocatorList();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   121
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   122
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   123
    synchronized void initialize() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   124
        selectInputMethodMenuTitle = Toolkit.getProperty("AWT.InputMethodSelectionMenu", "Select Input Method");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   125
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   126
        triggerMenuString = selectInputMethodMenuTitle;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   127
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   128
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   129
    public void run() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   130
        // If there are no multiple input methods to choose from, wait forever
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   131
        while (!hasMultipleInputMethods()) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   132
            try {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   133
                synchronized (this) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   134
                    wait();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   135
                }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   136
            } catch (InterruptedException e) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   137
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   138
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   139
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   140
        // Loop for processing input method change requests
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   141
        while (true) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   142
            waitForChangeRequest();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   143
            initializeInputMethodLocatorList();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   144
            try {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   145
                if (requestComponent != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   146
                    showInputMethodMenuOnRequesterEDT(requestComponent);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   147
                } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   148
                    // show the popup menu within the event thread
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   149
                    EventQueue.invokeAndWait(new Runnable() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   150
                        public void run() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   151
                            showInputMethodMenu();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   152
                        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   153
                    });
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   154
                }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   155
            } catch (InterruptedException ie) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   156
            } catch (InvocationTargetException ite) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   157
                // should we do anything under these exceptions?
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   158
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   159
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   160
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   161
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   162
    // Shows Input Method Menu on the EDT of requester component
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   163
    // to avoid side effects. See 6544309.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   164
    private void showInputMethodMenuOnRequesterEDT(Component requester)
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   165
        throws InterruptedException, InvocationTargetException {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   166
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   167
        if (requester == null){
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   168
            return;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   169
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   170
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   171
        class AWTInvocationLock {}
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   172
        Object lock = new AWTInvocationLock();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   173
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   174
        InvocationEvent event =
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   175
                new InvocationEvent(requester,
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   176
                                    new Runnable() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   177
                                        public void run() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   178
                                            showInputMethodMenu();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   179
                                        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   180
                                    },
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   181
                                    lock,
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   182
                                    true);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   183
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   184
        AppContext requesterAppContext = SunToolkit.targetToAppContext(requester);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   185
        synchronized (lock) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   186
            SunToolkit.postEvent(requesterAppContext, event);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   187
            while (!event.isDispatched()) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   188
                lock.wait();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   189
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   190
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   191
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   192
        Throwable eventThrowable = event.getThrowable();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   193
        if (eventThrowable != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   194
            throw new InvocationTargetException(eventThrowable);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   195
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   196
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   197
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   198
    void setInputContext(InputContext inputContext) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   199
        if (currentInputContext != null && inputContext != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   200
            // don't throw this exception until 4237852 is fixed
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   201
            // throw new IllegalStateException("Can't have two active InputContext at the same time");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   202
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   203
        currentInputContext = inputContext;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   204
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   205
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   206
    public synchronized void notifyChangeRequest(Component comp) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   207
        if (!(comp instanceof Frame || comp instanceof Dialog))
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   208
            return;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   209
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   210
        // if busy with the current request, ignore this request.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   211
        if (requestComponent != null)
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   212
            return;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   213
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   214
        requestComponent = comp;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   215
        notify();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   216
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   217
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   218
    public synchronized void notifyChangeRequestByHotKey(Component comp) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   219
        while (!(comp instanceof Frame || comp instanceof Dialog)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   220
            if (comp == null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   221
                // no Frame or Dialog found in containment hierarchy.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   222
                return;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   223
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   224
            comp = comp.getParent();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   225
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   226
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   227
        notifyChangeRequest(comp);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   228
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   229
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   230
    public String getTriggerMenuString() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   231
        return triggerMenuString;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   232
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   233
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   234
    /*
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   235
     * Returns true if the environment indicates there are multiple input methods
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   236
     */
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   237
    boolean hasMultipleInputMethods() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   238
        return ((hostAdapterLocator != null) && (javaInputMethodCount > 0)
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   239
                || (javaInputMethodCount > 1));
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   240
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   241
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   242
    private synchronized void waitForChangeRequest() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   243
        try {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   244
            while (requestComponent == null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   245
                wait();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   246
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   247
        } catch (InterruptedException e) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   248
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   249
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   250
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   251
    /*
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   252
     * initializes the input method locator list for all
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   253
     * installed input method descriptors.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   254
     */
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   255
    private void initializeInputMethodLocatorList() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   256
        synchronized (javaInputMethodLocatorList) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   257
            javaInputMethodLocatorList.clear();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   258
            try {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   259
                AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   260
                    public Object run() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   261
                        for (InputMethodDescriptor descriptor :
28093
270b6925cbc8 8062588: Support java.util.spi.*, java.text.spi.*, java.awt.im.spi loaded from classpath
naoto
parents: 25859
diff changeset
   262
                            ServiceLoader.load(InputMethodDescriptor.class,
270b6925cbc8 8062588: Support java.util.spi.*, java.text.spi.*, java.awt.im.spi loaded from classpath
naoto
parents: 25859
diff changeset
   263
                                               ClassLoader.getSystemClassLoader())) {
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   264
                            ClassLoader cl = descriptor.getClass().getClassLoader();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   265
                            javaInputMethodLocatorList.add(new InputMethodLocator(descriptor, cl, null));
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   266
                        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   267
                        return null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   268
                    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   269
                });
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   270
            }  catch (PrivilegedActionException e) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   271
                e.printStackTrace();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   272
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   273
            javaInputMethodCount = javaInputMethodLocatorList.size();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   274
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   275
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   276
        if (hasMultipleInputMethods()) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   277
            // initialize preferences
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   278
            if (userRoot == null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   279
                userRoot = getUserRoot();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   280
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   281
        } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   282
            // indicate to clients not to offer the menu
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   283
            triggerMenuString = null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   284
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   285
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   286
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   287
    private void showInputMethodMenu() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   288
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   289
        if (!hasMultipleInputMethods()) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   290
            requestComponent = null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   291
            return;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   292
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   293
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   294
        // initialize pop-up menu
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   295
        selectionMenu = InputMethodPopupMenu.getInstance(requestComponent, selectInputMethodMenuTitle);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   296
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   297
        // we have to rebuild the menu each time because
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   298
        // some input methods (such as IIIMP) may change
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   299
        // their list of supported locales dynamically
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   300
        selectionMenu.removeAll();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   301
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   302
        // get information about the currently selected input method
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   303
        // ??? if there's no current input context, what's the point
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   304
        // of showing the menu?
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   305
        String currentSelection = getCurrentSelection();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   306
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   307
        // Add menu item for host adapter
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   308
        if (hostAdapterLocator != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   309
            selectionMenu.addOneInputMethodToMenu(hostAdapterLocator, currentSelection);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   310
            selectionMenu.addSeparator();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   311
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   312
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   313
        // Add menu items for other input methods
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   314
        for (int i = 0; i < javaInputMethodLocatorList.size(); i++) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   315
            InputMethodLocator locator = javaInputMethodLocatorList.get(i);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   316
            selectionMenu.addOneInputMethodToMenu(locator, currentSelection);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   317
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   318
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   319
        synchronized (this) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   320
            selectionMenu.addToComponent(requestComponent);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   321
            requestInputContext = currentInputContext;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   322
            selectionMenu.show(requestComponent, 60, 80); // TODO: get proper x, y...
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   323
            requestComponent = null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   324
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   325
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   326
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   327
    private String getCurrentSelection() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   328
        InputContext inputContext = currentInputContext;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   329
        if (inputContext != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   330
            InputMethodLocator locator = inputContext.getInputMethodLocator();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   331
            if (locator != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   332
                return locator.getActionCommandString();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   333
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   334
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   335
        return null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   336
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   337
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   338
    synchronized void changeInputMethod(String choice) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   339
        InputMethodLocator locator = null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   340
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   341
        String inputMethodName = choice;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   342
        String localeString = null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   343
        int index = choice.indexOf('\n');
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   344
        if (index != -1) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   345
            localeString = choice.substring(index + 1);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   346
            inputMethodName = choice.substring(0, index);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   347
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   348
        if (hostAdapterLocator.getActionCommandString().equals(inputMethodName)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   349
            locator = hostAdapterLocator;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   350
        } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   351
            for (int i = 0; i < javaInputMethodLocatorList.size(); i++) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   352
                InputMethodLocator candidate = javaInputMethodLocatorList.get(i);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   353
                String name = candidate.getActionCommandString();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   354
                if (name.equals(inputMethodName)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   355
                    locator = candidate;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   356
                    break;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   357
                }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   358
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   359
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   360
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   361
        if (locator != null && localeString != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   362
            String language = "", country = "", variant = "";
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   363
            int postIndex = localeString.indexOf('_');
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   364
            if (postIndex == -1) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   365
                language = localeString;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   366
            } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   367
                language = localeString.substring(0, postIndex);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   368
                int preIndex = postIndex + 1;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   369
                postIndex = localeString.indexOf('_', preIndex);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   370
                if (postIndex == -1) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   371
                    country = localeString.substring(preIndex);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   372
                } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   373
                    country = localeString.substring(preIndex, postIndex);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   374
                    variant = localeString.substring(postIndex + 1);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   375
                }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   376
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   377
            Locale locale = new Locale(language, country, variant);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   378
            locator = locator.deriveLocator(locale);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   379
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   380
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   381
        if (locator == null)
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   382
            return;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   383
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   384
        // tell the input context about the change
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   385
        if (requestInputContext != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   386
            requestInputContext.changeInputMethod(locator);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   387
            requestInputContext = null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   388
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   389
            // remember the selection
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   390
            putPreferredInputMethod(locator);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   391
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   392
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   393
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   394
    InputMethodLocator findInputMethod(Locale locale) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   395
        // look for preferred input method first
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   396
        InputMethodLocator locator = getPreferredInputMethod(locale);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   397
        if (locator != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   398
            return locator;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   399
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   400
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   401
        if (hostAdapterLocator != null && hostAdapterLocator.isLocaleAvailable(locale)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   402
            return hostAdapterLocator.deriveLocator(locale);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   403
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   404
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   405
        // Update the locator list
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   406
        initializeInputMethodLocatorList();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   407
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   408
        for (int i = 0; i < javaInputMethodLocatorList.size(); i++) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   409
            InputMethodLocator candidate = javaInputMethodLocatorList.get(i);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   410
            if (candidate.isLocaleAvailable(locale)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   411
                return candidate.deriveLocator(locale);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   412
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   413
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   414
        return null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   415
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   416
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   417
    Locale getDefaultKeyboardLocale() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   418
        Toolkit toolkit = Toolkit.getDefaultToolkit();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   419
        if (toolkit instanceof InputMethodSupport) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   420
            return ((InputMethodSupport)toolkit).getDefaultKeyboardLocale();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   421
        } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   422
            return Locale.getDefault();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   423
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   424
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   425
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   426
    /**
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   427
     * Returns a InputMethodLocator object that the
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   428
     * user prefers for the given locale.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   429
     *
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   430
     * @param locale Locale for which the user prefers the input method.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   431
     */
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   432
    private synchronized InputMethodLocator getPreferredInputMethod(Locale locale) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   433
        InputMethodLocator preferredLocator = null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   434
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   435
        if (!hasMultipleInputMethods()) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   436
            // No need to look for a preferred Java input method
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   437
            return null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   438
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   439
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   440
        // look for the cached preference first.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   441
        preferredLocator = preferredLocatorCache.get(locale.toString().intern());
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   442
        if (preferredLocator != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   443
            return preferredLocator;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   444
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   445
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   446
        // look for the preference in the user preference tree
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   447
        String nodePath = findPreferredInputMethodNode(locale);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   448
        String descriptorName = readPreferredInputMethod(nodePath);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   449
        Locale advertised;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   450
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   451
        // get the locator object
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   452
        if (descriptorName != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   453
            // check for the host adapter first
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   454
            if (hostAdapterLocator != null &&
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   455
                hostAdapterLocator.getDescriptor().getClass().getName().equals(descriptorName)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   456
                advertised = getAdvertisedLocale(hostAdapterLocator, locale);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   457
                if (advertised != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   458
                    preferredLocator = hostAdapterLocator.deriveLocator(advertised);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   459
                    preferredLocatorCache.put(locale.toString().intern(), preferredLocator);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   460
                }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   461
                return preferredLocator;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   462
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   463
            // look for Java input methods
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   464
            for (int i = 0; i < javaInputMethodLocatorList.size(); i++) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   465
                InputMethodLocator locator = javaInputMethodLocatorList.get(i);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   466
                InputMethodDescriptor descriptor = locator.getDescriptor();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   467
                if (descriptor.getClass().getName().equals(descriptorName)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   468
                    advertised = getAdvertisedLocale(locator, locale);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   469
                    if (advertised != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   470
                        preferredLocator = locator.deriveLocator(advertised);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   471
                        preferredLocatorCache.put(locale.toString().intern(), preferredLocator);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   472
                    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   473
                    return preferredLocator;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   474
                }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   475
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   476
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   477
            // maybe preferred input method information is bogus.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   478
            writePreferredInputMethod(nodePath, null);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   479
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   480
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   481
        return null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   482
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   483
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   484
    private String findPreferredInputMethodNode(Locale locale) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   485
        if (userRoot == null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   486
            return null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   487
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   488
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   489
        // create locale node relative path
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   490
        String nodePath = preferredIMNode + "/" + createLocalePath(locale);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   491
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   492
        // look for the descriptor
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   493
        while (!nodePath.equals(preferredIMNode)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   494
            try {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   495
                if (userRoot.nodeExists(nodePath)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   496
                    if (readPreferredInputMethod(nodePath) != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   497
                        return nodePath;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   498
                    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   499
                }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   500
            } catch (BackingStoreException bse) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   501
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   502
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   503
            // search at parent's node
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   504
            nodePath = nodePath.substring(0, nodePath.lastIndexOf('/'));
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   505
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   506
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   507
        return null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   508
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   509
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   510
    private String readPreferredInputMethod(String nodePath) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   511
        if ((userRoot == null) || (nodePath == null)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   512
            return null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   513
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   514
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   515
        return userRoot.node(nodePath).get(descriptorKey, null);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   516
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   517
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   518
    /**
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   519
     * Writes the preferred input method descriptor class name into
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   520
     * the user's Preferences tree in accordance with the given locale.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   521
     *
30948
0a0972d3b58d 6587235: Incorrect javadoc: "no parameter" in 2d source code
serb
parents: 28093
diff changeset
   522
     * @param locator input method locator to remember.
14330
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   523
     */
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   524
    private synchronized void putPreferredInputMethod(InputMethodLocator locator) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   525
        InputMethodDescriptor descriptor = locator.getDescriptor();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   526
        Locale preferredLocale = locator.getLocale();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   527
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   528
        if (preferredLocale == null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   529
            // check available locales of the input method
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   530
            try {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   531
                Locale[] availableLocales = descriptor.getAvailableLocales();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   532
                if (availableLocales.length == 1) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   533
                    preferredLocale = availableLocales[0];
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   534
                } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   535
                    // there is no way to know which locale is the preferred one, so do nothing.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   536
                    return;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   537
                }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   538
            } catch (AWTException ae) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   539
                // do nothing here, either.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   540
                return;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   541
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   542
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   543
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   544
        // for regions that have only one language, we need to regard
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   545
        // "xx_YY" as "xx" when putting the preference into tree
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   546
        if (preferredLocale.equals(Locale.JAPAN)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   547
            preferredLocale = Locale.JAPANESE;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   548
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   549
        if (preferredLocale.equals(Locale.KOREA)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   550
            preferredLocale = Locale.KOREAN;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   551
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   552
        if (preferredLocale.equals(new Locale("th", "TH"))) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   553
            preferredLocale = new Locale("th");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   554
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   555
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   556
        // obtain node
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   557
        String path = preferredIMNode + "/" + createLocalePath(preferredLocale);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   558
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   559
        // write in the preference tree
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   560
        writePreferredInputMethod(path, descriptor.getClass().getName());
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   561
        preferredLocatorCache.put(preferredLocale.toString().intern(),
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   562
            locator.deriveLocator(preferredLocale));
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   563
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   564
        return;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   565
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   566
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   567
    private String createLocalePath(Locale locale) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   568
        String language = locale.getLanguage();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   569
        String country = locale.getCountry();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   570
        String variant = locale.getVariant();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   571
        String localePath = null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   572
        if (!variant.equals("")) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   573
            localePath = "_" + language + "/_" + country + "/_" + variant;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   574
        } else if (!country.equals("")) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   575
            localePath = "_" + language + "/_" + country;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   576
        } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   577
            localePath = "_" + language;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   578
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   579
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   580
        return localePath;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   581
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   582
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   583
    private void writePreferredInputMethod(String path, String descriptorName) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   584
        if (userRoot != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   585
            Preferences node = userRoot.node(path);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   586
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   587
            // record it
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   588
            if (descriptorName != null) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   589
                node.put(descriptorKey, descriptorName);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   590
            } else {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   591
                node.remove(descriptorKey);
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   592
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   593
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   594
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   595
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   596
    private Preferences getUserRoot() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   597
        return AccessController.doPrivileged(new PrivilegedAction<Preferences>() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   598
            public Preferences run() {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   599
                return Preferences.userRoot();
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   600
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   601
        });
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   602
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   603
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   604
    private Locale getAdvertisedLocale(InputMethodLocator locator, Locale locale) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   605
        Locale advertised = null;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   606
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   607
        if (locator.isLocaleAvailable(locale)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   608
            advertised = locale;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   609
        } else if (locale.getLanguage().equals("ja")) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   610
            // for Japanese, Korean, and Thai, check whether the input method supports
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   611
            // language or language_COUNTRY.
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   612
            if (locator.isLocaleAvailable(Locale.JAPAN)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   613
                advertised = Locale.JAPAN;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   614
            } else if (locator.isLocaleAvailable(Locale.JAPANESE)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   615
                advertised = Locale.JAPANESE;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   616
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   617
        } else if (locale.getLanguage().equals("ko")) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   618
            if (locator.isLocaleAvailable(Locale.KOREA)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   619
                advertised = Locale.KOREA;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   620
            } else if (locator.isLocaleAvailable(Locale.KOREAN)) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   621
                advertised = Locale.KOREAN;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   622
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   623
        } else if (locale.getLanguage().equals("th")) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   624
            if (locator.isLocaleAvailable(new Locale("th", "TH"))) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   625
                advertised = new Locale("th", "TH");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   626
            } else if (locator.isLocaleAvailable(new Locale("th"))) {
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   627
                advertised = new Locale("th");
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   628
            }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   629
        }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   630
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   631
        return advertised;
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   632
    }
e4cb78065603 8000970: break out auxiliary classes that will prevent multi-core compilation of the JDK
ohrstrom
parents:
diff changeset
   633
}