KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > loadprofile > gui > GroupDescriptionPage


1 /*
2  * CLIF is a Load Injection Framework
3  * Copyright (C) 2004 France Telecom R&D
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * CLIF
20  *
21  * Contact: clif@objectweb.org
22  */

23 package org.objectweb.clif.scenario.util.isac.loadprofile.gui;
24
25 import java.util.Vector JavaDoc;
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 /**
52  * This class implements a page for edit group description in a wizard
53  *
54  * @author JC Meillaud
55  * @author A Peyrard
56  */

57 public class GroupDescriptionPage extends WizardPage
58         implements
59             ModifyListener,
60             SelectionListener {
61     private Vector JavaDoc ids;
62     private Combo idsCombo;
63     private Button colorButton;
64     private Button forceStopThreadTrue ;
65     private Button forceStopThreadFalse ;
66     private String JavaDoc behaviorId;
67     private boolean forceStopThread ;
68     private Image colorImage;
69     private Color color;
70     private String JavaDoc rampId ;
71     private Vector JavaDoc subCurves ;
72     private Composite parent ;
73     // logger
74
static Category cat = Category.getInstance(GroupDescriptionPage.class
75             .getName());
76     // error message
77
private static final String JavaDoc errorColor = "You must edit the ramp color";
78     private static final String JavaDoc errorId = "You must edit the behavior ID";
79     // boolean which is true when all parameters has been edited
80
private boolean finish = false;
81
82     /**
83      * @param pageName
84      * @param ids The behavior ids
85      * @param rd The group description
86      */

87     public GroupDescriptionPage(String JavaDoc pageName, Vector JavaDoc 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         // Set the text
96
setTitle("Edit group description");
97         setDescription("Specify description of group");
98     }
99  
100 /**
101      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
102      */

103     public void createControl(Composite parent) {
104         this.parent = parent ;
105         // create the composite to hold the widgets
106
Composite composite = new Composite(parent, SWT.NONE);
107
108         // create the desired layout for this wizard page
109
GridLayout layout = new GridLayout();
110         layout.numColumns = 2;
111         layout.verticalSpacing = 20;
112         composite.setLayout(layout);
113
114         // add a label for show the ramp id
115
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         // add a choose behavior label
121
new Label(composite, SWT.NONE).setText("Behavior ID : ");
122         // add a combo to select a behavior
123
this.idsCombo = new Combo(composite, SWT.BORDER | SWT.READ_ONLY);
124         // create the values of the combo
125
this.idsCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
126         this.idsCombo.setItems((String JavaDoc[]) ids.toArray(new String JavaDoc[ids.size()]));
127         // set the value if exists
128
if (this.behaviorId != null)
129             this.idsCombo.setText(this.behaviorId) ;
130         // add modify listener
131
this.idsCombo.addModifyListener(this);
132
133         // add the stopping mode selector
134
new Label(composite, SWT.NONE).setText("Force the behaviors to stop : ");
135         // create a new group to put the two radiobutton
136
Group groupForceMode = new Group(composite,SWT.FLAT);
137         groupForceMode.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)) ;
138         // set the layout of the group
139
groupForceMode.setLayout(new FillLayout()) ;
140         // add the two button
141
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         // select the previous selected value
148
if (this.forceStopThread) {
149             this.forceStopThreadTrue.setSelection(true) ;
150         }
151         else {
152             this.forceStopThreadFalse.setSelection(true) ;
153         }
154         
155         // add the color chooser
156
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         // add a selection listener
163
this.colorButton.addSelectionListener(this);
164                 
165         // if color exists set the value
166
if (this.color != null)
167             this.setColor(this.color) ;
168         
169         this.setControl(composite);
170     }
171
172     /**
173      * Set the color field
174      *
175      * @param rgb
176      * The rgb of the color to set
177      */

178     private void setColor(RGB rgb) {
179         this.color = new Color(this.getShell().getDisplay(), rgb);
180         // draw the color on the image button
181
GC gc = new GC(this.colorImage);
182         gc.setBackground(this.color);
183         gc.fillRectangle(0, 0, 19, 19);
184         gc.dispose();
185
186         // update error message
187
this.updateErrorMessage();
188     }
189     
190     /**
191      * Set the color field
192      *
193      * @param color
194      * The color to set
195      */

196     private void setColor(Color c) {
197         this.color = c ;
198         // draw the color on the image button
199
GC gc = new GC(this.colorImage);
200         gc.setBackground(this.color);
201         gc.fillRectangle(0, 0, 19, 19);
202         gc.dispose();
203
204         // update error message
205
this.updateErrorMessage();
206     }
207
208     /**
209      * Update error log
210      */

211     private void updateErrorMessage() {
212         String JavaDoc errorMessage = "";
213         // check if behavior id is defined
214
if (this.idsCombo.getText().equals("")) {
215             errorMessage = errorMessage.concat(errorId + "\n");
216         }
217         // check if color has been defined
218
if (this.color == null)
219             errorMessage = errorMessage.concat(errorColor);
220         // si il y a des messages d'erreurs a afficher alors on les affiche
221
if (!errorMessage.equals("")) {
222             this.setErrorMessage(errorMessage);
223         } else {
224             this.setErrorMessage(null);
225             this.finish = true ;
226         }
227     }
228
229     /**
230      * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
231      */

232     public void modifyText(ModifyEvent event) {
233         if (!this.idsCombo.getText().equals(""))
234             this.behaviorId = this.idsCombo.getText() ;
235         updateErrorMessage();
236     }
237
238     /**
239      * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
240      */

241     public void widgetDefaultSelected(SelectionEvent event) {
242
243     }
244     /**
245      * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
246      */

247     public void widgetSelected(SelectionEvent event) {
248         // if color button
249
if (event.getSource() == this.colorButton) {
250             // open a color choice dialog
251
ColorDialog dialog = new ColorDialog(this.getShell());
252             // if color has been previously defined set it as default
253
if (color != null)
254                 dialog.setRGB(color.getRGB());
255             // get the color choosen in dialog
256
RGB rgbColor = dialog.open();
257             // if color has been choosed
258
if (rgbColor != null) {
259                 this.setColor(rgbColor);
260             }
261             return ;
262         }
263         // if the thread stop mode selector have been selected
264
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     /////////////////////////////////////////////////////////////////////////////////
275
// Attribute GETTERS
276
////////////////////////////////////////////////////////////////////////////////
277

278     /**
279      * @return Returns the behaviorId.
280      */

281     protected String JavaDoc getBehaviorId() {
282         return behaviorId;
283     }
284     /**
285      * @return Returns the color.
286      */

287     protected Color getColor() {
288         return color;
289     }
290     /**
291      * @return Returns the finish.
292      */

293     protected boolean isFinish() {
294         return finish;
295     }
296     /**
297      * @return Returns the forceStopThread.
298      */

299     public boolean isForceStopThread() {
300         return forceStopThread;
301     }
302 }
Popular Tags