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 = 750;
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                      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 = rObjectPattern.matcher(theObjectName);
00070                   java.util.regex.Matcher matcher3 = ivObjectPattern.matcher(theObjectName);
00071                   if(matcher.matches() || matcher2.matches() || matcher3.matches()) {
00072                        // if DCS enabled, and this is a new current test object (not downloaded from SCTDB)
00073                        if(!theObjectName.startsWith("SCTDBData") && !theObjectName.startsWith("RetrievedData")) guiControl.isInterface.fillDCSMap(theObjectName); // snapshot the DCS data
00074                      // if a new control object, add it to the list
00075                        guiControl.tablesDisplayPane.addNewTest(theObjectName);
00076                        guiControl.tablesDisplayPane.updateTables();  // immediately add the control info to the table
00077                        return;
00078                     }
00079                   else {
00080                     switch(guiControl.displayStatus.getStatus()) {
00081                      case DisplayStatus.IS_MONITOR:
00082                           guiControl.tablesDisplayPane.listISObjects(guiControl.displayPane.getLastClickedCell());
00083                           guiControl.displayPane.setDisplayColors();
00084                           guiControl.displayPane.refreshDisplay();  // just refresh the display
00085                           break;
00086                      case DisplayStatus.TEST_DATA:
00087                      case DisplayStatus.SCTDB_DATA:
00088                      case DisplayStatus.SCTDB_RODDAQ_DATA:
00089                         if(theObjectName.startsWith("TestData")) guiControl.tablesDisplayPane.updateTables(false);
00090                         else {
00091                            guiControl.displayPane.setDisplayColors();
00092                            guiControl.tablesDisplayPane.listTestResults();
00093                            guiControl.displayPane.refreshDisplay();  // just refresh the display
00094                              }
00095                         break;
00096                      case DisplayStatus.IV_DATA:    
00097                            guiControl.displayPane.setDisplayColors();
00098                            guiControl.tablesDisplayPane.listTestResults();
00099                            guiControl.displayPane.refreshDisplay();  // just refresh the display
00100                         break;
00101          
00102                      case DisplayStatus.DCS_DATA:
00103                            lastUpdateTime = guiUtilities.DaveUtils.getCurrentTime();
00104                            guiControl.tablesDisplayPane.updateTables(false);
00105 
00106                            break;
00107                      default:
00108                      }
00109                   }
00110                }
00111    public String getLastUpdateTime() {
00112        return lastUpdateTime;
00113        }
00114 
00115 
00116 
00117 }

Generated on Thu Jul 15 09:55:44 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5