DDCModuleSwitcher.java

00001 /*
00002  * DDCModuleSwitcher.java
00003  *
00004  * Created on 03 March 2005, 13:50
00005  */
00006 
00007 package DisplayGUI;
00008 import java.util.*;
00009 import GuiComponents.System.*;
00010 import Sct_SctApi.*;
00011 import Sct_SctApi.SctApiDDCServer;
00012 import java.awt.event.*;
00013 
00018 public class DDCModuleSwitcher extends javax.swing.JFrame implements displayParams,ActionListener {
00019 
00020 
00021     private javax.swing.JButton jButton1,jButton2,jButton3;
00022     private javax.swing.JComboBox jComboBox1,jComboBox2, jComboBox3;
00023     private javax.swing.JLabel jLabel1,jLabel2,jLabel3,jLabel4,jLabel5,jLabel6;
00024     String serialno;
00025     Set moduleList;
00026 
00028     public DDCModuleSwitcher(Set moduleList, String serialno) {
00029         super("Module HV/LV Control");
00030                 this.serialno=serialno;
00031                 this.moduleList=moduleList;
00032         initComponents();
00033     }
00034 
00035     public DDCModuleSwitcher(Set ModuleList) {
00036         super("Module HV/LV Control");
00037                 this.serialno=null;
00038                 this.moduleList=moduleList;
00039         initComponents();
00040     }
00041     
00047     private void initComponents() {
00048        
00049         java.awt.GridBagConstraints gridBagConstraints;
00050 
00051         jButton2 = new javax.swing.JButton();
00052         jButton2.setFont(displayTextFont);
00053         jComboBox1 = new javax.swing.JComboBox(moduleList.toArray());
00054         jComboBox1.setFont(displayTextFont);
00055         jComboBox1.setBackground(backgroundColor);
00056         jComboBox1.insertItemAt("All Modules",0);
00057         if(serialno!=null) jComboBox1.setSelectedItem(serialno);
00058         else jComboBox1.setSelectedIndex(0);
00059         jComboBox1.addActionListener(this);
00060 
00061         jComboBox2 = new javax.swing.JComboBox();
00062         jComboBox2.setFont(displayTextFont);
00063         jComboBox2.setBackground(backgroundColor);
00064         jComboBox2.addItem("OFF");
00065         jComboBox2.addItem("ON");
00066         
00067         jComboBox3 = new javax.swing.JComboBox();
00068         jComboBox3.setFont(displayTextFont);
00069         jComboBox3.setBackground(backgroundColor);
00070         jComboBox3.addItem("LV");
00071         jComboBox3.addItem("HV");
00072 
00073 
00074         jLabel1 = new javax.swing.JLabel();
00075         jLabel2 = new javax.swing.JLabel();
00076         jLabel3 = new javax.swing.JLabel();
00077         jLabel4 = new javax.swing.JLabel();
00078         jLabel5 = new javax.swing.JLabel();
00079         jLabel6 = new javax.swing.JLabel();
00080 
00081         jButton1 = new javax.swing.JButton();
00082         jButton1.setFont(displayTextFont);
00083         jButton3 = new javax.swing.JButton();
00084         jButton3.setFont(displayTextFont);
00085 
00086         getContentPane().setLayout(new java.awt.GridBagLayout());
00087 
00088         addWindowListener(new java.awt.event.WindowAdapter() {
00089             public void windowClosing(java.awt.event.WindowEvent evt) {
00090                 exitForm(evt);
00091             }
00092         });
00093 
00094         gridBagConstraints = new java.awt.GridBagConstraints();
00095         gridBagConstraints.gridx = 1;
00096         gridBagConstraints.gridy = 0;
00097         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00098         gridBagConstraints.weightx = 0.5;
00099         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00100         getContentPane().add(jComboBox1, gridBagConstraints);
00101 
00102         jLabel1.setText("Module LV and HV Control");
00103         jLabel1.setFont(displayTitleFont);
00104         jLabel1.setForeground(darkBlueColor);
00105         gridBagConstraints = new java.awt.GridBagConstraints();
00106         gridBagConstraints.gridx = 0;
00107         gridBagConstraints.gridy = 0;
00108         gridBagConstraints.gridwidth = 2;
00109         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00110         gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
00111         gridBagConstraints.weighty = 0.1;
00112         getContentPane().add(jLabel1, gridBagConstraints);
00113         
00114         jLabel2.setText("Module(s):");
00115         jLabel2.setFont(displayTextFont);
00116         gridBagConstraints = new java.awt.GridBagConstraints();
00117         gridBagConstraints.gridx = 0;
00118         gridBagConstraints.gridy = 1;
00119         gridBagConstraints.weightx = 0.5;
00120         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00121         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00122         getContentPane().add(jLabel2, gridBagConstraints);
00123 
00124         gridBagConstraints = new java.awt.GridBagConstraints();
00125         gridBagConstraints.gridx = 1;
00126         gridBagConstraints.gridy = 1;
00127         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00128         gridBagConstraints.weighty = 0.2;
00129         gridBagConstraints.weightx = 0.5;
00130         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00131         getContentPane().add(jComboBox1, gridBagConstraints);
00132         
00133         jLabel3.setText("Crate/Channel:");
00134         jLabel3.setFont(displayTextFont);
00135         gridBagConstraints = new java.awt.GridBagConstraints();
00136         gridBagConstraints.gridx = 0;
00137         gridBagConstraints.gridy = 2;
00138         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00139         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00140         getContentPane().add(jLabel3, gridBagConstraints);
00141         
00142         jLabel4.setText("All active Crates/Channels");
00143         jLabel4.setFont(displayTextFont);
00144         gridBagConstraints = new java.awt.GridBagConstraints();
00145         gridBagConstraints.gridx = 1;
00146         gridBagConstraints.gridy = 2;
00147         gridBagConstraints.weighty = 0.1;
00148         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00149         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00150         jLabel4.setForeground(darkGreenColor);
00151         getContentPane().add(jLabel4, gridBagConstraints);
00152         
00153         jLabel5.setText("State:");
00154         jLabel5.setFont(displayTextFont);
00155         gridBagConstraints = new java.awt.GridBagConstraints();
00156         gridBagConstraints.gridx = 0;
00157         gridBagConstraints.gridy = 3;
00158         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00159         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00160         getContentPane().add(jLabel5, gridBagConstraints);
00161 
00162         gridBagConstraints = new java.awt.GridBagConstraints();
00163         gridBagConstraints.gridx = 1;
00164         gridBagConstraints.gridy = 3;
00165         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00166         gridBagConstraints.weighty = 0.2;
00167         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00168         getContentPane().add(jComboBox2, gridBagConstraints);
00169 
00170         jLabel6.setText("Type:");
00171         jLabel6.setFont(displayTextFont);
00172         gridBagConstraints = new java.awt.GridBagConstraints();
00173         gridBagConstraints.gridx = 0;
00174         gridBagConstraints.gridy = 4;
00175         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00176         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00177         getContentPane().add(jLabel6, gridBagConstraints);
00178 
00179         gridBagConstraints = new java.awt.GridBagConstraints();
00180         gridBagConstraints.gridx = 1;
00181         gridBagConstraints.gridy = 4;
00182         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00183         gridBagConstraints.weighty = 0.2;
00184         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00185         getContentPane().add(jComboBox3, gridBagConstraints);
00186 
00187         jButton1.setText("Ok");
00188         gridBagConstraints = new java.awt.GridBagConstraints();
00189         gridBagConstraints.gridx = 0;
00190         gridBagConstraints.gridy = 5;
00191         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00192         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
00193         getContentPane().add(jButton1, gridBagConstraints);
00194         jButton1.addActionListener(new java.awt.event.ActionListener() {
00195                  public void actionPerformed(java.awt.event.ActionEvent evt) {
00196 
00197                   Sct_SctApi.SctApiDDCServer api = SystemInterface.getInstance().getSctApiDDCServer();
00198                   if(api==null) {
00199                     javax.swing.JOptionPane.showMessageDialog(null,"null SctApi pointer");
00200                     return;
00201                     }
00202                     
00203                   int state = 8;                         //LV Off=9, LV ON=6 HV off=9, HV on=7
00204                   if(jComboBox2.getSelectedIndex()==0) { // OFF state
00205                       state = (jComboBox3.getSelectedIndex()==0) ? 8 : 9;
00206                       }
00207                   else {                                 // ON state
00208                       state = (jComboBox3.getSelectedIndex()==0) ? 6 : 7;
00209                       }
00210                       
00211 
00212                    java.util.Set crateSet = new java.util.HashSet();
00213                    ConfigurationInterface conf = ConfigurationInterface.getInstance();
00214                    try {
00215                        if(jComboBox1.getSelectedIndex()==0) { //all modules
00216                         for (java.util.Iterator m = moduleList.iterator(); m.hasNext(); ) {
00217                 String sn=(String)m.next();
00218                 ModuleCell thisCell = conf.getModuleCell(sn);
00219                               int moduleGroup = thisCell.getModuleGroup();
00220                               moduleGroup++;
00221                               String grCmd = "gr"+Integer.toString(moduleGroup);
00222                           // for (int i=0;i<moduleList.size();i++) {
00223                          //    String sn=(String)moduleList.elementAt(i);
00224                              String crate = conf.getSNInfo(sn,SNInfo.DCS_CRATE);
00225                              if(crate.equals("-1")) continue;
00226                              if(crateSet.contains(crate+grCmd)) continue;
00227                              System.out.println("sctGUI - switching group "+Integer.toString(moduleGroup)+" module(s) in crate "+crate+" to state "+Integer.toString(state));
00228                              crateSet.add(crate+grCmd);
00229                              api.ddcChangeStates(Integer.valueOf(crate).intValue(),grCmd,(short)state);
00230                              }
00231                            System.out.println("sctGUI - all crate power switching completed.");
00232                         }
00233                        else {  // single module
00234                           String sn = (String)jComboBox1.getSelectedItem();
00235                           String crate = conf.getSNInfo(sn,SNInfo.DCS_CRATE);;
00236                           String channel = conf.getSNInfo(sn,SNInfo.DCS_CHANNEL);
00237                           System.out.println("Switching module "+sn+" (crate/channel "+crate+","+channel+") to state "+Integer.toString(state));
00238                           api.ddcChangeStates(Integer.valueOf(crate).intValue(),channel,(short)state);
00239                           System.out.println("Completed.");
00240                           }
00241                      }catch(Exception e){javax.swing.JOptionPane.showMessageDialog(null,"Exception "+e.toString());}
00242 
00243                      }
00244              });
00245 
00246         jButton2.setText("Close");
00247         gridBagConstraints = new java.awt.GridBagConstraints();
00248         gridBagConstraints.gridx = 1;
00249         gridBagConstraints.gridy = 5;
00250         gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
00251         gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
00252         gridBagConstraints.weighty = 0.1;
00253         getContentPane().add(jButton2, gridBagConstraints);
00254         jButton2.addActionListener(new java.awt.event.ActionListener() {
00255                  public void actionPerformed(java.awt.event.ActionEvent evt) {
00256                      exitForm(null);
00257                      }
00258              });
00259         getContentPane().setBackground(new java.awt.Color(255, 255, 255));
00260         
00261         if(serialno!=null) setLabel(serialno);
00262 
00263 
00264         pack();
00265             setVisible(true);
00266     }
00267 
00269     private void exitForm(java.awt.event.WindowEvent evt) {
00270        setVisible(false);
00271        dispose();
00272     }
00273     
00274    public void actionPerformed(ActionEvent e) {
00275         javax.swing.JComboBox cb = (javax.swing.JComboBox)e.getSource();
00276         if(cb.getSelectedIndex()==0) {
00277            jLabel4.setText("All active Crates/Channels");
00278            return;
00279            }
00280         String sn = (String)cb.getSelectedItem();
00281         setLabel(sn);
00282 
00283     }
00284     
00285  private void setLabel(String sn) {
00286         ConfigurationInterface conf = ConfigurationInterface.getInstance();
00287         String crate = conf.getSNInfo(sn,SNInfo.DCS_CRATE);
00288         String channel = conf.getSNInfo(sn,SNInfo.DCS_CHANNEL);
00289         jLabel4.setText("Crate "+crate+", Channel "+channel);
00290         }
00291 
00292 
00293 
00294 
00295 
00296 
00297 }

Generated on Mon Feb 6 14:12:10 2006 for SCT DAQ/DCS Software - Java by  doxygen 1.4.6