ISRequestBuffer.java

00001 package DisplayGUI;
00002 
00003 import java.awt.event.*;
00004 import javax.swing.*; 
00005 /*
00006 * class to limit IS requests to half-second intervals
00007 * @author robinson
00008 */
00009 class ISRequestBuffer {
00010 
00011 
00012     public final static int TIME_INTERVAL = 1000;
00013    
00014     gui guiControl;
00015     private Timer timer;
00016     String queuedObjectName;
00017     final java.util.regex.Pattern objectPattern = java.util.regex.Pattern.compile(".*TestData\\.[0-9]+\\.[0-9]+(.*Test)?");
00018 //    final java.util.regex.Pattern rObjectPattern = java.util.regex.Pattern.compile(".*TestData\\.[0-9]+\\.[0-9]+.*Test");
00019     final java.util.regex.Pattern ivObjectPattern = java.util.regex.Pattern.compile(".*(ControlIVScanData|SctRodDaqRefData).*");
00020 
00021     String lastUpdateTime = "No updates yet";
00022 
00023     public ISRequestBuffer(gui parent) {
00024 
00025        guiControl=parent;
00026     }
00027 
00028 
00029    public void queueObject(String objectName, boolean isNewObject) {   // queue it for later
00030 
00031        java.util.regex.Matcher matcher = objectPattern.matcher(objectName);
00032        java.util.regex.Matcher matcher2 = ivObjectPattern.matcher(objectName);
00033 
00034        if(matcher.matches() || matcher2.matches()) {
00035              if(!isNewObject) { // control object change - must be change in test running state
00036                      guiControl.tablesDisplayPane.indexTable.updateTest(objectName);
00037                      BookKeeper.getInstance().addTest(objectName); // update book-keeping
00038                      return;
00039                      }
00040              updateAll(objectName);  // if a control object, update immediately
00041              return;
00042              }
00043 
00044        if(timer!=null && timer.isRunning()) {
00045            queuedObjectName=objectName;
00046 //           System.out.println("Queueing "+queuedObjectName+" for later ...");
00047            return;   
00048            }
00049 // ok no requests queued, so update the display and start the timer
00050        timer = new Timer(TIME_INTERVAL, new ActionListener() {
00051             public void actionPerformed(ActionEvent evt) {
00052                if(queuedObjectName!=null) {
00053 //                   System.out.println("Timer: Now updating for queued object "+queuedObjectName);
00054                    updateAll(queuedObjectName);
00055                    queuedObjectName=null;
00056                    }
00057             }
00058         });
00059      timer.setRepeats(false);
00060      timer.start();
00061      updateAll(objectName);
00062      queuedObjectName=null;
00063      }
00064 
00065   private void updateAll(String theObjectName) {
00066 // NB updateTables does a display update, so don't call setDisplayColors after this call
00067 //                guiControl.displayPane.setDisplayColors();
00068                   java.util.regex.Matcher matcher = objectPattern.matcher(theObjectName);
00069                   java.util.regex.Matcher matcher2 = ivObjectPattern.matcher(theObjectName);
00070                   if(matcher.matches() || matcher2.matches()) {
00071                        // if DCS enabled, and this is a new current test object (not downloaded from SCTDB)
00072                        if(!theObjectName.startsWith("SCTDBData") && !theObjectName.startsWith("RetrievedData")) {
00073                                 guiControl.isInterface.fillDCSMap(theObjectName); // snapshot the DCS data
00074                                 BookKeeper.getInstance().addTest(theObjectName); // update book-keeping
00075                                 }
00076                      // if a new control object, add it to the list
00077                        guiControl.tablesDisplayPane.addNewTest(theObjectName);
00078                        guiControl.tablesDisplayPane.updateTables();  // immediately add the control info to the table
00079                        return;
00080                     }
00081                   else {
00082                     switch(guiControl.displayStatus.getStatus()) {
00083                      case DisplayStatus.IS_MONITOR:
00084                           guiControl.tablesDisplayPane.listISObjects(guiControl.displayPane.getLastClickedCell());
00085                           guiControl.displayPane.setDisplayColors();
00086                           guiControl.displayPane.refreshDisplay();  // just refresh the display
00087                           break;
00088                      case DisplayStatus.TEST_DATA:
00089                      case DisplayStatus.SCTDB_DATA:
00090                      case DisplayStatus.SCTDB_RODDAQ_DATA:
00091                         if(theObjectName.startsWith("TestData")) guiControl.tablesDisplayPane.updateTables(false);
00092                         else {
00093                            guiControl.displayPane.setDisplayColors();
00094                            guiControl.tablesDisplayPane.listTestResults();
00095                            guiControl.displayPane.refreshDisplay();  // just refresh the display
00096                              }
00097                         break;
00098                      case DisplayStatus.IV_DATA:    
00099                            guiControl.displayPane.setDisplayColors();
00100                            guiControl.tablesDisplayPane.listTestResults();
00101                            guiControl.displayPane.refreshDisplay();  // just refresh the display
00102                         break;
00103          
00104                      case DisplayStatus.DCS_DATA:
00105                            lastUpdateTime = guiUtilities.DaveUtils.getCurrentTime();
00106                            guiControl.isInterface.fillDCSCache();
00107                            guiControl.tablesDisplayPane.updateTables(false);
00108 
00109                            break;
00110                      default:
00111                      }
00112                   }
00113                }
00114    public String getLastUpdateTime() {
00115        return lastUpdateTime;
00116        }
00117 
00118 
00119 
00120 }

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