Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

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]+");
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.*");
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 = rObjectPattern.matcher(objectName);
00033        java.util.regex.Matcher matcher3 = ivObjectPattern.matcher(objectName);
00034       
00035        if(matcher.matches() || matcher2.matches() || matcher3.matches()) {
00036              if(!isNewObject) { // control object change - must be change in test running state
00037                      guiControl.tablesDisplayPane.updateTest(objectName);
00038                      BookKeeper.getInstance().addTest(objectName); // update book-keeping
00039                      return;
00040                      }
00041              updateAll(objectName);  // if a control object, update immediately
00042              return;
00043              }
00044 
00045        if(timer!=null && timer.isRunning()) {
00046            queuedObjectName=objectName;
00047 //           System.out.println("Queueing "+queuedObjectName+" for later ...");
00048            return;   
00049            }
00050 // ok no requests queued, so update the display and start the timer
00051        timer = new Timer(TIME_INTERVAL, new ActionListener() {
00052             public void actionPerformed(ActionEvent evt) {
00053                if(queuedObjectName!=null) {
00054 //                   System.out.println("Timer: Now updating for queued object "+queuedObjectName);
00055                    updateAll(queuedObjectName);
00056                    queuedObjectName=null;
00057                    }
00058             }
00059         });
00060      timer.setRepeats(false);
00061      timer.start();
00062      updateAll(objectName);
00063      queuedObjectName=null;
00064      }
00065 
00066   private void updateAll(String theObjectName) {
00067 // NB updateTables does a display update, so don't call setDisplayColors after this call
00068 //                guiControl.displayPane.setDisplayColors();
00069                   java.util.regex.Matcher matcher = objectPattern.matcher(theObjectName);
00070                   java.util.regex.Matcher matcher2 = rObjectPattern.matcher(theObjectName);
00071                   java.util.regex.Matcher matcher3 = ivObjectPattern.matcher(theObjectName);
00072                   if(matcher.matches() || matcher2.matches() || matcher3.matches()) {
00073                        // if DCS enabled, and this is a new current test object (not downloaded from SCTDB)
00074                        if(!theObjectName.startsWith("SCTDBData") && !theObjectName.startsWith("RetrievedData")) {
00075                                 guiControl.isInterface.fillDCSMap(theObjectName); // snapshot the DCS data
00076                                 BookKeeper.getInstance().addTest(theObjectName); // update book-keeping
00077                                 }
00078                      // if a new control object, add it to the list
00079                        guiControl.tablesDisplayPane.addNewTest(theObjectName);
00080                        guiControl.tablesDisplayPane.updateTables();  // immediately add the control info to the table
00081                        return;
00082                     }
00083                   else {
00084                     switch(guiControl.displayStatus.getStatus()) {
00085                      case DisplayStatus.IS_MONITOR:
00086                           guiControl.tablesDisplayPane.listISObjects(guiControl.displayPane.getLastClickedCell());
00087                           guiControl.displayPane.setDisplayColors();
00088                           guiControl.displayPane.refreshDisplay();  // just refresh the display
00089                           break;
00090                      case DisplayStatus.TEST_DATA:
00091                      case DisplayStatus.SCTDB_DATA:
00092                      case DisplayStatus.SCTDB_RODDAQ_DATA:
00093                         if(theObjectName.startsWith("TestData")) guiControl.tablesDisplayPane.updateTables(false);
00094                         else {
00095                            guiControl.displayPane.setDisplayColors();
00096                            guiControl.tablesDisplayPane.listTestResults();
00097                            guiControl.displayPane.refreshDisplay();  // just refresh the display
00098                              }
00099                         break;
00100                      case DisplayStatus.IV_DATA:    
00101                            guiControl.displayPane.setDisplayColors();
00102                            guiControl.tablesDisplayPane.listTestResults();
00103                            guiControl.displayPane.refreshDisplay();  // just refresh the display
00104                         break;
00105          
00106                      case DisplayStatus.DCS_DATA:
00107                            lastUpdateTime = guiUtilities.DaveUtils.getCurrentTime();
00108                            guiControl.isInterface.fillDCSCache();
00109                            guiControl.tablesDisplayPane.updateTables(false);
00110 
00111                            break;
00112                      default:
00113                      }
00114                   }
00115                }
00116    public String getLastUpdateTime() {
00117        return lastUpdateTime;
00118        }
00119 
00120 
00121 
00122 }

Generated on Thu Feb 10 02:44:27 2005 for SCT DAQ/DCS Software - Java by doxygen 1.3.5