Back to index

im-sdk  12.3.91
StatusWindow.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.text.*;
00048 import com.sun.iiim.*;
00049 
00050 class StatusWindow extends IIIMWindow implements IIIMStatusListener {
00051     static int xMargin;
00052     static int width;
00053     static int height;
00054     
00055     StatusPane pane;
00056     
00057     int columWidth, columHeight;
00058     FontMetrics fm;
00059     
00060     // Default, no arg constructor
00061     public StatusWindow() {
00062     }
00063     
00064     void init() {
00065         window = new Window(new Frame(""));
00066        window.enableInputMethods(false);        
00067        Font font = new Font("Monospaced", Font.PLAIN, 12);
00068        
00069         fm = window.getFontMetrics(font);
00070         int fontHeight = fm.getHeight();
00071         int fontWidth = fm.getMaxAdvance();
00072         int fontAscent = fm.getAscent();
00073         columWidth = fontWidth ;
00074         columHeight = fontHeight + 2;
00075               
00076         pane = new StatusPane();
00077         pane.setFont(font);
00078         
00079         window.add(pane);
00080     }
00081     
00082     /* These code causes focus flashing problem with Solaris JVM
00083        
00084     public void activate() {
00085         if (window == null) {
00086             return;
00087        }
00088        window.setVisible(true);
00089     }
00090 
00091     public void deactivate(boolean isTemporary) {
00092        if (window == null) {
00093            return;
00094        }
00095        window.setVisible(false);
00096     }
00097     */
00098 
00099     // StatusListener method
00100     public void statusStart(IIIMStatusEvent e) {
00101        if (window == null) {
00102            init();
00103        }
00104     }
00105 
00106     public void statusDone(IIIMStatusEvent e) {
00107        if (window != null) { 
00108            window.setVisible(false);
00109        }
00110     }
00111 
00112     public void statusDraw(IIIMStatusEvent e) {
00113        if (window == null) {
00114            return;
00115        }
00116        pane.handleEvent(e);
00117 
00118        if(pane.getData().length()==0) return;
00119        // "15" is the drawString space
00120        int width = pane.getData().length() * columWidth + 15;
00121        Insets inset = window.getInsets();
00122        int height = columHeight + inset.top + inset.bottom ;
00123         
00124        window.setSize(width, height);
00125         
00126        calculatePosition();
00127         
00128        window.setVisible(true);
00129     }
00130 
00131     public void setLocation(int x, int y) {
00132     }
00133     
00134     void calculatePosition() {
00135         double width = window.getSize().getWidth();
00136         
00137         Component component = getClientComponent();
00138 
00139         Component f = component;
00140         while(!(f instanceof Frame) && !(f instanceof Dialog)) {
00141             f = f.getParent();
00142         }
00143         
00144         Point point = f.getLocation();
00145         
00146         Dimension size = f.getSize();     
00147         
00148         double x = point.getX() + size.getWidth() - width;
00149         double y = point.getY() + size.getHeight();
00150         window.setLocation((int)x, (int)y);    
00151         // If window is out of screen, adjust it
00152         Point location = window.getLocation();
00153         double xl = location.getX();
00154         double yl = location.getY();
00155         Dimension dm = window.getSize();
00156         if((xl + dm.getWidth()) > screenWidth) 
00157             xl = screenWidth - dm.getWidth();
00158         if((yl + dm.getHeight()) > screenHeight) 
00159             yl = screenHeight - dm.getHeight();
00160         window.setLocation((int)xl, (int)yl);        
00161     }
00162     
00163 }