Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

SctConfGui.java

00001 package GuiComponents.Panels;
00002 
00003 import sctConf.*;
00004 import ipc.*;
00005 
00006 import GuiComponents.SctConf.*;
00007 import GuiComponents.System.*;
00008 
00009 import java.util.Enumeration;
00010 import java.util.Vector;
00011 import java.awt.Dimension;
00012 import java.awt.BorderLayout;
00013 import java.awt.event.WindowAdapter;
00014 import java.awt.event.WindowEvent;
00015 import java.awt.event.MouseAdapter;
00016 import java.awt.event.MouseEvent;
00017 import java.awt.event.ActionEvent;
00018 import java.awt.event.ActionListener;
00019 import javax.swing.*;
00020 
00021 import org.omg.CORBA.IntHolder;
00022 
00023 public class SctConfGui extends JPanel {
00024     private sctConf.Configuration config;
00025 
00026 //     final private SctConfigGui finalGui;
00027 
00028     public static void main(String args[]) {
00029         System.out.println("Hello world");
00030 
00031         JFrame frame = new JFrame("Configuration GUI");
00032         frame.getContentPane().add(new SctConfGui());
00033 
00034 //         frame.addWindowListener(new WindowAdapter() {
00035 //             public void windowClosing(WindowEvent e) {
00036 //                 System.exit(0);
00037 //             }
00038 //         });  
00039 
00040         frame.pack();
00041         frame.setVisible(true);
00042     }
00043 
00044     public SctConfGui() {
00045 //         finalGui = this;
00046 
00047         connectServer();
00048 
00049         if (config==null) {
00050             System.err.println("Error (check configuration running)");
00051             System.exit(0);
00052         }
00053         System.out.println("Found configuration");
00054 
00055         setLayout(new BorderLayout());
00056 
00057         JPanel buttons = new JPanel();
00058 
00059         JButton close = new JButton("Exit");
00060         close.addActionListener(new ActionListener() {
00061                 public void actionPerformed(ActionEvent e) {
00062                     System.exit(1);
00063 //                     ((Window)getTopLevelAncestor()).dispose();
00064                 }
00065             });
00066         buttons.add(close);
00067 
00068         JButton myTreeView = new JButton("Tree View");
00069         myTreeView.addActionListener(new ActionListener() {
00070                 public void actionPerformed(ActionEvent e) {
00071                     JFrame frame = new JFrame("Tree view");
00072                     if(config == null) {
00073                         connectServer();
00074                     }
00075                     frame.getContentPane().add(new TreeView(new Proxies(config), config));
00076 
00077                     frame.addWindowListener(new WindowAdapter() {
00078                             public void windowClosing(WindowEvent e) {
00079                                 e.getWindow().dispose();
00080                             }
00081                         });
00082                     frame.pack();
00083                     frame.setVisible(true);
00084                 }
00085             });
00086         buttons.add(myTreeView);
00087 
00088         JButton moduleListView = new JButton("Module List");
00089         moduleListView.addActionListener(new ActionListener() {
00090                 public void actionPerformed(ActionEvent e) {
00091                     JFrame frame = new JFrame("Module list");
00092                     if(config == null) {
00093                         connectServer();
00094                     }
00095                     frame.getContentPane().add(new ModuleListView(config));
00096 
00097                     frame.addWindowListener(new WindowAdapter() {
00098                             public void windowClosing(WindowEvent e) {
00099                                 e.getWindow().dispose();
00100                             }
00101                         });
00102                     frame.pack();
00103                     frame.setVisible(true);
00104                 }
00105             });
00106         buttons.add(moduleListView);
00107 
00108 //         JButton power = new JButton("Power mappings");
00109 //         power.addActionListener(new ActionListener() {
00110 //                 public void actionPerformed(ActionEvent e) {
00111 //                     JFrame frame = new JFrame("Power Mappings");
00112 //                     if(config == null) {
00113 //                         connectServer();
00114 //                     }
00115 //                     frame.getContentPane().add(new PowerMappings(config));
00116 
00117 //                     frame.addWindowListener(new WindowAdapter() {
00118 //                             public void windowClosing(WindowEvent e) {
00119 //                                 e.getWindow().dispose();
00120 //                             }
00121 //                         });
00122 //                     frame.pack();
00123 //                     frame.setVisible(true);
00124 //                 }
00125 //             });
00126 //         buttons.add(power);
00127 
00128         JButton physic = new JButton("View Physical");
00129         physic.addActionListener(new ActionListener() {
00130                 public void actionPerformed(ActionEvent e) {
00131                     JFrame frame = new JFrame("Physical view");
00132                     if(config == null) {
00133                         connectServer();
00134                     }
00135                     frame.getContentPane().add(new PhysicalView(config));
00136 
00137                     frame.addWindowListener(new WindowAdapter() {
00138                             public void windowClosing(WindowEvent e) {
00139                                 e.getWindow().dispose();
00140                             }
00141                         });
00142                     frame.pack();
00143                     frame.setVisible(true);
00144                 }
00145             });
00146         buttons.add(physic);
00147 
00148         JButton shutdown = new JButton("Shutdown server");
00149         shutdown.addActionListener(new ActionListener() {
00150                 public void actionPerformed(ActionEvent e) {
00151                     try {
00152                         System.out.println("Dump configuration");
00153                         config.saveConfiguration("Shutdown_Dump_From_ConfigGUI.xml");
00154                         System.out.println("Done");
00155                     } catch(ConfigurationException c) {
00156                         System.out.println("Shutdown xml dump failed");
00157                     } catch(Exception ex) {
00158                         // Exit whatever happens
00159                     }
00160                     try {
00161                         config.destroy();
00162                     } catch(Exception ex) {
00163                         // Exit whatever happens
00164                     }
00165 //                     ((Window)getTopLevelAncestor()).dispose();
00166                     System.exit(0);
00167                 }
00168             });
00169         buttons.add(shutdown);
00170 
00171         JButton saveConf = new JButton("Save configuration");
00172         saveConf.addActionListener(new ActionListener() {
00173                 public void actionPerformed(ActionEvent e) {
00174                     try {
00175                         System.out.println("Saving configuration to Dump_From_ConfigGUI.xml");
00176                         config.saveConfiguration("Dump_From_ConfigGUI.xml");
00177                     } catch(ConfigurationException c) {
00178                         JOptionPane.showMessageDialog(null, "Save configuration failed!");
00179                     }
00180                 }
00181             });
00182         buttons.add(saveConf);
00183 
00184         JButton loadConf = new JButton("Reload configuration");
00185         loadConf.addActionListener(new ActionListener() {
00186                 public void actionPerformed(ActionEvent e) {
00187                     try {
00188                         config.loadConfiguration("");
00189                     } catch(ConfigurationException c) {
00190                         JOptionPane.showMessageDialog(null, "Load configuration failed!");
00191                     }
00192                 }
00193             });
00194         buttons.add(loadConf);
00195 
00196         JButton reconnect = new JButton("Reconnect");
00197         reconnect.addActionListener(new ActionListener() {
00198                 public void actionPerformed(ActionEvent e) {
00199                     connectServer();
00200                 }
00201             });
00202         buttons.add(reconnect);
00203 
00204         add(buttons, BorderLayout.SOUTH);
00205 
00206         System.out.println("Set up GUI, wait for it to run");
00207     }
00208 
00209     public void connectServer() {
00210         SystemInterface sys = SystemInterface.getInstance();
00211         // If config server lost then need to reconnect
00212         sys.refresh();
00213         config = sys.getConfigurationService();
00214     }
00215 }

Generated on Thu Jul 15 09:55:48 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5