ALMA Computing Group

XmlComponentGui.java

Go to the documentation of this file.
00001 /* 00002 * ALMA - Atacama Large Millimiter Array 00003 * (c) European Southern Observatory, 2002 00004 * Copyright by ESO (in the framework of the ALMA collaboration), 00005 * All rights reserved 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2.1 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this library; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 00020 * MA 02111-1307 USA 00021 */ 00022 package alma.demo.client.guiapps; 00023 00024 import java.awt.Dimension; 00025 import java.awt.Toolkit; 00026 import java.awt.event.WindowAdapter; 00027 import java.awt.event.WindowEvent; 00028 import java.util.logging.Logger; 00029 00030 import javax.swing.JFrame; 00031 import javax.swing.JPanel; 00032 import javax.swing.WindowConstants; 00033 00034 import alma.acs.component.client.ComponentClient; 00035 import alma.acs.container.ContainerServices; 00036 00037 00041 public class XmlComponentGui 00042 { 00043 private ComponentClient m_componentClient; 00044 00045 private Logger m_logger; 00046 00047 00048 public XmlComponentGui() throws Exception // ok, dirty 00049 { 00050 m_componentClient = connect(); 00051 00052 ContainerServices containerServices = m_componentClient.getContainerServices(); 00053 00054 JPanel jpanel = new MySillyPanel(containerServices); 00055 00056 JFrame jframe = wrapWithFrame(jpanel); 00057 00058 jframe.addWindowListener( 00059 new WindowAdapter() 00060 { 00061 public void windowClosing(WindowEvent e) 00062 { 00063 try 00064 { 00065 m_componentClient.tearDown(); 00066 } 00067 catch (Exception ex) 00068 { 00069 // TODO Auto-generated catch block 00070 ex.printStackTrace(System.err); 00071 } 00072 } 00073 } 00074 ); 00075 jframe.setVisible(true); 00076 } 00077 00078 00079 private ComponentClient connect() throws Exception // ok, dirty 00080 { 00081 String managerLoc = System.getProperty("ACS.manager"); 00082 if (managerLoc == null) 00083 { 00084 throw new Exception("Java property 'ACS.manager' must be set to the corbaloc of the ACS manager!"); 00085 } 00086 String clientName = getClass().getName() + Long.toString(System.currentTimeMillis()); 00087 m_logger = Logger.getLogger(clientName); 00088 00089 ComponentClient componentClient = new ComponentClient(m_logger, managerLoc, clientName); 00090 00091 return componentClient; 00092 } 00093 00094 00095 private JFrame wrapWithFrame(JPanel jpanel) 00096 { 00097 JFrame jframe; 00098 jframe = new JFrame("XmlComponent's GUI"); 00099 jframe.getContentPane().add(jpanel); 00100 00101 // termination behav. 00102 jframe.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 00103 00104 // position the frame in the middle of the screen 00105 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 00106 int width = (int) screenSize.getWidth(); 00107 int height = (int) screenSize.getHeight(); 00108 width = (width >= 600 ? 600 : width); 00109 height = (height >= 400 ? 400 : height); 00110 jframe.setSize(width, height); 00111 jframe.setLocation((int)(screenSize.getWidth()-width)/2, (int)(screenSize.getHeight()-height)/2); 00112 00113 return jframe; 00114 } 00115 00116 00117 public static void main(String[] args) 00118 { 00119 try 00120 { 00121 new XmlComponentGui(); 00122 } 00123 catch (Exception e) 00124 { 00125 // TODO Auto-generated catch block 00126 e.printStackTrace(System.err); 00127 } 00128 } 00129 }