KickJava   Java API By Example, From Geeks To Geeks.

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


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.Enumeration JavaDoc;
26 import java.util.Hashtable JavaDoc;
27 import java.util.Vector JavaDoc;
28
29 import org.apache.log4j.Category;
30 import org.eclipse.jface.dialogs.MessageDialog;
31 import org.eclipse.jface.wizard.WizardDialog;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.custom.ScrolledComposite;
34 import org.eclipse.swt.events.ModifyEvent;
35 import org.eclipse.swt.events.ModifyListener;
36 import org.eclipse.swt.events.MouseEvent;
37 import org.eclipse.swt.events.MouseListener;
38 import org.eclipse.swt.events.MouseMoveListener;
39 import org.eclipse.swt.events.PaintEvent;
40 import org.eclipse.swt.events.PaintListener;
41 import org.eclipse.swt.events.SelectionEvent;
42 import org.eclipse.swt.events.SelectionListener;
43 import org.eclipse.swt.graphics.Color;
44 import org.eclipse.swt.graphics.Cursor;
45 import org.eclipse.swt.graphics.GC;
46 import org.eclipse.swt.graphics.Image;
47 import org.eclipse.swt.graphics.Rectangle;
48 import org.eclipse.swt.layout.FillLayout;
49 import org.eclipse.swt.layout.GridData;
50 import org.eclipse.swt.layout.GridLayout;
51 import org.eclipse.swt.widgets.Composite;
52 import org.eclipse.swt.widgets.Event;
53 import org.eclipse.swt.widgets.Label;
54 import org.eclipse.swt.widgets.Listener;
55 import org.eclipse.swt.widgets.Menu;
56 import org.eclipse.swt.widgets.MenuItem;
57 import org.eclipse.swt.widgets.Text;
58 import org.eclipse.swt.widgets.ToolBar;
59 import org.eclipse.swt.widgets.ToolItem;
60 import org.objectweb.clif.scenario.util.isac.FileName;
61 import org.objectweb.clif.scenario.util.isac.gui.Icons;
62 import org.objectweb.clif.scenario.util.isac.gui.ScenarioGUIEditor;
63 import org.objectweb.clif.scenario.util.isac.loadprofile.GroupDescription;
64 import org.objectweb.clif.scenario.util.isac.loadprofile.LoadProfileManager;
65 import org.objectweb.clif.scenario.util.isac.loadprofile.Point;
66 import org.objectweb.clif.scenario.util.isac.loadprofile.RampDescription;
67 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager;
68
69 /**
70  * The load drawing part
71  *
72  * @author JC Meillaud
73  * @author A Peyrard
74  */

