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.control.IllegalLifeCycleException; 43 import org.objectweb.fractal.api.control.LifeCycleController; 44 import org.objectweb.util.browser.api.Panel; 45 import org.objectweb.util.browser.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 95 public JPanel getPanel(){ 96 return panel_; 97 } 98 99 102 public void selected(TreeView treeView) { 103 treeView_ = treeView; 104 LifeCycleController lifeCycleController = (LifeCycleController)treeView.getSelectedObject(); 105 String value = null; 106 String status = lifeCycleController.getFcState(); 107 108 Box box_ = Box.createVerticalBox(); 109 box_.add(Box.createVerticalStrut(10)); 110 Box labelBox = Box.createHorizontalBox(); 111 labelBox.setAlignmentX(Component.CENTER_ALIGNMENT); 112 labelBox.add(Box.createHorizontalGlue()); 113 JLabel labelValue = new JLabel ("Component status : " + status); 114 labelBox.add(labelValue); 115 labelBox.add(Box.createHorizontalGlue()); 116 box_.add(labelBox); 117 118 if (status.equals("STARTED")) 119 value="Stop"; 120 else if (status.equals("STOPPED")) 121 value="Start"; 122 box_.add(Box.createVerticalStrut(10)); 123 Box buttonBox = Box.createHorizontalBox(); 124 buttonBox.add(Box.createHorizontalGlue()); 125 JButton bt = new JButton (new StartStopAction(value,lifeCycleController)); 126 bt.setPreferredSize(new Dimension (100,20)); 127 buttonBox.add(bt); 128 buttonBox.add(Box.createHorizontalGlue()); 129 box_.add(buttonBox); 130 box_.add(Box.createVerticalGlue()); 131 panel_.add(box_); 132 } 133 134 137 public void unselected(TreeView treeView) { 138 } 139 140 146 149 protected class StartStopAction extends AbstractAction { 150 151 152 protected LifeCycleController lifeCycleController_; 153 154 155 protected String value_; 156 157 160 public StartStopAction(String value, LifeCycleController lcc){ 161 super(value); 162 value_ = value; 163 lifeCycleController_ = lcc; 164 } 165 166 169 public void actionPerformed(ActionEvent e){ 170 try { 171 if (value_.equals("Start")) 172 lifeCycleController_.startFc(); 173 else if (value_.equals("Stop")) 174 lifeCycleController_.stopFc(); 175 } catch (IllegalLifeCycleException e1) { 176 e1.printStackTrace(); 177 } 178 LifeCycleControllerPanel.this.treeView_.getTree().refresh(); 179 } 180 } 181 182 } | Popular Tags |