Back to index

im-sdk  12.3.91
CompositeWindow.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.awt.*;
00047 import java.awt.im.*;
00048 import java.awt.font.*;
00049 import com.sun.iiim.*;
00050 
00051 // If the style for Window is mixture window
00052 // Then we will mix StatusWindow with LookupChoiceWindow
00053 class CompositeWindow extends IIIMWindow implements IIIMLookupListener , 
00054 IIIMStatusListener {
00055     private String style;
00056 
00057     int columHeight, columWidth;
00058     FontMetrics fm;    
00059     
00060     LookupPane lookupPane;
00061     StatusPane statusPane;
00062     
00063     int offset = 24;
00064     
00065     // Default, no-arg constructor
00066     public CompositeWindow() {
00067        // Add the LookupChoiceWindow and StatusWindow
00068        style = Manager.getProperty("iiimf.preedit.style");
00069        
00070        init();
00071     }
00072     
00073     void init() {
00074         window = new Dialog(new Frame(""));
00075         ((Dialog)window).setResizable(true);
00076         ((Dialog)window).setTitle("Input Window");
00077         
00078        Font font = new Font("Monospaced", Font.PLAIN, 12);
00079        
00080        fm = window.getFontMetrics(font);
00081         int fontHeight = fm.getHeight();
00082         int fontWidth = fm.getMaxAdvance();
00083         int fontAscent = fm.getAscent();
00084         columWidth = fontWidth ;
00085         columHeight = fontHeight + 2;
00086               
00087         window.setFont(font);
00088         
00089         lookupPane = new LookupPane();
00090         window.add(lookupPane);
00091         statusPane = new StatusPane();
00092         window.add(statusPane);
00093         
00094         window.pack();        
00095     }
00096     
00097     public void setStyle(String style) {
00098         this.style = style;
00099     }
00100     
00101     public String getStyle() {
00102         return style;
00103     }
00104         
00105     public void setLocation(int x, int y) {
00106         window.setLocation(x,y);
00107     }
00108     
00109     public void calculatePosition() {
00110         Component component = getClientComponent();
00111         
00112         Component frame = component;
00113         Insets inset = window.getInsets();
00114         
00115         while(!(frame instanceof Frame)) frame = frame.getParent();
00116         
00117         if(style.equals("BELOWSPOT") 
00118             && component instanceof InputMethodRequests) {
00119                 Rectangle rect = 
00120                     ((InputMethodRequests)component).getTextLocation(TextHitInfo.leading(0));
00121                 Point point = new Point();
00122                 point.x = rect.x;
00123                 point.y = rect.x + (int)rect.getHeight() + offset;
00124                 // Leave space for Preedit window
00125                 point.y += (inset.top + inset.bottom + fm.getHeight());
00126                 window.setLocation(point);                 
00127         }
00128         else {
00129             // For "ROOTWINDOW" style and component isn't InputMethodRequests
00130             // Place the window on the left-corner of client component
00131             
00132             Point point = frame.getLocation();
00133             Dimension size = frame.getSize();     
00134 
00135             double x = point.getX();
00136             // It must leave the position for PreeditWindow
00137             double y = point.getY() + size.getHeight() 
00138                 + inset.top + inset.bottom + fm.getHeight();
00139             
00140             window.setLocation((int)x, (int)y);        
00141         }                
00142     }
00143     
00144     // Listener method
00145     public void lookupStart(IIIMLookupEvent e) {}
00146     public void lookupDone(IIIMLookupEvent e) {}
00147     public void lookupDraw(IIIMLookupEvent e) {}
00148     public void lookupProcess(IIIMLookupEvent e) {}
00149 
00150     public void dispatchEvent(IIIMLookupEvent e) {
00151         lookupPane.handleEvent(e);
00152         window.doLayout();
00153         window.show();
00154     }
00155     
00156     public void statusStart(IIIMStatusEvent e) {}
00157     public void statusDone(IIIMStatusEvent e) {}
00158     public void statusDraw(IIIMStatusEvent e) {}
00159 
00160     public void dispatchEvent(IIIMStatusEvent e) {
00161         statusPane.handleEvent(e);
00162         window.doLayout();
00163         window.show();
00164     }
00165 
00166 }