75 public class LoadDrawingEditor
76         implements
77             MouseListener,
78             MouseMoveListener,
79             SelectionListener,
80             Listener,
81             PaintListener,
82             ModifyListener {
83     // flag to show warning dialog when an action is not allowed
84
private static final boolean SHOW_WARNING_DIALOGS = true;
85
86     private ScenarioGUIEditor window;
87     private Composite parent;
88     private Composite content;
89     private Composite toolBarComposite;
90     private Composite drawBarComposite;
91     private ScrolledComposite main;
92     private DrawableCanvas drawableCanvas;
93     private Composite canvasComposite;
94     // point
95
private Point first;
96     private Point last;
97     // toolbar buttons
98
private ToolBar toolBar;
99     private MenuItem showTextPopupItem;
100     private ToolItem createGroupToolBarItem;
101     private ToolItem selectionToolBarItem;
102     private Menu selectionMenu;
103     private Hashtable JavaDoc selectionMenuItems;
104     private ToolItem editDescriptionToolBarItem;
105     private ToolItem deleteSelectionToolBarItem;
106     private ToolItem changeScaleToolBarItem;
107     // drawBar button
108
private ToolBar drawBarLeft;
109     private ToolBar drawBarRight;
110     private ToolItem addPointDrawBarItem ;
111     private ToolItem deletePointDrawBarItem ;
112     private ToolItem selectionPointDrawBarItem;
113     private ToolItem drawNothingDrawBarItem;
114     private ToolItem drawLineDrawBarItem;
115     private ToolItem drawCrenelHVDrawBarItem;
116     private ToolItem drawCrenelVHDrawBarItem;
117     private MenuItem showTextDrawPopupItem;
118     private ToolItem normalViewBarItem;
119     private ToolItem maximizedViewBarItem;
120     private Text xAxisText;
121     private Text yAxisText;
122     // load profile desription manager
123
private LoadProfileManager loadManager;
124     // images
125
private Image selectionImg;
126     // logger
127
static Category cat = Category.getInstance(LoadDrawingEditor.class
128             .getName());
129     // drawing mode
130
private static final int DRAW_NOTHING = 0;
131     private static final int DRAW_LINE = 1;
132     private static final int CHANGE_POINT = 2;
133     private static final int SELECTION_POINT = 3;
134     private static final int DRAW_CRENEL_HV = 4;
135     private static final int DRAW_CRENEL_VH = 5;
136     private static final int ADD_POINT_MODE = 6 ;
137     private static final int DELETE_POINT_MODE = 7 ;
138
139     // current mode
140
private int currentMode;
141     // the ramp selected
142
// private RampDescription rampDescriptionSelected;
143
// the current group in which we are working
144
private GroupDescription groupDescriptionSelected;
145     private Point pointSelected = null;
146     // the scale convertor
147
private ScaleConvertor scaleConvertor;
148     // Label of drawbar items
149
private static final String JavaDoc deletePointText = "Delete point" ;
150     private static final String JavaDoc deletePointToolTip = "This mode permit to delete a selected point" ;
151     private static final String JavaDoc addPointText = "Add point" ;
152     private static final String JavaDoc addPointToolTip = "Add a new point" ;
153     private static final String JavaDoc drawCrenelHVText = "Draw Crenel";
154     private static final String JavaDoc drawCrenelVHText = "Draw Crenel";
155     private static final String JavaDoc drawCrenelHVToolTipText = "Draw a Crenel composed by two lines, the first one is horizontal and the second one vertical";
156     private static final String JavaDoc drawCrenelVHToolTipText = "Draw a Crenel composed by two lines, the first one is vertical and the second one horizontal";
157     private static final String JavaDoc drawNothingText = "Normal Mode";
158     private static final String JavaDoc drawNothingToolTipText = "This is the default mode, it draw nothing...";
159     private static final String JavaDoc drawLineText = "Draw Line";
160     private static final String JavaDoc drawLineEmptyRampToolTipText = "Draw a new line for this ramp";
161     private static final String JavaDoc drawLineToolTipText = drawLineText + "\n"
162             + "The starting point of the new line is the last point \n"
163             + "of the existing ramp curve";
164     private static final String JavaDoc maximizedViewText = "Maximize View";
165     private static final String JavaDoc normalViewText = "Normal View";
166     private static final String JavaDoc maximizedViewToolTipText = "Set the maximize the current view";
167     private static final String JavaDoc normalViewToolItemText = "Set the normal view";
168     // Label of the toolbar items
169
private static final String JavaDoc xAxisLabel = "X : ";
170     private static final String JavaDoc yAxisLabel = "Y : ";
171     private static final String JavaDoc axisEditorsToolTipText = "Click with the middle mouse button on a selectable point to edit it coordinates...";
172     private static final String JavaDoc changeScaleText = "Change scale";
173     private static final String JavaDoc changeScaleToolTipText = "Change the scale of the drawable editor";
174     private static final String JavaDoc showTextPopupText = "Show Text";
175     private static final String JavaDoc createGroupToolBarText = "Create Group..";
176     private static final String JavaDoc deleteSelectionText = "Delete Selection";
177     private static final String JavaDoc deleteSelectionToolTipText = "Delete the group description selected";
178     private static final String JavaDoc selectionText = "Select Group";
179     private static final String JavaDoc editDescriptionText = "Edit Properties";
180     private static final String JavaDoc editDescriptionToolTipText = "Edit the description of the selected element";
181     // other labels
182
private static final String JavaDoc createRampInformationTitle = "Create Ramp First";
183     private static final String JavaDoc createRampInformationContent = "There is no ramp description created\n"
184             + "Create a ramp description first !\n";
185     private static final String JavaDoc createBehaviorInformationTitle = "Create Behavior First";
186     private static final String JavaDoc createBehaviorInformationContent = "There is no behavior created\n"
187             + "Create a behavior first !\n";
188
189     // default color
190
public static Color defaultColor = null;
191
192     /**
193      * Build a new drawing load editor
194      *
195      * @param parent
196      * @param w
197      */

198     public LoadDrawingEditor(Composite parent, ScenarioGUIEditor w) {
199         cat.debug("-> constructor");
200         // init default color
201
defaultColor = parent.getDisplay().getSystemColor(SWT.COLOR_BLACK);
202
203         //set the scenarioGUI editor
204
this.window = w;
205         // init the load manager
206
this.loadManager = LoadProfileManager.getInstance();
207         this.loadManager.setDrawablePart(this);
208         // init the scale convertor
209
this.scaleConvertor = new ScaleConvertor();
210         // build the scrolled composite parent
211
this.parent = new Composite(parent, SWT.FLAT);
212         // edit the layout
213
GridLayout gridLayout = new GridLayout();
214         gridLayout.numColumns = 1;
215         gridLayout.marginHeight = 0;
216         gridLayout.marginWidth = 0;
217         gridLayout.verticalSpacing = 4;
218         this.parent.setLayout(gridLayout);
219         // create a composite as toolbar
220
this.toolBarComposite = new Composite(this.parent, SWT.BORDER);
221         // edit the grid data of the composite
222
GridData gridDataToolBar = new GridData();
223         gridDataToolBar.grabExcessHorizontalSpace = true;
224         gridDataToolBar.horizontalAlignment = GridData.FILL;
225         this.toolBarComposite.setLayoutData(gridDataToolBar);
226         // initialise the toolbar
227
this.initToolBar();
228         // create the contents composite
229
this.content = new Composite(this.parent, SWT.FLAT);
230         GridLayout gridContent = new GridLayout();
231         gridContent.marginHeight = 0;
232         gridContent.marginWidth = 0;
233         gridContent.horizontalSpacing = 4;
234         gridContent.numColumns = 2;
235         content.setLayout(gridContent);
236         GridData dataContent = new GridData();
237         dataContent.grabExcessHorizontalSpace = true;
238         dataContent.grabExcessVerticalSpace = true;
239         dataContent.verticalAlignment = GridData.FILL;
240         dataContent.horizontalAlignment = GridData.FILL;
241         content.setLayoutData(dataContent);
242
243         // init the drawBar composite
244
this.drawBarComposite = new Composite(content, SWT.BORDER);
245         GridData gridDataDrawBar = new GridData();
246         gridDataDrawBar.verticalAlignment = GridData.FILL;
247         gridDataDrawBar.grabExcessVerticalSpace = true;
248         this.drawBarComposite.setLayoutData(gridDataDrawBar);
249
250         // create the new main contents
251
this.main = new ScrolledComposite(content, SWT.BORDER | SWT.H_SCROLL
252                 | SWT.V_SCROLL);
253         this.main.setAlwaysShowScrollBars(false);
254         GridData gridDataContents = new GridData();
255         gridDataContents.horizontalAlignment = GridData.FILL;
256         gridDataContents.verticalAlignment = GridData.FILL;
257         gridDataContents.grabExcessHorizontalSpace = true;
258         gridDataContents.grabExcessVerticalSpace = true;
259         this.main.setLayoutData(gridDataContents);
260         this.main.setExpandHorizontal(true);
261         this.main.setExpandVertical(true);
262
263         // init the draw bar
264
this.initDrawBar();
265
266         // initialise the drawable part
267
this.initDrawablePart();
268
269         this.parent.layout();
270         // init the point
271
this.first = new Point(-1, -1);
272         this.last = new Point(-1, -1);
273
274         // init the mode
275
this.currentMode = DRAW_NOTHING;
276     }
277
278     /**
279      * Initialise the drawBar
280      */

281     private void initDrawBar() {
282         cat.debug("-> initDrawBar");
283         // set the layout of the drawBar
284
GridLayout gridDrawBarComposite = new GridLayout();
285         gridDrawBarComposite.numColumns = 2;
286         this.drawBarComposite.setLayout(gridDrawBarComposite);
287         // init the left draw bar
288
this.drawBarLeft = new ToolBar(this.drawBarComposite, SWT.VERTICAL
289                 | SWT.FLAT);
290         // init the grid Data for the draw bar which is the left bar
291
GridData gridDrawBarLeftData = new GridData();
292         gridDrawBarLeftData.horizontalAlignment = GridData.FILL;
293         gridDrawBarLeftData.verticalAlignment = GridData.FILL;
294         gridDrawBarLeftData.grabExcessVerticalSpace = true ;
295         this.drawBarLeft.setLayoutData(gridDrawBarLeftData);
296         // init the right draw bar
297
this.drawBarRight = new ToolBar(this.drawBarComposite, SWT.VERTICAL
298                 | SWT.FLAT);
299         // init the grid Data for the draw bar which is the right bar
300
GridData gridDrawBarRightData = new GridData();
301         gridDrawBarRightData.horizontalAlignment = GridData.FILL;
302         gridDrawBarRightData.verticalAlignment = GridData.FILL;
303         gridDrawBarRightData.grabExcessVerticalSpace = true ;
304         this.drawBarRight.setLayoutData(gridDrawBarRightData);
305
306         /////////////////////////////////////////////////
307
// add the items to the drawBar
308

309         // create the draw nothing item
310
drawNothingDrawBarItem = new ToolItem(drawBarLeft, SWT.RADIO);
311         drawNothingDrawBarItem.setToolTipText(drawNothingToolTipText);
312         drawNothingDrawBarItem.setImage(Icons.getImageRegistry().get(FileName.DRAW_NOTHING_ICON));
313         // create the draw line item
314
drawLineDrawBarItem = new ToolItem(drawBarLeft, SWT.RADIO);
315         drawLineDrawBarItem.setToolTipText(drawLineToolTipText);
316         // create the image item
317
Image img = new Image(this.parent.getDisplay(), new Rectangle(15, 15,
318                 15, 15));
319         img.setBackground(this.parent.getDisplay().getSystemColor(
320                 SWT.COLOR_WHITE));
321         drawLineDrawBarItem.setImage(img);
322         GC gc = new GC(img);
323         gc.setBackground(this.parent.getDisplay().getSystemColor(
324                 SWT.COLOR_WHITE));
325         gc.setForeground(this.parent.getDisplay().getSystemColor(
326                 SWT.COLOR_BLACK));
327         gc.drawLine(0, 0, 15, 15);
328         gc.dispose();
329         // create add point item
330
addPointDrawBarItem = new ToolItem(drawBarLeft, SWT.RADIO) ;
331         addPointDrawBarItem.setToolTipText(addPointToolTip) ;
332         addPointDrawBarItem.setImage(Icons.getImageRegistry().get(FileName.ADDPOINT_ICON)) ;
333
334         // end of the draw bar
335
// separator
336
new ToolItem(drawBarLeft, SWT.SEPARATOR);
337         // add the change view items
338
maximizedViewBarItem = new ToolItem(drawBarLeft, SWT.PUSH);
339         maximizedViewBarItem.setToolTipText(maximizedViewToolTipText);
340         maximizedViewBarItem.setImage(Icons.getImageRegistry().get(FileName.MAXIMIZEVIEW_ICON));
341         
342         // init a new empty image
343
Image imgTemp2 = new Image(this.parent.getDisplay(), new Rectangle(15,
344                 15, 15, 15));
345         GC gc2 = new GC(imgTemp2);
346         gc2.setForeground(this.parent.getDisplay().getSystemColor(
347                 SWT.COLOR_BLACK));
348         gc2.drawLine(4, 4, 11, 4);
349         gc2.drawLine(11, 4, 11, 11);
350         gc2.dispose();
351         // add the crenel draw items, in the right draw bar
352
drawCrenelHVDrawBarItem = new ToolItem(drawBarRight, SWT.RADIO);
353         drawCrenelHVDrawBarItem.setToolTipText(drawCrenelHVToolTipText);
354         drawCrenelHVDrawBarItem.setImage(imgTemp2);
355         // init a new empty image
356
Image imgTemp3 = new Image(this.parent.getDisplay(), new Rectangle(15,
357                 15, 15, 15));
358         GC gc3 = new GC(imgTemp3);
359         gc3.setForeground(this.parent.getDisplay().getSystemColor(
360                 SWT.COLOR_BLACK));
361         gc3.drawLine(4, 11, 4, 4);
362         gc3.drawLine(4, 4, 11, 4);
363         gc3.dispose();
364         drawCrenelVHDrawBarItem = new ToolItem(drawBarRight, SWT.RADIO);
365         drawCrenelVHDrawBarItem.setToolTipText(drawCrenelVHToolTipText);
366         drawCrenelVHDrawBarItem.setImage(imgTemp3);
367         
368 // create delete point item
369
deletePointDrawBarItem = new ToolItem(drawBarRight, SWT.RADIO) ;
370         deletePointDrawBarItem.setToolTipText(deletePointToolTip) ;
371         deletePointDrawBarItem.setImage(Icons.getImageRegistry().get(FileName.DELPOINT_ICON)) ;
372         // add separator
373
new ToolItem(drawBarRight, SWT.SEPARATOR) ;
374         normalViewBarItem = new ToolItem(drawBarRight, SWT.PUSH);
375         normalViewBarItem.setToolTipText(normalViewToolItemText);
376         normalViewBarItem.setImage(Icons.getImageRegistry().get(FileName.NORMALVIEW_ICON));
377
378
379         //////////////////////////////////
380
// set the listeners of items
381
drawNothingDrawBarItem.addSelectionListener(this);
382         drawLineDrawBarItem.addSelectionListener(this);
383         maximizedViewBarItem.addSelectionListener(this);
384         normalViewBarItem.addSelectionListener(this);
385         drawCrenelHVDrawBarItem.addSelectionListener(this);
386         drawCrenelVHDrawBarItem.addSelectionListener(this);
387         addPointDrawBarItem.addSelectionListener(this) ;
388         deletePointDrawBarItem.addSelectionListener(this) ;
389         
390         //////////////////////////////////////////////////////
391
// Popup toolbar menu
392
Menu popup = new Menu(this.drawBarLeft);
393         this.showTextDrawPopupItem = new MenuItem(popup, SWT.CHECK);
394         this.showTextDrawPopupItem.setSelection(false);
395         this.showTextDrawPopupItem.setText(showTextPopupText);
396         // add listener
397
this.showTextDrawPopupItem.addSelectionListener(this);
398         // add to the toolbar
399
this.drawBarLeft.setMenu(popup);
400         this.drawBarRight.setMenu(popup) ;
401         
402         // disable the draw bar
403
this.disableDrawBarItems();
404     }
405
406     /**
407      * Initialise the toolbar
408      */

409     private void initToolBar() {
410         cat.debug("-> initToolBar");
411         // set the layout of the toolbar
412
GridLayout toolBarLayout = new GridLayout();
413         toolBarLayout.numColumns = 5;
414         this.toolBarComposite.setLayout(toolBarLayout);
415         this.toolBar = new ToolBar(this.toolBarComposite, SWT.HORIZONTAL
416                 | SWT.FLAT);
417         // set the row data
418
GridData toolBarData = new GridData();
419         toolBarData.grabExcessHorizontalSpace = true;
420         toolBarData.horizontalAlignment = GridData.FILL;
421         this.toolBar.setLayoutData(toolBarData);
422
423         ///////////////////////////////////////////////
424
// add the items to the toolBar
425

426         // create ramp item
427
createGroupToolBarItem = new ToolItem(toolBar, SWT.PUSH);
428         createGroupToolBarItem.setImage(Icons.getImageRegistry().get(
429                 FileName.NEW_ICON));
430         createGroupToolBarItem
431                 .setToolTipText("Create a new ramp description for a behavior");
432
433         // add a select ramp item
434
selectionToolBarItem = new ToolItem(toolBar, SWT.DROP_DOWN);
435         // add a menu for ths item
436
selectionMenu = new Menu(this.parent.getShell(), SWT.POP_UP);
437         this.selectionMenuItems = new Hashtable JavaDoc();
438         this.selectionToolBarItem.setText(selectionText);
439         this.selectionImg = new Image(this.parent.getDisplay(), new Rectangle(
440                 15, 15, 15, 15));
441         selectionToolBarItem.setImage(this.selectionImg);
442         // init the items select ramp menu
443
this.initSelectGroupItems();
444
445         // add a edit properties item
446
this.editDescriptionToolBarItem = new ToolItem(toolBar, SWT.PUSH);
447         this.editDescriptionToolBarItem.setImage(Icons.getImageRegistry().get(
448                 FileName.PASTE_ICON));
449         this.editDescriptionToolBarItem
450                 .setToolTipText(editDescriptionToolTipText);
451
452         // add a delete ramp item
453
this.deleteSelectionToolBarItem = new ToolItem(toolBar, SWT.PUSH);
454         this.deleteSelectionToolBarItem.setImage(Icons.getImageRegistry().get(
455                 FileName.DELETE_ICON));
456         this.deleteSelectionToolBarItem
457                 .setToolTipText(deleteSelectionToolTipText);
458         // add separator
459
new ToolItem(toolBar, SWT.SEPARATOR);
460         // change scale item
461
this.changeScaleToolBarItem = new ToolItem(toolBar, SWT.PUSH);
462         this.changeScaleToolBarItem.setText(changeScaleText);
463         this.changeScaleToolBarItem.setToolTipText(changeScaleToolTipText);
464         Image imgChangeScale = new Image(this.parent.getDisplay(),
465                 new Rectangle(15, 15, 15, 15));
466         GC gc = new GC(imgChangeScale);
467         gc.drawLine(3, 3, 12, 12);
468         gc.drawLine(3, 12, 12, 3);
469         gc.dispose();
470         this.changeScaleToolBarItem.setImage(imgChangeScale);
471
472         ///////////////////////////////////////////////
473
// set the text of the items
474
this.addToolBarItemText();
475
476         //////////////////////////////////////////////
477
// add the listener
478

479         // add a selection listener to the toolbar item
480
this.createGroupToolBarItem.addSelectionListener(this);
481         // add a selection istener on the multiple line draw item
482
this.selectionToolBarItem.addSelectionListener(this);
483         // add the edit ramp properties listener
484
this.editDescriptionToolBarItem.addSelectionListener(this);
485         // add the delete ramp selected listener
486
this.deleteSelectionToolBarItem.addSelectionListener(this);
487         // add the change scale item listener
488
this.changeScaleToolBarItem.addSelectionListener(this);
489
490         //////////////////////////////////////////////////////
491
// Popup toolbar menu
492
Menu popup = new Menu(this.toolBar);
493         this.showTextPopupItem = new MenuItem(popup, SWT.CHECK);
494         this.showTextPopupItem.setSelection(true);
495         this.showTextPopupItem.setText(showTextPopupText);
496         // add listener
497
this.showTextPopupItem.addSelectionListener(this);
498         // add to the toolbar
499
this.toolBar.setMenu(popup);
500
501         /////////////////////////////////////////////////////
502
// Disable some not allowed action at the begining
503
this.deleteSelectionToolBarItem.setEnabled(false);
504         this.editDescriptionToolBarItem.setEnabled(false);
505
506         ///////////////////////////////////////////////////
507
// Add the axis editor
508

509         // X Axis editor
510
new Label(this.toolBarComposite, SWT.FLAT).setText(xAxisLabel);
511         this.xAxisText = new Text(this.toolBarComposite, SWT.BORDER);
512         GridData gridXAxis = new GridData();
513         gridXAxis.horizontalAlignment = GridData.FILL;
514         // gridXAxis.grabExcessHorizontalSpace = true ;
515
this.xAxisText.setLayoutData(gridXAxis);
516         // this.xAxisText.addModifyListener(this) ;
517

518         // Y Axis editor
519
new Label(this.toolBarComposite, SWT.FLAT).setText(yAxisLabel);
520         this.yAxisText = new Text(this.toolBarComposite, SWT.BORDER);
521         GridData gridYAxis = new GridData();
522         gridYAxis.horizontalAlignment = GridData.FILL;
523         // gridYAxis.grabExcessHorizontalSpace = true ;
524
this.yAxisText.setLayoutData(gridYAxis);
525         // this.yAxisText.addModifyListener(this) ;
526

527         // disable the coordinate text editor
528
this.disableCoordinateEdition();
529     }
530
531     /**
532      * This method enable the coordinate edition
533      */

534     private void enableCoordinateEdition() {
535         this.xAxisText.setEditable(true);
536         this.yAxisText.setEditable(true);
537         this.xAxisText.addModifyListener(this);
538         this.yAxisText.addModifyListener(this);
539     }
540
541     /**
542      * This method disable the coordinate edition
543      */

544     private void disableCoordinateEdition() {
545         this.xAxisText.setEditable(false);
546         this.yAxisText.setEditable(false);
547         this.xAxisText.removeModifyListener(this);
548         this.yAxisText.removeModifyListener(this);
549     }
550
551     /**
552      * Set the coordinate in the edition coordinate text
553      *
554      * @param current
555      * The current point
556      */

557     private void setCoordinateEditionPoint(Point current) {
558         // do changes
559
this.xAxisText.setText(Integer.toString(current.x));
560         this.yAxisText.setText(Integer.toString(current.y));
561     }
562
563     /**
564      * Disable all the items of the draw bar
565      */

566     private void disableDrawBarItems() {
567         ToolItem[] childrenLeft = this.drawBarLeft.getItems();
568         ToolItem[] childrenRight = this.drawBarRight.getItems();
569         // disable each child
570
for (int i = 0; i < childrenLeft.length; i++) {
571             childrenLeft[i].setEnabled(false);
572         }
573         for (int i = 0; i < childrenRight.length; i++) {
574             childrenRight[i].setEnabled(false);
575         }
576     }
577
578     /**
579      * Enable all the items in the draw bar
580      */

581     private void enableDrawBarItems() {
582         ToolItem[] childrenLeft = this.drawBarLeft.getItems();
583         // enable each child
584
for (int i = 0; i < childrenLeft.length; i++) {
585             childrenLeft[i].setEnabled(true);
586         }
587         ToolItem[] childrenRight = this.drawBarRight.getItems();
588         // enable each child
589
for (int i = 0; i < childrenRight.length; i++) {
590             childrenRight[i].setEnabled(true);
591         }
592         // set the normal mode as default
593
this.setNormalViewMode();
594         // set the default selection for this item
595
this.drawCrenelHVDrawBarItem.setSelection(false);
596         this.drawCrenelVHDrawBarItem.setSelection(false);
597         this.drawNothingDrawBarItem.setSelection(true);
598         this.drawLineDrawBarItem.setSelection(false);
599     }
600
601     /**
602      * Remove the text of the draw bar items
603      */

604     private void removeDrawBarItemText() {
605         cat.debug("-> removeDrawBarItemText");
606         this.drawNothingDrawBarItem.setText("");
607         this.drawLineDrawBarItem.setText("");
608         this.maximizedViewBarItem.setText("");
609         this.normalViewBarItem.setText("");
610         this.drawCrenelHVDrawBarItem.setText("") ;
611         this.drawCrenelVHDrawBarItem.setText("") ;
612         this.addPointDrawBarItem.setText("") ;
613         this.deletePointDrawBarItem.setText("") ;
614         // update layout
615
this.content.layout();
616     }
617
618     /**
619      * Put the text on the draw bar items
620      */

621     private void addDrawBarItemText() {
622         cat.debug("-> addDrawBarItemText");
623         this.drawNothingDrawBarItem.setText(drawNothingText);
624         this.drawLineDrawBarItem.setText(drawLineText);
625         this.maximizedViewBarItem.setText(maximizedViewText);
626         this.normalViewBarItem.setText(normalViewText);
627         this.drawCrenelHVDrawBarItem.setText(drawCrenelHVText) ;
628         this.drawCrenelVHDrawBarItem.setText(drawCrenelVHText) ;
629         this.addPointDrawBarItem.setText(addPointText) ;
630         this.deletePointDrawBarItem.setText(deletePointText) ;
631         // update layout
632
this.content.layout();
633     }
634
635     /**
636      * Remove the text of the toolbar items
637      */

638     private void removeTooBarItemText() {
639         cat.debug("-> removeToolBarItemText");
640         this.createGroupToolBarItem.setText("");
641         this.selectionToolBarItem.setText("");
642         this.editDescriptionToolBarItem.setText("");
643         this.deleteSelectionToolBarItem.setText("");
644         this.changeScaleToolBarItem.setText("");
645         // update layout
646
this.parent.layout();
647     }
648
649     private void addToolBarItemText() {
650         cat.debug("-> addToolBarItemText");
651         this.createGroupToolBarItem.setText(createGroupToolBarText);
652         this.selectionToolBarItem.setText(selectionText);
653         this.editDescriptionToolBarItem.setText(editDescriptionText);
654         this.deleteSelectionToolBarItem.setText(deleteSelectionText);
655         this.changeScaleToolBarItem.setText(changeScaleText);
656         // update layout
657
this.parent.layout();
658     }
659
660     /**
661      * Check if the event source is a select group item, in this case select the
662      * group
663      *
664      * @param source
665      * @return
666      */

667     private boolean switchSelectedGroup(Object JavaDoc source) {
668         cat.debug("-> switchSelectedRamp");
669         Enumeration JavaDoc items = this.selectionMenuItems.keys();
670         // check if the source is containig int the select load items
671
while (items.hasMoreElements()) {
672             Object JavaDoc item = items.nextElement();
673             // if it is this item
674
if (item == source) {
675                 // set the group selected
676
this
677                         .setSelectedGroup((GroupDescription) this.selectionMenuItems
678                                 .get(item));
679                 return true;
680             }
681         }
682         return false;
683     }
684
685     /**
686      * Set the toolbar item text and image in the item toolbar of the selected
687      * group
688      *
689      * @param gd
690      * The group description selected
691      */

692     public void setSelectedGroup(GroupDescription gd) {
693         cat.debug("-> setSelectedGroup");
694         // if there is no ramp selected specified reload the beginig
695
// settings
696
if (gd == null) {
697             // Draw the square of the color null
698
GC gc = new GC(this.selectionImg);
699             gc.setBackground(this.parent.getDisplay().getSystemColor(
700                     SWT.COLOR_WHITE));
701             gc.fillRectangle(0, 0, 15, 15);
702             gc.dispose();
703             // set the default text
704
this.selectionToolBarItem.setText(selectionText);
705             this.parent.layout();
706             // set the selected group to null
707
this.groupDescriptionSelected = null;
708             // disable the drawbar
709
this.disableDrawBarItems();
710             // redraw the canvas
711
this.drawableCanvas.redraw();
712             // Disable some toolbar items
713
this.deleteSelectionToolBarItem.setEnabled(false);
714             this.editDescriptionToolBarItem.setEnabled(false);
715
716             return;
717         }
718