home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / sun / awt / windows / WInputMethod.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  8.6 KB  |  430 lines

  1. package sun.awt.windows;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.Point;
  8. import java.awt.Rectangle;
  9. import java.awt.event.ComponentEvent;
  10. import java.awt.event.InputMethodEvent;
  11. import java.awt.font.TextAttribute;
  12. import java.awt.font.TextHitInfo;
  13. import java.awt.im.InputMethodHighlight;
  14. import java.awt.im.InputSubset;
  15. import java.awt.im.spi.InputMethodContext;
  16. import java.awt.peer.ComponentPeer;
  17. import java.awt.peer.LightweightPeer;
  18. import java.lang.Character.UnicodeBlock;
  19. import java.text.Annotation;
  20. import java.text.AttributedCharacterIterator;
  21. import java.text.AttributedString;
  22. import java.text.AttributedCharacterIterator.Attribute;
  23. import java.util.Collections;
  24. import java.util.HashMap;
  25. import java.util.Locale;
  26. import java.util.Map;
  27. import sun.awt.SunToolkit;
  28. import sun.awt.im.InputMethodAdapter;
  29.  
  30. public class WInputMethod extends InputMethodAdapter {
  31.    private InputMethodContext inputContext;
  32.    private Component awtFocussedComponent;
  33.    private WComponentPeer awtFocussedComponentPeer;
  34.    private boolean isActive;
  35.    private int context = this.createNativeContext();
  36.    private boolean open;
  37.    private int cmode;
  38.    private Locale currentLocale;
  39.    public static final byte ATTR_INPUT = 0;
  40.    public static final byte ATTR_TARGET_CONVERTED = 1;
  41.    public static final byte ATTR_CONVERTED = 2;
  42.    public static final byte ATTR_TARGET_NOTCONVERTED = 3;
  43.    public static final byte ATTR_INPUT_ERROR = 4;
  44.    public static final int IME_CMODE_ALPHANUMERIC = 0;
  45.    public static final int IME_CMODE_NATIVE = 1;
  46.    public static final int IME_CMODE_KATAKANA = 2;
  47.    public static final int IME_CMODE_LANGUAGE = 3;
  48.    public static final int IME_CMODE_FULLSHAPE = 8;
  49.    public static final int IME_CMODE_HANJACONVERT = 64;
  50.    public static final int IME_CMODE_ROMAN = 16;
  51.    private static final boolean COMMIT_INPUT = true;
  52.    private static final boolean DISCARD_INPUT = false;
  53.    private static Map[] highlightStyles;
  54.  
  55.    public WInputMethod() {
  56.       this.cmode = this.getConversionStatus(this.context);
  57.       this.open = this.getOpenStatus(this.context);
  58.       this.currentLocale = this.getNativeLocale();
  59.       if (this.currentLocale == null) {
  60.          this.currentLocale = Locale.getDefault();
  61.       }
  62.  
  63.    }
  64.  
  65.    protected void finalize() throws Throwable {
  66.       synchronized(this) {
  67.          if (this.context != 0) {
  68.             this.destroyNativeContext(this.context);
  69.             this.context = 0;
  70.          }
  71.       }
  72.  
  73.       super.finalize();
  74.    }
  75.  
  76.    public synchronized void setInputMethodContext(InputMethodContext var1) {
  77.       this.inputContext = var1;
  78.    }
  79.  
  80.    public final void dispose() {
  81.    }
  82.  
  83.    public Object getControlObject() {
  84.       return null;
  85.    }
  86.  
  87.    public boolean setLocale(Locale var1) {
  88.       return this.setLocale(var1, false);
  89.    }
  90.  
  91.    private boolean setLocale(Locale var1, boolean var2) {
  92.       Locale[] var3 = WInputMethodDescriptor.availableLocales;
  93.  
  94.       for(int var4 = 0; var4 < var3.length; ++var4) {
  95.          Locale var5 = var3[var4];
  96.          if (var1.equals(var5) || var5.equals(Locale.JAPAN) && var1.equals(Locale.JAPANESE) || var5.equals(Locale.KOREA) && var1.equals(Locale.KOREAN)) {
  97.             if (this.isActive) {
  98.                this.setNativeLocale(var5.toString(), var2);
  99.             }
  100.  
  101.             this.currentLocale = var5;
  102.             return true;
  103.          }
  104.       }
  105.  
  106.       return false;
  107.    }
  108.  
  109.    public Locale getLocale() {
  110.       if (this.isActive) {
  111.          this.currentLocale = this.getNativeLocale();
  112.          if (this.currentLocale == null) {
  113.             this.currentLocale = Locale.getDefault();
  114.          }
  115.       }
  116.  
  117.       return this.currentLocale;
  118.    }
  119.  
  120.    public void setCharacterSubsets(Character.Subset[] var1) {
  121.       if (var1 == null) {
  122.          this.setConversionStatus(this.context, this.cmode);
  123.          this.setOpenStatus(this.context, this.open);
  124.       } else {
  125.          Character.Subset var2 = var1[0];
  126.          Locale var3 = this.getNativeLocale();
  127.          if (var3 != null) {
  128.             if (var3.getLanguage().equals(Locale.JAPANESE.getLanguage())) {
  129.                if (var2 != UnicodeBlock.BASIC_LATIN && var2 != InputSubset.LATIN_DIGITS) {
  130.                   byte var4;
  131.                   if (var2 != UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS && var2 != InputSubset.KANJI && var2 != UnicodeBlock.HIRAGANA) {
  132.                      if (var2 == UnicodeBlock.KATAKANA) {
  133.                         var4 = 11;
  134.                      } else if (var2 == InputSubset.HALFWIDTH_KATAKANA) {
  135.                         var4 = 3;
  136.                      } else {
  137.                         if (var2 != InputSubset.FULLWIDTH_LATIN) {
  138.                            return;
  139.                         }
  140.  
  141.                         var4 = 8;
  142.                      }
  143.                   } else {
  144.                      var4 = 9;
  145.                   }
  146.  
  147.                   this.setOpenStatus(this.context, true);
  148.                   var4 |= this.getConversionStatus(this.context) & 16;
  149.                   this.setConversionStatus(this.context, var4);
  150.                } else {
  151.                   this.setOpenStatus(this.context, false);
  152.                }
  153.             } else if (var3.getLanguage().equals(Locale.KOREAN.getLanguage())) {
  154.                if (var2 != UnicodeBlock.BASIC_LATIN && var2 != InputSubset.LATIN_DIGITS) {
  155.                   byte var6;
  156.                   if (var2 != UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS && var2 != InputSubset.HANJA && var2 != UnicodeBlock.HANGUL_SYLLABLES && var2 != UnicodeBlock.HANGUL_JAMO && var2 != UnicodeBlock.HANGUL_COMPATIBILITY_JAMO) {
  157.                      if (var2 != InputSubset.FULLWIDTH_LATIN) {
  158.                         return;
  159.                      }
  160.  
  161.                      var6 = 8;
  162.                   } else {
  163.                      var6 = 1;
  164.                   }
  165.  
  166.                   this.setOpenStatus(this.context, true);
  167.                   this.setConversionStatus(this.context, var6);
  168.                } else {
  169.                   this.setOpenStatus(this.context, false);
  170.                }
  171.             } else if (var3.getLanguage().equals(Locale.CHINESE.getLanguage())) {
  172.                if (var2 != UnicodeBlock.BASIC_LATIN && var2 != InputSubset.LATIN_DIGITS) {
  173.                   byte var7;
  174.                   if (var2 != UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS && var2 != InputSubset.TRADITIONAL_HANZI && var2 != InputSubset.SIMPLIFIED_HANZI) {
  175.                      if (var2 != InputSubset.FULLWIDTH_LATIN) {
  176.                         return;
  177.                      }
  178.  
  179.                      var7 = 8;
  180.                   } else {
  181.                      var7 = 1;
  182.                   }
  183.  
  184.                   this.setOpenStatus(this.context, true);
  185.                   this.setConversionStatus(this.context, var7);
  186.                } else {
  187.                   this.setOpenStatus(this.context, false);
  188.                }
  189.             }
  190.  
  191.          }
  192.       }
  193.    }
  194.  
  195.    public void dispatchEvent(AWTEvent var1) {
  196.       if (var1 instanceof ComponentEvent) {
  197.          Component var2 = ((ComponentEvent)var1).getComponent();
  198.          if (var2 == this.awtFocussedComponent) {
  199.             if (this.awtFocussedComponentPeer.isDisposed()) {
  200.                this.awtFocussedComponentPeer = this.getNearestNativePeer(var2);
  201.             }
  202.  
  203.             if (this.awtFocussedComponentPeer != null) {
  204.                this.handleNativeIMEEvent(this.awtFocussedComponentPeer, var1);
  205.             }
  206.          }
  207.       }
  208.  
  209.    }
  210.  
  211.    public void activate() {
  212.       if (this.awtFocussedComponentPeer != null) {
  213.          this.enableNativeIME(this.awtFocussedComponentPeer, this.context, !((InputMethodAdapter)this).haveActiveClient());
  214.       }
  215.  
  216.       this.isActive = true;
  217.       this.setLocale(this.currentLocale, true);
  218.    }
  219.  
  220.    public void deactivate(boolean var1) {
  221.       this.getLocale();
  222.       if (this.awtFocussedComponentPeer != null) {
  223.          this.disableNativeIME(this.awtFocussedComponentPeer);
  224.       }
  225.  
  226.       this.isActive = false;
  227.    }
  228.  
  229.    protected void setAWTFocussedComponent(Component var1) {
  230.       if (var1 != null) {
  231.          WComponentPeer var2 = this.getNearestNativePeer(var1);
  232.          if (this.isActive) {
  233.             if (this.awtFocussedComponentPeer != null) {
  234.                this.disableNativeIME(this.awtFocussedComponentPeer);
  235.             }
  236.  
  237.             if (var2 != null) {
  238.                this.enableNativeIME(var2, this.context, !((InputMethodAdapter)this).haveActiveClient());
  239.             }
  240.          }
  241.  
  242.          this.awtFocussedComponent = var1;
  243.          this.awtFocussedComponentPeer = var2;
  244.       }
  245.    }
  246.  
  247.    public void hideWindows() {
  248.       if (this.awtFocussedComponentPeer != null) {
  249.          this.hideWindowsNative(this.awtFocussedComponentPeer);
  250.       }
  251.  
  252.    }
  253.  
  254.    public void removeNotify() {
  255.       this.endCompositionNative(this.context, false);
  256.    }
  257.  
  258.    static Map mapInputMethodHighlight(InputMethodHighlight var0) {
  259.       int var2 = var0.getState();
  260.       int var1;
  261.       if (var2 == 0) {
  262.          var1 = 0;
  263.       } else {
  264.          if (var2 != 1) {
  265.             return null;
  266.          }
  267.  
  268.          var1 = 2;
  269.       }
  270.  
  271.       if (var0.isSelected()) {
  272.          ++var1;
  273.       }
  274.  
  275.       return highlightStyles[var1];
  276.    }
  277.  
  278.    protected boolean supportsBelowTheSpot() {
  279.       return true;
  280.    }
  281.  
  282.    public void endComposition() {
  283.       this.endCompositionNative(this.context, ((InputMethodAdapter)this).haveActiveClient());
  284.    }
  285.  
  286.    public void setCompositionEnabled(boolean var1) {
  287.       this.setOpenStatus(this.context, var1);
  288.    }
  289.  
  290.    public boolean isCompositionEnabled() {
  291.       return this.getOpenStatus(this.context);
  292.    }
  293.  
  294.    public void sendInputMethodEvent(int var1, String var2, int[] var3, String[] var4, int[] var5, byte[] var6, int var7, int var8, int var9) {
  295.       AttributedCharacterIterator var10 = null;
  296.       if (var2 != null) {
  297.          AttributedString var11 = new AttributedString(var2);
  298.          var11.addAttribute(Attribute.LANGUAGE, Locale.getDefault(), 0, var2.length());
  299.          if (var3 != null && var4 != null && var4.length != 0 && var3.length == var4.length + 1 && var3[0] == 0 && var3[var4.length] == var2.length()) {
  300.             for(int var12 = 0; var12 < var3.length - 1; ++var12) {
  301.                var11.addAttribute(Attribute.INPUT_METHOD_SEGMENT, new Annotation((Object)null), var3[var12], var3[var12 + 1]);
  302.                var11.addAttribute(Attribute.READING, new Annotation(var4[var12]), var3[var12], var3[var12 + 1]);
  303.             }
  304.          } else {
  305.             var11.addAttribute(Attribute.INPUT_METHOD_SEGMENT, new Annotation((Object)null), 0, var2.length());
  306.             var11.addAttribute(Attribute.READING, new Annotation(new String("")), 0, var2.length());
  307.          }
  308.  
  309.          if (var5 != null && var6 != null && var6.length != 0 && var5.length == var6.length + 1 && var5[0] == 0 && var5[var6.length] == var2.length()) {
  310.             for(int var15 = 0; var15 < var5.length - 1; ++var15) {
  311.                InputMethodHighlight var13;
  312.                switch (var6[var15]) {
  313.                   case 0:
  314.                   case 4:
  315.                   default:
  316.                      var13 = InputMethodHighlight.UNSELECTED_RAW_TEXT_HIGHLIGHT;
  317.                      break;
  318.                   case 1:
  319.                      var13 = InputMethodHighlight.SELECTED_CONVERTED_TEXT_HIGHLIGHT;
  320.                      break;
  321.                   case 2:
  322.                      var13 = InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT;
  323.                      break;
  324.                   case 3:
  325.                      var13 = InputMethodHighlight.SELECTED_RAW_TEXT_HIGHLIGHT;
  326.                }
  327.  
  328.                var11.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, var13, var5[var15], var5[var15 + 1]);
  329.             }
  330.          } else {
  331.             var11.addAttribute(TextAttribute.INPUT_METHOD_HIGHLIGHT, InputMethodHighlight.UNSELECTED_CONVERTED_TEXT_HIGHLIGHT, 0, var2.length());
  332.          }
  333.  
  334.          var10 = var11.getIterator();
  335.       }
  336.  
  337.       Component var14 = ((InputMethodAdapter)this).getClientComponent();
  338.       if (var14 != null) {
  339.          InputMethodEvent var16 = new InputMethodEvent(var14, var1, var10, var7, TextHitInfo.leading(var8), TextHitInfo.leading(var9));
  340.          SunToolkit.postEvent(SunToolkit.targetToAppContext(var14), var16);
  341.       }
  342.    }
  343.  
  344.    public Point inquireCandidatePosition() {
  345.       Component var1 = ((InputMethodAdapter)this).getClientComponent();
  346.       if (var1 == null) {
  347.          return new Point(0, 0);
  348.       } else if (((InputMethodAdapter)this).haveActiveClient()) {
  349.          Rectangle var4 = this.inputContext.getTextLocation(TextHitInfo.leading(0));
  350.          return new Point(var4.x, var4.y + var4.height);
  351.       } else {
  352.          Point var2 = var1.getLocationOnScreen();
  353.          Dimension var3 = var1.getSize();
  354.          return new Point(var2.x, var2.y + var3.height);
  355.       }
  356.    }
  357.  
  358.    private WComponentPeer getNearestNativePeer(Component var1) {
  359.       if (var1 == null) {
  360.          return null;
  361.       } else {
  362.          ComponentPeer var2 = ((Component)var1).getPeer();
  363.          if (var2 == null) {
  364.             return null;
  365.          } else {
  366.             while(var2 instanceof LightweightPeer) {
  367.                var1 = ((Component)var1).getParent();
  368.                if (var1 == null) {
  369.                   return null;
  370.                }
  371.  
  372.                var2 = ((Component)var1).getPeer();
  373.                if (var2 == null) {
  374.                   return null;
  375.                }
  376.             }
  377.  
  378.             return var2 instanceof WComponentPeer ? (WComponentPeer)var2 : null;
  379.          }
  380.       }
  381.    }
  382.  
  383.    private native int createNativeContext();
  384.  
  385.    private native void destroyNativeContext(int var1);
  386.  
  387.    private native void enableNativeIME(WComponentPeer var1, int var2, boolean var3);
  388.  
  389.    private native void disableNativeIME(WComponentPeer var1);
  390.  
  391.    private native void handleNativeIMEEvent(WComponentPeer var1, AWTEvent var2);
  392.  
  393.    private native void endCompositionNative(int var1, boolean var2);
  394.  
  395.    private native void setConversionStatus(int var1, int var2);
  396.  
  397.    private native int getConversionStatus(int var1);
  398.  
  399.    private native void setOpenStatus(int var1, boolean var2);
  400.  
  401.    private native boolean getOpenStatus(int var1);
  402.  
  403.    private native Locale getNativeLocale();
  404.  
  405.    private native boolean setNativeLocale(String var1, boolean var2);
  406.  
  407.    private native void hideWindowsNative(WComponentPeer var1);
  408.  
  409.    static {
  410.       Map[] var0 = new Map[4];
  411.       HashMap var1 = new HashMap(1);
  412.       var1.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED);
  413.       var0[0] = Collections.unmodifiableMap(var1);
  414.       var1 = new HashMap(1);
  415.       var1.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_GRAY);
  416.       var0[1] = Collections.unmodifiableMap(var1);
  417.       var1 = new HashMap(1);
  418.       var1.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_DOTTED);
  419.       var0[2] = Collections.unmodifiableMap(var1);
  420.       var1 = new HashMap(4);
  421.       Color var2 = new Color(0, 0, 128);
  422.       var1.put(TextAttribute.FOREGROUND, var2);
  423.       var1.put(TextAttribute.BACKGROUND, Color.white);
  424.       var1.put(TextAttribute.SWAP_COLORS, TextAttribute.SWAP_COLORS_ON);
  425.       var1.put(TextAttribute.INPUT_METHOD_UNDERLINE, TextAttribute.UNDERLINE_LOW_ONE_PIXEL);
  426.       var0[3] = Collections.unmodifiableMap(var1);
  427.       highlightStyles = var0;
  428.    }
  429. }
  430.