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     int currentBin=-1;
00024     int maxBin=-1;
00025 
00026     public CalibrationControllerPanel2(gui parent) {
00027         guiControl=parent;
00028         setBackground(new java.awt.Color(255, 255, 255));
00029         is = GuiComponents.System.ISInterface.getInstance();
00030         initComponents();
00031         subscribeToServers();
00032         updateStatus();
00033         addMouseListener(new ccMouseAdapter());
00034     }
00035     
00036     public void subscribeToServers() {
00037         //Get Status from IS if it is there
00038         close();  //in case old subscriptions are still valid
00039         try {
00040             status = new CalibrationControllerStatus();
00041             is.getRepository().getValue(SctNames.getControlISServer() + ".Status", status);
00042             updateStatus();
00043         } catch (RuntimeException e) {
00044             status=null;
00045             System.err.println("Couldn't get CalibrationController Status: " + e.getMessage());
00046             updateStatus();
00047         }
00048         
00049         //Now subscribe to IS server
00050         try {
00051             is.subscribe(SctNames.getControlISServer(), "Status", false, this);
00052         } catch (RuntimeException e) {
00053             System.err.println("Couldn't subscribe to ControlData IS Server: " + e.getMessage());
00054         }
00055 
00056         try {
00057            is.subscribe("SCTAPIServer","currentBin",false,this);
00058            is.subscribe("SCTAPIServer","maxBin",false,this);
00059         } catch (RuntimeException e2) {
00060             System.err.println("Couldn't subscribe to SCTAPIServer: " + e2.getMessage());
00061         }
00062 
00063     }
00064     
00068     void close() {
00069         //Unsubscribe from IS
00070         try {
00071             is.unsubscribe(SctNames.getControlISServer(), "Status");
00072         } catch (RuntimeException e) {
00073             System.err.println("Couldn't unsubscribe from ControlData IS Server: " + e.getMessage());
00074         }
00075         try {
00076             is.unsubscribe("SCTAPIServer","currentBin");
00077             is.unsubscribe("SCTAPIServer","maxBin");
00078         } catch (RuntimeException e2) {
00079             System.err.println("Couldn't unsubscribe from SCTAPIServer: " + e2.getMessage());
00080         }
00081     }
00082     
00083 
00084     private void initComponents() {//GEN-BEGIN:initComponents
00085 
00086         jLabel1 = new javax.swing.JLabel();
00087         statusField = new javax.swing.JTextField();
00088         jLabel2 = new javax.swing.JLabel();
00089         testField = new javax.swing.JTextField();
00090         jLabel3 = new javax.swing.JLabel();
00091         sequenceField = new javax.swing.JTextField();
00092         jLabel4 = new javax.swing.JLabel();
00093         scanIndexField = new javax.swing.JTextField();
00094         jLabel5 = new javax.swing.JLabel();
00095 //        currentBinField = new javax.swing.JTextField();
00096         progressBar = new javax.swing.JProgressBar();
00097 //        progressBar.setIndeterminate(true);
00098         progressBar.setStringPainted(true);
00099         progressBar.setString("");
00100         progressBar.setMaximum(100);
00101         progressBar.setValue(0);
00102 //        progressBar.setString("50 out of 100");
00103         progressBar.setForeground(darkBlueColor);
00104 
00105         setLayout(new java.awt.GridLayout(5, 2));
00106 
00107         setBackground(backgroundColor);
00108         jLabel1.setFont(displayCCBoldFont);
00109         jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
00110         jLabel1.setText("CalibrationController Status : ");
00111         add(jLabel1);
00112 
00113         statusField.setBackground(backgroundColor);
00114         statusField.setColumns(15);
00115         statusField.setEditable(false);
00116         statusField.setFont(displayCCFont);
00117         statusField.addMouseListener(new ccMouseAdapter());
00118         statusField.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
00119         statusField.setDisabledTextColor(new java.awt.Color(255, 255, 255));
00120         add(statusField);
00121 
00122         jLabel2.setFont(displayCCBoldFont);
00123         jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
00124         jLabel2.setText("Current Test : ");
00125         add(jLabel2);
00126 
00127         testField.setBackground(backgroundColor);
00128         testField.setColumns(15);
00129         testField.setEditable(false);
00130         testField.setFont(displayCCFont);
00131         testField.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
00132         testField.setDisabledTextColor(new java.awt.Color(255, 255, 255));
00133         testField.addMouseListener(new ccMouseAdapter());
00134         add(testField);
00135 
00136         jLabel3.setFont(displayCCBoldFont);
00137         jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
00138         jLabel3.setText("Current Sequence : ");
00139         add(jLabel3);
00140 
00141         sequenceField.setBackground(backgroundColor);
00142         sequenceField.setColumns(15);
00143         sequenceField.setEditable(false);
00144         sequenceField.setFont(displayCCFont);
00145         sequenceField.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
00146         sequenceField.setDisabledTextColor(new java.awt.Color(255, 255, 255));
00147         sequenceField.addMouseListener(new ccMouseAdapter());
00148         add(sequenceField);
00149 
00150         jLabel4.setFont(displayCCBoldFont);
00151         jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
00152         jLabel4.setText("Current Scan Index : ");
00153         add(jLabel4);
00154 
00155         scanIndexField.setBackground(backgroundColor);
00156         scanIndexField.setColumns(15);
00157         scanIndexField.setEditable(false);
00158         scanIndexField.setFont(displayCCFont);
00159         scanIndexField.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
00160         scanIndexField.setDisabledTextColor(new java.awt.Color(255, 255, 255));
00161         scanIndexField.addMouseListener(new ccMouseAdapter());
00162         add(scanIndexField);
00163 
00164         jLabel5.setFont(displayCCBoldFont);
00165         jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
00166         jLabel5.setText("Scan Progress : ");
00167         add(jLabel5);
00168 
00169 //        currentBinField.setBackground(backgroundColor);
00170 //        currentBinField.setColumns(15);
00171 //        currentBinField.setEditable(false);
00172 //        currentBinField.setFont(displayCCFont);
00173 //        currentBinField.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
00174 //        currentBinField.setDisabledTextColor(new java.awt.Color(255, 255, 255));
00175 //        currentBinField.addMouseListener(new ccMouseAdapter());
00176 //        add(currentBinField);
00177         progressBar.setBackground(backgroundColor);
00178 //        progressBar.setEditable(false);
00179         progressBar.setFont(displayCCFont);
00180         progressBar.setBorderPainted(false);
00181         progressBar.setBorder(new javax.swing.border.EmptyBorder(new java.awt.Insets(1, 1, 1, 1)));
00182 //        currentBinField.setDisabledTextColor(new java.awt.Color(255, 255, 255));
00183         progressBar.addMouseListener(new ccMouseAdapter());
00184         add(progressBar);
00185 
00186 
00187 
00188        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)));
00189         
00190     }
00191     
00192 //***********************************************************************************    
00193     void updateStatus() {
00194 // run this in the eventDispatching thread, because it changes the gui display
00195        javax.swing.SwingUtilities.invokeLater(new Runnable() {
00196           public void run() {  
00197 
00198         if (status == null) {
00199             statusField.setText("UNAVAILABLE");
00200             statusField.setForeground(java.awt.Color.red);
00201             guiControl.menuBar.enableCCMenuItems(false);
00202         } else {
00203             switch (status.status) {
00204                 case CalibrationControllerStatus.LOADED:
00205                     statusField.setText("LOADED");
00206                     statusField.setForeground(darkGreenColor); // dark green
00207                     guiControl.menuBar.enableCCMenuItems(false);
00208                     break;
00209                 case CalibrationControllerStatus.INCONTROL:
00210                     statusField.setText("INCONTROL");
00211                     statusField.setForeground(darkGreenColor);
00212                     guiControl.menuBar.enableCCMenuItems(true);
00213                     break;
00214                 case CalibrationControllerStatus.BUSY:
00215                     statusField.setText("BUSY");
00216                     statusField.setForeground(java.awt.Color.orange);
00217                     guiControl.menuBar.enableCCMenuItems(false);
00218                     break;
00219                 case CalibrationControllerStatus.ERROR:
00220                     statusField.setText("ERROR");
00221                     statusField.setForeground(java.awt.Color.orange);
00222                     guiControl.menuBar.enableCCMenuItems(false);
00223                     break;
00224                 default:
00225                     statusField.setText("UNKNOWN");
00226                     statusField.setForeground(java.awt.Color.red);
00227                     guiControl.menuBar.enableCCMenuItems(false);
00228             }
00229             sequenceField.setText(status.currentSequence);
00230             testField.setText(status.currentTest);
00231             scanIndexField.setText(Integer.toString(status.currentScanIndex));
00232             guiControl.menuBar.checkCCUpdateMode(); // update status indicators
00233         }
00234           }
00235         });
00236     }
00237 
00238     void updateProgressBar() {
00239 // run this in the eventDispatching thread, because it changes the gui display
00240        javax.swing.SwingUtilities.invokeLater(new Runnable() {
00241           public void run() { 
00242             if(maxBin==-1) progressBar.setMaximum(1000);
00243             else progressBar.setMaximum(maxBin);
00244             if(currentBin==-1) {
00245                progressBar.setValue(0);
00246                progressBar.setString("");
00247                }
00248             else {
00249                progressBar.setValue(currentBin);
00250                if(maxBin==-1) progressBar.setString(Integer.toString(currentBin));
00251                else {
00252                      progressBar.setString(Integer.toString(currentBin)+" out of "+Integer.toString(maxBin)+" bins");
00253                      if(maxBin==currentBin) progressBar.setForeground(darkGreenColor);
00254                      else progressBar.setForeground(darkBlueColor);
00255                     }
00256             }
00257           }
00258         });
00259     }
00260     
00261     abstract class StringRunnable implements Runnable {
00262         protected is.InfoEvent infoEvent;
00263         StringRunnable(is.InfoEvent infoEvent) {
00264             this.infoEvent = infoEvent;
00265         }
00266     }
00267 
00268     
00269     public void infoCreated(is.InfoEvent infoEvent) {
00270        javax.swing.SwingUtilities.invokeLater(new StringRunnable(infoEvent) {
00271           public void run() {
00272             String name = infoEvent.getName();
00273             if(name.equals(SctNames.getControlISServer() + ".Status")) {
00274               try {
00275                  status = new CalibrationControllerStatus();
00276                  infoEvent.getValue(status);
00277               } catch (InfoNotCompatibleException e) {
00278                 status=null;
00279                 System.err.println("Unable to read IS object - not a CalibrationControllerStatus: " + e.getMessage());
00280                 }
00281               updateStatus();
00282            }
00283         else { // SCTAPIServer
00284           try {
00285             is.AnyInfo theValue = new is.AnyInfo();
00286             infoEvent.getValue(theValue);
00287             if(name.equals("SCTAPIServer.currentBin")) currentBin=((Integer) theValue.getAttribute(0)).intValue();
00288             else if(name.equals("SCTAPIServer.maxBin")) maxBin=((Integer) theValue.getAttribute(0)).intValue();
00289             updateProgressBar();
00290            }catch(Exception e2){ 
00291             System.err.println("Unable to update progressBar - "+e2.toString());
00292             }
00293            
00294            }
00295          }
00296         });
00297       
00298 
00299     }
00300     
00301     public void infoDeleted(is.InfoEvent infoEvent) {
00302        javax.swing.SwingUtilities.invokeLater(new StringRunnable(infoEvent) {
00303           public void run() {
00304              if(infoEvent.getName().equals(SctNames.getControlISServer() + ".Status")) {
00305                status=null;
00306                updateStatus();
00307                }
00308              else {
00309               currentBin=-1;
00310               maxBin=-1;
00311               updateProgressBar();
00312               }
00313         }
00314         });
00315     }
00316     
00317     //Pass to infoCreated
00318     public void infoUpdated(is.InfoEvent infoEvent) {
00319         infoCreated(infoEvent);
00320     }
00321     
00322     // Variables declaration - do not modify//GEN-BEGIN:variables
00323 
00324     private javax.swing.JLabel jLabel1;
00325     private javax.swing.JLabel jLabel2;
00326     private javax.swing.JLabel jLabel3;
00327     private javax.swing.JLabel jLabel4;
00328     private javax.swing.JLabel jLabel5;
00329     private javax.swing.JTextField scanIndexField;
00330     private javax.swing.JTextField sequenceField;
00331     private javax.swing.JTextField statusField;
00332     private javax.swing.JTextField testField;
00333 //    private javax.swing.JTextField currentBinField;
00334     private javax.swing.JProgressBar progressBar;
00335 
00336      private GuiComponents.System.ISInterface is;
00337 
00338     class ccMouseAdapter extends java.awt.event.MouseAdapter {
00339             public void mouseClicked(java.awt.event.MouseEvent e) {
00340                switch(e.getModifiers()) {
00341                  case java.awt.event.InputEvent.BUTTON2_MASK:
00342                  case java.awt.event.InputEvent.BUTTON3_MASK:             
00343                  guiControl.menuBar.showCCPopupMenu(e);
00344                  break;
00345                  default:
00346                  }
00347             }
00348     }
00349  
00350 }
00351 
00352 

Generated on Fri Sep 16 18:05:53 2005 for SCT DAQ/DCS Software - Java by doxygen 1.3.5