1 26 27 package DiningPhilosophers.explorer; 28 29 30 import org.objectweb.util.explorer.api.Panel; 31 import org.objectweb.util.explorer.api.TreeView; 32 33 34 import org.objectweb.openccm.corba.TheRootPOA; 35 36 37 import java.awt.Color ; 38 import javax.swing.Box ; 39 import javax.swing.JPanel ; 40 import javax.swing.AbstractAction ; 41 import javax.swing.JOptionPane ; 42 import javax.swing.JTextArea ; 43 44 45 import org.omg.PortableServer.POA ; 46 import org.omg.Components.Cookie; 47 import org.omg.Components.InvalidConnection; 48 49 50 import DiningPhilosophers.*; 51 import DiningPhilosophers.cif.StatusInfoFactory; 52 import DiningPhilosophers.cif.StatusInfoImpl; 53 54 61 public class PhilosopherPanel 62 implements Panel 63 { 64 65 71 static 73 { 74 DiningPhilosophers.StatusInfoFactoryHelper.register(new StatusInfoFactory()); 76 } 77 78 84 85 protected JPanel compositePanel_ = null; 86 87 88 protected DiningPhilosophers.cif.PhilosopherPanel phPanel_ = null; 89 90 91 protected Cookie cookie_ = null; 92 93 94 protected Philosopher philosopher_ = null; 95 96 97 protected StatusInfoConsumerImpl info_ = null; 98 99 100 protected byte[] servantId_ = null; 101 102 108 111 protected void setOpaque(javax.swing.JComponent comp) 112 { 113 comp.setOpaque(false); 114 java.awt.Component [] subComponents = comp.getComponents(); 115 for(int i = 0 ; i < subComponents.length ; i++) 116 { 117 setOpaque((javax.swing.JComponent )subComponents[i]); 118 } 119 } 120 121 127 130 public void selected(TreeView treeView) 131 { 132 133 philosopher_ = (Philosopher) treeView.getSelectedObject(); 135 136 compositePanel_ = new JPanel (); 138 compositePanel_.setBackground(Color.white); 139 140 JPanel titlePanel = new JPanel (); 142 titlePanel.setBackground(Color.white); 143 titlePanel.add(new javax.swing.JLabel (philosopher_.name() + " panel")); 144 145 phPanel_ = new DiningPhilosophers.cif.PhilosopherPanel(new StatusInfoImpl(PhilosopherState.from_int(1), philosopher_.name(), 0, false, false)); 147 javax.swing.border.Border border = javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED); 148 phPanel_.setBorder(javax.swing.BorderFactory.createTitledBorder(border, "Observer")); 149 setOpaque(phPanel_); 150 151 Box box = Box.createVerticalBox(); 153 box.add(Box.createVerticalGlue()); 154 box.add(titlePanel); 155 box.add(Box.createVerticalStrut(10)); 156 box.add(phPanel_); 157 box.add(Box.createVerticalGlue()); 158 compositePanel_.add(box); 159 160 info_ = new StatusInfoConsumerImpl(phPanel_); 162 try 163 { 164 POA poa = TheRootPOA.getRootPOA(); 165 servantId_ = poa.activate_object(info_); 166 cookie_ = philosopher_.subscribe_info(StatusInfoConsumerHelper.narrow(poa.id_to_reference(servantId_))); 167 } 168 catch ( java.lang.Exception ex ) 169 { 170 System.err.println( "An exception has been intercepted" ); 171 ex.printStackTrace(); 172 } 173 } 174 175 179 public Object getPanel() 180 { 181 return compositePanel_; 182 } 183 184 187 public void unselected(TreeView treeView) 188 { 189 try 190 { 191 philosopher_.unsubscribe_info(cookie_); 192 } 193 catch(InvalidConnection e) 194 { 195 System.err.println("InvalidConnection: " + e.getMessage()); 196 } 197 198 try 199 { 200 TheRootPOA.getRootPOA().deactivate_object(servantId_); 201 } 202 catch ( java.lang.Exception ex ) 203 { 204 System.err.println( "An exception has been intercepted" ); 205 ex.printStackTrace(); 206 } 207 208 } 209 210 } 211 | Popular Tags |