00001 package DisplayGUI;
00002 import java.awt.event.*;
00003 import javax.swing.JMenuBar;
00004 import javax.swing.JMenuItem;
00005 import javax.swing.JMenu;
00006 import javax.swing.JCheckBox;
00007 import javax.swing.JPopupMenu;
00008
00009 import Preferences.*;
00010 import guiUtilities.ChoiceDialog;
00011
00012 import Sct.Version;
00013 import Sct_CalibrationController.TestRequest;
00014 import Sct_CalibrationController.SequenceRequest;
00015
00016 import GuiComponents.System.*;
00017 import GuiComponents.scripting.*;
00018 import GuiComponents.Console.JConsole;
00019
00020 import Sct_SctApi.*;
00021 import Sct.*;
00022 import sctConf.*;
00023 import SctData.*;
00024 import Sct.IS.*;
00025
00027 public class MenuActions implements displayParams,TestDataInfo {
00028 gui guiControl;
00029
00030 private SystemInterface si;
00031 String option;
00032
00033 private JMenu sctdbSCTDAQOptionMenu,sctdbRODDAQOptionMenu, panelsctdbSCTDAQOptionMenu,panelsctdbRODDAQOptionMenu;
00034
00035 public boolean enableAutoUpload=false;
00036 JMenuItem autoAssemblyUploadItem;
00037
00038 private JMenuItem testReportItem;
00039
00040
00041
00042 int itemIndex;
00043
00044
00045 public MenuActions(gui parent) {
00046 guiControl=parent;
00047 }
00048
00049
00050 public JMenuBar createMenuBar() {
00051
00052 JMenuBar mb = new JMenuBar();
00053
00054 mb.add(guiControl.guiMenus.getMenu(GuiMenus.MENUBAR_SYSTEM));
00055 mb.add(guiControl.guiMenus.getMenu(GuiMenus.MENUBAR_DISPLAY));
00056 mb.add(guiControl.guiMenus.getMenu(GuiMenus.MENUBAR_TESTMENU));
00057
00058 sctdbSCTDAQOptionMenu = getDBSCTDAQDataOptionMenu(false);
00059 sctdbRODDAQOptionMenu = getDBRODDAQDataOptionMenu(false);
00060 JMenu menu = new JMenu("Options");
00061 menu.setBackground(backgroundColor);
00062 menu.setFont(menuFont);
00063 menu.setForeground(menuColor);
00064
00065
00066 menu.add(guiControl.guiMenus.getMenu(GuiMenus.OPTIONS_CONFIG));
00067 menu.add(guiControl.guiMenus.getMenu(GuiMenus.OPTIONS_DISPLAY));
00068
00069 JMenu sctdbMenu = new JMenu("SCT Database");
00070 sctdbMenu.setFont(menuFont);
00071 sctdbMenu.add(sctdbSCTDAQOptionMenu);
00072 sctdbMenu.add(sctdbRODDAQOptionMenu);
00073 sctdbMenu.add(getAssemblyOptionMenu());
00074 menu.add(sctdbMenu);
00075
00076 menu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DCS));
00077
00078 menu.add(getBookkeepingMenu());
00079
00080 mb.add(menu);
00081
00082 panelsctdbSCTDAQOptionMenu = getDBSCTDAQDataOptionMenu(true);
00083 panelsctdbRODDAQOptionMenu = getDBRODDAQDataOptionMenu(true);
00084
00085
00086
00087
00088 mb.add(guiControl.guiMenus.getMenu(GuiMenus.MENUBAR_TOOLS));
00089 mb.add(guiControl.guiMenus.getMenu(GuiMenus.MENUBAR_HELP));
00090 mb.add(javax.swing.Box.createHorizontalGlue());
00091 mb.add(guiControl.guiMenus.getMenu(GuiMenus.MENUBAR_PREFERENCES));
00092
00093 mb.setBorder(javax.swing.BorderFactory.createEmptyBorder());
00094 mb.setBackground(backgroundColor);
00095 return mb;
00096 }
00097
00098
00099 public void enableCCMenuItems(boolean enabled) {
00100 guiControl.guiMenus.enableSubMenuItems(guiControl.guiMenus.getMenu(GuiMenus.PANEL_TESTMENU),enabled);
00101 guiControl.guiMenus.enableSubMenuItems(guiControl.guiMenus.getMenu(GuiMenus.MENUBAR_TESTMENU),enabled);
00102 }
00103
00104
00105
00106 public void enableDisplayMenuItems(boolean enabled) {
00107 guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY).setEnabled(enabled);
00108 guiControl.guiMenus.getMenu(GuiMenus.MENUBAR_DISPLAY).setEnabled(enabled);
00109 }
00110
00111
00112 protected boolean addNewConsole(Interpreter interpreter, String suffix) {
00113 if (interpreter == null) {
00114 System.out.println("Can only have 1 scripting window open at once\n");
00115 return false;
00116 }
00117 javax.swing.JFrame frame = new javax.swing.JFrame();
00118 javax.swing.JScrollPane scroll = new javax.swing.JScrollPane();
00119 scroll.setViewportView(interpreter.getConsole());
00120 frame.getContentPane().add(scroll);
00121 frame.setTitle("Scripting Window:" + suffix);
00122 frame.setVisible(true);
00123 frame.setSize(800, 500);
00124 return true;
00125 }
00126
00127
00128
00129
00130 public void showTablesPopupMenu(int clickedTable, MouseEvent e) {
00131 JPopupMenu pMenu;
00132 switch(clickedTable) {
00133 case 1:
00134 switch(guiControl.displayStatus.getStatus()) {
00135 case DisplayStatus.MODULE_GROUP_SELECTION:
00136 if(guiControl.selectorPane.getDisplayParameterIndex()>0) {
00137 pMenu = guiControl.guiMenus.getMenu(GuiMenus.MODULE_BOC).getPopupMenu();
00138 pMenu.show(e.getComponent(),e.getX(),e.getY());
00139 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.MODULE_BOC));
00140 }
00141 break;
00142
00143 case DisplayStatus.IS_MONITOR:
00144 pMenu = guiControl.guiMenus.getMenu(GuiMenus.MODULE_DATA_MANAGER).getPopupMenu();
00145 pMenu.show(e.getComponent(),e.getX(),e.getY());
00146 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.MODULE_DATA_MANAGER));
00147 break;
00148 case DisplayStatus.TEST_DATA:
00149 pMenu = guiControl.guiMenus.getMenu(GuiMenus.MODULE_RESULTS).getPopupMenu();
00150 pMenu.show(e.getComponent(),e.getX(),e.getY());
00151 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.MODULE_RESULTS));
00152 break;
00153 case DisplayStatus.SCTDB_DATA:
00154 pMenu = guiControl.guiMenus.getMenu(GuiMenus.MODULE_SCTDB).getPopupMenu();
00155 pMenu.show(e.getComponent(),e.getX(),e.getY());
00156 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.MODULE_SCTDB));
00157 break;
00158 case DisplayStatus.SCTDB_RODDAQ_DATA:
00159 pMenu = guiControl.guiMenus.getMenu(GuiMenus.MODULE_SCTDB).getPopupMenu();
00160 pMenu.show(e.getComponent(),e.getX(),e.getY());
00161 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.MODULE_SCTDB));
00162 break;
00163 case DisplayStatus.IV_DATA:
00164 pMenu = guiControl.guiMenus.getMenu(GuiMenus.MODULE_IVSCAN).getPopupMenu();
00165 pMenu.show(e.getComponent(),e.getX(),e.getY());
00166 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.MODULE_IVSCAN));
00167 break;
00168 case DisplayStatus.DCS_DATA:
00169 pMenu = guiControl.guiMenus.getMenu(GuiMenus.MODULE_DCS).getPopupMenu();
00170 pMenu.show(e.getComponent(),e.getX(),e.getY());
00171 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.MODULE_DCS));
00172 break;
00173 default:
00174 }
00175 break;
00176 case 0:
00177 switch(guiControl.displayStatus.getStatus()) {
00178 case DisplayStatus.IS_MONITOR:
00179 pMenu = getTable0Menu().getPopupMenu();
00180 pMenu.show(e.getComponent(),e.getX(),e.getY());
00181
00182 break;
00183 case DisplayStatus.TEST_DATA:
00184 pMenu = guiControl.guiMenus.getMenu(GuiMenus.TEST_FILTER).getPopupMenu();
00185 pMenu.show(e.getComponent(),e.getX(),e.getY());
00186 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.TEST_FILTER));
00187 break;
00188 default:
00189 }
00190 break;
00191 default:
00192 }
00193
00194 }
00195
00196 public void showRODMenu(MouseEvent e) {
00197 JPopupMenu pMenu;
00198 JMenu newMenu = new JMenu();
00199 JMenuItem item = new JMenuItem("ROD Diagnostic...");
00200 item.setFont(menuFont);
00201 newMenu.add(item);
00202 item.addActionListener(new java.awt.event.ActionListener() {
00203 public void actionPerformed(java.awt.event.ActionEvent evt) {
00204 showRodDiagnosticWindow();
00205 }
00206 });
00207 pMenu = newMenu.getPopupMenu();
00208 pMenu.show(e.getComponent(),e.getX(),e.getY());
00209 pMenu.setInvoker(newMenu);
00210 }
00211
00212 public void showTIMRegisterMenu(MouseEvent e) {
00213 JPopupMenu pMenu;
00214 JMenu newMenu = new JMenu();
00215 JMenuItem item = new JMenuItem("TIM Registers...");
00216 item.setFont(menuFont);
00217 newMenu.add(item);
00218 item.addActionListener(new java.awt.event.ActionListener() {
00219 public void actionPerformed(java.awt.event.ActionEvent evt) {
00220 javax.swing.JOptionPane.showMessageDialog(null,"TIM Register gui not yet ready...Try again soon!");
00221 }
00222 });
00223 pMenu = newMenu.getPopupMenu();
00224 pMenu.show(e.getComponent(),e.getX(),e.getY());
00225 pMenu.setInvoker(newMenu);
00226 }
00227
00228
00229 public void showPopupMenu(MouseEvent e) {
00230 JPopupMenu pMenu;
00231 JMenu newMenu = new JMenu();
00232 switch(guiControl.displayStatus.getStatus()) {
00233 case DisplayStatus.UNDEFINED:
00234 pMenu = guiControl.guiMenus.getMenu(GuiMenus.OPTIONS_CONFIG).getPopupMenu();
00235 pMenu.show(e.getComponent(),e.getX(),e.getY());
00236 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.OPTIONS_CONFIG));
00237 break;
00238 case DisplayStatus.MODULE_GROUP_SELECTION:
00239 if(guiControl.selectorPane.getDisplayParameterIndex()==0) {
00240 pMenu = guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY).getPopupMenu();
00241 pMenu.show(e.getComponent(),e.getX(),e.getY());
00242 pMenu.setInvoker(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY));
00243 }
00244 else {
00245 JMenuItem item = new JMenuItem("ReRead BOC Data");
00246 item.setFont(menuFont);
00247 newMenu.add(item);
00248 item.addActionListener(new java.awt.event.ActionListener() {
00249 public void actionPerformed(java.awt.event.ActionEvent evt) {
00250 try {
00251 SctApiInfo.getInstance().probeConfig(guiControl.selectorPane.getViewCategoryIndex(),guiControl.selectorPane.getViewIndex(),guiControl.selectorPane.getDisplayParameterIndex());
00252 guiControl.displayPane.setDisplayColors();
00253 guiControl.displayPane.refreshDisplay();
00254 guiControl.tablesDisplayPane.updateTables();
00255 }catch(Exception e){javax.swing.JOptionPane.showMessageDialog(null,"SctApi Exception "+e.toString());}
00256 }
00257 });
00258 newMenu.addSeparator();
00259 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY));
00260 pMenu = newMenu.getPopupMenu();
00261 pMenu.show(e.getComponent(),e.getX(),e.getY());
00262 pMenu.setInvoker(newMenu);
00263 }
00264 break;
00265 case DisplayStatus.IS_MONITOR:
00266 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY));
00267 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_TESTMENU));
00268 newMenu.addSeparator();
00269 JMenuItem rItem = new JMenuItem("Retrieve Archived Data");
00270 rItem.setFont(menuFont);
00271 newMenu.add(rItem);
00272 rItem.addActionListener(new java.awt.event.ActionListener() {
00273 public void actionPerformed(java.awt.event.ActionEvent evt) {
00274 ArchiveQueryBox b = new ArchiveQueryBox(guiControl);
00275 b.setLocationRelativeTo(guiControl);
00276 b.setVisible(true);
00277 }
00278 });
00279
00280
00281 pMenu = newMenu.getPopupMenu();
00282 pMenu.show(e.getComponent(),e.getX(),e.getY());
00283
00284 pMenu.setInvoker(newMenu);
00285 break;
00286 case DisplayStatus.TEST_DATA:
00287 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY));
00288 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_TESTMENU));
00289 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_TESTDATA));
00290
00291 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00292 if(testSelection!=null && testSelection.getTestIndex()==TEST_RXTHRESHOLDBASEDONCONFIGREGISTER) {
00293 JMenuItem item = new JMenuItem("RxThreshold Comparison Report...");
00294 item.setFont(menuFont);
00295 item.addActionListener(new java.awt.event.ActionListener() {
00296 public void actionPerformed(java.awt.event.ActionEvent evt) {
00297 String txt = javax.swing.JOptionPane.showInputDialog(null,"List channels with RxThreshold shifted by more than:","10");
00298 if(txt==null) return;
00299 try {
00300 int shift = Integer.valueOf(txt).intValue();
00301 if(shift<0) {
00302 javax.swing.JOptionPane.showMessageDialog(null,"Shift must be a positive number.");
00303 return;
00304 }
00305 java.util.Vector theTable = checkBOCRxThresholds(shift);
00306 if(theTable==null) return;
00307 if(theTable.size()>1) guiUtilities.SpreadsheetViewer.getInstance().update("Comparison of optimised RxThresholds with with XML file settings for channels with RxThreshold shift greater than "+txt,theTable);
00308 else javax.swing.JOptionPane.showMessageDialog(null,"All RxThreshold values in the xml files are within "+shift+" counts of the optimal values.");
00309 }catch(Exception e){javax.swing.JOptionPane.showMessageDialog(null,"You must enter a positive number.");}
00310 }
00311 });
00312 newMenu.add(item);
00313 item = new JMenuItem("Update XML Files...");
00314 item.setFont(menuFont);
00315 item.addActionListener(new java.awt.event.ActionListener() {
00316 public void actionPerformed(java.awt.event.ActionEvent evt) {
00317 String txt = javax.swing.JOptionPane.showInputDialog(null,"Update files if RxThreshold shifted by more than:","10");
00318 if(txt==null) return;
00319 try {
00320 int shift = Integer.valueOf(txt).intValue();
00321 if(shift<0) {
00322 javax.swing.JOptionPane.showMessageDialog(null,"Shift must be a positive number.");
00323 return;
00324 }
00325 java.util.Vector theTable = checkBOCRxThresholds(shift);
00326 if(theTable==null) return;
00327 System.out.println("theTable has size "+theTable.size());
00328 if(theTable.size()>1) {
00329 RxThresholdData rxFileData = RxThresholdData.getInstance();
00330 rxFileData.updateXMLfiles(theTable,shift);
00331 if(rxFileData.getErrorString()!=null) {
00332 javax.swing.JOptionPane.showMessageDialog(null,rxFileData.getErrorString());
00333 return;
00334 }
00335 }
00336 else javax.swing.JOptionPane.showMessageDialog(null,"No updates made. All RxThreshold values in the xml files are within "+shift+" counts of the optimal values.");
00337 }catch(Exception e){javax.swing.JOptionPane.showMessageDialog(null,"You must enter a positive number.");}
00338 }
00339 });
00340 newMenu.add(item);
00341 }
00342
00343 pMenu = newMenu.getPopupMenu();
00344 pMenu.show(e.getComponent(),e.getX(),e.getY());
00345 pMenu.setInvoker(newMenu);
00346 break;
00347 case DisplayStatus.SCTDB_DATA:
00348 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY));
00349 newMenu.add(panelsctdbSCTDAQOptionMenu);
00350 pMenu = newMenu.getPopupMenu();
00351 pMenu.show(e.getComponent(),e.getX(),e.getY());
00352 pMenu.setInvoker(newMenu);
00353 break;
00354 case DisplayStatus.SCTDB_RODDAQ_DATA:
00355 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY));
00356 newMenu.add(panelsctdbRODDAQOptionMenu);
00357 pMenu = newMenu.getPopupMenu();
00358 pMenu.show(e.getComponent(),e.getX(),e.getY());
00359 pMenu.setInvoker(newMenu);
00360 break;
00361 case DisplayStatus.DCS_DATA:
00362 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY));
00363 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_TESTMENU));
00364 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DCS));
00365 pMenu = newMenu.getPopupMenu();
00366 pMenu.show(e.getComponent(),e.getX(),e.getY());
00367 pMenu.setInvoker(newMenu);
00368 break;
00369 case DisplayStatus.IV_DATA:
00370 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY));
00371 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.OPTIONS_IVSCAN));
00372 pMenu = newMenu.getPopupMenu();
00373 pMenu.show(e.getComponent(),e.getX(),e.getY());
00374 pMenu.setInvoker(newMenu);
00375 break;
00376 case DisplayStatus.PROBE_DATA:
00377 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_DISPLAY));
00378 newMenu.add(guiControl.guiMenus.getMenu(GuiMenus.PANEL_PROBE));
00379 pMenu = newMenu.getPopupMenu();
00380 pMenu.show(e.getComponent(),e.getX(),e.getY());
00381 pMenu.setInvoker(newMenu);
00382 break;
00383
00384 default:
00385 }
00386 }
00387
00388
00389 private JMenu getBookkeepingMenu() {
00390 JMenu thisMenu = new JMenu("BookKeeping");
00391 thisMenu.setFont(menuFont);
00392
00393 BookKeeper sbk = BookKeeper.getInstance();
00394
00395 thisMenu.add(sbk.bookkeepingEnabledItem);
00396
00397
00398 thisMenu.addSeparator();
00399
00400 thisMenu.add(sbk.runPromptEnabledItem);
00401 thisMenu.add(sbk.testPromptEnabledItem);
00402
00403 return thisMenu;
00404 }
00405
00406 private JMenu getTable0Menu() {
00407 JMenu thisMenu = new JMenu("Data Manager - table0");
00408
00409 thisMenu.setFont(menuFont);
00410
00411 JMenuItem item = new JMenuItem("Add/Edit Run Comments...");
00412 item.setFont(menuFont);
00413 item.addActionListener(new java.awt.event.ActionListener() {
00414 public void actionPerformed(java.awt.event.ActionEvent evt) {
00415 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00416 if(testSelection==null) {
00417 javax.swing.JOptionPane.showMessageDialog(null,"No test selected.");
00418 return;
00419 }
00420 BookKeeper.getInstance().showCommentPrompt(testSelection.getRunNo(), testSelection.getScanNo(), null);
00421 }
00422 });
00423 thisMenu.add(item);
00424
00425 item = new JMenuItem("Add/Edit Test Comments...");
00426 item.setFont(menuFont);
00427 item.addActionListener(new java.awt.event.ActionListener() {
00428 public void actionPerformed(java.awt.event.ActionEvent evt) {
00429 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00430 if(testSelection==null) {
00431 javax.swing.JOptionPane.showMessageDialog(null,"No test selected.");
00432 return;
00433 }
00434 BookKeeper.getInstance().showCommentPrompt(testSelection.getRunNo(), testSelection.getScanNo(), testSelection.getTestName());
00435 }
00436 });
00437 thisMenu.add(item);
00438
00439 thisMenu.addSeparator();
00440
00441 item = new JMenuItem("Delete Selected Test(s)");
00442 item.setFont(menuFont);
00443 item.addActionListener(new java.awt.event.ActionListener() {
00444 public void actionPerformed(java.awt.event.ActionEvent evt) {
00445 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00446 if(testSelection==null) {
00447 javax.swing.JOptionPane.showMessageDialog(null,"No data selected.");
00448 return;
00449 }
00450 int selectedRow = guiControl.tablesDisplayPane.getSelectedTest();
00451 int response = javax.swing.JOptionPane.showConfirmDialog(null,"Delete "+testSelection.getTestName()+" test for Run/Scan "+testSelection.getRunNo()+"/"+testSelection.getScanNo()+"?","Confirm Deletion",javax.swing.JOptionPane.YES_NO_OPTION,javax.swing.JOptionPane.QUESTION_MESSAGE);
00452 if(response==javax.swing.JOptionPane.NO_OPTION) return;
00453 guiControl.isInterface.removeTests(guiControl.tablesDisplayPane.getTestControlObjectNames(),selectedRow,selectedRow);
00454 guiControl.tablesDisplayPane.updateTables();
00455 }
00456 });
00457 thisMenu.add(item);
00458
00459
00460
00461 return thisMenu;
00462 }
00463
00464 private void setAssemblyUploadItem() {
00465 autoAssemblyUploadItem.setText(enableAutoUpload ? "Disable auto-upload of module positions" : "Enable auto-upload of module positions");
00466 }
00467
00468 private JMenu getAssemblyOptionMenu() {
00469 JMenu thisMenu = new JMenu("Assembly");
00470
00471 thisMenu.setFont(menuFont);
00472
00473
00474 autoAssemblyUploadItem = new JMenuItem("Item");
00475 autoAssemblyUploadItem.setFont(menuFont);
00476 enableAutoUpload = PreferencesInterface.getInstance().getPreference(PreferencesInterface.ASSEMBLY_UPLOADS).equals("TRUE");
00477 setAssemblyUploadItem();
00478 autoAssemblyUploadItem.addActionListener(new java.awt.event.ActionListener() {
00479 public void actionPerformed(java.awt.event.ActionEvent evt) {
00480 enableAutoUpload = !enableAutoUpload;
00481 setAssemblyUploadItem();
00482 PreferencesInterface.getInstance().setPreference(PreferencesInterface.ASSEMBLY_UPLOADS,enableAutoUpload ? "TRUE" : "FALSE");
00483 }
00484 });
00485 thisMenu.add(autoAssemblyUploadItem);
00486
00487 thisMenu.addSeparator();
00488
00489 JMenuItem item = new JMenuItem("Upload Module Assembly Positions");
00490 item.setFont(menuFont);
00491 thisMenu.add(item);
00492 item.addActionListener(new java.awt.event.ActionListener() {
00493 public void actionPerformed(java.awt.event.ActionEvent evt) {
00494 guiControl.isInterface.uploadAssemblyInfo();
00495 }
00496 });
00497
00498 return thisMenu;
00499 }
00500
00501
00502 private JMenu getDBSCTDAQDataOptionMenu(boolean isPanel) {
00503 JMenu thisMenu = new JMenu("SCTDAQ Reference");
00504
00505 thisMenu.setFont(menuFont);
00506
00507 JMenuItem item = new JMenuItem("Download SCTDAQ Reference Data");
00508 item.setFont(menuFont);
00509 thisMenu.add(item);
00510 item.addActionListener(new java.awt.event.ActionListener() {
00511 public void actionPerformed(java.awt.event.ActionEvent evt) {
00512 guiControl.isInterface.downloadTests(-1);
00513 }
00514 });
00515 item = new JMenuItem("SCTDAQ Test Location ...");
00516 item.setFont(menuFont);
00517 thisMenu.add(item);
00518 item.addActionListener(new java.awt.event.ActionListener() {
00519 public void actionPerformed(java.awt.event.ActionEvent evt) {
00520 java.util.Vector listOfLocations = new java.util.Vector();
00521 try {
00522 listOfLocations = ProdDatabase.GeneralUtilities.getLocationList();
00523 }catch(Exception e2){}
00524 listOfLocations.insertElementAt("Any",0);
00525 guiUtilities.userPrompt thisPrompt = new guiUtilities.userPrompt(guiControl,"Any","Institute", listOfLocations);
00526 thisPrompt.pack();
00527 thisPrompt.setLocationRelativeTo(guiControl);
00528 thisPrompt.setVisible(true);
00529 String thisLocation = thisPrompt.getValidatedText();
00530 if (!thisLocation.equals("None")) {
00531 guiControl.isInterface.setLocation(thisLocation);
00532
00533 guiControl.selectorPane.initParamList();
00534 guiControl.colorScalePane.setColorScale();
00535 guiControl.displayPane.setDisplayColors();
00536 guiControl.displayPane.refreshDisplay();
00537 guiControl.tablesDisplayPane.listTestResults();
00538 }
00539
00540 }
00541 });
00542 return thisMenu;
00543 }
00544
00545 private JMenu getDBRODDAQDataOptionMenu(boolean isPanel) {
00546 JMenu thisMenu = new JMenu("SctRodDaq Downloads");
00547
00548 thisMenu.setFont(menuFont);
00549
00550
00551 JMenuItem item = new JMenuItem("Download SctRodDaq Data ...");
00552 item.setFont(menuFont);
00553 thisMenu.add(item);
00554 item.addActionListener(new java.awt.event.ActionListener() {
00555 public void actionPerformed(java.awt.event.ActionEvent evt) {
00556 new DatabaseLister().show();
00557 }
00558 });
00559
00560 return thisMenu;
00561 }
00562
00563
00564
00565 public void updateMenuStates() {
00566
00567
00568
00569
00570
00571
00572
00573 }
00574
00575
00576
00577 public void plotIVScanData(String serialNo) {
00578 IVTestSelection ivTestSelection = guiControl.tablesDisplayPane.getIVTestSelection();
00579 if(ivTestSelection==null) {
00580 javax.swing.JOptionPane.showMessageDialog(null,"No IV Scan selected.");
00581 return;
00582 }
00583 String summary = "IV Scan Plots for Run "+Integer.toString(ivTestSelection.getRunNo())+", Scan "+Integer.toString(ivTestSelection.getScanNo());
00584 DisplayGUI.plotters.IVScansData ivScansData = new DisplayGUI.plotters.IVScansData(summary);
00585 for (java.util.Iterator m = ConfigurationInterface.getInstance().getSerialNumberList(guiControl.selectorPane.getViewCategoryIndex(),guiControl.selectorPane.getViewIndex()).iterator(); m.hasNext(); ) {
00586 String sn=(String)m.next();
00587 SummaryReader.IVData ivData = guiControl.isInterface.getIVData(ivTestSelection.getResultObjectHeader(),sn);
00588 if(ivData!=null) ivScansData.add(sn,ivData.getDataPointSet());
00589 }
00590 DisplayGUI.plotters.IVPlotDisplay ivPlotDisplay = new DisplayGUI.plotters.IVPlotDisplay();
00591 ivPlotDisplay.showData(ivScansData,serialNo);
00592 }
00593
00594
00595 private java.util.Vector checkBOCRxThresholds(int shift) {
00596 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00597 int testIndex = (testSelection!=null) ? testSelection.getTestIndex() : -1;
00598 if(testIndex==-1) {
00599 javax.swing.JOptionPane.showMessageDialog(null,"No test is currently selected.");
00600 return null;
00601 }
00602
00603
00604 RxThresholdData rxFileData = RxThresholdData.getInstance();
00605 rxFileData.refresh();
00606 if(rxFileData.getErrorString()!=null) {
00607 javax.swing.JOptionPane.showMessageDialog(null,rxFileData.getErrorString());
00608 return null;
00609 }
00610 java.util.Vector theTable = new java.util.Vector();
00611 java.util.Vector theLine = new java.util.Vector();
00612 theLine.addElement("Serial No");
00613 theLine.addElement("Stream");
00614 theLine.addElement("MUR");
00615 theLine.addElement("Module ID");
00616 theLine.addElement("Optimal RxThr");
00617 theLine.addElement("File Value");
00618 theLine.addElement("Shift");
00619 theTable.addElement(theLine);
00620
00621
00622 for (java.util.Iterator m = ConfigurationInterface.getInstance().getSerialNumberList(guiControl.selectorPane.getViewCategoryIndex(),guiControl.selectorPane.getViewIndex()).iterator(); m.hasNext(); ) {
00623 String sn=(String)m.next();
00624 for(int stream=0;stream<2;stream++) {
00625 theLine = new java.util.Vector();
00626 theLine.addElement(sn);
00627 theLine.addElement(new Integer(stream));
00628 theLine.addElement(rxFileData.getMurID(sn));
00629 theLine.addElement(rxFileData.getModuleID(sn));
00630 String resultObjectHeader = testSelection.getResultObjectHeader();
00631 SummaryReader.Test testResult = guiControl.isInterface.getTest(resultObjectHeader,sn,null);
00632 Double rxData = testResult.getLinkInfo().get(stream,2);
00633 int rxDataInt = (int)rxData.doubleValue();
00634 theLine.addElement(Integer.toString(rxDataInt));
00635 String fileData = rxFileData.getStreamFileData(sn,stream);
00636 if(fileData==null)continue;
00637 theLine.addElement(fileData);
00638 Integer fileDataInteger = guiUtilities.DaveUtils.getIntFromHex(fileData);
00639 if(fileDataInteger==null) continue;
00640 int diff = (rxDataInt==-1) ? -1 : rxDataInt - fileDataInteger.intValue();
00641 if(Math.abs(diff)<=shift) continue;
00642 theLine.addElement(new Integer(diff));
00643
00644 theTable.addElement(theLine);
00645 }
00646 }
00647 return theTable;
00648 }
00649
00650
00651
00652
00653
00654
00655
00656 public void makeComparisonReport(boolean isSCTDAQ) {
00657 Object[] runList=null;
00658 TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00659 int testIndex = (testSelection!=null) ? testSelection.getTestIndex() : -1;
00660 if(testIndex==-1) {
00661 javax.swing.JOptionPane.showMessageDialog(null,"No test is currently selected.");
00662 return;
00663 }
00664 if(!testIsSCTDAQ[testIndex]) {
00665 javax.swing.JOptionPane.showMessageDialog(null,testNames[testIndex]+" is not a SCTDAQ test - no reference comparison is possible.");
00666 return;
00667 }
00668 java.util.Vector sctdbObjectHeaderList = new java.util.Vector();
00669 if(isSCTDAQ) sctdbObjectHeaderList.addElement(testSelection.getSCTDBObjectHeader());
00670 else {
00671 java.util.Vector vTest = new java.util.Vector();
00672 String[] objectList = guiControl.isInterface.getDBISObjects(testIndex);
00673
00674 if(objectList.length==0) {
00675 javax.swing.JOptionPane.showMessageDialog(null,"There is no "+testNames[testIndex]+" SctRodDaq reference data yet downloaded\nPlease download data from the Options menu or via the SctRodDaq Reference display.");
00676 return;
00677 }
00678 guiUtilities.ChoiceDialog rnd = new guiUtilities.ChoiceDialog(guiControl,"Choose Reference Data",90,16,objectList,true);
00679 rnd.pack();
00680 rnd.setLocationRelativeTo(guiControl);
00681 rnd.setVisible(true);
00682 runList = rnd.getSelectedObjects();
00683 if(runList==null || runList.length==0) return;
00684
00685 for(int k=0;k<runList.length;k++) {
00686 String sctdbObject = (String)runList[k];
00687
00688 java.util.regex.Matcher matcher = ISInterface.SctRodDaqRefPattern.matcher(sctdbObject);
00689 if(matcher.matches()) {
00690
00691 TestSelection thisSel = new TestSelection(sctdbObject,sctdbObject.substring(matcher.start(ISInterface.LOCATION),matcher.end(ISInterface.LOCATION)));
00692
00693 sctdbObjectHeaderList.addElement(thisSel.getSCTDBRodDaqObjectHeader());
00694 }
00695 }
00696 }
00697
00698 String header = testSelection.getResultObjectHeader();
00699
00700 java.util.Vector theTable = new java.util.Vector();
00701 java.util.Vector theLine = new java.util.Vector();
00702 theLine.addElement("Serial No");
00703 theLine.addElement("Parameter");
00704 theLine.addElement("Tolerance");
00705 theLine.addElement("SctRodDaq Data");
00706 theLine.addElement("Reference Data");
00707 theLine.addElement("Comments");
00708 theTable.addElement(theLine);
00709
00710 String resultObjectHeader = testSelection.getResultObjectHeader();
00711 java.util.regex.Pattern defectPattern = java.util.regex.Pattern.compile("^[^-]+-(.*)");
00712 java.util.regex.Matcher matcher;
00713
00714
00715
00716
00717 for (java.util.Iterator i = ConfigurationInterface.getInstance().getSerialNumberList(guiControl.selectorPane.getViewCategoryIndex(),guiControl.selectorPane.getViewIndex()).iterator(); i.hasNext(); ) {
00718
00719 String sn=(String)i.next();
00720 ModuleConfiguration mConfig=null;
00721 try {
00722 Sct_SctApi.SctApiIPC api = SystemInterface.getInstance().getSctApi();
00723 if (api != null) {
00724 int mid = api.findModuleSerial(sn);
00725 ABCDModule data = api.retrieveModule(mid);
00726 mConfig = new ModuleConfiguration(data);
00727 }
00728 }catch(Exception e2){System.err.println("SctGUI: Cannot access module config for module "+sn);}
00729
00730 SummaryReader.Test newTestResult = guiControl.isInterface.getTest(resultObjectHeader,sn,null);
00731 if(newTestResult==null) continue;
00732 SummaryReader.Test refTestResult = null;
00733 HEADERLOOP:
00734 for(int j=0;j<sctdbObjectHeaderList.size();j++) {
00735 String sctdbObject = (String)sctdbObjectHeaderList.elementAt(j)+sn;
00736
00737 if(SctNames.getISRepository().contains(sctdbObject)) {
00738 refTestResult = guiControl.isInterface.getSCTDBTest(sctdbObject);
00739 break HEADERLOOP;
00740 }
00741 }
00742
00743
00744 if(refTestResult==null) {
00745 theLine = new java.util.Vector();
00746 theLine.addElement(sn);
00747 theLine.addElement("n/a");
00748 theLine.addElement("n/a");
00749 theLine.addElement("n/a");
00750 theLine.addElement("NO DATA");
00751 theLine.addElement("Please download reference data");
00752 theTable.addElement(theLine);
00753 continue;
00754 }
00755
00756
00757
00758 java.util.Map refDefectKeys = new java.util.HashMap();
00759 for(int k=0;k<refTestResult.getNoDefects();k++) {
00760 SummaryReader.DefectInfo defectInfo = refTestResult.getDefectInfo(k);
00761 String defectKey = defectInfo.getDefectKey();
00762 matcher = defectPattern.matcher(defectKey);
00763 String chans = matcher.matches() ? defectKey.substring(matcher.start(1),matcher.end(1)) : defectKey;
00764 refDefectKeys.put(chans,defectInfo.getName());
00765
00766 }
00767 for(int k=0;k<newTestResult.getNoDefects();k++) {
00768 SummaryReader.DefectInfo defectInfo = newTestResult.getDefectInfo(k);
00769 String newKey = defectInfo.getDefectKey();
00770 matcher = defectPattern.matcher(newKey);
00771 String chans = matcher.matches() ? newKey.substring(matcher.start(1),matcher.end(1)) : newKey;
00772 String newName = defectInfo.getName();
00773
00774 if(refDefectKeys.containsKey(chans)) {
00775
00776 String name = (String)refDefectKeys.get(chans);
00777 if(name.equals(newName)) continue;
00778
00779 theLine = new java.util.Vector();
00780 theLine.addElement(sn);
00781 theLine.addElement("Defects");
00782 theLine.addElement("Zero");
00783 theLine.addElement(chans+" ("+newName+")");
00784 theLine.addElement(chans+" ("+name+")");
00785 theLine.addElement("Different defect type");
00786 theTable.addElement(theLine);
00787 continue;
00788 }
00789 theLine = new java.util.Vector();
00790 theLine.addElement(sn);
00791 theLine.addElement("Defects");
00792 theLine.addElement("Zero");
00793 theLine.addElement(chans+" ("+newName+")");
00794 theLine.addElement("Not Present");
00795 theLine.addElement("NEW DEFECT");
00796 theTable.addElement(theLine);
00797 }
00798
00799 java.util.Map newDefectKeys = new java.util.HashMap();
00800 for(int k=0;k<newTestResult.getNoDefects();k++) {
00801 SummaryReader.DefectInfo defectInfo = newTestResult.getDefectInfo(k);
00802 String defectKey = defectInfo.getDefectKey();
00803 matcher = defectPattern.matcher(defectKey);
00804 String chans = matcher.matches() ? defectKey.substring(matcher.start(1),matcher.end(1)) : defectKey;
00805 newDefectKeys.put(chans,defectInfo.getName());
00806 }
00807 for(int k=0;k<refTestResult.getNoDefects();k++) {
00808 SummaryReader.DefectInfo defectInfo = refTestResult.getDefectInfo(k);
00809 String refKey = defectInfo.getDefectKey();
00810 matcher = defectPattern.matcher(refKey);
00811 String chans = matcher.matches() ? refKey.substring(matcher.start(1),matcher.end(1)) : refKey;
00812 String refName = defectInfo.getName();
00813 if(!newDefectKeys.containsKey(chans)) {
00814 theLine = new java.util.Vector();
00815 theLine.addElement(sn);
00816 theLine.addElement("Defects");
00817 theLine.addElement("Zero");
00818 theLine.addElement("Not Present");
00819 theLine.addElement(chans+" ("+refName+")");
00820 theLine.addElement("Old defect no longer present");
00821 theTable.addElement(theLine);
00822 }
00823 }
00824
00825 PARAMLOOP:
00826 for(int parameterIndex=0;parameterIndex<testParameters[testIndex].length;parameterIndex++) {
00827 if(!testIsDefined[testIndex]) continue;
00828 if(!doComparisons[testIndex][parameterIndex]) continue;
00829 for(int k=4;k<chipOptions.length;k++) {
00830 Double newData = newTestResult.getLastDataBlock().get(k,parameterIndex-parameterOffset);
00831 Double refData = (refTestResult!=null) ? refTestResult.getLastDataBlock().get(k,parameterIndex-parameterOffset) : null;
00832 if(refData==null) {
00833 theLine = new java.util.Vector();
00834 theLine.addElement(sn);
00835 theLine.addElement(testParameters[testIndex][parameterIndex]);
00836 theLine.addElement(Double.toString(testDataTolerances[testIndex][parameterIndex]));
00837 theLine.addElement(newData.toString());
00838 theLine.addElement("NO DATA");
00839 theLine.addElement("Please download reference data!");
00840 theTable.addElement(theLine);
00841 break PARAMLOOP;
00842 }
00843 double referenceData = refData.doubleValue();
00844 if(isSCTDAQ) {
00845 try {
00846
00847 switch(testIndex) {
00848 case TEST_3PTGAIN:
00849 case TEST_NPTGAIN:
00850 if(mConfig!=null) {
00851 double cfactor = (double)mConfig.getChipConfiguration(k-4).getCalFactor();
00852 if(parameterIndex==11) referenceData *= cfactor;
00853 else if(parameterIndex==6) referenceData /= cfactor;
00854 }
00855 break;
00856 case TEST_NOISE:
00857 if(mConfig!=null && parameterIndex==7) {
00858 double cfactor = (double)mConfig.getChipConfiguration(k-4).getCalFactor();
00859 referenceData *= cfactor;
00860 }
00861 break;
00862 default:
00863 }
00864 }catch(Exception e3){System.err.println("Exception retrieving cfactor for chip "+Integer.toString(k-4)+", module "+sn);}
00865 }
00866
00867
00868 double diff = newData.doubleValue()-referenceData;
00869 if(Math.abs(diff)>testDataTolerances[testIndex][parameterIndex]) {
00870 theLine = new java.util.Vector();
00871 theLine.addElement(sn);
00872 theLine.addElement(testParameters[testIndex][parameterIndex]);
00873 theLine.addElement(Double.toString(testDataTolerances[testIndex][parameterIndex]));
00874 theLine.addElement(newData.toString());
00875 theLine.addElement(refData.toString());
00876 String label = (diff>0.) ? "too high" : "too Low";
00877 theLine.addElement(chipOptions[k]+" data "+label);
00878 theTable.addElement(theLine);
00879 }
00880 }
00881 }
00882 }
00883 if(theTable.size()==1) {
00884 StringBuffer b = new StringBuffer("SctRodDaq in good agreement with SCTDAQ Reference Data");
00885 b.append("\nfor "+testNames[testSelection.getTestIndex()]+" Run "+Integer.toString(testSelection.getRunNo())+" Scan "+Integer.toString(testSelection.getScanNo()));
00886 b.append("\nParameters compared:");
00887 for(int parameterIndex=0;parameterIndex<testParameters[testIndex].length;parameterIndex++) {
00888 if(testIsDefined[testIndex] && doComparisons[testIndex][parameterIndex]) b.append("\n"+testParameters[testIndex][parameterIndex]);
00889 }
00890 javax.swing.JOptionPane.showMessageDialog(null,b.toString());
00891 return;
00892 }
00893 String param = "None";
00894 if(isSCTDAQ) param = "SctRodDaq/SCTDAQ Discrepancy List for "+testNames[testSelection.getTestIndex()]+" Run "+Integer.toString(testSelection.getRunNo())+" Scan "+Integer.toString(testSelection.getScanNo());
00895 else {
00896 StringBuffer dText = new StringBuffer();
00897 for(int k=0;k<runList.length;k++) {
00898 String ob = (String)runList[k];
00899 matcher = ISInterface.SctRodDaqRefPattern.matcher(ob);
00900 if(matcher.matches()) {
00901 if(k<0) dText.append(" and Run/Scan ");
00902 else dText.append(",");
00903 dText.append(ob.substring(matcher.start(ISInterface.RUNNO),matcher.end(ISInterface.RUNNO))+"/"+ob.substring(matcher.start(ISInterface.SCANNO),matcher.end(ISInterface.SCANNO)));
00904 }
00905 }
00906 param =testNames[testSelection.getTestIndex()]+" Comparison between new data (Run/Scan "+Integer.toString(testSelection.getRunNo())+"/"+Integer.toString(testSelection.getScanNo())+") and "+dText.toString();
00907 }
00908 guiUtilities.SpreadsheetViewer.getInstance().update(param,theTable);
00909 }
00910
00911 public void showRodDiagnosticWindow() {
00912 ConfigurationInterface config = ConfigurationInterface.getInstance();
00913 int slot = guiControl.displayPane.getLastClickedRodSlot();
00914 if(slot<0) return;
00915 String sn = config.getASerialNumberForSlot(guiControl.selectorPane.getViewIndex(),slot);
00916 if(sn==null) return;
00917 javax.swing.JFrame rodFrame = new javax.swing.JFrame("ROD diagnostics");
00918 int partition = Integer.parseInt(config.getSNInfo(sn,SNInfo.PARTITION));
00919 int crate = Integer.parseInt(config.getSNInfo(sn,SNInfo.ROD_CRATE));
00920 int rod = Integer.parseInt(config.getSNInfo(sn,SNInfo.ROD_NUMBER));
00921 try {
00922 java.awt.Component c = (java.awt.Component)new GuiComponents.SctApi.RodDiagnostics(partition, crate, rod, SystemInterface.getInstance().getSctApi());
00923 rodFrame.getContentPane().add(c);
00924 rodFrame.pack();
00925 rodFrame.setVisible(true);
00926 }catch(Exception e2){javax.swing.JOptionPane.showMessageDialog(null,"Exception"+e2.toString());}
00927 }
00928
00929 }
00930