SctApiGui.java

00001 package GuiComponents.Panels;
00002 
00003 import Sct_SctApi.*;
00004 import ipc.*;
00005 
00006 import Sct.gui.SelectionDialog;
00007 
00008 import GuiComponents.SctApi.*;
00009 import GuiComponents.System.*;
00010 
00011 import java.util.Arrays;
00012 
00013 import java.awt.Component;
00014 import java.awt.Window;
00015 import java.awt.event.ActionEvent;
00016 import java.awt.event.ActionListener;
00017 import javax.swing.BoxLayout;
00018 import javax.swing.JFrame;
00019 import javax.swing.JPanel;
00020 import javax.swing.JButton;
00021 import javax.swing.JOptionPane;
00022 
00023 import org.omg.CORBA.IntHolder;
00024 
00025 public class SctApiGui extends JPanel {
00026     private Sct_SctApi.SctApiIPC api;
00027 
00028     public static void main(String args[]) {
00029         System.out.println("Hello world");
00030 
00031         JFrame frame = new JFrame("SctApi GUI");
00032         frame.getContentPane().add(new SctApiGui());
00033 
00034         frame.pack();
00035         frame.setVisible(true);
00036     }
00037 
00038     public SctApiGui() {
00039         connectServer();
00040 
00041         JPanel topButtons = new JPanel();
00042         JPanel middleButtons = new JPanel();
00043         JPanel lowerMiddleButtons = new JPanel();
00044         JPanel bottomButtons = new JPanel();
00045 
00046         setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
00047 
00048         topButtons.setLayout(new BoxLayout(topButtons, BoxLayout.X_AXIS));
00049         middleButtons.setLayout(new BoxLayout(middleButtons, BoxLayout.X_AXIS));
00050         lowerMiddleButtons.setLayout(new BoxLayout(lowerMiddleButtons, BoxLayout.X_AXIS));
00051         bottomButtons.setLayout(new BoxLayout(bottomButtons, BoxLayout.X_AXIS));
00052 
00053         JButton close = new JButton("Close Panel");
00054         close.addActionListener(new ActionListener() {
00055                 public void actionPerformed(ActionEvent e) {
00056                     ((Window)getTopLevelAncestor()).dispose();
00057                 }
00058             });
00059 
00060         JButton shutdown = new JButton("Shutdown server");
00061         shutdown.addActionListener(new ActionListener() {
00062                 public void actionPerformed(ActionEvent e) {
00063                     shutDownAction();
00064                 }
00065             });
00066 
00067         JButton probeButton = new JButton("Probe Modules");
00068         probeButton.addActionListener(new ActionListener() {
00069                 public void actionPerformed(ActionEvent e) {
00070                     probeAction();
00071                 }
00072             });
00073 
00074         /*AT 19042004 implementation: harness tests */
00075         JButton harnessTestButton = new JButton("Harness Test");
00076         harnessTestButton.addActionListener(new ActionListener() {
00077                 public void actionPerformed(ActionEvent e) {
00078                     harnessTestAction();
00079                 }
00080             });
00081         
00082         JButton listScan = new JButton("List scans");
00083         listScan.addActionListener(new ActionListener() {
00084                 public void actionPerformed(ActionEvent e) {
00085                     Sct_SctApi.Scan[] scans = api.knownScans();
00086 
00087                     JFrame scanListFrame = new JFrame("List of known scans");
00088                     scanListFrame.getContentPane().add((Component)(new ScanList(api, scans)));
00089 
00090                     scanListFrame.pack();
00091                     scanListFrame.setVisible(true);
00092                 }
00093             });
00094 
00095         JButton rodDiag = new JButton("ROD diagnostics");
00096         rodDiag.addActionListener(new ActionListener() {
00097                 public void actionPerformed(ActionEvent e) {
00098                     rodDiagAction();
00099                 }
00100             });
00101 
00102         JButton bocDiag = new JButton("BOC diagnostics");
00103         bocDiag.addActionListener(new ActionListener() {
00104                 public void actionPerformed(ActionEvent e) {
00105                     bocDiagAction();
00106                 }
00107             });
00108 
00109         JButton timDiag = new JButton("TIM diagnostics");
00110         timDiag.addActionListener(new ActionListener() {
00111                 public void actionPerformed(ActionEvent e) {
00112                     timDiagAction();
00113                 }
00114             });
00115 
00116         JButton confDiag = new JButton("Module Configuration diagnostics");
00117         confDiag.addActionListener(new ActionListener() {
00118                 public void actionPerformed(ActionEvent e) {
00119                     moduleConfAction();
00120                 }
00121             });
00122 
00123         JButton ddcDiag = new JButton("DDC diagnostics");
00124         ddcDiag.addActionListener(new ActionListener() {
00125                 public void actionPerformed(ActionEvent e) {
00126                     JFrame ddcFrame = new JFrame("DDC diagnostics");
00127                     Component c = (Component)new DdcDiagnostics();
00128                     ddcFrame.getContentPane().add(c);
00129                     ddcFrame.pack();
00130                     ddcFrame.setVisible(true);
00131                 }
00132             });
00133 
00134         JButton debugButton = new JButton("Set debug options");
00135         debugButton.addActionListener(new ActionListener() {
00136                 public void actionPerformed(ActionEvent e) {
00137                     debugLevelAction();
00138                 }
00139             });
00140 
00141         JButton statusButton = new JButton("Show status");
00142         statusButton.addActionListener(new ActionListener() {
00143                 public void actionPerformed(ActionEvent e) {
00144                     api.status();
00145                 }
00146             });
00147 
00148         JButton standardDump = new JButton("Do standard dump");
00149         standardDump.addActionListener(new ActionListener() {
00150                 public void actionPerformed(ActionEvent e) {
00151                     api.standardRegisterDumpAll();
00152                 }
00153             });
00154 
00155         JButton reconnect = new JButton("Reconnect");
00156         reconnect.addActionListener(new ActionListener() {
00157                 public void actionPerformed(ActionEvent e) {
00158                     connectServer();
00159                 }
00160             });
00161 
00162         JButton reloadConfig = new JButton("Reload module configuration");
00163         reloadConfig.addActionListener(new ActionListener() {
00164                 public void actionPerformed(ActionEvent e) {
00165                     try {
00166                         api.loadConfiguration("");
00167                     } catch(Sct_SctApi.SctApiException s) {
00168                         javax.swing.JOptionPane.showMessageDialog(null, "Failed to reload module configuration: " + s.detail);
00169                     }
00170                 }
00171             });
00172 
00173         JButton configModules = new JButton("Send module configs");
00174         configModules.addActionListener(new ActionListener() {
00175                 public void actionPerformed(ActionEvent e) {
00176                     try {
00177                         api.sendABCDModules(Sct_SctApi.BankType.PHYSICS_CONFIG);
00178                     } catch(SctApiException s) {
00179                         javax.swing.JOptionPane.showMessageDialog(null, "Failed to Configure modules: " + s.detail);
00180                     }
00181                 }
00182             });
00183 
00184         JButton freeTriggers = new JButton("Send free triggers");
00185         freeTriggers.addActionListener(new ActionListener() {
00186                 public void actionPerformed(ActionEvent e) {
00187                     try {
00188                         TimDoublet td = inputTimDoublet();
00189                         api.freeTriggers(td.partition, td.crate);
00190                     } catch(SelectionDialog.InvalidDialogException i) {
00191                         javax.swing.JOptionPane.showMessageDialog(null, "Failed to interpet TIM entry");
00192                     } catch(SelectionDialog.CancelledDialogException c) {
00193                     }
00194                 }
00195             });
00196 
00197         JButton stopTriggers = new JButton("Stop free triggers");
00198         stopTriggers.addActionListener(new ActionListener() {
00199                 public void actionPerformed(ActionEvent e) {
00200                     try {
00201                         TimDoublet td = inputTimDoublet();
00202                         api.stopTriggers(td.partition, td.crate);
00203                     } catch(SelectionDialog.InvalidDialogException i) {
00204                         javax.swing.JOptionPane.showMessageDialog(null, "Failed to interpet TIM entry");
00205                     } catch(SelectionDialog.CancelledDialogException c) {
00206                     }
00207                 }
00208             });
00209 
00210         JButton autoConfigure = new JButton("Run auto-configurer");
00211         autoConfigure.addActionListener(new ActionListener() {
00212                 public void actionPerformed(ActionEvent e) {
00213                     autoConfigAction();
00214                 }
00215             });
00216 
00217         // Action panels
00218         topButtons.add(probeButton);
00219         topButtons.add(harnessTestButton);
00220         topButtons.add(listScan);
00221         topButtons.add(autoConfigure);
00222 
00223         topButtons.add(freeTriggers);
00224         topButtons.add(stopTriggers);
00225 
00226         // Diagnostics
00227         middleButtons.add(rodDiag);
00228         middleButtons.add(bocDiag);
00229         middleButtons.add(timDiag);
00230         middleButtons.add(confDiag);
00231         middleButtons.add(ddcDiag);
00232         lowerMiddleButtons.add(debugButton);
00233         lowerMiddleButtons.add(standardDump);
00234         lowerMiddleButtons.add(configModules);
00235 
00236         // Overall 
00237         bottomButtons.add(statusButton);
00238         bottomButtons.add(close);
00239         bottomButtons.add(shutdown);
00240         bottomButtons.add(reconnect);
00241         bottomButtons.add(reloadConfig);
00242 
00243         add(topButtons);
00244         add(middleButtons);
00245         add(lowerMiddleButtons);
00246         add(bottomButtons);
00247 
00248         System.out.println("Set up GUI, wait for it to run");
00249     }
00250 
00251 
00252     void connectServer() {
00253         // Replace with SystemInterface!
00254         SystemInterface sys = SystemInterface.getInstance();
00255         // If config server lost then need to reconnect
00256         sys.refresh();
00257         api = sys.getSctApi();
00258 
00259         if (api==null) {
00260             System.err.println("Error (check SCTAPI running)");
00261         } else {
00262             System.out.println("Found SCTAPI");
00263         }
00264     }
00265 
00266     void shutDownAction() {
00267         try {
00268             System.out.println("Shutdown system");
00269             api.shutdownAll();
00270             System.out.println("Done");
00271             api.shutdown();
00272             ((Window)getTopLevelAncestor()).dispose();
00273         } catch(Exception ex) {
00274             // Exit whatever happens
00275         }
00276         System.exit(0);
00277     }
00278 
00279     void probeAction() {
00280         try {
00281             RodTriplet rt = inputRodTriplet();
00282             JFrame probeFrame = new JFrame("Probe modules");
00283 
00284             Component c = (Component)new ProbeView(rt.partition, rt.crate, rt.rod, api);
00285             probeFrame.getContentPane().add(c);
00286             probeFrame.pack();
00287             probeFrame.setVisible(true);
00288         } catch(SelectionDialog.InvalidDialogException i) {
00289             javax.swing.JOptionPane.showMessageDialog(null, "Failed to interpet ROD entry");
00290         } catch(SelectionDialog.CancelledDialogException c) {
00291         }
00292     }
00293 
00294     /*AT 042004 harness tests     */
00295     void harnessTestAction() {
00296             //try {
00297             //RodQuadruplet rt = inputRodQuadruplet();
00298             JFrame harnessTestFrame = new JFrame("Harness Test");
00299 
00300             //Component c = (Component)new HarnessTestView(rt.partition, rt.crate, rt.rod, rt.harness, api);
00301             Component c = (Component) new HarnessTestView(api);
00302             harnessTestFrame.getContentPane().add(c);
00303             harnessTestFrame.pack();
00304             harnessTestFrame.setVisible(true);
00305             //} catch(SelectionDialog.InvalidDialogException i) {
00306             //javax.swing.JOptionPane.showMessageDialog(null, "Failed to interpet ROD entry");
00307             //} catch(SelectionDialog.CancelledDialogException c) {
00308             //}
00309     }
00310 
00311     void rodDiagAction() {
00312         try {
00313             RodTriplet rt = inputRodTriplet();
00314             JFrame rodFrame = new JFrame("ROD diagnostics");
00315             Component c = (Component)new RodDiagnostics(rt.partition, rt.crate, rt.rod, api);
00316             rodFrame.getContentPane().add(c);
00317             rodFrame.pack();
00318             rodFrame.setVisible(true);
00319         } catch(SelectionDialog.InvalidDialogException i) {
00320             javax.swing.JOptionPane.showMessageDialog(null, "Failed to interpet ROD entry");
00321         } catch(SelectionDialog.CancelledDialogException c) {
00322         }
00323     }
00324 
00325     void bocDiagAction() {
00326         try {
00327             RodTriplet rt = inputRodTriplet();
00328             JFrame bocFrame = new JFrame("BOC diagnostics");
00329             Component c = (Component)new BocDiagnostics(rt.partition, rt.crate, rt.rod, api);
00330             bocFrame.getContentPane().add(c);
00331             bocFrame.pack();
00332             bocFrame.setVisible(true);
00333         } catch(SelectionDialog.InvalidDialogException i) {
00334             javax.swing.JOptionPane.showMessageDialog(null, "Failed to interpet BOC entry");
00335         } catch(SelectionDialog.CancelledDialogException c) {
00336         }
00337     }
00338 
00339     void moduleConfAction() {
00340         try {
00341             RodTriplet rt = inputRodTriplet();
00342             JFrame confFrame = new JFrame("Module configuration diagnostics");
00343             Component c = (Component)new ModuleConfigurations(rt.partition, rt.crate, rt.rod, api);
00344             confFrame.getContentPane().add(c);
00345             confFrame.pack();
00346             confFrame.setVisible(true);
00347         } catch(SelectionDialog.InvalidDialogException i) {
00348             javax.swing.JOptionPane.showMessageDialog(null, "Failed to interpet ROD entry");
00349         } catch(SelectionDialog.CancelledDialogException c) {
00350         }
00351     }
00352 
00353     void timDiagAction() {
00354         try {
00355             SctApiGui.TimDoublet td = inputTimDoublet();
00356             JFrame timFrame = new JFrame("TIM diagnostics");
00357             Component c = (Component)new TimDiagnostics(td.partition, td.crate, api);
00358             timFrame.getContentPane().add(c);
00359             timFrame.pack();
00360             timFrame.setVisible(true);
00361         } catch(SelectionDialog.InvalidDialogException i) {
00362             javax.swing.JOptionPane.showMessageDialog(null, "Failed to interpet TIM entry");
00363         } catch(SelectionDialog.CancelledDialogException c) {
00364         }
00365     }
00366 
00367     void debugLevelAction() {
00368         String[] possibilities = api.listDebugOptions();
00369 
00370         Sct.Corba.UniqueCrateIdentifier[] ucids = api.getCrateUCIDs();
00371         for (int ucidInt=0; ucidInt<ucids.length; ++ucidInt) {
00372             Sct_SctApi.CrateIPC crate = api.getCrate(ucids[ucidInt]);
00373 
00374             String[] enabled = crate.listEnabledDebugOptions();
00375             
00376             int[] preSelected = new int[enabled.length];
00377             
00378             Arrays.sort(possibilities);
00379             
00380             // Find options that are selected
00381             for(int i=0; i<enabled.length; i++) {
00382                 int result = Arrays.binarySearch(possibilities, enabled[i]);
00383                 if(result < 0) {
00384                     // Strange! ignore it
00385                     preSelected[i] = -1;
00386                 } else {
00387                     preSelected[i] = result;
00388                 }
00389             }
00390             
00391             String selected [] = 
00392                 Sct.gui.MultiSelectionDialog.showDialog(null, "Select Debug Options", 
00393                                                         possibilities, preSelected);
00394             
00395             if (selected != null) {
00396                 Arrays.sort(selected);
00397                 Arrays.sort(enabled);
00398                 
00399                 // Find options that are selected that shouldn't be
00400                 for(int i=0; i<enabled.length; i++) {
00401                     if(Arrays.binarySearch(selected, enabled[i]) < 0) {
00402                         crate.unsetDebugOption(enabled[i]);
00403                     }
00404                 }
00405                 
00406                 // Find options that aren't selected that should be
00407                 for(int i=0; i<selected.length; i++) {
00408                     if(Arrays.binarySearch(enabled, selected[i]) < 0) {
00409                         crate.setDebugOption(selected[i]);
00410                     }
00411                 }
00412             }
00413         }
00414     }
00415 
00416     void autoConfigAction() {
00417         JFrame autoFrame = new JFrame("Auto configure");
00418         Component c = (Component) new GuiComponents.SctApi.AutoConfigure(api);
00419         autoFrame.getContentPane().add(c);
00420         autoFrame.pack();
00421         autoFrame.setVisible(true);
00422     }
00423 
00424     RodTriplet inputRodTriplet() throws SelectionDialog.InvalidDialogException, SelectionDialog.CancelledDialogException {
00425         String [] labels = {"Partition", "Crate", "ROD"};
00426         String [] defaults = {"0", "0", "0"};
00427 
00428         SelectionDialog dia = new SelectionDialog(null, "Get ROD index", labels, defaults);
00429 
00430         dia.pack();
00431         dia.setVisible(true);
00432 
00433         return new RodTriplet(dia.getIntFieldValue(0), 
00434                               dia.getIntFieldValue(1), 
00435                               dia.getIntFieldValue(2));
00436     }
00437 
00438 
00439     /*AT    */
00440     RodQuadruplet inputRodQuadruplet() throws SelectionDialog.InvalidDialogException, SelectionDialog.CancelledDialogException {
00441         String [] labels = {"Partition", "Crate", "ROD", "Harness"};
00442         String [] defaults = {"0", "0", "0", "0"};
00443 
00444         SelectionDialog dia = new SelectionDialog(null, "Get ROD index", labels, defaults);
00445 
00446         dia.pack();
00447         dia.setVisible(true);
00448 
00449         return new RodQuadruplet(dia.getIntFieldValue(0), 
00450                                  dia.getIntFieldValue(1), 
00451                                  dia.getIntFieldValue(2),
00452                                  dia.getIntFieldValue(3));
00453     }
00454 
00455     public class RodTriplet {
00456         int partition;
00457         int crate;
00458         int rod;
00459         RodTriplet(int p, int c, int r) {
00460             partition = p;
00461             crate = c;
00462             rod = r;
00463             
00464         }
00465     }
00466 
00467 
00468     /*AT   */
00469     public class RodQuadruplet {
00470         int partition;
00471         int crate;
00472         int rod;
00473         int harness;
00474         RodQuadruplet(int p, int c, int r, int h) {
00475             partition = p;
00476             crate = c;
00477             rod = r;
00478             harness = h;
00479         }
00480     }
00481 
00482     TimDoublet inputTimDoublet() throws SelectionDialog.InvalidDialogException, SelectionDialog.CancelledDialogException {
00483         String [] labels = {"Partition", "Crate"};
00484         String [] defaults = {"0", "0"};
00485 
00486         SelectionDialog dia = new SelectionDialog(null, "Get TIM index", labels, defaults);
00487 
00488         dia.pack();
00489         dia.setVisible(true);
00490 
00491         return new TimDoublet(dia.getIntFieldValue(0), 
00492                               dia.getIntFieldValue(1));
00493     }
00494 
00495     public class TimDoublet {
00496         int partition;
00497         int crate;
00498         TimDoublet(int p, int c) {
00499             partition = p;
00500             crate = c;
00501         }
00502     }
00503 }

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