jdk/src/solaris/classes/sun/awt/X11InputMethod.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 6839 1e57288ce186
child 14498 317e4103662e
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6839
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3938
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.AWTEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.AWTException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.awt.Component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.awt.Container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.awt.EventQueue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.awt.Window;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.im.InputContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.awt.im.InputMethodHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.awt.im.spi.InputMethodContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import sun.awt.im.InputMethodAdapter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.awt.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.event.MouseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.awt.event.ComponentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.awt.event.WindowEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.awt.event.InputMethodEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.awt.font.TextHitInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.awt.peer.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.lang.Character.Subset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.text.AttributedString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.text.AttributedCharacterIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.io.FileReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.io.IOException;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    60
import sun.util.logging.PlatformLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import java.util.regex.Pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Input Method Adapter for XIM
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @author JavaSoft International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public abstract class X11InputMethod extends InputMethodAdapter {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    71
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11InputMethod");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * The following XIM* values must be the same as those defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * Xlib.h
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static final int XIMReverse = (1<<0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    private static final int XIMUnderline = (1<<1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static final int XIMHighlight = (1<<2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final int XIMPrimary = (1<<5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static final int XIMSecondary = (1<<6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static final int XIMTertiary = (1<<7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * visible position values
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    private static final int XIMVisibleToForward = (1<<8);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    private static final int XIMVisibleToBackward = (1<<9);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final int XIMVisibleCenter = (1<<10);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final int XIMVisibleMask = (XIMVisibleToForward|
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                               XIMVisibleToBackward|
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                                               XIMVisibleCenter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private Locale locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static boolean isXIMOpened = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected Container clientComponentWindow = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    private Component awtFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    private Component lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private boolean   isLastXICActive = false;
6839
1e57288ce186 6575419: Solaris : XSetICFoucs is not called with Java application at appropriate timing
naoto
parents: 5506
diff changeset
    99
    private boolean   isLastTemporary = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    private boolean   isActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    private boolean   isActiveClient = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private static Map[] highlightStyles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private boolean disposed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    //reset the XIC if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    private boolean   needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    private Component needResetXICClient = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    // The use of compositionEnableSupported is to reduce unnecessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // native calls if set/isCompositionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    // throws UnsupportedOperationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    // It is set to false if that exception is thrown first time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // either of the two methods are called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private boolean compositionEnableSupported = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    // The savedCompositionState indicates the composition mode when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // endComposition or setCompositionEnabled is called. It doesn't always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    // reflect the actual composition state because it doesn't get updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // when the user changes the composition state through direct interaction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    // with the input method. It is used to save the composition mode when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    // focus is traversed across different client components sharing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    // same java input context. Also if set/isCompositionEnabled are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    // supported, it remains false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private boolean savedCompositionState = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    // variables to keep track of preedit context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    // these variables need to be accessed within AWT_LOCK/UNLOCK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    private String committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private StringBuffer composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private IntBuffer rawFeedbacks;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    // private data (X11InputMethodData structure defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    // awt_InputMethod.c) for native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    // this structure needs to be accessed within AWT_LOCK/UNLOCK
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    transient private long pData = 0; // accessed by native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    // Initialize highlight mapping table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        Map styles[] = new Map[4];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        HashMap map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // UNSELECTED_RAW_TEXT_HIGHLIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        map = new HashMap(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        map.put(TextAttribute.WEIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                  TextAttribute.WEIGHT_BOLD);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        styles[0] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // SELECTED_RAW_TEXT_HIGHLIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        map = new HashMap(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        map.put(TextAttribute.SWAP_COLORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                  TextAttribute.SWAP_COLORS_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        styles[1] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        // UNSELECTED_CONVERTED_TEXT_HIGHLIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        map = new HashMap(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        map.put(TextAttribute.INPUT_METHOD_UNDERLINE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                  TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        styles[2] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        // SELECTED_CONVERTED_TEXT_HIGHLIGHT
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        map = new HashMap(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        map.put(TextAttribute.SWAP_COLORS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                  TextAttribute.SWAP_COLORS_ON);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        styles[3] = Collections.unmodifiableMap(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        highlightStyles = styles;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Initialize JNI field and method IDs for fields that may be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
       accessed from C.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * Constructs an X11InputMethod instance. It initializes the XIM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * environment if it's not done yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception AWTException if XOpenIM() failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public X11InputMethod() throws AWTException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        // supports only the locale in which the VM is started
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        locale = X11InputMethodDescriptor.getSupportedLocale();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        if (initXIM() == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            throw new AWTException("Cannot open X Input Method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    protected void finalize() throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        super.finalize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * Invokes openIM() that invokes XOpenIM() if it's not opened yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @return  true if openXIM() is successful or it's already been opened.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    private synchronized boolean initXIM() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (isXIMOpened == false)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            isXIMOpened = openXIM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return isXIMOpened;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    protected abstract boolean openXIM();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    protected boolean isDisposed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return disposed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    protected abstract void setXICFocus(ComponentPeer peer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                                    boolean value, boolean active);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Does nothing - this adapter doesn't use the input method context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @see java.awt.im.spi.InputMethod#setInputMethodContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public void setInputMethodContext(InputMethodContext context) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Set locale to input. If input method doesn't support specified locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * false will be returned and its behavior is not changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @param lang locale to input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @return the true is returned when specified locale is supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    public boolean setLocale(Locale lang) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (lang.equals(locale)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        // special compatibility rule for Japanese and Korean
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        if (locale.equals(Locale.JAPAN) && lang.equals(Locale.JAPANESE) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                locale.equals(Locale.KOREA) && lang.equals(Locale.KOREAN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * Returns current input locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public Locale getLocale() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Does nothing - XIM doesn't let you specify which characters you expect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @see java.awt.im.spi.InputMethod#setCharacterSubsets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public void setCharacterSubsets(Subset[] subsets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Dispatch event to input method. InputContext dispatch event with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * method. Input method set consume flag if event is consumed in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * @param e event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    public void dispatchEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    protected final void resetXICifneeded(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        /* needResetXIC is used to indicate whether to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
           resetXIC on the active client. resetXIC will always be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
           called on the passive client when endComposition is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (needResetXIC && haveActiveClient() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            getClientComponent() != needResetXICClient){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            resetXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            // needs to reset the last xic focussed component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
            isLastXICActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            needResetXICClient = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * Reset the composition state to the current composition state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    private void resetCompositionState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if (compositionEnableSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                /* Restore the composition mode to the last saved composition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                   mode. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                setCompositionEnabled(savedCompositionState);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            } catch (UnsupportedOperationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                compositionEnableSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * Query and then return the current composition state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @returns the composition state if isCompositionEnabled call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * is successful. Otherwise, it returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    private boolean getCompositionState() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        boolean compositionState = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (compositionEnableSupported) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                compositionState = isCompositionEnabled();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            } catch (UnsupportedOperationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                compositionEnableSupported = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        return compositionState;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * Activate input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
    public synchronized void activate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        clientComponentWindow = getClientComponentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        if (clientComponentWindow == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        if (lastXICFocussedComponent != null){
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   328
            if (log.isLoggable(PlatformLogger.FINE)) log.fine("XICFocused {0}, AWTFocused {1}",
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   329
                                                              lastXICFocussedComponent, awtFocussedComponent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        if (pData == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            if (!createXIC()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            disposed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        /*  reset input context if necessary and set the XIC focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        resetXICifneeded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        ComponentPeer lastXICFocussedComponentPeer = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        ComponentPeer awtFocussedComponentPeer = getPeer(awtFocussedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        if (lastXICFocussedComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
           lastXICFocussedComponentPeer = getPeer(lastXICFocussedComponent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        /* If the last XIC focussed component has a different peer as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
           current focussed component, change the XIC focus to the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
           focussed component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        */
6839
1e57288ce186 6575419: Solaris : XSetICFoucs is not called with Java application at appropriate timing
naoto
parents: 5506
diff changeset
   353
        if (isLastTemporary || lastXICFocussedComponentPeer != awtFocussedComponentPeer ||
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            isLastXICActive != haveActiveClient()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (lastXICFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                setXICFocus(lastXICFocussedComponentPeer, false, isLastXICActive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            if (awtFocussedComponentPeer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                setXICFocus(awtFocussedComponentPeer, true, haveActiveClient());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            lastXICFocussedComponent = awtFocussedComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            isLastXICActive = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        resetCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        isActive = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    protected abstract boolean createXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Deactivate input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public synchronized void deactivate(boolean isTemporary) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        boolean   isAc =  haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        /* Usually as the client component, let's call it component A,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
           loses the focus, this method is called. Then when another client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
           component, let's call it component B,  gets the focus, activate is first called on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
           the previous focused compoent which is A, then endComposition is called on A,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
           deactivate is called on A again. And finally activate is called on the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
           focused component B. Here is the call sequence.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
           A loses focus               B gains focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
           -------------> deactivate A -------------> activate A -> endComposition A ->
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
           deactivate A -> activate B ----....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
           So in order to carry the composition mode across the components sharing the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
           input context, we save it when deactivate is called so that when activate is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
           called, it can be restored correctly till activate is called on the newly focused
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
           component. (See also sun/awt/im/InputContext and bug 6184471).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
           Last note, getCompositionState should be called before setXICFocus since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
           setXICFocus here sets the XIC to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        savedCompositionState = getCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        if (isTemporary){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            //turn the status window off...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            turnoffStatusWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        /* Delay resetting the XIC focus until activate is called and the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
           focussed component has a different peer as the last focussed component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        lastXICFocussedComponent = awtFocussedComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        isLastXICActive = isAc;
6839
1e57288ce186 6575419: Solaris : XSetICFoucs is not called with Java application at appropriate timing
naoto
parents: 5506
diff changeset
   405
        isLastTemporary = isTemporary;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        isActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * Explicitly disable the native IME. Native IME is not disabled when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * deactivate is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void disableInputMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (lastXICFocussedComponent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            setXICFocus(getPeer(lastXICFocussedComponent), false, isLastXICActive);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            isLastXICActive = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    // implements java.awt.im.spi.InputMethod.hideWindows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public void hideWindows() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        // ??? need real implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @see java.awt.Toolkit#mapInputMethodHighlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public static Map mapInputMethodHighlight(InputMethodHighlight highlight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        int state = highlight.getState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        if (state == InputMethodHighlight.RAW_TEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        } else if (state == InputMethodHighlight.CONVERTED_TEXT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            index = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        if (highlight.isSelected()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            index += 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return highlightStyles[index];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @see sun.awt.im.InputMethodAdapter#setAWTFocussedComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    protected void setAWTFocussedComponent(Component component) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if (component == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (isActive) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            // deactivate/activate are being suppressed during a focus change -
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            // this may happen when an input method window is made visible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            boolean ac = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            setXICFocus(getPeer(awtFocussedComponent), false, ac);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            setXICFocus(getPeer(component), true, ac);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        awtFocussedComponent = component;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @see sun.awt.im.InputMethodAdapter#stopListening
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    protected void stopListening() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        // It is desirable to disable XIM by calling XSetICValues with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        // XNPreeditState == XIMPreeditDisable.  But Solaris 2.6 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        // Solaris 7 do not implement this correctly without a patch,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        // so just call resetXIC here.  Prior endComposition call commits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // the existing composed text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        endComposition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        // disable the native input method so that the other input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        // method could get the input focus.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        disableInputMethod();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        if (needResetXIC) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            resetXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            needResetXICClient = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Returns the Window instance in which the client component is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * contained. If not found, null is returned. (IS THIS POSSIBLE?)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    private Window getClientComponentWindow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        Component client = getClientComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        Container container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (client instanceof Container) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            container = (Container) client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            container = getParent(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        while (container != null && !(container instanceof java.awt.Window)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            container = getParent(container);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        return (Window) container;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    protected abstract Container getParent(Component client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * Returns peer of the given client component. If the given client component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * doesn't have peer, peer of the native container of the client is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    protected abstract ComponentPeer getPeer(Component client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * Used to protect preedit data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    protected abstract void awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    protected abstract void awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Creates an input method event from the arguments given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * and posts it on the AWT event queue. For arguments,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * see InputMethodEvent. Called by input method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @see java.awt.event.InputMethodEvent#InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    private void postInputMethodEvent(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                                      AttributedCharacterIterator text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                                      int committedCharacterCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                                      TextHitInfo caret,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                                      TextHitInfo visiblePosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                                      long when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        Component source = getClientComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        if (source != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            InputMethodEvent event = new InputMethodEvent(source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                id, when, text, committedCharacterCount, caret, visiblePosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            SunToolkit.postEvent(SunToolkit.targetToAppContext(source), (AWTEvent)event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    private void postInputMethodEvent(int id,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                                      AttributedCharacterIterator text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                                      int committedCharacterCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                                      TextHitInfo caret,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                      TextHitInfo visiblePosition) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        postInputMethodEvent(id, text, committedCharacterCount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                             caret, visiblePosition, EventQueue.getMostRecentEventTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * Dispatches committed text from XIM to the awt event queue. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * method is invoked from the event handler in canvas.c in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * AWT Toolkit thread context and thus inside the AWT Lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @param   str     committed text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @param   long    when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    void dispatchCommittedText(String str, long when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        if (str == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        if (composedText == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            AttributedString attrstr = new AttributedString(str);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
            postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                                 attrstr.getIterator(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                 str.length(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                 when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            // if there is composed text, wait until the preedit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            // callback is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            committedText = str;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    private void dispatchCommittedText(String str) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        dispatchCommittedText(str, EventQueue.getMostRecentEventTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * Updates composed text with XIM preedit information and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * posts composed text to the awt event queue. The args of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * this method correspond to the XIM preedit callback
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * information. The XIM highlight attributes are translated via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     * fixed mapping (i.e., independent from any underlying input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * method engine). This method is invoked in the AWT Toolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * (X event loop) thread context and thus inside the AWT Lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    void dispatchComposedText(String chgText,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                           int chgStyles[],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                           int chgOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                                           int chgLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                                           int caretPosition,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                                           long when) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        if (disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        //Workaround for deadlock bug on solaris2.6_zh bug#4170760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        if (chgText == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            && chgStyles == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            && chgOffset == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            && chgLength == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            && caretPosition == 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            && composedText == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            && committedText == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        if (composedText == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            // TODO: avoid reallocation of those buffers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            composedText = new StringBuffer(INITIAL_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            rawFeedbacks = new IntBuffer(INITIAL_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        if (chgLength > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            if (chgText == null && chgStyles != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                rawFeedbacks.replace(chgOffset, chgStyles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                if (chgLength == composedText.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    // optimization for the special case to replace the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    // entire previous text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    composedText = new StringBuffer(INITIAL_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    rawFeedbacks = new IntBuffer(INITIAL_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    if (composedText.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                        if (chgOffset+chgLength < composedText.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                            String text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                            text = composedText.toString().substring(chgOffset+chgLength,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                                                                     composedText.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                            composedText.setLength(chgOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                            composedText.append(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                            // in case to remove substring from chgOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                            // to the end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                            composedText.setLength(chgOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                        rawFeedbacks.remove(chgOffset, chgLength);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        if (chgText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            composedText.insert(chgOffset, chgText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            if (chgStyles != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                rawFeedbacks.insert(chgOffset, chgStyles);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        if (composedText.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            rawFeedbacks = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
            // if there is any outstanding committed text stored by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            // dispatchCommittedText(), it has to be sent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            // client component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            if (committedText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                dispatchCommittedText(committedText, when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            // otherwise, send null text to delete client's composed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            // text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                                 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                                 when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        // Now sending the composed text to the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
        int composedOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        AttributedString inputText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        // if there is any partially committed text, concatenate it to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
        // the composed text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        if (committedText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
            composedOffset = committedText.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
            inputText = new AttributedString(committedText + composedText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            composedOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
            inputText = new AttributedString(composedText.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        int currentFeedback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        int nextFeedback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        int startOffset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        int currentOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        int visiblePosition = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        TextHitInfo visiblePositionInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        rawFeedbacks.rewind();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        currentFeedback = rawFeedbacks.getNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        rawFeedbacks.unget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        while ((nextFeedback = rawFeedbacks.getNext()) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            if (visiblePosition == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                visiblePosition = nextFeedback & XIMVisibleMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                if (visiblePosition != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                    int index = rawFeedbacks.getOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                    if (visiblePosition == XIMVisibleToBackward)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                        visiblePositionInfo = TextHitInfo.leading(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                        visiblePositionInfo = TextHitInfo.trailing(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            nextFeedback &= ~XIMVisibleMask;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
            if (currentFeedback != nextFeedback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                rawFeedbacks.unget();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                currentOffset = rawFeedbacks.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                inputText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                                       convertVisualFeedbackToHighlight(currentFeedback),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                                       composedOffset + startOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
                                       composedOffset + currentOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                startOffset = currentOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                currentFeedback = nextFeedback;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        currentOffset = rawFeedbacks.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        if (currentOffset >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
            inputText.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                                   convertVisualFeedbackToHighlight(currentFeedback),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                                   composedOffset + startOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
                                   composedOffset + currentOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                             inputText.getIterator(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                             composedOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                             TextHitInfo.leading(caretPosition),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                             visiblePositionInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                             when);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * Flushes composed and committed text held in this context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * This method is invoked in the AWT Toolkit (X event loop) thread context
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * and thus inside the AWT Lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    // NOTE: This method may be called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
    //       This functionality is implemented in a package-private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    //       to insure that it cannot be overridden by client subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    void flushText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
        String flush = (committedText != null ? committedText : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        if (composedText != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            flush += composedText.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        if (!flush.equals("")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            AttributedString attrstr = new AttributedString(flush);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                                 attrstr.getIterator(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                                 flush.length(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                                 null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                                 EventQueue.getMostRecentEventTime());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * Subclasses should override disposeImpl() instead of dispose(). Client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * code should always invoke dispose(), never disposeImpl().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
    protected synchronized void disposeImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        disposeXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
        composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        committedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        rawFeedbacks = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
        awtFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        lastXICFocussedComponent = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * Frees all X Window resources associated with this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * @see java.awt.im.spi.InputMethod#dispose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    public final void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        boolean call_disposeImpl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        if (!disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                if (!disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                    disposed = call_disposeImpl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        if (call_disposeImpl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
            disposeImpl();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * Returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * @see java.awt.im.spi.InputMethod#getControlObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    public Object getControlObject() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @see java.awt.im.spi.InputMethod#removeNotify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    public synchronized void removeNotify() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * @see java.awt.im.spi.InputMethod#setCompositionEnabled(boolean)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    public void setCompositionEnabled(boolean enable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        /* If the composition state is successfully changed, set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
           the savedCompositionState to 'enable'. Otherwise, simply
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
           return.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
           setCompositionEnabledNative may throw UnsupportedOperationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
           Don't try to catch it since the method may be called by clients.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
           Use package private mthod 'resetCompositionState' if you want the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
           exception to be caught.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        if (setCompositionEnabledNative(enable)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            savedCompositionState = enable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @see java.awt.im.spi.InputMethod#isCompositionEnabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
    public boolean isCompositionEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
        /* isCompositionEnabledNative may throw UnsupportedOperationException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
           Don't try to catch it since this method may be called by clients.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
           Use package private method 'getCompositionState' if you want the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
           exception to be caught.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        return isCompositionEnabledNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     * Ends any input composition that may currently be going on in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * context. Depending on the platform and possibly user preferences,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * this may commit or delete uncommitted text. Any changes to the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * are communicated to the active component using an input method event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * A text editing component may call this in a variety of situations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * for example, when the user moves the insertion point within the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * (but outside the composed text), or when the component's text is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * saved to a file or copied to the clipboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    public void endComposition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
        if (disposed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
        /* Before calling resetXIC, record the current composition mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
           so that it can be restored later. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        savedCompositionState = getCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
        boolean active = haveActiveClient();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
        if (active && composedText == null && committedText == null){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
            needResetXIC = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            needResetXICClient = getClientComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        String text = resetXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        /* needResetXIC is only set to true for active client. So passive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
           client should not reset the flag to false. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        if (active) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            needResetXIC = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        // Remove any existing composed text by posting an InputMethodEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        // with null composed text.  It would be desirable to wait for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        // dispatchComposedText call from X input method engine, but some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        // input method does not conform to the XIM specification and does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        // not call the preedit callback to erase preedit text on calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        // XmbResetIC.  To work around this problem, do it here by ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        composedText = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        postInputMethodEvent(InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                             null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
                             0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
                             null,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
                             null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
        if (text != null && text.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
            dispatchCommittedText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        // Restore the preedit state if it was enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        if (savedCompositionState) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            resetCompositionState();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * Returns a string with information about the current input method server, or null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * On both Linux & SunOS, the value of environment variable XMODIFIERS is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * returned if set. Otherwise, on SunOS, $HOME/.dtprofile will be parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * to find out the language service engine (atok or wnn) since there is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     * no API in Xlib which returns the information of native
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * IM server or language service and we want to try our best to return as much
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * information as possible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Note: This method could return null on Linux if XMODIFIERS is not set properly or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * if any IOException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * See man page of XSetLocaleModifiers(3X11) for the usgae of XMODIFIERS,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * atok12setup(1) and wnn6setup(1) for the information written to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * $HOME/.dtprofile when you run these two commands.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
    public String getNativeInputMethodInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
        String xmodifiers = System.getenv("XMODIFIERS");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        String imInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
        // If XMODIFIERS is set, return the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
        if (xmodifiers != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            int imIndex = xmodifiers.indexOf("@im=");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            if (imIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                imInfo = xmodifiers.substring(imIndex + 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        } else if (System.getProperty("os.name").startsWith("SunOS")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
            File dtprofile = new File(System.getProperty("user.home") +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                                      "/.dtprofile");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            String languageEngineInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
                BufferedReader br = new BufferedReader(new FileReader(dtprofile));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
                String line = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
                while ( languageEngineInfo == null && (line = br.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
                    if (line.contains("atok") || line.contains("wnn")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
                        StringTokenizer tokens =  new StringTokenizer(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
                        while (tokens.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                            String token = tokens.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                            if (Pattern.matches("atok.*setup", token) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                                Pattern.matches("wnn.*setup", token)){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                                languageEngineInfo = token.substring(0, token.indexOf("setup"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                br.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            } catch(IOException ioex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                // Since this method is provided for internal testing only,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                // we dump the stack trace for the ease of debugging.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                ioex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
            imInfo = "htt " + languageEngineInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        return imInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * Performs mapping from an XIM visible feedback value to Java IM highlight.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * @return Java input method highlight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    private InputMethodHighlight convertVisualFeedbackToHighlight(int feedback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        InputMethodHighlight highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
        switch (feedback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        case XIMUnderline:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
            highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        case XIMReverse:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        case XIMHighlight:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        case XIMPrimary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
            highlight = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        case XIMSecondary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            highlight = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        case XIMTertiary:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
            highlight = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        return highlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    // initial capacity size for string buffer, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
    private static final int INITIAL_SIZE = 64;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * IntBuffer is an inner class that manipulates an int array and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * provides UNIX file io stream-like programming interfaces to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * access it. (An alternative would be to use ArrayList which may
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * be too expensive for the work.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    private final class IntBuffer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        private int[] intArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        private int size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        private int index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        IntBuffer(int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            intArray = new int[initialCapacity];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        void insert(int offset, int[] values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            int newSize = size + values.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            if (intArray.length < newSize) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                int[] newIntArray = new int[newSize * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                System.arraycopy(intArray, 0, newIntArray, 0, size);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                intArray = newIntArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            System.arraycopy(intArray, offset, intArray, offset+values.length,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                             size - offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            System.arraycopy(values, 0, intArray, offset, values.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            size += values.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            if (index > offset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                index = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        void remove(int offset, int length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            if (offset + length != size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                System.arraycopy(intArray, offset+length, intArray, offset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                                 size - offset - length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            size -= length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            if (index > offset)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                index = offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        void replace(int offset, int[] values) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            System.arraycopy(values, 0, intArray, offset, values.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        void rewind() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            index = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
        int getNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            if (index == size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            return intArray[index++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        void unget() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            if (index != 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                index--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        int getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            return index;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            StringBuffer s = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            for (int i = 0; i < size;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                s.append(intArray[i++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                if (i < size)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                    s.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            return s.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * Native methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    protected native String resetXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
    private native void disposeXIC();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    private native boolean setCompositionEnabledNative(boolean enable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
    private native boolean isCompositionEnabledNative();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
    private native void turnoffStatusWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
}