Back to index

im-sdk  12.3.91
IIIMPAdapter.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 import sun.awt.im.InputMethodContext;
00058 import com.sun.iiim.*;
00059 
00060 public class IIIMPAdapter extends sun.awt.im.InputMethodAdapter
00061        implements IIIMListener, IIIMPreeditListener,
00062                   IIIMCommittedListener {
00063 
00064     // private variables
00065     private static Manager manager;
00066     private Component currentClient;
00067 
00068     protected Component getClientComponent() {
00069        return currentClient;
00070     }
00071 
00072     // --------------------------------------------------------       
00073     // sun.awt.im.InputMethodAdapter implementation
00074     // --------------------------------------------------------
00075 
00079     public static Locale[] getAvailableLocales() {
00080        if (manager == null) {
00081            manager = Manager.getInstance();
00082        }
00083        Locale[] la = manager.getAvailableLocales();
00084        return la;
00085     }
00086 
00090     public boolean setLocale(Locale locale) {
00091        return manager.setLocale(locale);
00092     } 
00093 
00097     public void setCharacterSubsets(Subset[] subsets) {
00098        manager.setCharacterSubsets(subsets);
00099     }
00100 
00105     public synchronized void dispatchEvent(AWTEvent event) {
00106        if (event instanceof KeyEvent) {
00107            IIIMEvent e = new IIIMEvent(event);
00108            manager.dispatchEvent(e);
00109        }
00110     }
00111 
00112     private InputMethodContext imc;
00113 
00117     public void activate() {
00118        currentClient = super.getClientComponent();
00119        manager.setIIIMPAdapter(this);
00120        manager.setIIIMCommittedListener(this);
00121        if (preeditListener == null) {
00122            setPreeditListener(this);
00123        }
00124        if (statusListener == null) {
00125            setStatusListener(new StatusWindow());
00126        }
00127        if (lookupListener == null) {
00128            setLookupListener(new LookupWindow());
00129        }
00130        manager.setIIIMPreeditListener(preeditListener);
00131        manager.setIIIMStatusListener(statusListener);
00132        manager.setIIIMLookupListener(lookupListener);
00133        manager.activate();
00134     }
00135 
00139     public void deactivate(boolean isTemporary) {
00140        manager.deactivate(isTemporary);
00141     }
00142 
00146     public void removeNotify() {
00147        manager.removeNotify();
00148     }
00149 
00153     public void endComposition() {
00154        manager.endComposition();
00155     }
00156 
00160     public void dispose() {
00161        manager.dispose();
00162     }
00163 
00167     public Object getControlObject() {
00168        return manager.getControlObject();
00169     }
00170 
00171     private IIIMPreeditListener preeditListener;
00172     private static IIIMStatusListener statusListener;
00173     private IIIMLookupListener lookupListener;
00174 
00175     void setPreeditListener(IIIMPreeditListener l) {
00176        preeditListener = l;
00177     }
00178 
00179     void setStatusListener(IIIMStatusListener l) {
00180        statusListener = l;
00181     }
00182 
00183     void setLookupListener(IIIMLookupListener l) {
00184        lookupListener = l;
00185     }
00186 
00187     public IIIMPAdapter() {
00188        if (manager == null) {
00189            // set static member manager
00190            manager = Manager.getInstance();
00191        }
00192     }
00193 
00194     // --------------------------------------------------------       
00195     // sun.awt.im.iiimp.IIIMListener implementation
00196     // --------------------------------------------------------
00197 
00204     public void dispatchEvent(IIIMEvent e) {
00205     }
00206 
00207     // --------------------------------------------------------       
00208     // sun.awt.im.iiimp.IIIMPreeditListener implementation
00209     // --------------------------------------------------------
00210 
00215     public void preeditStart(IIIMPreeditEvent e) {}
00216     public void preeditDone(IIIMPreeditEvent e) {}
00217     public synchronized void preeditDraw(IIIMPreeditEvent e) {
00218        AttributedCharacterIterator iterator = e.getIterator();
00219        int pos = iterator.getEndIndex(); 
00220 
00221        inputContext.dispatchInputMethodEvent(InputMethodEvent.
00222                                          INPUT_METHOD_TEXT_CHANGED,
00223                                          iterator,
00224                                          0,
00225                                          TextHitInfo.leading(pos),
00226                                          null);
00227     }
00228 
00229     // --------------------------------------------------------       
00230     // sun.awt.im.iiimp.IIIMCommitedListener implementation
00231     // --------------------------------------------------------
00232 
00237     public void committedPerformed(IIIMCommittedEvent e) {
00238        String committed = e.getCommittedString();
00239        AttributedCharacterIterator iterator =
00240            new AttributedString(committed).getIterator();
00241 
00242        inputContext.dispatchInputMethodEvent(InputMethodEvent.
00243                                          INPUT_METHOD_TEXT_CHANGED,
00244                                          iterator,
00245                                          committed.length(),
00246                                          null,
00247                                          null);
00248     }
00249 }