1 26 27 package DiningPhilosophers.monolithic; 28 29 import DiningPhilosophers.*; 30 31 48 49 public class ObserverImpl 50 extends org.omg.CORBA.LocalObject 51 implements CCM_Observer, 52 CCM_StatusInfoConsumer, 53 org.omg.Components.SessionComponent 54 { 55 61 62 private CCM_Observer_Context the_context_; 63 64 65 private java.util.Hashtable philosopherStates_; 66 67 68 private javax.swing.JFrame frame_; 69 70 71 private java.util.Hashtable philosopherPanels_; 72 73 74 private javax.swing.Box box_; 75 76 82 83 public 84 ObserverImpl() 85 { 86 philosopherStates_ = new java.util.Hashtable (); 87 philosopherPanels_ = new java.util.Hashtable (); 88 } 89 90 96 102 108 115 public void 116 configuration_complete() 117 throws org.omg.Components.InvalidConfiguration 118 { 119 121 frame_ = new javax.swing.JFrame ("The Observer's GUI"); 123 frame_.setSize(400, 300); 125 126 box_ = javax.swing.Box.createVerticalBox(); 128 frame_.getContentPane().add(box_); 129 frame_.pack(); 130 frame_.show(); 131 } 132 133 139 144 public void 145 set_session_context(org.omg.Components.SessionContext context) 146 throws org.omg.Components.CCMException 147 { 148 the_context_ = (CCM_Observer_Context)context; 149 } 150 151 156 public void 157 ccm_activate() 158 throws org.omg.Components.CCMException 159 { 160 } 162 163 168 public void 169 ccm_passivate() 170 throws org.omg.Components.CCMException 171 { 172 } 174 175 180 public void 181 ccm_remove() 182 throws org.omg.Components.CCMException 183 { 184 frame_.dispose(); 186 frame_ = null; 187 } 188 189 195 199 public void 200 push_info(StatusInfo event) 201 { 202 push(event); 203 } 204 205 211 216 public synchronized void 217 push(StatusInfo event) 218 { 219 if (! philosopherPanels_.containsKey(event.name)) { 220 PhilosopherPanel panel = new PhilosopherPanel(event); 221 box_.add(panel); 222 philosopherPanels_.put(event.name, panel); 223 frame_.pack(); 224 frame_.show(); 225 } else { 226 PhilosopherPanel panel; 227 panel = (PhilosopherPanel)philosopherPanels_.get(event.name); 228 panel.updatePanel(event); 229 } 230 } 231 } 232 | Popular Tags |