home *** CD-ROM | disk | FTP | other *** search
- package sun.awt.windows;
-
- import java.awt.AWTEvent;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.event.ComponentEvent;
- import java.awt.event.InputMethodEvent;
- import java.awt.font.TextAttribute;
- import java.awt.font.TextHitInfo;
- import java.awt.im.InputMethodHighlight;
- import java.awt.im.InputSubset;
- import java.awt.im.spi.InputMethodContext;
- import java.awt.peer.ComponentPeer;
- import java.awt.peer.LightweightPeer;
- import java.lang.Character.UnicodeBlock;
- import java.text.Annotation;
- import java.text.AttributedCharacterIterator;
- import java.text.AttributedString;
- import java.text.AttributedCharacterIterator.Attribute;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.Locale;
- import java.util.Map;
- import sun.awt.SunToolkit;
- import sun.awt.im.InputMethodAdapter;
-
- public class WInputMethod extends InputMethodAdapter {
- private InputMethodContext inputContext;
- private Component awtFocussedComponent;
- private WComponentPeer awtFocussedComponentPeer;
- private boolean isActive;
- private int context = this.createNativeContext();
- private boolean open;
- private int cmode;
- private Locale currentLocale;
- public static final byte ATTR_INPUT = 0;
- public static final byte ATTR_TARGET_CONVERTED = 1;
- public static final byte ATTR_CONVERTED = 2;
- public static final byte ATTR_TARGET_NOTCONVERTED = 3;
- public static final byte ATTR_INPUT_ERROR = 4;
- public static final int IME_CMODE_ALPHANUMERIC = 0;
- public static final int IME_CMODE_NATIVE = 1;
- public static final int IME_CMODE_KATAKANA = 2;
- public static final int IME_CMODE_LANGUAGE = 3;
- public static final int IME_CMODE_FULLSHAPE = 8;
- public static final int IME_CMODE_HANJACONVERT = 64;
- public static final int IME_CMODE_ROMAN = 16;
- private static final boolean COMMIT_INPUT = true;
- private static final boolean DISCARD_INPUT = false;
- private static Map[] highlightStyles;
-
- public WInputMethod() {
- this.cmode = this.getConversionStatus(this.context);
- this.open = this.getOpenStatus(this.context);
- this.currentLocale = this.getNativeLocale();
- if (this.currentLocale == null) {
- this.currentLocale = Locale.getDefault();
- }
-
- }
-
- protected void finalize() throws Throwable {
- synchronized(this) {
- if (this.context != 0) {
- this.destroyNativeContext(this.context);
- this.context = 0;
- }
- }
-
- super.finalize();
- }
-
- public synchronized void setInputMethodContext(InputMethodContext var1) {
- this.inputContext = var1;
- }
-
- public final void dispose() {
- }
-
- public Object getControlObject() {
- return null;
- }
-
- public boolean setLocale(Locale var1) {
- return this.setLocale(var1, false);
- }
-
- private boolean setLocale(Locale var1, boolean var2) {
- Locale[] var3 = WInputMethodDescriptor.availableLocales;
-
- for(int var4 = 0; var4 < var3.length; ++var4) {
- Locale var5 = var3[var4];
- if (var1.equals(var5) || var5.equals(Locale.JAPAN) && var1.equals(Locale.JAPANESE) || var5.equals(Locale.KOREA) && var1.equals(Locale.KOREAN)) {
- if (this.isActive) {
- this.setNativeLocale(var5.toString(), var2);
- }
-
- this.currentLocale = var5;
- return true;
- }
- }
-
- return false;
- }
-
- public Locale getLocale() {
- if (this.isActive) {
- this.currentLocale = this.getNativeLocale();
- if (this.currentLocale == null) {
- this.currentLocale = Locale.getDefault();
- }
- }
-
- return this.currentLocale;
- }
-
- public void setCharacterSubsets(Character.Subset[] var1) {
- if (var1 == null) {
- this.setConversionStatus(this.context, this.cmode);
- this.setOpenStatus(this.context, this.open);
- } else {
- Character.Subset var2 = var1[0];
- Locale var3 = this.getNativeLocale();
- if (var3 != null) {
- if (var3.getLanguage().equals(Locale.JAPANESE.getLanguage())) {
- if (var2 != UnicodeBlock.BASIC_LATIN && var2 != InputSubset.LATIN_DIGITS) {
- byte var4;
- if (var2 != UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS && var2 != InputSubset.KANJI && var2 != UnicodeBlock.HIRAGANA) {
- if (var2 == UnicodeBlock.KATAKANA) {
- var4 = 11;
- } else if (var2 == InputSubset.HALFWIDTH_KATAKANA) {
- var4 = 3;
- } else {
- if (var2 != InputSubset.FULLWIDTH_LATIN) {
- return;
- }
-
- var4 = 8;
- }
- } else {
- var4 = 9;
- }
-
- this.setOpenStatus(this.context, true);
- var4 |= this.getConversionStatus(this.context) & 16;
- this.setConversionStatus(this.context, var4);
- } else {
- this.setOpenStatus(this.context, false);
- }
- } else if (var3.getLanguage().equals(Locale.KOREAN.getLanguage())) {
- if (var2 != UnicodeBlock.BASIC_LATIN && var2 != InputSubset.LATIN_DIGITS) {
- byte var6;
- if (var2 != UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS && var2 != InputSubset.HANJA && var2 != UnicodeBlock.HANGUL_SYLLABLES && var2 != UnicodeBlock.HANGUL_JAMO && var2 != UnicodeBlock.HANGUL_COMPATIBILITY_JAMO) {
- if (var2 != InputSubset.FULLWIDTH_LATIN) {
- return;
- }
-
- var6 = 8;
- } else {
- var6 = 1;
- }
-
- this.setOpenStatus(this.context, true);
- this.setConversionStatus(this.context, var6);
- } else {
- this.setOpenStatus(this.context, false);
- }
- } else if (var3.getLanguage().equals(Locale.CHINESE.getLanguage())) {
- if (var2 != UnicodeBlock.BASIC_LATIN && var2 != InputSubset.LATIN_DIGITS) {
- byte var7;
- if (var2 != UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS && var2 != InputSubset.TRADITIONAL_HANZI && var2 != InputSubset.SIMPLIFIED_HANZI) {
- if (var2 != InputSubset.FULLWIDTH_LATIN) {
- return;
- }
-
- var7 = 8;
- } else {
- var7 = 1;
- }
-
- this.setOpenStatus(this.context, true);
- this.setConversionStatus(this.context, var7);
- } else {
- this.setOpenStatus(this.context, false);
- }
- }
-
- }
- }
- }
-
- public void dispatchEvent(AWTEvent var1) {
- if (var1 instanceof ComponentEvent) {
- Component var2 = ((ComponentEvent)var1).getComponent();
- if (var2 == this.awtFocussedComponent) {
- if (this.awtFocussedComponentPeer.isDisposed()) {
- this.awtFocussedComponentPeer = this.getNearestNativePeer(var2);
- }
-
- if (this.awtFocussedComponentPeer != null) {
- this.handleNativeIMEEvent(this.awtFocussedComponentPeer, var1);
- }
- }
- }
-
- }
-
- public void activate() {
- if (this.awtFocussedComponentPeer != null) {
- this.enableNativeIME(this.awtFocussedComponentPeer, this.context, !((InputMethodAdapter)this).haveActiveClient());
- }
-
- this.isActive = true;
- this.setLocale(this.currentLocale, true);
- }
-
- public void deactivate(boolean var1) {
- this.getLocale();
- if (this.awtFocussedComponentPeer != null) {
- this.disableNativeIME(this.awtFocussedComponentPeer);
- }
-
- this.isActive = false;
- }
-
- protected void setAWTFocussedComponent(Component var1) {
- if (var1 != null) {
- WComponentPeer var2 = this.getNearestNativePeer(var1);
- if (this.isActive) {
- if (this.awtFocussedComponentPeer != null) {
- this.disableNativeIME(this.awtFocussedComponentPeer);
- }
-
- if (var2 != null) {
- this.enableNativeIME(var2, this.context, !((InputMethodAdapter)this).haveActiveClient());
- }
- }
-
- this.awtFocussedComponent = var1;
- this.awtFocussedComponentPeer = var2;
- }
- }
-
- public void hideWindows() {
- if (this.awtFocussedComponentPeer != null) {
- this.hideWindowsNative(this.awtFocussedComponentPeer);
- }
-
- }
-
- public void removeNotify() {
- this.endCompositionNative(this.context, false);
- }
-
- static Map mapInputMethodHighlight(InputMethodHighlight var0) {
- int var2 = var0.getState();
- int var1;
- if (var2 == 0) {
- var1 = 0;
- } else {
- if (var2 != 1) {
- return null;
- }
-
- var1 = 2;
- }
-
- if (var0.isSelected()) {
- ++var1;
- }
-
- return highlightStyles[var1];
- }
-
- protected boolean supportsBelowTheSpot() {
- return true;
- }
-
- public void endComposition() {
- this.endCompositionNative(this.context, ((InputMethodAdapter)this).haveActiveClient());
- }
-
- public void setCompositionEnabled(boolean var1) {
- this.setOpenStatus(this.context, var1);
- }
-
- public boolean isCompositionEnabled() {
- return this.getOpenStatus(this.context);
- }
-
- public void sendInputMethodEvent(int var1, String var2, int[] var3, String[] var4, int[] var5, byte[] var6, int var7, int var8, int var9) {
- AttributedCharacterIterator var10 = null;
- if (var2 != null) {
- AttributedString var11 = new AttributedString(var2);
- var11.addAttribute(Attribute.LANGUAGE, Locale.getDefault(), 0, var2.length());
- if (var3 != null && var4 != null && var4.length != 0 && var3.length == var4.length + 1 && var3[0] == 0 && var3[var4.length] == var2.length()) {
- for(int var12 = 0; var12 < var3.length - 1; ++var12) {
- var11.addAttribute(Attribute.INPUT_METHOD_SEGMENT, new Annotation((Object)null), var3[var12], var3[var12 + 1]);
- var11.addAttribute(Attribute.READING, new Annotation(var4[var12]), var3[var12], var3[var12 + 1]);
- }
- } else {
- var11.addAttribute(Attribute.INPUT_METHOD_SEGMENT, new Annotation((Object)null), 0, var2.length());
- var11.addAttribute(Attribute.READING, new Annotation(new String("")), 0, var2.length());
- }
-
- if (var5 != null && var6 != null && var6.length != 0 && var5.length == var6.length + 1 && var5[0] == 0 && var5[var6.length] == var2.length()) {
- for(int var15 = 0; var15 < var5.length - 1; ++var15) {
- InputMethodHighlight var13;
- switch (var6[var15]) {
- case 0:
- case 4:
- default:
- var13 = InputMethodHighlight.UNSELECTED_RAW_TEXT_HIGHLIGHT;
- break;
- case 1:
- var13 = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
- break;
- case 2:
- var13 = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
- break;
- case 3:
- var13 = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
- }
-
- var11.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, var13, var5[var15], var5[var15 + 1]);
- }
- } else {
- var11.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT, 0, var2.length());
- }
-
- var10 = var11.getIterator();
- }
-
- Component var14 = ((InputMethodAdapter)this).getClientComponent();
- if (var14 != null) {
- InputMethodEvent var16 = new InputMethodEvent(var14, var1, var10, var7, TextHitInfo.leading(var8), TextHitInfo.leading(var9));
- SunToolkit.postEvent(SunToolkit.targetToAppContext(var14), var16);
- }
- }
-
- public Point inquireCandidatePosition() {
- Component var1 = ((InputMethodAdapter)this).getClientComponent();
- if (var1 == null) {
- return new Point(0, 0);
- } else if (((InputMethodAdapter)this).haveActiveClient()) {
- Rectangle var4 = this.inputContext.getTextLocation(TextHitInfo.leading(0));
- return new Point(var4.x, var4.y + var4.height);
- } else {
- Point var2 = var1.getLocationOnScreen();
- Dimension var3 = var1.getSize();
- return new Point(var2.x, var2.y + var3.height);
- }
- }
-
- private WComponentPeer getNearestNativePeer(Component var1) {
- if (var1 == null) {
- return null;
- } else {
- ComponentPeer var2 = ((Component)var1).getPeer();
- if (var2 == null) {
- return null;
- } else {
- while(var2 instanceof LightweightPeer) {
- var1 = ((Component)var1).getParent();
- if (var1 == null) {
- return null;
- }
-
- var2 = ((Component)var1).getPeer();
- if (var2 == null) {
- return null;
- }
- }
-
- return var2 instanceof WComponentPeer ? (WComponentPeer)var2 : null;
- }
- }
- }
-
- private native int createNativeContext();
-
- private native void destroyNativeContext(int var1);
-
- private native void enableNativeIME(WComponentPeer var1, int var2, boolean var3);
-
- private native void disableNativeIME(WComponentPeer var1);
-
- private native void handleNativeIMEEvent(WComponentPeer var1, AWTEvent var2);
-
- private native void endCompositionNative(int var1, boolean var2);
-
- private native void setConversionStatus(int var1, int var2);
-
- private native int getConversionStatus(int var1);
-
- private native void setOpenStatus(int var1, boolean var2);
-
- private native boolean getOpenStatus(int var1);
-
- private native Locale getNativeLocale();
-
- private native boolean setNativeLocale(String var1, boolean var2);
-
- private native void hideWindowsNative(WComponentPeer var1);
-
- static {
- Map[] var0 = new Map[4];
- HashMap var1 = new HashMap(1);
- var1.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED);
- var0[0] = Collections.unmodifiableMap(var1);
- var1 = new HashMap(1);
- var1.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_GRAY);
- var0[1] = Collections.unmodifiableMap(var1);
- var1 = new HashMap(1);
- var1.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED);
- var0[2] = Collections.unmodifiableMap(var1);
- var1 = new HashMap(4);
- Color var2 = new Color(0, 0, 128);
- var1.put(TextAttribute.FOREGROUND, var2);
- var1.put(TextAttribute.BACKGROUND, Color.white);
- var1.put(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON);
- var1.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
- var0[3] = Collections.unmodifiableMap(var1);
- highlightStyles = var0;
- }
- }
-