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

CalibrationControllerPanel2.java

00001 /*
00002  * CalibrationControllerPanel.java
00003  *
00004  * Created on 30 July 2003, 23:01
00005  */
00006 
00007 package DisplayGUI;
00008 
00009 import javax.swing.*;
00010 import Sct_CalibrationController.*;
00011 import Sct.IS.SctNames;
00012 import is.*;
00013 
00019 public class CalibrationControllerPanel2 extends javax.swing.JPanel implements InfoListener, displayParams {
00020     
00021     gui guiControl;
00022     CalibrationControllerStatus status=null;
00023     java.util.regex.Pattern testdatapattern = java.util.regex.Pattern.compile(".*\\.(\\d+\\.\\d+.*)");
00024     java.util.regex.Matcher matcher;
00025     int currentBin=-1;
00026     int maxBin=-1;
00027 
00028         CalibrationControllerPanelMenu calibrationControllerPanelMenu;
00029 
00030     public CalibrationControllerPanel2(gui parent) {
00031         guiControl=parent;
00032 
00033                 calibrationControllerPanelMenu = new CalibrationControllerPanelMenu(guiControl);
00034 
00035         setBackground(new java.awt.Color(255, 255, 255));
00036         is = GuiComponents.System.ISInterface.getInstance();
00037         initComponents();
00038         subscribeToServers();
00039         updateStatus();
00040         addMouseListener(new ccMouseAdapter());
00041     }
00042     
00043     public void subscribeToServers() {
00044         //Get Status from IS if it is there
00045         close();  //in case old subscriptions are still valid
00046         try {
00047             status = new CalibrationControllerStatus();
00048             is.getRepository().getValue(SctNames.getControlISServer() + ".Status", status);
00049             updateStatus();
00050         } catch (RuntimeException e) {
00051             status=null;
00052             System.err.println("Couldn't get CalibrationController Status: " + e.getMessage());
00053             updateStatus();
00054         }
00055         
00056         //Now subscribe to IS server
00057         try {
00058             is.subscribe(SctNames.getControlISServer(), "Status", false, this);
00059         } catch (RuntimeException e) {
00060             System.err.println("Couldn't subscribe to ControlData IS Server: " + e.getMessage());
00061         }
00062 
00063         try {
00064            is.subscribe("SCTAPIServer","currentBin",false,this);
00065            is.subscribe("SCTAPIServer","maxBin",false,this);
00066         } catch (RuntimeException e2) {
00067             System.err.println("Couldn't subscribe to SCTAPIServer: " + e2.getMessage());
00068         }
00069 
00070     }
00071     
00075     void close() {
00076         //Unsubscribe from IS
00077         try {
00078             is.unsubscribe(SctNames.getControlISServer(), "Status");
00079         } catch (RuntimeException e) {
00080             System.err.println("Couldn't unsubscribe from ControlData IS Server: " + e.getMessage());
00081         }
00082         try {
00083             is.unsubscribe("SCTAPIServer","currentBin");
00084             is.unsubscribe("SCTAPIServer","maxBin");
00085         } catch (RuntimeException e2) {
00086             System.err.println("Couldn't unsubscribe from SCTAPIServer: " + e2.getMessage());
00087         }
00088     }
00089     
00090 
00091     private void initComponents() {//GEN-BEGIN:initComponents
00092 
00093         jLabel1 = new javax.swing.JLabel();
00094         statusField = new javax.swing.JLabel();
00095         jLabel2 = new javax.swing.JLabel();
00096         testField = new javax.swing.JLabel();
00097         jLabel3 = new javax.swing.JLabel();
00098         sequenceField = new javax.swing.JLabel();
00099         jLabel4 = new javax.swing.JLabel();
00100         scanIndexField = new javax.swing.JLabel();
00101         jLabel5 = new javax.swing.JLabel();
00102 //        currentBinField = new javax.swing.JLabel();
00103         progressBar = new javax.swing.JProgressBar();
00104 //        progressBar.setIndeterminate(true);
00105         progressBar.setStringPainted(true);
00106         progressBar.setString("");
00107         progressBar.setMaximum(100);
00108         progressBar.setValue(0);
00109 //        progressBar.setString("50 out of 100");
00110         progressBar.setForeground(darkBlueColor);
00111 
00112  //       setLayout(new java.awt.GridLayout(5, 2));
00113         setLayout(new java.awt.GridBagLayout());
00114         setBackground(backgroundColor);
00115 
00116         jLabel1.setFont(displayCCBoldFont);
00117 //        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
00118         jLabel1.setText("CC Status : ");
00119         jLabel1.setHorizontalAlignment(JLabel.RIGHT);
00120         java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
00121         gridBagConstraints.gridx = 0;
00122         gridBagConstraints.gridy = 0;
00123         gridBagConstraints.weighty = 0.2;
00124         gridBagConstraints.weightx = 0.3;
00125 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00126         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00127         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00128         add(jLabel1, gridBagConstraints);
00129 
00130 
00131         statusField.setBackground(backgroundColor);
00132         statusField.setFont(displayCCFont);
00133         statusField.addMouseListener(new ccMouseAdapter());
00134         gridBagConstraints = new java.awt.GridBagConstraints();
00135         gridBagConstraints.gridx = 1;
00136         gridBagConstraints.gridy = 0;
00137         gridBagConstraints.weightx = 0.7;
00138 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00139         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00140         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00141         add(statusField, gridBagConstraints);
00142 
00143         jLabel2.setFont(displayCCBoldFont);
00144         jLabel2.setText("Current Test : ");
00145         jLabel2.setHorizontalAlignment(JLabel.RIGHT);
00146         gridBagConstraints = new java.awt.GridBagConstraints();
00147         gridBagConstraints.gridx = 0;
00148         gridBagConstraints.gridy = 1;
00149         gridBagConstraints.weighty = 0.2;
00150 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00151         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00152         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00153         add(jLabel2, gridBagConstraints);
00154 
00155         testField.setBackground(backgroundColor);
00156         testField.setMaximumSize(new java.awt.Dimension(5,5));
00157         testField.setFont(displayCCFont);
00158         testField.addMouseListener(new ccMouseAdapter());
00159         gridBagConstraints = new java.awt.GridBagConstraints();
00160         gridBagConstraints.gridx = 1;
00161         gridBagConstraints.gridy = 1;
00162 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00163         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00164         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00165         add(testField, gridBagConstraints);
00166 
00167         jLabel3.setFont(displayCCBoldFont);
00168         jLabel3.setText("Current Sequence : ");
00169         jLabel3.setHorizontalAlignment(JLabel.RIGHT);
00170         gridBagConstraints = new java.awt.GridBagConstraints();
00171         gridBagConstraints.gridx = 0;
00172         gridBagConstraints.gridy = 2;
00173         gridBagConstraints.weighty = 0.2;
00174 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00175         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00176         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00177         add(jLabel3, gridBagConstraints);
00178 
00179         sequenceField.setBackground(backgroundColor);
00180         sequenceField.setFont(displayCCFont);
00181         sequenceField.addMouseListener(new ccMouseAdapter());
00182         gridBagConstraints = new java.awt.GridBagConstraints();
00183         gridBagConstraints.gridx = 1;
00184         gridBagConstraints.gridy = 2;
00185 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00186         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00187         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00188         add(sequenceField, gridBagConstraints);
00189 
00190         jLabel4.setFont(displayCCBoldFont);
00191         jLabel4.setText("Current Scan Index : ");
00192         jLabel4.setHorizontalAlignment(JLabel.RIGHT);
00193         gridBagConstraints = new java.awt.GridBagConstraints();
00194         gridBagConstraints.gridx = 0;
00195         gridBagConstraints.gridy = 3;
00196         gridBagConstraints.weighty = 0.2;
00197 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00198         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00199         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00200         add(jLabel4, gridBagConstraints);
00201 
00202         scanIndexField.setBackground(backgroundColor);
00203         scanIndexField.setFont(displayCCFont);
00204         scanIndexField.addMouseListener(new ccMouseAdapter());
00205         gridBagConstraints = new java.awt.GridBagConstraints();
00206         gridBagConstraints.gridx = 1;
00207         gridBagConstraints.gridy = 3;
00208 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00209         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00210         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00211         add(scanIndexField, gridBagConstraints);
00212 
00213         jLabel5.setFont(displayCCBoldFont);
00214         jLabel5.setText("Scan Progress : ");
00215         jLabel5.setHorizontalAlignment(JLabel.RIGHT);
00216         gridBagConstraints = new java.awt.GridBagConstraints();
00217         gridBagConstraints.gridx = 0;
00218         gridBagConstraints.gridy = 4;
00219         gridBagConstraints.weighty = 0.2;
00220 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00221         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00222         gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
00223         add(jLabel5, gridBagConstraints);
00224 
00225         progressBar.setBackground(backgroundColor);
00226         progressBar.setFont(displayCCFont);
00227         progressBar.setBorderPainted(false);
00228         progressBar.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
00229         progressBar.addMouseListener(new ccMouseAdapter());
00230         gridBagConstraints = new java.awt.GridBagConstraints();
00231         gridBagConstraints.gridx = 1;
00232         gridBagConstraints.gridy = 4;
00233 //        gridBagConstraints.insets = new java.awt.Insets(10,10,0,10);
00234         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
00235         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
00236         add(progressBar, gridBagConstraints);
00237 
00238 
00239 
00240        setBorder(new javax.swing.border.TitledBorder(null, "Scan Status", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 11), new java.awt.Color(0, 0, 153)));
00241         
00242     }
00243     
00244 //***********************************************************************************    
00245     void updateStatus() {
00246 // run this in the eventDispatching thread, because it changes the gui display
00247        javax.swing.SwingUtilities.invokeLater(new Runnable() {
00248           public void run() {  
00249 
00250         if (status == null) {
00251             statusField.setText("UNAVAILABLE");
00252             statusField.setForeground(java.awt.Color.red);
00253             guiControl.menuActions.enableCCMenuItems(false);
00254         } else {
00255             switch (status.status) {
00256                 case CalibrationControllerStatus.LOADED:
00257                     statusField.setText("LOADED");
00258                     statusField.setForeground(darkGreenColor); // dark green
00259                     guiControl.menuActions.enableCCMenuItems(false);
00260                     break;
00261                 case CalibrationControllerStatus.INCONTROL:
00262                     statusField.setText("INCONTROL");
00263                     statusField.setForeground(darkGreenColor);
00264                     guiControl.menuActions.enableCCMenuItems(true);
00265                     break;
00266                 case CalibrationControllerStatus.BUSY:
00267                     statusField.setText("BUSY");
00268                     statusField.setForeground(java.awt.Color.orange);
00269                     guiControl.menuActions.enableCCMenuItems(false);
00270                     break;
00271                 case CalibrationControllerStatus.ERROR:
00272                     statusField.setText("ERROR");
00273                     statusField.setForeground(java.awt.Color.orange);
00274                     guiControl.menuActions.enableCCMenuItems(false);
00275                     break;
00276                 default:
00277                     statusField.setText("UNKNOWN");
00278                     statusField.setForeground(java.awt.Color.red);
00279                     guiControl.menuActions.enableCCMenuItems(false);
00280             }
00281 
00282             testField.setText(getLabel(status.currentTest));
00283             sequenceField.setText(getLabel(status.currentSequence));
00284             scanIndexField.setText(Integer.toString(status.currentScanIndex));
00285             calibrationControllerPanelMenu.checkCCUpdateMode(); // update status indicators
00286         }
00287           }
00288         });
00289     }
00290 
00291     public String getLabel(String original_string) {
00292             matcher = testdatapattern.matcher(original_string);
00293             String label = matcher.matches() ? original_string.substring(matcher.start(1),matcher.end(1)) : original_string;
00294             if (label.length()>30) label = label.substring(0,30)+"...";
00295             return label;
00296             }
00297 
00298 
00299     void updateProgressBar() {
00300 // run this in the eventDispatching thread, because it changes the gui display
00301        javax.swing.SwingUtilities.invokeLater(new Runnable() {
00302           public void run() {
00303             if(maxBin==-1) progressBar.setMaximum(1000);
00304             else progressBar.setMaximum(maxBin);
00305             if(currentBin==-1) {
00306                progressBar.setValue(0);
00307                progressBar.setString("");
00308                }
00309             else {
00310                progressBar.setValue(currentBin);
00311                if(maxBin==-1) progressBar.setString(Integer.toString(currentBin));
00312                else {
00313                      progressBar.setString(Integer.toString(currentBin)+" out of "+Integer.toString(maxBin)+" bins");
00314                      if(maxBin==currentBin) progressBar.setForeground(darkGreenColor);
00315                      else progressBar.setForeground(darkBlueColor);
00316                     }
00317             }
00318           }
00319         });
00320     }
00321     
00322     abstract class StringRunnable implements Runnable {
00323         protected is.InfoEvent infoEvent;
00324         StringRunnable(is.InfoEvent infoEvent) {
00325             this.infoEvent = infoEvent;
00326         }
00327     }
00328 
00329     
00330     public void infoCreated(is.InfoEvent infoEvent) {
00331        javax.swing.SwingUtilities.invokeLater(new StringRunnable(infoEvent) {
00332           public void run() {
00333             String name = infoEvent.getName();
00334             if(name.equals(SctNames.getControlISServer() + ".Status")) {
00335               try {
00336                  status = new CalibrationControllerStatus();
00337                  infoEvent.getValue(status);
00338               } catch (InfoNotCompatibleException e) {
00339                 status=null;
00340                 System.err.println("Unable to read IS object - not a CalibrationControllerStatus: " + e.getMessage());
00341                 }
00342               updateStatus();
00343            }
00344         else { // SCTAPIServer
00345           try {
00346             is.AnyInfo theValue = new is.AnyInfo();
00347             infoEvent.getValue(theValue);
00348             if(name.equals("SCTAPIServer.currentBin")) currentBin=((Integer) theValue.getAttribute(0)).intValue();
00349             else if(name.equals("SCTAPIServer.maxBin")) maxBin=((Integer) theValue.getAttribute(0)).intValue();
00350             updateProgressBar();
00351            }catch(Exception e2){ 
00352             System.err.println("Unable to update progressBar - "+e2.toString());
00353             }
00354            
00355            }
00356          }
00357         });
00358       
00359 
00360     }
00361     
00362     public void infoDeleted(is.InfoEvent infoEvent) {
00363        javax.swing.SwingUtilities.invokeLater(new StringRunnable(infoEvent) {
00364           public void run() {
00365              if(infoEvent.getName().equals(SctNames.getControlISServer() + ".Status")) {
00366                status=null;
00367                updateStatus();
00368                }
00369              else {
00370               currentBin=-1;
00371               maxBin=-1;
00372               updateProgressBar();
00373               }
00374         }
00375         });
00376     }
00377     
00378     //Pass to infoCreated
00379     public void infoUpdated(is.InfoEvent infoEvent) {
00380         infoCreated(infoEvent);
00381     }
00382     
00383     // Variables declaration - do not modify//GEN-BEGIN:variables
00384 
00385     private javax.swing.JLabel jLabel1;
00386     private javax.swing.JLabel jLabel2;
00387     private javax.swing.JLabel jLabel3;
00388     private javax.swing.JLabel jLabel4;
00389     private javax.swing.JLabel jLabel5;
00390     private javax.swing.JLabel scanIndexField;
00391     private javax.swing.JLabel sequenceField;
00392     private javax.swing.JLabel statusField;
00393     private javax.swing.JLabel testField;
00394 //    private javax.swing.JLabel currentBinField;
00395     private javax.swing.JProgressBar progressBar;
00396 
00397      private GuiComponents.System.ISInterface is;
00398 
00399     class ccMouseAdapter extends java.awt.event.MouseAdapter {
00400             public void mouseClicked(java.awt.event.MouseEvent e) {
00401                switch(e.getModifiers()) {
00402                  case java.awt.event.InputEvent.BUTTON2_MASK:
00403                  case java.awt.event.InputEvent.BUTTON3_MASK:             
00404                         JPopupMenu pMenu = calibrationControllerPanelMenu.getPopupMenu();
00405                                         pMenu.show(e.getComponent(),e.getX(),e.getY());
00406 //                                      pMenu.setInvoker(guiControl.guiMenus.getCCPanelMenu());
00407                  break;
00408                  default:
00409                  }
00410             }
00411     }
00412  
00413 }
00414 
00415 

Generated on Thu Dec 15 21:22:34 2005 for SCT DAQ/DCS Software - Java by doxygen 1.3.5