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 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
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(api);
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
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
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
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
00254 SystemInterface sys = SystemInterface.getInstance();
00255
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.destroy();
00272 ((Window)getTopLevelAncestor()).dispose();
00273 } catch(Exception ex) {
00274
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
00295 void harnessTestAction() {
00296
00297
00298 JFrame harnessTestFrame = new JFrame("Harness Test");
00299
00300
00301 Component c = (Component) new HarnessTestView(api);
00302 harnessTestFrame.getContentPane().add(c);
00303 harnessTestFrame.pack();
00304 harnessTestFrame.setVisible(true);
00305
00306
00307
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 String[] enabled = api.listEnabledDebugOptions();
00371
00372 int[] preSelected = new int[enabled.length];
00373
00374 Arrays.sort(possibilities);
00375
00376
00377 for(int i=0; i<enabled.length; i++) {
00378 int result = Arrays.binarySearch(possibilities, enabled[i]);
00379 if(result < 0) {
00380
00381 preSelected[i] = -1;
00382 } else {
00383 preSelected[i] = result;
00384 }
00385 }
00386
00387 String selected [] =
00388 Sct.gui.MultiSelectionDialog.showDialog(null, "Select Debug Options",
00389 possibilities, preSelected);
00390
00391 if (selected != null) {
00392 Arrays.sort(selected);
00393 Arrays.sort(enabled);
00394
00395
00396 for(int i=0; i<enabled.length; i++) {
00397 if(Arrays.binarySearch(selected, enabled[i]) < 0) {
00398 api.unsetDebugOption(enabled[i]);
00399 }
00400 }
00401
00402
00403 for(int i=0; i<selected.length; i++) {
00404 if(Arrays.binarySearch(enabled, selected[i]) < 0) {
00405 api.setDebugOption(selected[i]);
00406 }
00407 }
00408 }
00409 }
00410
00411 void autoConfigAction() {
00412 JFrame autoFrame = new JFrame("Auto configure");
00413 Component c = (Component)new AutoConfigure(api);
00414 autoFrame.getContentPane().add(c);
00415 autoFrame.pack();
00416 autoFrame.setVisible(true);
00417 }
00418
00419 RodTriplet inputRodTriplet() throws SelectionDialog.InvalidDialogException, SelectionDialog.CancelledDialogException {
00420 String [] labels = {"Partition", "Crate", "ROD"};
00421 String [] defaults = {"0", "0", "0"};
00422
00423 SelectionDialog dia = new SelectionDialog(null, "Get ROD index", labels, defaults);
00424
00425 dia.pack();
00426 dia.setVisible(true);
00427
00428 return new RodTriplet(dia.getIntFieldValue(0),
00429 dia.getIntFieldValue(1),
00430 dia.getIntFieldValue(2));
00431 }
00432
00433
00434
00435 RodQuadruplet inputRodQuadruplet() throws SelectionDialog.InvalidDialogException, SelectionDialog.CancelledDialogException {
00436 String [] labels = {"Partition", "Crate", "ROD", "Harness"};
00437 String [] defaults = {"0", "0", "0", "0"};
00438
00439 SelectionDialog dia = new SelectionDialog(null, "Get ROD index", labels, defaults);
00440
00441 dia.pack();
00442 dia.setVisible(true);
00443
00444 return new RodQuadruplet(dia.getIntFieldValue(0),
00445 dia.getIntFieldValue(1),
00446 dia.getIntFieldValue(2),
00447 dia.getIntFieldValue(3));
00448 }
00449
00450 public class RodTriplet {
00451 int partition;
00452 int crate;
00453 int rod;
00454 RodTriplet(int p, int c, int r) {
00455 partition = p;
00456 crate = c;
00457 rod = r;
00458
00459 }
00460 }
00461
00462
00463
00464 public class RodQuadruplet {
00465 int partition;
00466 int crate;
00467 int rod;
00468 int harness;
00469 RodQuadruplet(int p, int c, int r, int h) {
00470 partition = p;
00471 crate = c;
00472 rod = r;
00473 harness = h;
00474 }
00475 }
00476
00477 TimDoublet inputTimDoublet() throws SelectionDialog.InvalidDialogException, SelectionDialog.CancelledDialogException {
00478 String [] labels = {"Partition", "Crate"};
00479 String [] defaults = {"0", "0"};
00480
00481 SelectionDialog dia = new SelectionDialog(null, "Get TIM index", labels, defaults);
00482
00483 dia.pack();
00484 dia.setVisible(true);
00485
00486 return new TimDoublet(dia.getIntFieldValue(0),
00487 dia.getIntFieldValue(1));
00488 }
00489
00490 public class TimDoublet {
00491 int partition;
00492 int crate;
00493 TimDoublet(int p, int c) {
00494 partition = p;
00495 crate = c;
00496 }
00497 }
00498 }