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