Back to index

im-sdk  12.3.91
IIIMFAdapter.java
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 
00043 
00044 package sun.awt.im.iiimp;
00045 
00046 import java.util.Locale;
00047 import java.lang.Character.Subset;
00048 import java.awt.Component;
00049 import java.awt.AWTEvent;
00050 import java.awt.EventQueue;
00051 import java.awt.event.KeyEvent;
00052 import java.awt.event.InputMethodEvent;
00053 import java.awt.font.TextHitInfo;
00054 import java.text.AttributedString;
00055 import java.text.AttributedCharacterIterator;
00056 import java.text.CharacterIterator;
00057 
00058 import java.awt.im.spi.InputMethod;
00059 import java.awt.im.spi.InputMethodContext;
00060 
00061 import com.sun.iiim.*;
00062 
00063 public class IIIMFAdapter extends sun.awt.im.InputMethodAdapter implements
00064        IIIMListener, IIIMPreeditListener, IIIMCommittedListener {
00065 
00066     // private variables
00067     private static Manager manager;
00068     private Component currentClient;
00069     private InputMethodContext inputMethodContext;
00070     private Locale locale;
00071     private IIIMPreeditListener preeditListener;
00072     private static IIIMStatusListener statusListener;
00073     private IIIMLookupListener lookupListener;
00074 
00075     public IIIMFAdapter() {
00076        manager = Manager.getInstance();
00077        locale = Locale.getDefault();
00078     }
00079 
00080     // --------------------------------------------------------
00081     // java.awt.im.spi.InputMethod implementation
00082     // --------------------------------------------------------
00083 
00087     public void activate() {
00088        currentClient = super.getClientComponent();
00089        manager.setIIIMFAdapter(this);
00090        manager.setIIIMCommittedListener(this);
00091        if (preeditListener == null) {
00092            setPreeditListener(this);
00093        }
00094        if (statusListener == null) {
00095            setStatusListener(new StatusWindow());
00096        }
00097        if (lookupListener == null) {
00098            setLookupListener(new LookupWindow());
00099        }
00100        manager.setIIIMPreeditListener(preeditListener);
00101        manager.setIIIMStatusListener(statusListener);
00102        manager.setIIIMLookupListener(lookupListener);
00103        manager.activate();
00104     }
00105 
00109     public void deactivate(boolean isTemporary) {
00110        manager.deactivate(isTemporary);
00111     }
00112 
00116     public synchronized void dispatchEvent(AWTEvent event) {
00117        if (event instanceof KeyEvent) {
00118            IIIMEvent e = new IIIMEvent(event);
00119            manager.dispatchEvent(e);
00120        }
00121     }
00122 
00126     public void dispose() {
00127        manager.dispose();
00128     }
00129 
00133     public void endComposition() {
00134        manager.endComposition();
00135     }
00136 
00140     public Object getControlObject() {
00141        return manager.getControlObject();
00142     }
00143 
00147     public Locale getLocale() {
00148        return locale;
00149     }
00150 
00155     public void hideWindows() {
00156     }
00157 
00161     public void removeNotify() {
00162        manager.removeNotify();
00163     }
00164     
00168     public void setCharacterSubsets(Subset[] subsets) {
00169        manager.setCharacterSubsets(subsets);
00170     }
00171 
00175     public void setInputMethodContext(InputMethodContext context) {
00176        inputMethodContext = context;
00177     }
00178 
00182     public boolean setLocale(Locale locale) {
00183        boolean b = manager.setLocale(locale);
00184        if (b) {
00185            this.locale = locale;
00186        }
00187        return b;
00188     }
00189 
00190     public void setCompositionEnabled(boolean enable) {
00191        throw new UnsupportedOperationException();
00192     }
00193 
00194     public boolean isCompositionEnabled() {
00195        throw new UnsupportedOperationException();
00196     }
00197        
00198 
00199     // -----------------------------------------------------------
00200 
00201     protected Component getClientComponent() {
00202        return currentClient;
00203     }
00204 
00205     void setPreeditListener(IIIMPreeditListener l) {
00206        preeditListener = l;
00207     }
00208 
00209     void setStatusListener(IIIMStatusListener l) {
00210        statusListener = l;
00211     }
00212 
00213     void setLookupListener(IIIMLookupListener l) {
00214        lookupListener = l;
00215     }
00216 
00217     // --------------------------------------------------------       
00218     // sun.awt.im.iiimp.IIIMListener implementation
00219     // --------------------------------------------------------
00220 
00227     public void dispatchEvent(IIIMEvent e) {
00228     }
00229 
00230     // --------------------------------------------------------       
00231     // sun.awt.im.iiimp.IIIMPreeditListener implementation
00232     // --------------------------------------------------------
00233 
00238     public void preeditStart(IIIMPreeditEvent e) {}
00239     public void preeditDone(IIIMPreeditEvent e) {}
00240     public synchronized void preeditDraw(IIIMPreeditEvent e) {
00241        AttributedCharacterIterator iterator = e.getIterator();
00242        int pos = iterator.getEndIndex(); 
00243 
00244        inputMethodContext.dispatchInputMethodEvent(InputMethodEvent.
00245                                          INPUT_METHOD_TEXT_CHANGED,
00246                                          iterator,
00247                                          0,
00248                                          TextHitInfo.leading(pos),
00249                                          null);
00250     }
00251 
00252     // --------------------------------------------------------       
00253     // sun.awt.im.iiimp.IIIMCommitedListener implementation
00254     // --------------------------------------------------------
00255 
00260     public void committedPerformed(IIIMCommittedEvent e) {
00261        String committed = e.getCommittedString();
00262        AttributedCharacterIterator iterator =
00263            new AttributedString(committed).getIterator();
00264 
00265        inputMethodContext.dispatchInputMethodEvent(InputMethodEvent.
00266                                          INPUT_METHOD_TEXT_CHANGED,
00267                                          iterator,
00268                                          committed.length(),
00269                                          null,
00270                                          null);
00271     }
00272 }