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