1 28 29 package org.objectweb.util.browser.plugins.fractal.panel; 30 31 import java.awt.Color ; 32 import java.awt.Component ; 33 import java.awt.Dimension ; 34 import java.awt.event.ActionEvent ; 35 36 import javax.swing.AbstractAction ; 37 import javax.swing.Box ; 38 import javax.swing.JButton ; 39 import javax.swing.JLabel ; 40 import javax.swing.JPanel ; 41 42 import org.objectweb.fractal.api.NoSuchInterfaceException; 43 import org.objectweb.fractal.api.control.IllegalLifeCycleException; 44 import org.objectweb.fractal.api.control.LifeCycleController; 45 import org.objectweb.util.browser.api.Panel; 46 import org.objectweb.util.browser.api.TreeView; 47 48 53 public class LifeCycleControllerComponentPanel 54 implements Panel 55 { 56 62 protected TreeView treeView_ = null; 63 64 protected JPanel panel_ = null; 65 66 72 75 public LifeCycleControllerComponentPanel() { 76 panel_ = new JPanel (); 77 panel_.setBackground(Color.white); 78 } 79 80 86 92 96 public JPanel getPanel(){ 97 return panel_; 98 } 99 100 103 public void selected(TreeView treeView) { 104 treeView_ = treeView; 105 org.objectweb.fractal.api.Component ci = (org.objectweb.fractal.api.Component)treeView.getSelectedObject(); 106 try { 107 LifeCycleController lifeCycleController = (LifeCycleController)ci.getFcInterface("lifecycle-controller"); 108 String value = null; 109 String status = lifeCycleController.getFcState(); 110 111 Box box_ = Box.createVerticalBox(); 112 box_.add(Box.createVerticalStrut(10)); 113 114 Box labelBox = Box.createHorizontalBox(); 115 labelBox.setAlignmentX(Component.CENTER_ALIGNMENT); 116 labelBox.add(Box.createHorizontalGlue()); 117 JLabel labelValue = new JLabel ("Component status : " + status); 118 labelBox.add(labelValue); 119 labelBox.add(Box.createHorizontalGlue()); 120 box_.add(labelBox); 121 122 if (status.equals(LifeCycleController.STARTED)) 123 value="Stop"; 124 else if (status.equals(LifeCycleController.STOPPED)) 125 value="Start"; 126 box_.add(Box.createVerticalStrut(10)); 127 Box buttonBox = Box.createHorizontalBox(); 128 buttonBox.add(Box.createHorizontalGlue()); 129 JButton bt = new JButton (new StartStopAction(value,lifeCycleController)); 130 bt.setPreferredSize(new Dimension (100,20)); 131 buttonBox.add(bt); 132 buttonBox.add(Box.createHorizontalGlue()); 133 box_.add(buttonBox); 134 box_.add(Box.createVerticalGlue()); 135 panel_.add(box_); 136 } catch (NoSuchInterfaceException e) { 137 e.printStackTrace(); 138 } 139 } 140 141 144 public void unselected(TreeView treeView) { 145 } 146 147 153 156 protected class StartStopAction extends AbstractAction { 157 158 159 protected LifeCycleController lifeCycleController_; 160 161 162 protected String value_; 163 164 167 public StartStopAction(String value, LifeCycleController lcc){ 168 super(value); 169 value_ = value; 170 lifeCycleController_ = lcc; 171 } 172 173 176 public void actionPerformed(ActionEvent e){ 177 try { 178 if (value_.equals("Start")) 179 lifeCycleController_.startFc(); 180 else if (value_.equals("Stop")) 181 lifeCycleController_.stopFc(); 182 } catch (IllegalLifeCycleException e1) { 183 e1.printStackTrace(); 184 } 185 LifeCycleControllerComponentPanel.this.treeView_.getTree().refresh(); 186 } 187 } 188 189 } | Popular Tags |