1 28 29 package org.objectweb.fractal.explorer.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.explorer.api.Panel; 46 import org.objectweb.util.explorer.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 95 public Object getPanel(){ 96 return panel_; 97 } 98 99 102 public void selected(TreeView treeView) { 103 treeView_ = treeView; 104 org.objectweb.fractal.api.Component ci = (org.objectweb.fractal.api.Component)treeView.getSelectedObject(); 105 try { 106 LifeCycleController lifeCycleController = (LifeCycleController)ci.getFcInterface("lifecycle-controller"); 107 String value = null; 108 String status = lifeCycleController.getFcState(); 109 110 Box box_ = Box.createVerticalBox(); 111 box_.add(Box.createVerticalStrut(10)); 112 113 Box labelBox = Box.createHorizontalBox(); 114 labelBox.setAlignmentX(Component.CENTER_ALIGNMENT); 115 labelBox.add(Box.createHorizontalGlue()); 116 JLabel labelValue = new JLabel ("Component status : " + status); 117 labelBox.add(labelValue); 118 labelBox.add(Box.createHorizontalGlue()); 119 box_.add(labelBox); 120 121 if (status.equals(LifeCycleController.STARTED)) 122 value="Stop"; 123 else if (status.equals(LifeCycleController.STOPPED)) 124 value="Start"; 125 box_.add(Box.createVerticalStrut(10)); 126 Box buttonBox = Box.createHorizontalBox(); 127 buttonBox.add(Box.createHorizontalGlue()); 128 JButton bt = new JButton (new StartStopAction(value,lifeCycleController)); 129 bt.setPreferredSize(new Dimension (100,20)); 130 buttonBox.add(bt); 131 buttonBox.add(Box.createHorizontalGlue()); 132 box_.add(buttonBox); 133 box_.add(Box.createVerticalGlue()); 134 panel_.add(box_); 135 } catch (NoSuchInterfaceException e) { 136 e.printStackTrace(); 137 } 138 } 139 140 143 public void unselected(TreeView treeView) { 144 } 145 146 152 155 protected class StartStopAction extends AbstractAction { 156 157 158 protected LifeCycleController lifeCycleController_; 159 160 161 protected String value_; 162 163 166 public StartStopAction(String value, LifeCycleController lcc){ 167 super(value); 168 value_ = value; 169 lifeCycleController_ = lcc; 170 } 171 172 175 public void actionPerformed(ActionEvent e){ 176 try { 177 if (value_.equals("Start")) 178 lifeCycleController_.startFc(); 179 else if (value_.equals("Stop")) 180 lifeCycleController_.stopFc(); 181 } catch (IllegalLifeCycleException e1) { 182 e1.printStackTrace(); 183 } 184 LifeCycleControllerComponentPanel.this.treeView_.getTree().refreshAll(); 185 } 186 } 187 188 } | Popular Tags |