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 / im / InputMethodContext.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  4.5 KB  |  171 lines

  1. package sun.awt.im;
  2.  
  3. import java.awt.AWTEvent;
  4. import java.awt.Component;
  5. import java.awt.Rectangle;
  6. import java.awt.Toolkit;
  7. import java.awt.Window;
  8. import java.awt.event.InputMethodEvent;
  9. import java.awt.event.KeyEvent;
  10. import java.awt.font.TextHitInfo;
  11. import java.awt.im.InputMethodRequests;
  12. import java.awt.im.spi.InputMethod;
  13. import java.security.AccessController;
  14. import java.text.AttributedCharacterIterator;
  15. import java.text.AttributedString;
  16. import java.util.EventObject;
  17. import sun.awt.SunToolkit;
  18. import sun.security.action.GetPropertyAction;
  19.  
  20. public class InputMethodContext extends InputContext implements java.awt.im.spi.InputMethodContext {
  21.    private boolean dispatchingCommittedText;
  22.    private CompositionAreaHandler compositionAreaHandler;
  23.    private static boolean belowTheSpotInputRequested;
  24.    private boolean inputMethodSupportsBelowTheSpot;
  25.  
  26.    void setInputMethodSupportsBelowTheSpot(boolean var1) {
  27.       this.inputMethodSupportsBelowTheSpot = var1;
  28.    }
  29.  
  30.    private boolean useBelowTheSpotInput() {
  31.       return belowTheSpotInputRequested && this.inputMethodSupportsBelowTheSpot;
  32.    }
  33.  
  34.    private boolean haveActiveClient() {
  35.       Component var1 = ((InputContext)this).getClientComponent();
  36.       return var1 != null && var1.getInputMethodRequests() != null;
  37.    }
  38.  
  39.    public void dispatchInputMethodEvent(int var1, AttributedCharacterIterator var2, int var3, TextHitInfo var4, TextHitInfo var5) {
  40.       Component var6 = ((InputContext)this).getClientComponent();
  41.       InputMethodEvent var7 = new InputMethodEvent(var6, var1, var2, var3, var4, var5);
  42.       if (this.haveActiveClient() && !this.useBelowTheSpotInput()) {
  43.          var6.dispatchEvent(var7);
  44.       } else {
  45.          this.getCompositionAreaHandler(true).processInputMethodEvent(var7);
  46.       }
  47.  
  48.    }
  49.  
  50.    synchronized void dispatchCommittedText(Component var1, AttributedCharacterIterator var2, int var3) {
  51.       if (var3 != 0 && var2.getEndIndex() > var2.getBeginIndex()) {
  52.          long var4 = System.currentTimeMillis();
  53.          this.dispatchingCommittedText = true;
  54.  
  55.          try {
  56.             InputMethodRequests var6 = var1.getInputMethodRequests();
  57.             if (var6 != null) {
  58.                int var7 = var2.getBeginIndex();
  59.                AttributedCharacterIterator var8 = (new AttributedString(var2, var7, var7 + var3)).getIterator();
  60.                InputMethodEvent var9 = new InputMethodEvent(var1, 1100, var8, var3, (TextHitInfo)null, (TextHitInfo)null);
  61.                var1.dispatchEvent(var9);
  62.             } else {
  63.                for(char var14 = var2.first(); var3-- > 0 && var14 != '\uffff'; var14 = var2.next()) {
  64.                   KeyEvent var15 = new KeyEvent(var1, 400, var4, 0, 0, var14);
  65.                   var1.dispatchEvent(var15);
  66.                }
  67.             }
  68.          } finally {
  69.             this.dispatchingCommittedText = false;
  70.          }
  71.  
  72.       }
  73.    }
  74.  
  75.    public void dispatchEvent(AWTEvent var1) {
  76.       if (var1 instanceof InputMethodEvent) {
  77.          if (((Component)((EventObject)var1).getSource()).getInputMethodRequests() == null || this.useBelowTheSpotInput() && !this.dispatchingCommittedText) {
  78.             this.getCompositionAreaHandler(true).processInputMethodEvent((InputMethodEvent)var1);
  79.          }
  80.       } else if (!this.dispatchingCommittedText) {
  81.          super.dispatchEvent(var1);
  82.       }
  83.  
  84.    }
  85.  
  86.    private synchronized CompositionAreaHandler getCompositionAreaHandler(boolean var1) {
  87.       if (this.compositionAreaHandler == null) {
  88.          this.compositionAreaHandler = new CompositionAreaHandler(this);
  89.       }
  90.  
  91.       this.compositionAreaHandler.setClientComponent(((InputContext)this).getClientComponent());
  92.       if (var1) {
  93.          this.compositionAreaHandler.grabCompositionArea(false);
  94.       }
  95.  
  96.       return this.compositionAreaHandler;
  97.    }
  98.  
  99.    synchronized void grabCompositionArea(boolean var1) {
  100.       if (this.compositionAreaHandler != null) {
  101.          this.compositionAreaHandler.grabCompositionArea(var1);
  102.       } else {
  103.          CompositionAreaHandler.closeCompositionArea();
  104.       }
  105.  
  106.    }
  107.  
  108.    synchronized void releaseCompositionArea() {
  109.       if (this.compositionAreaHandler != null) {
  110.          this.compositionAreaHandler.releaseCompositionArea();
  111.       }
  112.  
  113.    }
  114.  
  115.    public Rectangle getTextLocation(TextHitInfo var1) {
  116.       return this.getReq().getTextLocation(var1);
  117.    }
  118.  
  119.    public TextHitInfo getLocationOffset(int var1, int var2) {
  120.       return this.getReq().getLocationOffset(var1, var2);
  121.    }
  122.  
  123.    public int getInsertPositionOffset() {
  124.       return this.getReq().getInsertPositionOffset();
  125.    }
  126.  
  127.    public AttributedCharacterIterator getCommittedText(int var1, int var2, AttributedCharacterIterator.Attribute[] var3) {
  128.       return this.getReq().getCommittedText(var1, var2, var3);
  129.    }
  130.  
  131.    public int getCommittedTextLength() {
  132.       return this.getReq().getCommittedTextLength();
  133.    }
  134.  
  135.    public AttributedCharacterIterator cancelLatestCommittedText(AttributedCharacterIterator.Attribute[] var1) {
  136.       return this.getReq().cancelLatestCommittedText(var1);
  137.    }
  138.  
  139.    public AttributedCharacterIterator getSelectedText(AttributedCharacterIterator.Attribute[] var1) {
  140.       return this.getReq().getSelectedText(var1);
  141.    }
  142.  
  143.    private InputMethodRequests getReq() {
  144.       return (InputMethodRequests)(this.haveActiveClient() && !this.useBelowTheSpotInput() ? ((InputContext)this).getClientComponent().getInputMethodRequests() : this.getCompositionAreaHandler(false));
  145.    }
  146.  
  147.    public Window createInputMethodWindow(String var1, boolean var2) {
  148.       InputMethodContext var3 = var2 ? this : null;
  149.       return createInputMethodWindow(var1, var3);
  150.    }
  151.  
  152.    static Window createInputMethodWindow(String var0, InputContext var1) {
  153.       SunToolkit var2 = (SunToolkit)Toolkit.getDefaultToolkit();
  154.       return var2.createInputMethodWindow(var0, var1);
  155.    }
  156.  
  157.    public void enableClientWindowNotification(InputMethod var1, boolean var2) {
  158.       super.enableClientWindowNotification(var1, var2);
  159.    }
  160.  
  161.    static {
  162.       String var0 = (String)AccessController.doPrivileged(new GetPropertyAction("java.awt.im.style", (String)null));
  163.       if (var0 == null) {
  164.          Toolkit.getDefaultToolkit();
  165.          var0 = Toolkit.getProperty("java.awt.im.style", (String)null);
  166.       }
  167.  
  168.       belowTheSpotInputRequested = "below-the-spot".equals(var0);
  169.    }
  170. }
  171.