1 23 package org.objectweb.clif.scenario.util.isac.loadprofile.gui; 24 25 import java.util.Vector ; 26 27 import org.apache.log4j.Category; 28 import org.eclipse.jface.wizard.WizardPage; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.events.ModifyEvent; 31 import org.eclipse.swt.events.ModifyListener; 32 import org.eclipse.swt.events.SelectionEvent; 33 import org.eclipse.swt.events.SelectionListener; 34 import org.eclipse.swt.graphics.Color; 35 import org.eclipse.swt.graphics.GC; 36 import org.eclipse.swt.graphics.Image; 37 import org.eclipse.swt.graphics.RGB; 38 import org.eclipse.swt.graphics.Rectangle; 39 import org.eclipse.swt.layout.FillLayout; 40 import org.eclipse.swt.layout.GridData; 41 import org.eclipse.swt.layout.GridLayout; 42 import org.eclipse.swt.widgets.Button; 43 import org.eclipse.swt.widgets.ColorDialog; 44 import org.eclipse.swt.widgets.Combo; 45 import org.eclipse.swt.widgets.Composite; 46 import org.eclipse.swt.widgets.Group; 47 import org.eclipse.swt.widgets.Label; 48 import org.eclipse.swt.widgets.Text; 49 import org.objectweb.clif.scenario.util.isac.loadprofile.GroupDescription; 50 51 57 public class GroupDescriptionPage extends WizardPage 58 implements 59 ModifyListener, 60 SelectionListener { 61 private Vector ids; 62 private Combo idsCombo; 63 private Button colorButton; 64 private Button forceStopThreadTrue ; 65 private Button forceStopThreadFalse ; 66 private String behaviorId; 67 private boolean forceStopThread ; 68 private Image colorImage; 69 private Color color; 70 private String rampId ; 71 private Vector subCurves ; 72 private Composite parent ; 73 static Category cat = Category.getInstance(GroupDescriptionPage.class 75 .getName()); 76 private static final String errorColor = "You must edit the ramp color"; 78 private static final String errorId = "You must edit the behavior ID"; 79 private boolean finish = false; 81 82 87 public GroupDescriptionPage(String pageName, Vector ids, GroupDescription rd) { 88 super(pageName); 89 this.ids = ids; 90 this.rampId = rd.getGroupId() ; 91 this.behaviorId = rd.getBehaviorId() ; 92 this.forceStopThread = rd.isForceStop() ; 93 this.color = rd.getCurveColor() ; 94 this.subCurves = rd.getRamps() ; 95 setTitle("Edit group description"); 97 setDescription("Specify description of group"); 98 } 99 100 103 public void createControl(Composite parent) { 104 this.parent = parent ; 105 Composite composite = new Composite(parent, SWT.NONE); 107 108 GridLayout layout = new GridLayout(); 110 layout.numColumns = 2; 111 layout.verticalSpacing = 20; 112 composite.setLayout(layout); 113 114 new Label(composite, SWT.NONE).setText("Group ID : "); 116 Text text = new Text(composite, SWT.READ_ONLY | SWT.BORDER) ; 117 text.setText(rampId) ; 118 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 119 120 new Label(composite, SWT.NONE).setText("Behavior ID : "); 122 this.idsCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY); 124 this.idsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 126 this.idsCombo.setItems((String []) ids.toArray(new String [ids.size()])); 127 if (this.behaviorId != null) 129 this.idsCombo.setText(this.behaviorId) ; 130 this.idsCombo.addModifyListener(this); 132 133 new Label(composite, SWT.NONE).setText("Force the behaviors to stop : "); 135 Group groupForceMode = new Group(composite,SWT.FLAT); 137 groupForceMode.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) ; 138 groupForceMode.setLayout(new FillLayout()) ; 140 this.forceStopThreadTrue = new Button(groupForceMode, SWT.RADIO) ; 142 this.forceStopThreadTrue.setText("true") ; 143 this.forceStopThreadTrue.addSelectionListener(this) ; 144 this.forceStopThreadFalse = new Button(groupForceMode, SWT.RADIO) ; 145 this.forceStopThreadFalse.setText("false") ; 146 this.forceStopThreadFalse.addSelectionListener(this) ; 147 if (this.forceStopThread) { 149 this.forceStopThreadTrue.setSelection(true) ; 150 } 151 else { 152 this.forceStopThreadFalse.setSelection(true) ; 153 } 154 155 new Label(composite, SWT.FLAT).setText("Select a curve color : "); 157 this.colorButton = new Button(composite, SWT.FLAT); 158 this.colorImage = new Image(parent.getDisplay(), new Rectangle(20, 20, 159 20, 20)); 160 this.colorButton.setImage(this.colorImage); 161 this.colorButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 162 this.colorButton.addSelectionListener(this); 164 165 if (this.color != null) 167 this.setColor(this.color) ; 168 169 this.setControl(composite); 170 } 171 172 178 private void setColor(RGB rgb) { 179 this.color = new Color(this.getShell().getDisplay(), rgb); 180 GC gc = new GC(this.colorImage); 182 gc.setBackground(this.color); 183 gc.fillRectangle(0, 0, 19, 19); 184 gc.dispose(); 185 186 this.updateErrorMessage(); 188 } 189 190 196 private void setColor(Color c) { 197 this.color = c ; 198 GC gc = new GC(this.colorImage); 200 gc.setBackground(this.color); 201 gc.fillRectangle(0, 0, 19, 19); 202 gc.dispose(); 203 204 this.updateErrorMessage(); 206 } 207 208 211 private void updateErrorMessage() { 212 String errorMessage = ""; 213 if (this.idsCombo.getText().equals("")) { 215 errorMessage = errorMessage.concat(errorId + "\n"); 216 } 217 if (this.color == null) 219 errorMessage = errorMessage.concat(errorColor); 220 if (!errorMessage.equals("")) { 222 this.setErrorMessage(errorMessage); 223 } else { 224 this.setErrorMessage(null); 225 this.finish = true ; 226 } 227 } 228 229 232 public void modifyText(ModifyEvent event) { 233 if (!this.idsCombo.getText().equals("")) 234 this.behaviorId = this.idsCombo.getText() ; 235 updateErrorMessage(); 236 } 237 238 241 public void widgetDefaultSelected(SelectionEvent event) { 242 243 } 244 247 public void widgetSelected(SelectionEvent event) { 248 if (event.getSource() == this.colorButton) { 250 ColorDialog dialog = new ColorDialog(this.getShell()); 252 if (color != null) 254 dialog.setRGB(color.getRGB()); 255 RGB rgbColor = dialog.open(); 257 if (rgbColor != null) { 259 this.setColor(rgbColor); 260 } 261 return ; 262 } 263 if (event.getSource() == this.forceStopThreadTrue) { 265 this.forceStopThread = true ; 266 return ; 267 } 268 if (event.getSource() == this.forceStopThreadFalse) { 269 this.forceStopThread = false ; 270 return ; 271 } 272 } 273 274 278 281 protected String getBehaviorId() { 282 return behaviorId; 283 } 284 287 protected Color getColor() { 288 return color; 289 } 290 293 protected boolean isFinish() { 294 return finish; 295 } 296 299 public boolean isForceStopThread() { 300 return forceStopThread; 301 } 302 } | Popular Tags |