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

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

Generated on Fri Sep 16 18:05:55 2005 for SCT DAQ/DCS Software - Java by doxygen 1.3.5