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.control.IllegalLifeCycleException; 43 import org.objectweb.fractal.api.control.LifeCycleController; 44 import org.objectweb.util.explorer.api.Panel; 45 import org.objectweb.util.explorer.api.TreeView; 46 47 52 public class LifeCycleControllerPanel 53 implements Panel 54 { 55 61 protected TreeView treeView_ = null; 62 63 protected JPanel panel_ = null; 64 65 71 74 public LifeCycleControllerPanel() { 75 panel_ = new JPanel (); 76 panel_.setBackground(Color.white); 77 } 78 79 85 91 94 public Object getPanel(){ 95 return panel_; 96 } 97 98 101 public void selected(TreeView treeView) { 102 treeView_ = treeView; 103 LifeCycleController lifeCycleController = (LifeCycleController)treeView.getSelectedObject(); 104 String value = null; 105 String status = lifeCycleController.getFcState(); 106 107 Box box_ = Box.createVerticalBox(); 108 box_.add(Box.createVerticalStrut(10)); 109 Box labelBox = Box.createHorizontalBox(); 110 labelBox.setAlignmentX(Component.CENTER_ALIGNMENT); 111 labelBox.add(Box.createHorizontalGlue()); 112 JLabel labelValue = new JLabel ("Component status : " + status); 113 labelBox.add(labelValue); 114 labelBox.add(Box.createHorizontalGlue()); 115 box_.add(labelBox); 116 117 if (status.equals("STARTED")) 118 value="Stop"; 119 else if (status.equals("STOPPED")) 120 value="Start"; 121 box_.add(Box.createVerticalStrut(10)); 122 Box buttonBox = Box.createHorizontalBox(); 123 buttonBox.add(Box.createHorizontalGlue()); 124 JButton bt = new JButton (new StartStopAction(value,lifeCycleController)); 125 bt.setPreferredSize(new Dimension (100,20)); 126 buttonBox.add(bt); 127 buttonBox.add(Box.createHorizontalGlue()); 128 box_.add(buttonBox); 129 box_.add(Box.createVerticalGlue()); 130 panel_.add(box_); 131 } 132 133 136 public void unselected(TreeView treeView) { 137 } 138 139 145 148 protected class StartStopAction extends AbstractAction { 149 150 151 protected LifeCycleController lifeCycleController_; 152 153 154 protected String value_; 155 156 159 public StartStopAction(String value, LifeCycleController lcc){ 160 super(value); 161 value_ = value; 162 lifeCycleController_ = lcc; 163 } 164 165 168 public void actionPerformed(ActionEvent e){ 169 try { 170 if (value_.equals("Start")) 171 lifeCycleController_.startFc(); 172 else if (value_.equals("Stop")) 173 lifeCycleController_.stopFc(); 174 } catch (IllegalLifeCycleException e1) { 175 e1.printStackTrace(); 176 } 177 LifeCycleControllerPanel.this.treeView_.getTree().refreshAll(); 178 } 179 } 180 181 } | Popular Tags |