00001
00002
00003
00004
00005
00006
00007 package DisplayGUI;
00008
00009 import Sct.IS.SctNames;
00010 import is.*;
00011 import rc.RCStateInfo;
00012 import dsa.DSAApplication;
00013
00014
00015 public class ConfigurationListener implements InfoListener {
00016
00017 gui guiControl;
00018 String cc_status="none";
00019 String rc_status="none";
00020
00021 public ConfigurationListener(gui parent) {
00022 guiControl=parent;
00023 is = GuiComponents.System.ISInterface.getInstance();
00024 subscribe();
00025 }
00026
00027 private void subscribe() {
00028
00029
00030 try {
00031 is.subscribe("ConfigurationServer","ModuleConfChangeCount",false,this);
00032 is.subscribe("ConfigurationServer","ModuleMappingChangeCount",false,this);
00033 is.subscribe("ConfigurationServer","SystemStructureChangeCount",false,this);
00034 } catch (RuntimeException e2) {
00035 System.err.println("SctGUI::ConfigurationListener::Couldn't subscribe to ConfigurationServer: " + e2.toString());
00036 }
00037 try {
00038 is.subscribe("RunCtrl","Application_CalibrationController",false,this);
00039 is.subscribe("RunCtrl","SCTRootSegmentController",false,this);
00040 } catch (RuntimeException e3) {
00041 System.err.println("SctGUI::ConfigurationListener::Couldn't subscribe to RunCtrl Applications: " + e3.toString());
00042 }
00043 }
00044
00045 void close() {
00046
00047
00048 try {
00049 is.unsubscribe("ConfigurationServer","ModuleConfChangeCount");
00050 is.unsubscribe("ConfigurationServer","ModuleMappingChangeCount");
00051 is.unsubscribe("ConfigurationServer","SystemStructureChangeCount");
00052 is.unsubscribe("RunCtrl","Application_CalibrationController");
00053 is.unsubscribe("RunCtrl","SCTRootSegmentController");
00054 } catch (RuntimeException e2) {
00055 System.err.println("Couldn't unsubscribe from ConfigurationServer: " + e2.getMessage());
00056 }
00057 }
00058
00059 abstract class StringRunnable implements Runnable {
00060 protected String name;
00061 StringRunnable(String name) {
00062 this.name = name;
00063 }
00064 }
00065
00066 public void infoCreated(is.InfoEvent infoEvent) {
00067
00068
00069
00070
00071
00072 infoUpdated(infoEvent);
00073 }
00074
00075 public void infoDeleted(is.InfoEvent infoEvent) {
00076 infoUpdated(infoEvent);
00077 }
00078
00079 public void infoUpdated(is.InfoEvent infoEvent) {
00080
00081 javax.swing.SwingUtilities.invokeLater(new StringRunnable(infoEvent.getName()) {
00082 public void run() {
00083 if(name.startsWith("ConfigurationServer")) resetDisplayConfiguration();
00084 else if(name.matches(".*SCTRootSegmentController.*")) {
00085 if(GuiComponents.System.ISInterface.getInstance().getRepository().contains(name)) {
00086 RCStateInfo rc = new RCStateInfo();
00087 GuiComponents.System.ISInterface.getInstance().getRepository().getValue(name, rc);
00088 if(rc.state.matches("CONFIGURED") && rc_status.matches("INITIAL|LOADED")) resetDisplayConfiguration();
00089 rc_status=rc.state;
00090 }
00091 else rc_status="none";
00092
00093 }
00094 else if(name.matches(".*Calibration.*")) {
00095 DSAApplication rc = new DSAApplication();
00096 GuiComponents.System.ISInterface.getInstance().getRepository().getValue(name, rc);
00097
00098 if(rc.status.matches("IDLE|RUNNING") && !cc_status.equals(rc.status)) {
00099 resetCCPanel();
00100 cc_status=rc.status;
00101 }
00102 }
00103
00104 }
00105 });
00106 }
00107
00108
00109 private void resetCCPanel() {
00110 GuiComponents.System.SystemInterface.getInstance().refresh();
00111 GuiComponents.System.ISInterface.getInstance().refresh();
00112 guiControl.calibrationControllerPanel.subscribeToServers();
00113 guiControl.menuBar.buildAutoTestsMenu();
00114 }
00115
00116 private void resetDisplayConfiguration() {
00117 GuiComponents.System.SystemInterface.getInstance().refresh();
00118 GuiComponents.System.ISInterface.getInstance().refresh();
00119 ConfigurationInterface.getInstance().Refresh();
00120 guiControl.displayStatus.setConfigurationMode();
00121 int nmods = ConfigurationInterface.getInstance().getTotalNumberOfModules();
00122 System.out.println("Configuration updated with "+nmods+" modules.");
00123 int cacheSize = nmods<200 ? 200 : nmods;
00124 cacheSize*=2;
00125 guiControl.isInterface.setCacheSize(cacheSize);
00126 }
00127
00128
00129 private GuiComponents.System.ISInterface is;
00130
00131
00132
00133 }
00134
00135