Back to index

wims  3.65+svn20090927
CloseDialog.java
Go to the documentation of this file.
00001 package rene.gui;
00002 
00003 import java.awt.*;
00004 import java.awt.event.*;
00005 import rene.dialogs.InfoDialog;
00006 
00016 public class CloseDialog extends Dialog
00017     implements WindowListener, ActionListener, DoActionListener, KeyListener,
00018     FocusListener
00019 {      boolean Dispose=true;
00020        public boolean Aborted=false;
00021        Frame F;      
00022        public String Subject="";
00023 
00024        public CloseDialog (Frame f, String s, boolean modal)
00025        {      super(f,s,modal);
00026               F=f;
00027               if (Global.ControlBackground!=null)
00028                      setBackground(Global.ControlBackground);
00029            addWindowListener(this);
00030            addKeyListener(this);
00031            addFocusListener(this);
00032        }
00033 
00034        public void windowActivated (WindowEvent e) {}
00035        public void windowClosed (WindowEvent e) {}
00036        public void windowClosing (WindowEvent e)
00037        {   if (close()) doclose();
00038        }
00039        public void windowDeactivated (WindowEvent e) {}
00040        public void windowDeiconified (WindowEvent e) {}
00041        public void windowIconified (WindowEvent e) {}
00042        public void windowOpened (WindowEvent e) {}
00043 
00047        public boolean close ()
00048        {      return true;
00049        }
00050 
00055        public boolean escape ()
00056        {      return close();
00057        }
00058        
00059        public ActionEvent E;
00060 
00061        public void actionPerformed (ActionEvent e)
00062        {   E=e;
00063               doAction(e.getActionCommand());
00064        }
00065        public void doAction (String o)
00066        {   if ("Close".equals(o) && close())
00067               {      Aborted=true;
00068                      doclose();
00069               }
00070               else if (o.equals("Help"))
00071               {      showHelp();
00072               }
00073        }
00074        
00075        public void showHelp ()
00076        {      InfoDialog.Subject=Subject;
00077               InfoDialog id=new InfoDialog(F);
00078        }
00079        
00080        public void itemAction (String o, boolean flag) {}
00081 
00082        public void keyPressed (KeyEvent e)
00083        {      if (e.getKeyCode()==KeyEvent.VK_ESCAPE && escape()) doclose();
00084        }
00085        public void keyReleased (KeyEvent e) {}
00086        public void keyTyped (KeyEvent e) {}
00087 
00092        public void doclose ()
00093        {      setVisible(false);
00094               // Because of a bug in Linux Java 1.4.2 etc.
00095               // dispose in a separate thread.
00096               Thread t=new Thread ()
00097               {      public void run ()
00098                      {      if (Dispose) dispose();
00099                      }
00100               };
00101               t.start();
00102        }
00103 
00104        public void center (Frame f)
00105        {      Dimension 
00106                      si=f.getSize(),
00107                      d=getSize(),
00108                      dscreen=getToolkit().getScreenSize();
00109               Point lo=f.getLocation();
00110               int x=lo.x+si.width/2-d.width/2;
00111               int y=lo.y+si.height/2-d.height/2;
00112               if (x+d.width>dscreen.width) x=dscreen.width-d.width-10;
00113               if (x<10) x=10;
00114               if (y+d.height>dscreen.height) y=dscreen.height-d.height-10;
00115               if (y<10) y=10;
00116               setLocation(x,y);
00117        }
00118        static public void center (Frame f, Dialog dialog)
00119        {      Dimension 
00120                      si=f.getSize(),
00121                      d=dialog.getSize(),
00122                      dscreen=f.getToolkit().getScreenSize();
00123               Point lo=f.getLocation();
00124               int x=lo.x+si.width/2-d.width/2;
00125               int y=lo.y+si.height/2-d.height/2;
00126               if (x+d.width>dscreen.width) x=dscreen.width-d.width-10;
00127               if (x<10) x=10;
00128               if (y+d.height>dscreen.height) y=dscreen.height-d.height-10;
00129               if (y<10) y=10;
00130               dialog.setLocation(x,y);
00131        }
00132        public void centerOut (Frame f)
00133        {      Dimension si=f.getSize(),d=getSize(),
00134                      dscreen=getToolkit().getScreenSize();
00135               Point lo=f.getLocation();
00136               int x=lo.x+si.width-getSize().width+20;
00137               int y=lo.y+si.height/2+40;
00138               if (x+d.width>dscreen.width) x=dscreen.width-d.width-10;
00139               if (x<10) x=10;
00140               if (y+d.height>dscreen.height) y=dscreen.height-d.height-10;
00141               if (y<10) y=10;
00142               setLocation(x,y);
00143        }
00144        public void center ()
00145        {      Dimension d=getSize(),dscreen=getToolkit().getScreenSize();
00146               setLocation((dscreen.width-d.width)/2,
00147                      (dscreen.height-d.height)/2);
00148        }
00149        
00153        public void notePosition (String name)
00154        {      Point l=getLocation();
00155               Dimension d=getSize();
00156               Global.setParameter(name+".x",l.x);
00157               Global.setParameter(name+".y",l.y);
00158               Global.setParameter(name+".w",d.width);
00159               if (d.height-Global.getParameter(name+".h",0)!=19)
00160                      // works around a bug in Windows
00161                      Global.setParameter(name+".h",d.height);
00162               boolean maximized=false;
00163        }
00164 
00168        public void setPosition (String name)
00169        {      Point l=getLocation();
00170               Dimension d=getSize();
00171               Dimension dscreen=getToolkit().getScreenSize();
00172               int x=Global.getParameter(name+".x",l.x);
00173               int y=Global.getParameter(name+".y",l.y);
00174               int w=Global.getParameter(name+".w",d.width);
00175               int h=Global.getParameter(name+".h",d.height);
00176               if (w>dscreen.width) w=dscreen.width;
00177               if (h>dscreen.height) h=dscreen.height;
00178               if (x<0) x=0;
00179               if (x+w>dscreen.width) x=dscreen.width-w;
00180               if (y<0) y=0;
00181               if (y+h>dscreen.height) y=dscreen.height-h;
00182               setLocation(x,y);
00183               setSize(w,h);
00184        }
00185        
00186        
00190        public void focusGained (FocusEvent e) {}
00191        public void focusLost (FocusEvent e) {}
00192 
00196        public void noteSize (String name)
00197        {      Dimension d=getSize();
00198               Global.setParameter(name+".w",d.width);
00199               Global.setParameter(name+".h",d.height);
00200        }
00201 
00205        public void setSize (String name)
00206        {      if (!Global.haveParameter(name+".w")) pack();
00207               else
00208               {      Dimension d=getSize();
00209                      int w=Global.getParameter(name+".w",d.width);
00210                      int h=Global.getParameter(name+".h",d.height);
00211                      setSize(w,h);
00212               }
00213        }
00214        
00218        public void setDispose (boolean flag)
00219        {      Dispose=flag;
00220        }
00221        
00222        public boolean isAborted ()
00223        {      return Aborted;
00224        }
00225        
00231        public void addHelp (Panel p, String subject)
00232        {      p.add(new MyLabel(""));
00233               p.add(new ButtonAction(this,Global.name("help"),"Help"));
00234               Subject=subject;
00235        }
00236 
00237 }