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         // set the selected group description
719
this.groupDescriptionSelected = gd;
720         // Draw the square of the color of the group selected
721
GC gc = new GC(this.selectionImg);
722         gc.setBackground(this.groupDescriptionSelected.getCurveColor());
723         gc.fillRectangle(0, 0, 15, 15);
724         gc.dispose();
725         // set the text
726
this.selectionToolBarItem.setText("Group " + gd.getGroupId() + " ("
727                 + gd.getBehaviorId() + ")");
728         this.parent.layout();
729         // enable the draw bar
730
this.enableDrawBarItems();
731         // redraw the canvas
732
this.drawableCanvas.redraw();
733         // enable some toolbar items
734
this.deleteSelectionToolBarItem.setEnabled(true);
735         this.editDescriptionToolBarItem.setEnabled(true);
736     }
737
738     /**
739      * @return Returns the groupDescriptionSelected.
740      */

741     public GroupDescription getGroupDescriptionSelected() {
742         return groupDescriptionSelected;
743     }
744
745     /**
746      * @return Returns the parent.
747      */

748     public Composite getParent() {
749         return parent;
750     }
751
752     /**
753      * Dispose all of the items in the selectloadmenuitems vector
754      */

755     private void disposeSelectionItems() {
756         cat.debug("-> disposeSelectionItems");
757         Enumeration JavaDoc items = this.selectionMenuItems.keys();
758         // dispose each items of the vector
759
while (items.hasMoreElements())
760             ((MenuItem) items.nextElement()).dispose();
761     }
762
763     /**
764      * Initialise the select items
765      */

766     private void initSelectGroupItems() {
767         cat.debug("-> initSelectRampItems");
768         // dispose all the previous items
769
this.disposeSelectionItems();
770         // delete all the previous items
771
this.selectionMenuItems.clear();
772
773         Enumeration JavaDoc elements = this.loadManager.getElements();
774         // for each elements
775
while (elements.hasMoreElements()) {
776             GroupDescription gd = (GroupDescription) elements.nextElement();
777             // build a new item for this ramp
778
MenuItem item = new MenuItem(this.selectionMenu, SWT.PUSH);
779             item.setText("Group " + gd.getGroupId() + "(" + gd.getBehaviorId()
780                     + ")");
781             // build a new image
782
Image img = new Image(this.parent.getDisplay(), new Rectangle(10,
783                     10, 10, 10));
784             // set the image item
785
item.setImage(img);
786             // draw a square of the ramp color
787
GC gc = new GC(img);
788             gc.setBackground(gd.getCurveColor());
789             gc.fillRectangle(0, 0, 10, 10);
790             gc.dispose();
791             // add a selection listener to this item
792
item.addSelectionListener(this);
793             // add to the vector
794
this.selectionMenuItems.put(item, gd);
795         }
796     }
797
798     /**
799      * Initialise the drawing part
800      */

801     private void initDrawablePart() {
802         cat.debug("-> initDrawablePart");
803         // intialise the canvas
804
this.canvasComposite = new Composite(this.main, SWT.FLAT);
805         // set the layout of the canvas composite
806
this.canvasComposite.setLayout(new FillLayout());
807         // set the canvas as content of the scrollable main part
808
this.main.setContent(this.canvasComposite);
809         // add the drawable canvas
810
this.drawableCanvas = new DrawableCanvas(this.canvasComposite, SWT.FLAT);
811         // add some mous listener on the drawable canvas
812
this.drawableCanvas.addMouseListener(this);
813         this.drawableCanvas.addMouseMoveListener(this);
814         this.drawableCanvas.addListener(SWT.RESIZE, this);
815         this.drawableCanvas.addPaintListener(this);
816
817         // set a minimum size
818
this.setDrawablePartSize(new Point(
819                 ScaleConvertor.DEFAULT_MIN_CANVAS_SIZE.getWidth(),
820                 ScaleConvertor.DEFAULT_MIN_CANVAS_SIZE.getHeight()));
821     }
822
823     /**
824      * Set the minimum size of the canvas as p
825      *
826      * @param p
827      * The point representing the minimum size of the main part
828      */

829     private void setDrawablePartSize(Point p) {
830         cat.debug("-> setDrawablePartSize");
831         this.main.setMinSize(p.toEclipsePoint());
832     }
833
834     /**
835      * Get the size of the canvas
836      *
837      * @return The size
838      */

839     private Size getDrawableCanvasSize() {
840         // get the actual size of the canvas
841
Rectangle size = this.drawableCanvas.getBounds();
842         return new Size(size.width, size.height);
843     }
844
845     /////////////////////////////////////////////////////////////////////////////////////////////
846
// Drawing methods
847
/////////////////////////////////////////////////////////////////////////////////////////////
848

849     /**
850      * Draw all curves
851      */

852     private void drawAll() {
853         // get the actual size of the canvas
854
Rectangle size = this.drawableCanvas.getBounds();
855         // set the size in the scale convertor
856
this.scaleConvertor.setCanvasSize(new Size(size.width, size.height));
857
858         // draw all groups
859
Enumeration JavaDoc e = this.loadManager.getElements() ;
860         while (e.hasMoreElements())
861             this.drawGroup((GroupDescription)e.nextElement()) ;
862         
863         if (this.groupDescriptionSelected == null)
864             return;
865         // draw the group
866
if (this.pointSelected != null) {
867             this.drawableCanvas.selectPoint(this.scaleConvertor
868                     .realPointToEditorPoint(this.pointSelected), true);
869         }
870 // this.drawGroup(this.groupDescriptionSelected);
871
// if there is a rmp selected, select it on the drawable editor
872
if (this.groupDescriptionSelected != null)
873             this.drawGroupSelection(groupDescriptionSelected);
874     }
875
876     /**
877      * Draw the group selection (select all points of the ramps)
878      *
879      * @param gd
880      * The group description to select
881      */

882     private void drawGroupSelection(GroupDescription rd) {
883         // get the actual size of the canvas
884
Rectangle size = this.drawableCanvas.getBounds();
885         // set the size in the scale convertor
886
this.scaleConvertor.setCanvasSize(new Size(size.width, size.height));
887         GroupDescription groupWithEditorPoints = this.scaleConvertor
888                 .realGroupToEditorGroup(rd);
889         this.drawableCanvas.selectGroup(groupWithEditorPoints);
890     }
891
892     /**
893      * Draw a group given in parameter
894      *
895      * @param gd
896      * The group description to draw
897      */

898     private void drawGroup(GroupDescription gd) {
899         Enumeration JavaDoc e = gd.getElements();
900         // draw each ramp of the group
901
while (e.hasMoreElements())
902             drawRamp((RampDescription) e.nextElement(), gd.getCurveColor());
903     }
904
905     /**
906      * Draw a ramp description given in parameter
907      *
908      * @param rd
909      * The ramp description to draw
910      * @param c
911      * The color of the ramp to draw
912      */

913     private void drawRamp(RampDescription rd, Color c) {
914         RampDescription rampWithEditorPoints = this.scaleConvertor
915                 .realRampToEditorRamp(rd);
916         this.drawableCanvas.drawRamp(rampWithEditorPoints, c);
917     }
918
919     /**
920      * Draw the mark bar, with the scale printed on them
921      */

922     private void drawMark() {
923         // get the actual size of the canvas
924
Size canvasSize = this.getDrawableCanvasSize();
925         // get a color for the graphic
926
Color c = this.parent.getDisplay().getSystemColor(SWT.COLOR_BLACK);
927
928         int w = canvasSize.getWidth();
929         int h = canvasSize.getHeight();
930
931         // set the current size to the scale convertor
932
this.scaleConvertor.setCanvasSize(canvasSize);
933         // set the color of the mark
934
Color color = this.parent.getDisplay().getSystemColor(SWT.COLOR_BLACK);
935
936         // draw the two lines of the mark
937
this.drawableCanvas.drawRamp(this.scaleConvertor
938                 .realRampToEditorRamp(new RampDescription("temp",
939                         RampDescription.LINE, new Point(0, 0), new Point(
940                                 this.scaleConvertor.getScale().getWidth(), 0),
941                         new Point(-1, -1))), color);
942         this.drawableCanvas.drawRamp(this.scaleConvertor
943                 .realRampToEditorRamp(new RampDescription("temp",
944                         RampDescription.LINE, new Point(0, 0), new Point(0,
945                                 this.scaleConvertor.getScale().getHeight()),
946                         new Point(-1, -1))), color);
947         // draw the arrows
948
this.drawableCanvas.drawArrow(new Point(ScaleConvertor.MARGIN_LEFT,
949                 ScaleConvertor.MARGIN_TOP), 8, 0, c);
950         this.drawableCanvas.drawArrow(
951                 new Point(w - ScaleConvertor.MARGIN_RIGHT, h
952                         - ScaleConvertor.MARGIN_BACK), 8, 1, c);
953         // put the name of the two graphics lines
954
this.drawableCanvas.drawString(new Point(5, 2), "Nb Behaviors", c);
955         this.drawableCanvas.drawString(new Point(w - 90, h - 20), "Nb Seconds",
956                 c);
957     }
958     
959     /**
960      * This method draw graduation on the mark axis
961      */

962     private void drawGrad() {
963         // get the actual scale of the canvas
964
Size canvasScale = this.scaleConvertor.getScale() ;
965         // get a color for the graphic
966
Color c = this.parent.getDisplay().getSystemColor(SWT.COLOR_BLACK);
967
968         int w = canvasScale.getWidth();
969         int h = canvasScale.getHeight();
970         // get the log of the size
971
int logw = ScaleConvertor.logTen(w);
972         int logh = ScaleConvertor.logTen(h);
973         // init the graduation unit
974
int unitw = 1 ;
975         int unith = 1 ;
976         for (int i=0;i<logw-1;i++) unitw = unitw*10;
977         for (int i=0;i<logh-1;i++) unith = unith*10;
978         // check if we need to draw sub grad
979
boolean subh = false;
980         boolean subw = false;
981         if (h/unith < 5) subh = true;
982         if (w/unitw < 5) subw = true;
983         // draw the graduation for x axis
984
int countw = 0 ;
985         while (countw < w) {
986             // get the editor point
987
Point editorGrad = this.scaleConvertor.realPointToEditorPoint(new Point(countw,0)) ;
988             // draw the grad
989
this.drawableCanvas.drawLine(editorGrad
990                                         ,new Point(editorGrad.x, editorGrad.y+ScaleConvertor.GRAD_SIZE)
991                                         ,c);
992             this.drawableCanvas.drawString(new Point(editorGrad.x-3,editorGrad.y+10),Integer.toString(countw),c);
993             if (subw)
994                 countw += (unitw/2);
995             else
996                 countw += unitw ;
997         }
998         
999         // draw the graduation for y axis
1000
int counth = 0 ;
1001        while (counth < h) {
1002            // get the editor point
1003
Point editorGrad = this.scaleConvertor.realPointToEditorPoint(new Point(0,counth)) ;
1004            // draw the grad
1005
this.drawableCanvas.drawLine(editorGrad
1006                                        ,new Point(editorGrad.x-ScaleConvertor.GRAD_SIZE,editorGrad.y)
1007                                        ,c);
1008            this.drawableCanvas.drawString(new Point(editorGrad.x-ScaleConvertor.MARGIN_LEFT,editorGrad.y-8),Integer.toString(counth),c);
1009            if (subh)
1010                counth += (unith/2);
1011            else
1012                counth += unith ;
1013        }
1014    }
1015
1016    /////////////////////////////////////////////////////////////////////////////////////////////
1017
// starting and stopping mode methods
1018
/////////////////////////////////////////////////////////////////////////////////////////////
1019

1020    /**
1021     * Initialise the change point mode
1022     *
1023     * @param selected
1024     * The selected point to change it axis
1025     */

1026    private void initChangePointMode(Point selected) {
1027        cat.warn("-> initChangePointMode : " + selected);
1028        // set the current mode
1029
this.currentMode = CHANGE_POINT;
1030        // init the cursor
1031
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1032                SWT.CURSOR_SIZEALL));
1033        // init the first point as the selected point and the last too, the last
1034
// will be never changed
1035
this.first = this.scaleConvertor.realPointToEditorPoint(new Point(
1036                selected.x, selected.y));
1037        this.last = new Point(selected.x, selected.y);
1038
1039        // erase the selection of the point on the draw
1040
this.drawableCanvas.eraseSelectionPoint(this.first);
1041    }
1042
1043    /**
1044     * Init the selection point mode, this mode will be used to change
1045     * coordinate of the selected point
1046     *
1047     * @param selected
1048     * The selected point
1049     */

1050    private void initSelectionPointMode(Point selected) {
1051        cat.warn("-> initSelectionPointMode : " + selected);
1052        // set the current mode
1053
this.currentMode = SELECTION_POINT;
1054        // set the selected point
1055
this.pointSelected = selected;
1056        // redraw canvas
1057
this.drawableCanvas.redraw();
1058        // enable coordinate edition
1059
this.enableCoordinateEdition();
1060        // set the selected point
1061
this.setCoordinateEditionPoint(selected);
1062        // change the cursor
1063
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1064                SWT.CURSOR_ARROW));
1065    }
1066
1067    /**
1068     * Initialise the crenel horizontal-vertical drawing mode
1069     */

1070    private void initDrawCrenelHVMode() {
1071        cat.debug("-> initDrawCrenelHVMode");
1072        // set the current mode
1073
this.currentMode = DRAW_CRENEL_HV;
1074        // set the selected item in the draw bar
1075
this.deletePointDrawBarItem.setSelection(false) ;
1076        this.drawCrenelHVDrawBarItem.setSelection(true);
1077        this.drawCrenelVHDrawBarItem.setSelection(false);
1078        this.drawNothingDrawBarItem.setSelection(false);
1079        this.drawLineDrawBarItem.setSelection(false);
1080        this.addPointDrawBarItem.setSelection(false) ;
1081        // init the cursor
1082
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1083                SWT.CURSOR_CROSS));
1084        // check if the current group has already some ramps drawed
1085
if (this.groupDescriptionSelected.getRamps().size() != 0) {
1086            // get the last drawed point
1087
Point lastDrawed = ((RampDescription) this.groupDescriptionSelected
1088                    .getRamps()
1089                    .elementAt(
1090                            this.groupDescriptionSelected.getRamps().size() - 1))
1091                    .getEnd();
1092            // init the first point as the last drawed point
1093
this.first = new Point(lastDrawed.x, lastDrawed.y);
1094        } else {
1095            // reinitialise the points
1096
this.first = new Point(-1, -1);
1097        }
1098        this.last = new Point(-1, -1);
1099    }
1100
1101    /**
1102     * Initialise the crenel vertical-horizontal drawing mode
1103     */

1104    private void initDrawCrenelVHMode() {
1105        cat.debug("-> initDrawCrenelVHMode");
1106        // set the current mode
1107
this.currentMode = DRAW_CRENEL_VH;
1108        // set the selected item in the draw bar
1109
this.drawCrenelHVDrawBarItem.setSelection(false);
1110        this.drawCrenelVHDrawBarItem.setSelection(true);
1111        this.drawNothingDrawBarItem.setSelection(false);
1112        this.addPointDrawBarItem.setSelection(false) ;
1113        this.deletePointDrawBarItem.setSelection(false) ;
1114        this.drawLineDrawBarItem.setSelection(false);
1115        // init the cursor
1116
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1117                SWT.CURSOR_CROSS));
1118        // check if the current group has already some ramps drawed
1119
if (this.groupDescriptionSelected.getRamps().size() != 0) {
1120            // get the last drawed point
1121
Point lastDrawed = ((RampDescription) this.groupDescriptionSelected
1122                    .getRamps()
1123                    .elementAt(
1124                            this.groupDescriptionSelected.getRamps().size() - 1))
1125                    .getEnd();
1126            // init the first point as the last drawed point
1127
this.first = new Point(lastDrawed.x, lastDrawed.y);
1128        } else {
1129            // reinitialise the points
1130
this.first = new Point(-1, -1);
1131        }
1132        this.last = new Point(-1, -1);
1133    }
1134    
1135    /**
1136     * Initialise the multiple line drawing mode
1137     */

1138    private void initLineMode() {
1139        cat.debug("-> initLineMode");
1140        // set the current Mode
1141
this.currentMode = DRAW_LINE;
1142        // set the selected item in the draw bar
1143
this.drawCrenelHVDrawBarItem.setSelection(false);
1144        this.drawCrenelVHDrawBarItem.setSelection(false);
1145        this.drawNothingDrawBarItem.setSelection(false);
1146        this.drawLineDrawBarItem.setSelection(true);
1147        this.deletePointDrawBarItem.setSelection(false) ;
1148        this.addPointDrawBarItem.setSelection(false) ;
1149        // init the cursor
1150
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1151                SWT.CURSOR_CROSS));
1152        // check if the current group has already some ramps drawed
1153
if (this.groupDescriptionSelected.getRamps().size() != 0) {
1154            // get the last drawed point
1155
Point lastDrawed = ((RampDescription) this.groupDescriptionSelected
1156                    .getRamps()
1157                    .elementAt(
1158                            this.groupDescriptionSelected.getRamps().size() - 1))
1159                    .getEnd();
1160            // init the first point as the last drawed point
1161
this.first = new Point(
1162                    lastDrawed.x, lastDrawed.y);
1163        } else {
1164            // reinitialise the points
1165
this.first = new Point(-1, -1);
1166        }
1167        this.last = new Point(-1, -1);
1168    }
1169    
1170    /**
1171     * Initialise the addPointMode
1172     */

1173    private void initAddPointMode() {
1174        cat.debug("-> initAddPointMode") ;
1175        // set the current mode
1176
this.currentMode = ADD_POINT_MODE ;
1177        // set the selected item in the draw bar
1178
this.drawCrenelHVDrawBarItem.setSelection(false);
1179        this.drawCrenelVHDrawBarItem.setSelection(false);
1180        this.drawNothingDrawBarItem.setSelection(false);
1181        this.drawLineDrawBarItem.setSelection(false);
1182        this.addPointDrawBarItem.setSelection(true) ;
1183        this.deletePointDrawBarItem.setSelection(false) ;
1184        // init the cursor
1185
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1186                SWT.CURSOR_CROSS));
1187    }
1188    
1189    /**
1190     * Initialise the deletePointMode
1191     */

1192    private void initDeletePointMode() {
1193        cat.debug("-> initDeletePointMode") ;
1194        // set the current mode
1195
this.currentMode = DELETE_POINT_MODE ;
1196        // set the selected item in the draw bar
1197
this.drawCrenelHVDrawBarItem.setSelection(false);
1198        this.drawCrenelVHDrawBarItem.setSelection(false);
1199        this.drawNothingDrawBarItem.setSelection(false);
1200        this.drawLineDrawBarItem.setSelection(false);
1201        this.addPointDrawBarItem.setSelection(false) ;
1202        this.deletePointDrawBarItem.setSelection(true) ;
1203        // init the cursor
1204
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1205                SWT.CURSOR_CROSS));
1206    }
1207    
1208    /**
1209     * Finish the drawing crenel mode
1210     */

1211    private void finishDrawCrenelXXMode() {
1212        cat.debug("-> finishDrawCrenelXXMode") ;
1213        // if we have draw temporary line erase the last one
1214
if (this.first.x != -1) {
1215            // redraw the canvas
1216
this.drawableCanvas.redraw();
1217        }
1218        // change the cursor to the classic arrow
1219
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1220                SWT.CURSOR_ARROW));
1221    }
1222    
1223    /**
1224     * This method is called when the user cancel the changing point mode
1225     */

1226    private void finishChangePointMode() {
1227        cat.debug("-> finish change point mode");
1228        // redraw the canvas
1229
this.drawableCanvas.redraw();
1230        // set the default mode
1231
this.currentMode = DRAW_NOTHING;
1232    }
1233    
1234    private void finishAddPointMode() {
1235        cat.debug("-> finishAddPointMode") ;
1236        // redraw the canvas
1237
this.drawableCanvas.redraw() ;
1238        // change the cursor to the classic one
1239
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1240                SWT.CURSOR_ARROW));
1241    }
1242    
1243    private void finishDeletePointMode() {
1244        cat.debug("-> finishDeletePointMode") ;
1245        // redraw the canvas
1246
this.drawableCanvas.redraw() ;
1247        // change the cursor to the classic one
1248
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1249                SWT.CURSOR_ARROW));
1250    }
1251
1252    /**
1253     * Finish the endLineMode
1254     */

1255    private void finishLineMode() {
1256        cat.warn("-> finishLineMode");
1257        // if we have draw temporary line erase the last one
1258
if (this.first.x != -1) {
1259            // redraw the canvas
1260
this.drawableCanvas.redraw();
1261        }
1262        // change the cursor to the classic arrow
1263
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1264                SWT.CURSOR_ARROW));
1265    }
1266
1267    /**
1268     * Finish the selection point mode
1269     */

1270    private void finishSelectionPointMode() {
1271        cat.warn("-> finishSelectionPointMode");
1272        // disable the coordinate edition
1273
this.disableCoordinateEdition();
1274        // unselect the point
1275
this.pointSelected = null;
1276        // redraw the canvas
1277
this.drawableCanvas.redraw();
1278    }
1279
1280    /**
1281     * Finish the current mode
1282     */

1283    private void finishMode() {
1284        cat.debug("-> finishMode");
1285        // switch between the existing mode to finish the right one
1286
switch (this.currentMode) {
1287            case DELETE_POINT_MODE :
1288                finishDeletePointMode() ;
1289                break ;
1290            case ADD_POINT_MODE :
1291                finishAddPointMode() ;
1292                break ;
1293            case DRAW_LINE :
1294                finishLineMode();
1295                break;
1296            case DRAW_NOTHING :
1297                // do nothing
1298
break;
1299            case CHANGE_POINT :
1300                finishChangePointMode();
1301                break;
1302            case SELECTION_POINT :
1303                finishSelectionPointMode();
1304                break;
1305            // same finish action for the drawing crenel mode
1306
case DRAW_CRENEL_HV :
1307            case DRAW_CRENEL_VH :
1308                finishDrawCrenelXXMode() ;
1309                break ;
1310            default :
1311                cat.warn("This draw mode is UNKNOW");
1312        }
1313        // select the draw nothing item
1314
this.drawCrenelHVDrawBarItem.setSelection(false);
1315        this.drawCrenelVHDrawBarItem.setSelection(false);
1316        this.addPointDrawBarItem.setSelection(false) ;
1317        this.drawNothingDrawBarItem.setSelection(true);
1318        this.deletePointDrawBarItem.setSelection(false) ;
1319        this.drawLineDrawBarItem.setSelection(false);
1320        // set the current mode as nothing draw mode
1321
this.currentMode = DRAW_NOTHING;
1322    }
1323
1324    ////////////////////////////////////////////////////////////////////////////////////
1325
// Events mode methods...
1326
////////////////////////////////////////////////////////////////////////////////////
1327

1328    /**
1329     * This method test if the point is not in margins parts or if the point is
1330     * after the last point in the time scale
1331     *
1332     * @param p
1333     * The point to analyse
1334     * @param showWarning True if we must show the warning dialogs
1335     * @return True if there is no warning false else...
1336     */

1337    private boolean isCorrectDrawablePoint(Point p, boolean showWarning) {
1338        // check if the point is not in margins
1339
if (this.scaleConvertor.isInMarginPoint(p)) {
1340            if (showWarning)
1341                MessageDialog.openWarning(this.parent.getShell(), "Warning",
1342                        "The selecting point is outside the drawable area...");
1343            return false;
1344        }
1345        // chek if the point is after the last point
1346
if ((this.first.x != -1) && (this.first.y != -1)) {
1347            // the frist point has real coordinates
1348
// so transform them into editor coordinates
1349
Point firstEditor = this.scaleConvertor.realPointToEditorPoint(this.first) ;
1350            if (p.x <= firstEditor.x) {
1351                if (showWarning)
1352                    MessageDialog
1353                            .openWarning(this.parent.getShell(), "Warning",
1354                                    "The selected point must be after the first point of the ramp... " + p.x + ", " + firstEditor.x) ;
1355                return false;
1356            }
1357        }
1358        // all test have been succeed, so the point is correct
1359
return true;
1360    }
1361
1362    /**
1363     * Test if a ramp is correct
1364     *
1365     * @param rd
1366     * The ramp description with real point
1367     * @return True is the ramp is correct
1368     */

1369    private boolean isCorrectDrawableRamp(RampDescription rd, boolean showWarning) {
1370        // check if the begin point is not in margins
1371
if (this.scaleConvertor.isInMarginPoint(this.scaleConvertor
1372                .realPointToEditorPoint(rd.getStart()))) {
1373            if (showWarning)
1374                MessageDialog.openWarning(this.parent.getShell(), "Warning",
1375                        "The selecting point is outside the drawable area...");
1376            return false;
1377        }
1378        // check if the end point is not in margins
1379
if (this.scaleConvertor.isInMarginPoint(this.scaleConvertor
1380                .realPointToEditorPoint(rd.getEnd()))) {
1381            if (showWarning)
1382                MessageDialog.openWarning(this.parent.getShell(), "Warning",
1383                        "The selecting point is outside the drawable area...");
1384            return false;
1385        }
1386        // check if end is after start in the time scale
1387
if (rd.getStart().x > rd.getEnd().x) {
1388            if (showWarning)
1389                MessageDialog
1390                        .openWarning(this.parent.getShell(), "Warning",
1391                                "The selected point must be after the first point of the ramp...");
1392            return false;
1393        }
1394        // all test have been succeed, so the ramp is correct
1395
return true;
1396    }
1397
1398    /**
1399     * This method is called when we are in the draw crenel hv mode
1400     * It adds a new crenel hv ramp description to the current group
1401     * @param e The mouse event
1402     */

1403    private void clickCrenelHVMode(MouseEvent e) {
1404        cat.debug("-> clickCrenelHVMode") ;
1405        // get the real point
1406
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1407                e.y));
1408        // set coordinate edition
1409
this.setCoordinateEditionPoint(real);
1410        // if the button 2 is clicked switch the crenel mode
1411
if (e.button == 2) {
1412            // finish this mode
1413
this.finishMode() ;
1414            // init the crenel vh mode
1415
this.initDrawCrenelVHMode() ;
1416            this.moveCrenelVHMode(e) ;
1417            return ;
1418        }
1419        // check if the point is correct
1420
if (!this.isCorrectDrawablePoint(new Point(e.x, e.y), SHOW_WARNING_DIALOGS)) {
1421            // do as the user have not click
1422
return;
1423        }
1424        // test if we have already fix a starting point
1425
if (this.first.x == -1 && this.first.y == -1) {
1426            // init the first point
1427
this.first = real ;
1428            // do nothing else
1429
return ;
1430        }
1431        
1432        // generate a new RampId
1433
String JavaDoc rampId = this.loadManager.rampIdGenerator() ;
1434        
1435        // draw the previous crenel
1436
RampDescription tempToAdd = new RampDescription(rampId, RampDescription.CRENEL_HV) ;
1437        tempToAdd.setStart(new Point(this.first.x, this.first.y)) ;
1438        tempToAdd.setEnd(new Point(real.x, real.y)) ;
1439        
1440        // add the ramp to the group
1441
this.groupDescriptionSelected.addRamp(tempToAdd) ;
1442        // redraw the canvas
1443
this.drawableCanvas.redraw() ;
1444        // update the first drawed point, used if we want to draw another crenel after this one
1445
this.first = new Point(real.x, real.y) ;
1446
1447    }
1448    
1449    /**
1450     * This method is called when we are in the draw crenel vh mode
1451     * It adds a new crenel vh ramp description to the current group
1452     * @param e The mouse event
1453     */

1454    private void clickCrenelVHMode(MouseEvent e) {
1455        cat.debug("-> clickCrenelVHMode") ;
1456        // get the real point
1457
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1458                e.y));
1459        // set coordinate edition
1460
this.setCoordinateEditionPoint(real);
1461        // if the button 2 is clicked switch the crenel mode
1462
if (e.button == 2) {
1463            // finish this mode
1464
this.finishMode() ;
1465            // init the crenel vh mode
1466
this.initDrawCrenelHVMode() ;
1467            this.moveCrenelHVMode(e) ;
1468            return ;
1469        }
1470        // check if the point is correct
1471
if (!this.isCorrectDrawablePoint(new Point(e.x, e.y), SHOW_WARNING_DIALOGS)) {
1472            // do as the user have not click
1473
return;
1474        }
1475        // test if we have already fix a starting point
1476
if (this.first.x == -1 && this.first.y == -1) {
1477            // init the first point
1478
this.first = real ;
1479            // do nothing else
1480
return ;
1481        }
1482        // update the last drawed point
1483
this.last = real ;
1484        
1485        // generate a new RampId
1486
String JavaDoc rampId = this.loadManager.rampIdGenerator() ;
1487        
1488        // draw the previous crenel
1489
RampDescription tempToAdd = new RampDescription(rampId, RampDescription.CRENEL_VH) ;
1490        tempToAdd.setStart(new Point(this.first.x, this.first.y)) ;
1491        tempToAdd.setEnd(new Point(this.last.x, this.last.y)) ;
1492        
1493        // add the ramp to the group
1494
this.groupDescriptionSelected.addRamp(tempToAdd) ;
1495        // redraw the canvas
1496
this.drawableCanvas.redraw() ;
1497        // update the first drawed point, used if we want to draw another crenel after this one
1498
this.first = new Point(real.x, real.y) ;
1499    }
1500    
1501    /**
1502     * This method is used when we click on the canvas and we are in line mode
1503     * edition
1504     */

1505    private void clickLineMode(MouseEvent e) {
1506        // check if the point is correct
1507
if (!this.isCorrectDrawablePoint(new Point(e.x, e.y), SHOW_WARNING_DIALOGS)) {
1508            // do as the user has not clicked
1509
return;
1510        }
1511        // in this case we made the first click of the draw line mode
1512
if ((this.first.x == -1) && (this.first.y == -1)) {
1513            // Set the first point of the line
1514
this.first = this.scaleConvertor.editorPointToRealPoint(new Point(e.x, e.y)) ;
1515            // do nothing else
1516
return;
1517        }
1518
1519        // in this case we have already made the first point so the point
1520
// selected is the last one of the line
1521
this.last = this.scaleConvertor.editorPointToRealPoint(new Point(e.x, e.y)) ;
1522
1523        // add this curve description to the selected group
1524
if (this.groupDescriptionSelected != null) {
1525            // set the ramp id before adding it
1526
String JavaDoc tempID = this.loadManager.rampIdGenerator();
1527            RampDescription curveWithRealPoints = new RampDescription(tempID, RampDescription.LINE, this.first, this.last, new Point(-1,-1)) ;
1528            this.groupDescriptionSelected.addRamp(curveWithRealPoints);
1529            // redraw the drawable part
1530
this.drawableCanvas.redraw();
1531        } else {
1532            // should never append
1533
cat
1534                    .warn("There is no group description selected, so we can't save the current ramp drawed");
1535            ;
1536        }
1537        // put the last one as the first point, because the new line that
1538
// will be created after this one, will begin at this point
1539
this.first.x = this.last.x;
1540        this.first.y = this.last.y;
1541    }
1542
1543    /**
1544     * Method which is called when the user click on the canvas and when we are
1545     * in draw nothing mode...
1546     *
1547     * @param e
1548     * The mouse event
1549     */

1550    private void clickNothingMode(MouseEvent e) {
1551        // if there is no group selected
1552
if (this.groupDescriptionSelected == null) {
1553            // do nothing
1554
return;
1555        }
1556        // get the selectable point which is clicked, else {-1,-1}
1557
Point temp = this.scaleConvertor.editorPointIsSelectableRealGroupPoint(
1558                new Point(e.x, e.y), this.groupDescriptionSelected);
1559        if (!temp.equals(new Point(-1, -1))) {
1560            // analyse the button clicked if left, so entering change point
1561
// mode, else select the point
1562
if (e.button == 1) {
1563                // init the change point mode
1564
this.initChangePointMode(temp);
1565            }
1566            if (e.button == 2) {
1567                // select the point
1568
this.initSelectionPointMode(temp);
1569            }
1570            // do nothing else
1571
return;
1572        }
1573    }
1574
1575    /**
1576     * Method which is called when the user click on the canvas and the state
1577     * mode is changing point
1578     *
1579     * @param e
1580     * The mouse event
1581     */

1582    private void clickChangePointMode(MouseEvent e) {
1583
1584        // Get the real point
1585
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1586                e.y));
1587        // set the point to the curves
1588
Point curvesNumbers = this.groupDescriptionSelected
1589                .rampsWhichContains(this.last);
1590
1591        RampDescription c1 = null;
1592        RampDescription c2 = null;
1593        RampDescription clone1 = null;
1594        RampDescription clone2 = null;
1595        if (curvesNumbers.x != -1) {
1596            c1 = (RampDescription) this.groupDescriptionSelected.getRamps()
1597                    .elementAt((int) curvesNumbers.x);
1598            // test the changes...
1599
clone1 = (RampDescription) c1.clone();
1600            clone1.getEnd().x = real.x;
1601            clone1.getEnd().y = real.y;
1602        }
1603        if (curvesNumbers.y != -1) {
1604            c2 = (RampDescription) this.groupDescriptionSelected.getRamps()
1605                    .elementAt((int) curvesNumbers.y);
1606            // test the changes...
1607
clone2 = (RampDescription) c2.clone();
1608            clone2.getStart().x = real.x;
1609            clone2.getStart().y = real.y;
1610        }
1611        // test all case, two point will be modified
1612
if ((c1 != null) && (c2 != null)) {
1613            // if they are correct do them
1614
if (isCorrectDrawableRamp(clone1, SHOW_WARNING_DIALOGS) && isCorrectDrawableRamp(clone2, SHOW_WARNING_DIALOGS)) {
1615                c1.getEnd().x = real.x;
1616                c1.getEnd().y = real.y;
1617                c2.getStart().x = real.x;
1618                c2.getStart().y = real.y;
1619            } else {
1620                return;
1621            }
1622        }
1623        // only the first one need to be modified
1624
else if (c1 != null) {
1625            if (isCorrectDrawableRamp(clone1, SHOW_WARNING_DIALOGS)) {
1626                c1.getEnd().x = real.x;
1627                c1.getEnd().y = real.y;
1628            } else
1629                return;
1630        }
1631        // only the second one need to be modified
1632
else if (c2 != null) {
1633            if (isCorrectDrawableRamp(clone2, SHOW_WARNING_DIALOGS)) {
1634                c2.getStart().x = real.x;
1635                c2.getStart().y = real.y;
1636            } else
1637                return;
1638        }
1639
1640        // Change to the default mode
1641
this.currentMode = DRAW_NOTHING;
1642        // redraw the group
1643
this.drawableCanvas.redraw();
1644    }
1645
1646    /**
1647     * This method is called when a user click and if the program is in add point mode
1648     * @param e The mouse event
1649     */

1650    private void clickAddPointMode(MouseEvent e) {
1651        cat.debug("-> clickAddPointMode") ;
1652        // check if the point is correct
1653
if (this.scaleConvertor.isInMarginPoint(new Point(e.x,e.y))) {
1654            if (SHOW_WARNING_DIALOGS)
1655                MessageDialog.openWarning(this.parent.getShell(), "Warning",
1656                        "The selecting point is outside the drawable area...");
1657            return;
1658        }
1659        // add the point to the selected group
1660
if (this.groupDescriptionSelected == null) {
1661            // should never append
1662
return ;
1663        }
1664        // transfrom the point coordinates into real coordinates
1665
Point realPoint = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,e.y)) ;
1666        // add the point to the group
1667
this.groupDescriptionSelected.addPoint(realPoint) ;
1668        
1669        // redraw the group
1670
this.drawableCanvas.redraw();
1671    }
1672    
1673    /**
1674     * This method is called when a user click and if the program is in delete point mode
1675     * @param e The mouse event
1676     */

1677    private void clickDeletePointMode(MouseEvent e) {
1678        cat.debug("-> clickDeletePointMode") ;
1679        // check if the point is correct
1680
if (this.scaleConvertor.isInMarginPoint(new Point(e.x,e.y))) {
1681            if (SHOW_WARNING_DIALOGS)
1682                MessageDialog.openWarning(this.parent.getShell(), "Warning",
1683                        "The selecting point is outside the drawable area...");
1684            return;
1685        }
1686        // add the point to the selected group
1687
if (this.groupDescriptionSelected == null) {
1688            // should never append
1689
return ;
1690        }
1691        Point temp = this.scaleConvertor.editorPointIsSelectableRealGroupPoint(
1692                new Point(e.x, e.y), this.groupDescriptionSelected);
1693        // if the point is selectable
1694
if (temp.x != -1 && temp.y != -1) {
1695            // delete the point to the group
1696
this.groupDescriptionSelected.deletePoint(temp) ;
1697        }
1698        // redraw the group
1699
this.drawableCanvas.redraw();
1700    }
1701    
1702    /**
1703     * Method which draw a previous crenel HV
1704     * @param e The mouse event
1705     */

1706    private void moveCrenelHVMode(MouseEvent e) {
1707        cat.debug("-> moveCrenelHVMode") ;
1708        // get the real point
1709
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1710                e.y));
1711        // set coordinate edition
1712
this.setCoordinateEditionPoint(real);
1713        // test if we have already fix a starting point
1714
if (this.first.x == -1 && this.first.y == -1) {
1715            // do nothing
1716
return ;
1717        }
1718        // erase the previous drawing curve, if there is a previous crenel drawed
1719
if (this.last.x != -1 && this.last.y != -1) {
1720            RampDescription tempToErase = new RampDescription("temp", RampDescription.CRENEL_HV) ;
1721            tempToErase.setStart(new Point(this.first.x, this.first.y)) ;
1722            tempToErase.setEnd(new Point(this.last.x, this.last.y)) ;
1723            this.drawableCanvas.drawRamp(this.scaleConvertor.realRampToEditorRamp(tempToErase), this.parent.getDisplay().getSystemColor(DrawableCanvas.BACK_COLOR)) ;
1724        }
1725        // update the last drawed point
1726
this.last = real ;
1727        
1728        // draw the previous crenel
1729
RampDescription tempToDraw = new RampDescription("temp", RampDescription.CRENEL_HV) ;
1730        tempToDraw.setStart(new Point(this.first.x, this.first.y)) ;
1731        tempToDraw.setEnd(new Point(this.last.x, this.last.y)) ;
1732        this.drawableCanvas.drawRamp(this.scaleConvertor.realRampToEditorRamp(tempToDraw), this.groupDescriptionSelected.getCurveColor()) ;
1733    }
1734    
1735    /**
1736     * Method which draw a previous crenel VH
1737     * @param e The mouse event
1738     */

1739    private void moveCrenelVHMode(MouseEvent e) {
1740        cat.debug("-> moveCrenelVHMode") ;
1741        // get the real point
1742
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1743                e.y));
1744        // set coordinate edition
1745
this.setCoordinateEditionPoint(real);
1746        // test if we have already fix a starting point
1747
if (this.first.x == -1 && this.first.y == -1) {
1748            // do nothing
1749
return ;
1750        }
1751        // erase the previous drawing curve, if there is a previous crenel drawed
1752
if (this.last.x != -1 && this.last.y != -1) {
1753            RampDescription tempToErase = new RampDescription("temp", RampDescription.CRENEL_VH) ;
1754            tempToErase.setStart(new Point(this.first.x, this.first.y)) ;
1755            tempToErase.setEnd(new Point(this.last.x, this.last.y)) ;
1756            this.drawableCanvas.drawRamp(this.scaleConvertor.realRampToEditorRamp(tempToErase), this.parent.getDisplay().getSystemColor(DrawableCanvas.BACK_COLOR)) ;
1757        }
1758        // update the last drawed point
1759
this.last = real ;
1760        
1761        // draw the previous crenel
1762
RampDescription tempToDraw = new RampDescription("temp", RampDescription.CRENEL_VH) ;
1763        tempToDraw.setStart(new Point(this.first.x, this.first.y)) ;
1764        tempToDraw.setEnd(new Point(this.last.x, this.last.y)) ;
1765        this.drawableCanvas.drawRamp(this.scaleConvertor.realRampToEditorRamp(tempToDraw), this.groupDescriptionSelected.getCurveColor()) ;
1766    }
1767    
1768    /**
1769     * Method which change the axis of a point when the mouse move
1770     *
1771     * @param e
1772     * The mouse event
1773     */

1774    private void moveChangePointMode(MouseEvent e) {
1775        cat.warn("-> moveChangePointMode");
1776        // get the real point
1777
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1778                e.y));
1779        // set coordinate edition
1780
this.setCoordinateEditionPoint(real);
1781
1782        // get the numbers of the curves that contains the selectable point
1783
// original
1784
Point curvesParentNumber = this.groupDescriptionSelected
1785                .rampsWhichContains(this.last);
1786
1787        // we don't test if the point returned is not null, because in the use
1788
// of this method we are sure, that the point point is selectable
1789
// if the point is the last point of the ramp
1790
if (curvesParentNumber.x != -1) {
1791            RampDescription tempDesc = (RampDescription) this.groupDescriptionSelected
1792                    .getRamps().elementAt((int) curvesParentNumber.x);
1793            RampDescription editorCurve = this.scaleConvertor
1794                    .realRampToEditorRamp(tempDesc);
1795            // erase the last drawed curve
1796
this.drawableCanvas.drawRamp(new RampDescription("temp",
1797                    editorCurve.getType(), editorCurve.getStart(), this.first,
1798                    editorCurve.getAngle()), this.parent.getDisplay()
1799                    .getSystemColor(DrawableCanvas.BACK_COLOR));
1800            // draw the new curve
1801
this.drawableCanvas.drawRamp(new RampDescription("temp",
1802                    editorCurve.getType(), editorCurve.getStart(), new Point(
1803                            e.x, e.y), editorCurve.getAngle()),
1804                    this.groupDescriptionSelected.getCurveColor());
1805        }
1806        // if the point is the first point of the ramp
1807
if (curvesParentNumber.y != -1) {
1808            // get the last curve of the ramp
1809
RampDescription tempDesc = (RampDescription) this.groupDescriptionSelected
1810                    .getRamps().elementAt((int) curvesParentNumber.y);
1811            // convert the curve in a drawable curve, which means they have
1812
// editor scale points
1813
RampDescription editorCurve = this.scaleConvertor
1814                    .realRampToEditorRamp(tempDesc);
1815            // erase the last drawed curve
1816
this.drawableCanvas.drawRamp(new RampDescription("temp",
1817                    editorCurve.getType(), this.first, editorCurve.getEnd(),
1818                    editorCurve.getAngle()), this.parent.getDisplay()
1819                    .getSystemColor(DrawableCanvas.BACK_COLOR));
1820            // draw the new curve
1821
this.drawableCanvas.drawRamp(new RampDescription("temp",
1822                    editorCurve.getType(), new Point(e.x, e.y), editorCurve
1823                            .getEnd(), editorCurve.getAngle()),
1824                    this.groupDescriptionSelected.getCurveColor());
1825        }
1826        // change the last edited point
1827
this.first.x = e.x;
1828        this.first.y = e.y;
1829    }
1830
1831    /**
1832     * Method which change the cursor if the point is a selectable point
1833     *
1834     * @param e
1835     * The mouse event
1836     */

1837    private void moveNothingMode(MouseEvent e) {
1838        // get the real point
1839
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1840                e.y));
1841        // set coordinate edition
1842
this.setCoordinateEditionPoint(real);
1843        // if there is no group selected
1844
if (this.groupDescriptionSelected == null) {
1845            // do nothing
1846
return;
1847        }
1848        Point temp = this.scaleConvertor.editorPointIsSelectableRealGroupPoint(
1849                new Point(e.x, e.y), this.groupDescriptionSelected);
1850        if (!temp.equals(new Point(-1, -1))) {
1851            // change the cursor
1852
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1853                    SWT.CURSOR_SIZEALL));
1854            // do nothing else
1855
return;
1856        }
1857        // put the arrow cursor
1858
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1859                SWT.CURSOR_ARROW));
1860    }
1861
1862    /**
1863     * Method which draw a previous to the line that can be added to the curve
1864     * if the user click on the mouse left button
1865     *
1866     * @param e
1867     * The mouse event
1868     */

1869    private void moveLineMode(MouseEvent e) {
1870        // get the real point
1871
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1872                e.y));
1873        // set coordinate edition
1874
this.setCoordinateEditionPoint(real);
1875        // if we have not fix the first point
1876
if (this.first.x == -1) {
1877            // do nothing
1878
return;
1879        }
1880        
1881        // get the first point with editor coordinate
1882
Point firstEditor = this.scaleConvertor.realPointToEditorPoint(this.first) ;
1883        
1884        // if we have drawed a temporary line erase it
1885
if (this.last.x != -1 && this.last.y != -1) {
1886            this.drawableCanvas.eraseLine(firstEditor, this.last) ;
1887        }
1888        
1889        // draw a temporary line
1890
this.drawableCanvas.drawLine(firstEditor, new Point(e.x, e.y),
1891                this.groupDescriptionSelected.getCurveColor());
1892        // change the last point
1893
this.last = new Point(e.x, e.y) ;
1894    }
1895    
1896    /**
1897     * This function is called when the mouse move in the add point mode
1898     * @param e The mouse event
1899     */

1900    private void moveAddPointMode(MouseEvent e) {
1901        // get the real point
1902
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1903                e.y));
1904        // set coordinate edition
1905
this.setCoordinateEditionPoint(real);
1906        // if we have already draw a temporary point, erase it
1907
if (this.last.x != -1 && this.last.y != -1)
1908            this.drawableCanvas.eraseSelectionPoint(this.last) ;
1909        // update the last point
1910
this.last = new Point(e.x,e.y) ;
1911        // draw a temporary selectable point
1912
this.drawableCanvas.selectPoint(this.last, false) ;
1913    }
1914
1915    /**
1916     * Method called when the state is DELETE_POINT_MODE, and when the mouse is moving
1917     * @param e
1918     * The mouse event
1919     */

1920    private void moveDeletePointMode(MouseEvent e) {
1921        cat.warn("-> moveDeletePointMode");
1922        // get the real point
1923
Point real = this.scaleConvertor.editorPointToRealPoint(new Point(e.x,
1924                e.y));
1925        // set coordinate edition
1926
this.setCoordinateEditionPoint(real);
1927
1928        // if there is no group selected
1929
if (this.groupDescriptionSelected == null) {
1930            // do nothing
1931
return;
1932        }
1933        Point temp = this.scaleConvertor.editorPointIsSelectableRealGroupPoint(
1934                new Point(e.x, e.y), this.groupDescriptionSelected);
1935        if (!temp.equals(new Point(-1, -1))) {
1936            // change the cursor
1937
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1938                    SWT.CURSOR_HAND));
1939            // do nothing else
1940
return;
1941        }
1942        // put the arrow cursor
1943
this.drawableCanvas.setCursor(new Cursor(this.parent.getDisplay(),
1944                SWT.CURSOR_CROSS));
1945    }
1946    
1947    /////////////////////////////////////////////////////////////////////////////////////////////
1948
// View mode methods
1949
/////////////////////////////////////////////////////////////////////////////////////////////
1950

1951    /**
1952     * Set the maximized view
1953     */

1954    private void setMaximizedViewMode() {
1955        // enable the normal view and disable the maximized
1956
this.normalViewBarItem.setEnabled(true);
1957        this.maximizedViewBarItem.setEnabled(false);
1958        // get the scale
1959
Size scale = this.scaleConvertor.getScale();
1960        // add the margins
1961
Size toSet = new Size(scale.getWidth() + ScaleConvertor.MARGIN_LEFT
1962                + ScaleConvertor.MARGIN_RIGHT, scale.getHeight()
1963                + ScaleConvertor.MARGIN_TOP + ScaleConvertor.MARGIN_BACK);
1964        // change the minimium size viewed
1965
this.setDrawablePartSize(toSet.toPoint());
1966    }
1967
1968    /**
1969     * Set the normal view
1970     */

1971    private void setNormalViewMode() {
1972        // disable the normal view and enable the maximized
1973
this.normalViewBarItem.setEnabled(false);
1974        this.maximizedViewBarItem.setEnabled(true);
1975        // get the scale
1976
Size scale = ScaleConvertor.DEFAULT_MIN_CANVAS_SIZE;
1977        // change the minimium size viewed
1978
this.setDrawablePartSize(scale.toPoint());
1979    }
1980    
1981    /**
1982     * Change the scale
1983     * @param newScale The new scale to set
1984     */

1985    public void setScale(Size newScale) {
1986        if (newScale != null) {
1987            this.scaleConvertor.setScale(newScale);
1988            this.drawableCanvas.redraw();
1989        }
1990    }
1991
1992    /////////////////////////////////////////////////////////////////////////////////////////////
1993
// Listeners ...
1994
/////////////////////////////////////////////////////////////////////////////////////////////
1995

1996    /**
1997     * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
1998     */

1999    public void mouseDoubleClick(MouseEvent event) {
2000        cat.debug("-> mouseDoubleClick");
2001    }
2002
2003    /**
2004     * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
2005     */

2006    public void mouseDown(MouseEvent event) {
2007        cat.debug("-> mouseDown");
2008    }
2009
2010    /**
2011     * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
2012     */

2013    public void mouseUp(MouseEvent event) {
2014        cat.debug("-> MOUSE UP - " + event.button);
2015        // get the actual size of the canvas
2016
Rectangle size = this.drawableCanvas.getBounds();
2017        // set the size in the scale convertor
2018
this.scaleConvertor.setCanvasSize(new Size(size.width, size.height));
2019        // if the button which was pressed was the right one, end the current
2020
// draw mode
2021
if (event.button == 3) {
2022            cat
2023                    .warn("The button PRESSED is THE RIGHT ONE !!! End the current mode");
2024            this.finishMode();
2025            // do nothing else
2026
return;
2027        }
2028        // in this case the button clicked was the left one, switch between the
2029
// drawing mode
2030
switch (this.currentMode) {
2031            case DELETE_POINT_MODE :
2032                this.clickDeletePointMode(event) ;
2033                break ;
2034            case ADD_POINT_MODE :
2035                this.clickAddPointMode(event) ;
2036                break ;
2037            case DRAW_NOTHING :
2038                this.clickNothingMode(event);
2039                break;
2040            case DRAW_LINE :
2041                this.clickLineMode(event);
2042                break;
2043            case CHANGE_POINT :
2044                this.clickChangePointMode(event);
2045                break;
2046            case SELECTION_POINT :
2047                this.finishMode();
2048                this.clickNothingMode(event);
2049                break;
2050            case DRAW_CRENEL_HV :
2051                this.clickCrenelHVMode(event) ;
2052                break ;
2053            case DRAW_CRENEL_VH :
2054                this.clickCrenelVHMode(event) ;
2055                break ;
2056            default :
2057                // no others choices
2058
cat.warn("UNKNOW DRAWING MODE : " + this.currentMode);
2059        }
2060    }
2061
2062    /**
2063     * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
2064     */

2065    public void mouseMove(MouseEvent event) {
2066        // switch between all the drawing mode..
2067
switch (this.currentMode) {
2068            case DELETE_POINT_MODE :
2069                this.moveDeletePointMode(event) ;
2070                break ;
2071            case ADD_POINT_MODE :
2072                this.moveAddPointMode(event) ;
2073                break ;
2074            case DRAW_NOTHING :
2075                this.moveNothingMode(event);
2076                break;
2077            case DRAW_LINE :
2078                this.moveLineMode(event);
2079                break;
2080            case CHANGE_POINT :
2081                this.moveChangePointMode(event);
2082                break;
2083            case DRAW_CRENEL_HV :
2084                this.moveCrenelHVMode(event) ;
2085                break ;
2086            case DRAW_CRENEL_VH :
2087                this.moveCrenelVHMode(event) ;
2088                break ;
2089            case SELECTION_POINT :
2090                // do nothing
2091
break;
2092            default :
2093                cat.warn("UNKNOW DRAW MODE : " + this.currentMode);
2094        }
2095    }
2096
2097    /**
2098     * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
2099     */

2100    public void widgetDefaultSelected(SelectionEvent event) {
2101        cat.debug("-> widgetDefaultSelected");
2102    }
2103    /**
2104     * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
2105     */

2106    public void widgetSelected(SelectionEvent event) {
2107        cat.warn("-> WidgetSelected");
2108        ///////////////////////////////////////////////////////////////
2109
// switch between all the toolbar items
2110

2111        // Create ramp item
2112
if (event.getSource() == this.createGroupToolBarItem) {
2113            // get the behaviors ids
2114
Vector JavaDoc ids = (TreeManager.getTreeManager(null)).getBehaviorsIds();
2115            // if there is no behavior created
2116
if (ids.size() == 0) {
2117                if (SHOW_WARNING_DIALOGS)
2118                    MessageDialog.openInformation(this.parent.getShell(),
2119                            createBehaviorInformationTitle,
2120                            createBehaviorInformationContent);
2121                return;
2122            }
2123            // init a new ramp description
2124
GroupDescription lpd = new GroupDescription(this.loadManager
2125                    .groupIdGenerator());
2126            // launch wizard
2127
GroupDescriptionWizard wizard = new GroupDescriptionWizard(lpd, ids);
2128            WizardDialog dialog = new WizardDialog(this.parent.getShell(),
2129                    wizard);
2130            int erno = dialog.open();
2131            // if all has been edited
2132
if (erno == 0) {
2133                String JavaDoc id = null;
2134                // add the new group
2135
this.loadManager.addGroupDescription(lpd);
2136                // set the selected group as the added group
2137
this.setSelectedGroup(lpd);
2138            }
2139            return;
2140        }
2141
2142        // select ramp item
2143
if (event.getSource() == this.selectionToolBarItem) {
2144            // init the ramp items
2145
this.initSelectGroupItems();
2146            // if there is no items in the menu
2147
if (this.selectionMenuItems.size() == 0) {
2148                if (SHOW_WARNING_DIALOGS)
2149                    MessageDialog.openInformation(this.parent.getShell(),
2150                            createRampInformationTitle,
2151                            createRampInformationContent);
2152                return;
2153            }
2154            // draw the menu
2155
Rectangle rect = this.selectionToolBarItem.getBounds();
2156            org.eclipse.swt.graphics.Point pt = new org.eclipse.swt.graphics.Point(
2157                    rect.x, rect.y + rect.height);
2158            pt = this.toolBar.toDisplay(pt);
2159            this.selectionMenu.setLocation(pt.x, pt.y);
2160            this.selectionMenu.setVisible(true);
2161            return;
2162        }
2163
2164        // delete ramp item
2165
if (event.getSource() == this.deleteSelectionToolBarItem) {
2166            if (this.groupDescriptionSelected != null) {
2167                // delete the group
2168
this.loadManager
2169                        .removeGroupDescription(this.groupDescriptionSelected);
2170                // unselect the deleted group
2171
this.setSelectedGroup(null);
2172                // notify that the scenario changed
2173
this.window.setScenarioSavedState(false);
2174            }
2175            return;
2176        }
2177
2178        // edit ramp item
2179
if (event.getSource() == this.editDescriptionToolBarItem) {
2180            if (this.groupDescriptionSelected != null) {
2181                // get the behaviors ids
2182
Vector JavaDoc ids = TreeManager.getTreeManager(null).getBehaviorsIds();
2183                // open the wizard for editing current ramp values
2184
GroupDescriptionWizard wizard = new GroupDescriptionWizard(
2185                        this.groupDescriptionSelected, ids);
2186                WizardDialog dialog = new WizardDialog(this.parent.getShell(),
2187                        wizard);
2188                int erno = dialog.open();
2189                // reload the description of the selected toolbar item
2190
this.setSelectedGroup(this.groupDescriptionSelected);
2191                // notify that the scenario changed
2192
this.window.setScenarioSavedState(false);
2193            }
2194            return;
2195        }
2196
2197        // change scale item
2198
if (event.getSource() == this.changeScaleToolBarItem) {
2199            // open the change scale dialog
2200
ChangeScaleDialog dialog = new ChangeScaleDialog(this.toolBar
2201                    .getShell(), this.scaleConvertor.getScale());
2202            Size newScale = dialog.open();
2203            this.setScale(newScale) ;
2204            return;
2205        }
2206
2207        ///////////////////////////////////////////////////////////
2208
// popup items
2209

2210        // show text item of toolBar
2211
if (event.getSource() == this.showTextPopupItem) {
2212            // if text was checked
2213
if (!this.showTextPopupItem.getSelection()) {
2214                // delete labels
2215
this.removeTooBarItemText();
2216                this.showTextPopupItem.setSelection(false);
2217                return;
2218            }
2219            // add text for the toolbar items
2220
this.addToolBarItemText();
2221            this.showTextPopupItem.setSelection(true);
2222            return;
2223        }
2224
2225        // show text item of drawBar
2226
if (event.getSource() == this.showTextDrawPopupItem) {
2227            // if text was checked
2228
if (!this.showTextDrawPopupItem.getSelection()) {
2229                // delete labels
2230
this.removeDrawBarItemText();
2231                this.showTextDrawPopupItem.setSelection(false);
2232                return;
2233            }
2234            // add text for the toolbar items
2235
this.addDrawBarItemText();
2236            this.showTextDrawPopupItem.setSelection(true);
2237            return;
2238        }
2239
2240        //////////////////////////////////////////////////////////////
2241
// drawBar items
2242

2243        boolean tempSavedState = this.window.getScenarioSavedState() ;
2244        if (tempSavedState)
2245            this.window.setScenarioSavedState(false);
2246        
2247        // delete point item
2248
if (event.getSource() == this.deletePointDrawBarItem) {
2249            // finish the current mode
2250
this.finishMode() ;
2251            // init the add point mode
2252
this.initDeletePointMode() ;
2253        }
2254        
2255        // add point item
2256
if (event.getSource() == this.addPointDrawBarItem) {
2257            // finish the current mode
2258
this.finishMode() ;
2259            // init the add point mode
2260
this.initAddPointMode() ;
2261        }
2262        
2263        // draw nothing item
2264
if (event.getSource() == this.drawNothingDrawBarItem) {
2265            // finish the current mode
2266
this.finishMode();
2267            // if needed init draw nothing mode
2268
// but now it is useless
2269
return;
2270        }
2271
2272        // draw line item
2273
if (event.getSource() == this.drawLineDrawBarItem) {
2274            // finish the current mode
2275
this.finishMode();
2276            // init the new draw line mode
2277
this.initLineMode();
2278            return;
2279        }
2280        
2281        // draw crenel hv item
2282
if (event.getSource() == this.drawCrenelHVDrawBarItem) {
2283            // finish the current mode
2284
this.finishMode();
2285            // init the new draw crenel hv mode
2286
this.initDrawCrenelHVMode() ;
2287            return;
2288        }
2289        
2290        // draw crenel vh item
2291
if (event.getSource() == this.drawCrenelVHDrawBarItem) {
2292            // finish the current mode
2293
this.finishMode();
2294            // init the new draw crenel hv mode
2295
this.initDrawCrenelVHMode() ;
2296            return;
2297        }
2298
2299        // maximize view item
2300
if (event.getSource() == this.maximizedViewBarItem) {
2301            // set the maximized view mode
2302
this.setMaximizedViewMode();
2303            return;
2304        }
2305
2306        // normal view item
2307
if (event.getSource() == this.normalViewBarItem) {
2308            // set the normal view mode
2309
this.setNormalViewMode();
2310            return;
2311        }
2312
2313        // if we reach this line we don't use any draw bar item so
2314
// put the previous saved state
2315
this.window.setScenarioSavedState(tempSavedState);
2316        
2317        /////////////////////////////////////////////////////////////
2318
// Ramp selector
2319
if (this.switchSelectedGroup(event.getSource())) {
2320            this.loadManager
2321                    .notifySelectionChangedInDrawable(this.groupDescriptionSelected);
2322            return;
2323        }
2324    }
2325
2326    /**
2327     * This method is called when the canvas is resized
2328     *
2329     * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event)
2330     */

2331    public void handleEvent(Event e) {
2332        cat.warn("CANVAS RESIZED !!! resize event = " + (e.type == SWT.RESIZE));
2333        // get the actual size of the canvas
2334
Rectangle size = this.drawableCanvas.getBounds();
2335        // set the size in the scale convertor
2336
cat.warn("New SIZE : " + new Size(size.width, size.height));
2337        this.scaleConvertor.setCanvasSize(new Size(size.width, size.height));
2338    }
2339
2340    /**
2341     * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
2342     */

2343    public void paintControl(PaintEvent arg0) {
2344        cat.warn("PAINT LISTENER : REDRAW !!!!");
2345        // draw the mark
2346
this.drawMark();
2347        // draw the graduation
2348
this.drawGrad();
2349        // draw all ramps in the group
2350
this.drawAll();
2351    }
2352
2353    /**
2354     * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
2355     */

2356    public void modifyText(ModifyEvent event) {
2357        if (this.pointSelected == null) {
2358            cat.warn("There is no point selected...");
2359            return;
2360        }
2361
2362        //////////////////////////////////////////////////////////////
2363
// get the coordinate edited
2364
int XAxisValue = 0;
2365        try {
2366            XAxisValue = (new Integer JavaDoc(this.xAxisText.getText())).intValue();
2367        } catch (NumberFormatException JavaDoc nfe) {
2368            cat.warn("The coordinate X edited is not a valid number format...");
2369            return;
2370        }
2371        int YAxisValue = 0;
2372        try {
2373            YAxisValue = (new Integer JavaDoc(this.yAxisText.getText())).intValue();
2374        } catch (NumberFormatException JavaDoc nfe) {
2375            cat.warn("The coordinate Y edited is not a valid number format...");
2376            return;
2377        }
2378        // if there is no change
2379
if (this.pointSelected.equals(new Point(XAxisValue, YAxisValue))) {
2380            cat.warn("The point has not been modified, so do nothing");
2381            return;
2382        }
2383
2384        /////////////////////////////////////////////////////////////
2385
// if xAxis has been modified
2386
if (event.getSource() == this.xAxisText) {
2387            cat.warn("MODIFY XAXIS...");
2388            // set the point to the curves
2389
Point curvesNumbers = this.groupDescriptionSelected
2390                    .rampsWhichContains(this.pointSelected);
2391
2392            RampDescription c1 = null;
2393            RampDescription c2 = null;
2394            RampDescription clone1 = null;
2395            RampDescription clone2 = null;
2396            if (curvesNumbers.x != -1) {
2397                c1 = (RampDescription) this.groupDescriptionSelected.getRamps()
2398                        .elementAt((int) curvesNumbers.x);
2399                // test the changes...
2400
clone1 = (RampDescription) c1.clone();
2401                clone1.getEnd().x = XAxisValue;
2402            }
2403            if (curvesNumbers.y != -1) {
2404                c2 = (RampDescription) this.groupDescriptionSelected.getRamps()
2405                        .elementAt((int) curvesNumbers.y);
2406                // test the changes...
2407
clone2 = (RampDescription) c2.clone();
2408                clone2.getStart().x = XAxisValue;
2409            }
2410            // test all case, two point will be modified
2411
if ((c1 != null) && (c2 != null)) {
2412                // if they are correct do them
2413
if (isCorrectDrawableRamp(clone1, false)
2414                        && isCorrectDrawableRamp(clone2, false)) {
2415                    c1.getEnd().x = XAxisValue;
2416                    c2.getStart().x = XAxisValue;
2417                } else {
2418                    // this.setCoordinateEditionPoint(this.pointSelected);
2419
return;
2420                }
2421            }
2422            // only the first one need to be modified
2423
else if (c1 != null) {
2424                if (isCorrectDrawableRamp(clone1, false)) {
2425                    c1.getEnd().x = XAxisValue;
2426                } else {
2427                    // this.setCoordinateEditionPoint(this.pointSelected);
2428
return;
2429                }
2430            }
2431            // only the second one need to be modified
2432
else if (c2 != null) {
2433                if (isCorrectDrawableRamp(clone2, false)) {
2434                    c2.getStart().x = XAxisValue;
2435                } else {
2436                    // this.setCoordinateEditionPoint(this.pointSelected);
2437
return;
2438                }
2439            }
2440            this.pointSelected.x = XAxisValue;
2441        }
2442        // if yAxis has been modified
2443
if (event.getSource() == this.yAxisText) {
2444            cat.warn("MODIFY YAXIS...");
2445            // set the point to the curves
2446
Point curvesNumbers = this.groupDescriptionSelected
2447                    .rampsWhichContains(this.pointSelected);
2448
2449            RampDescription c1 = null;
2450            RampDescription c2 = null;
2451            RampDescription clone1 = null;
2452            RampDescription clone2 = null;
2453            if (curvesNumbers.x != -1) {
2454                c1 = (RampDescription) this.groupDescriptionSelected.getRamps()
2455                        .elementAt((int) curvesNumbers.x);
2456                // test the changes...
2457
clone1 = (RampDescription) c1.clone();
2458                clone1.getEnd().y = YAxisValue;
2459            }
2460            if (curvesNumbers.y != -1) {
2461                c2 = (RampDescription) this.groupDescriptionSelected.getRamps()
2462                        .elementAt((int) curvesNumbers.y);
2463                // test the changes...
2464
clone2 = (RampDescription) c2.clone();
2465                clone2.getStart().y = YAxisValue;
2466                if (isCorrectDrawableRamp(clone2, false)) {
2467                    c2.getStart().y = YAxisValue;
2468                } else {
2469                    // this.setCoordinateEditionPoint(this.pointSelected);
2470
return;
2471                }
2472            }
2473            // test all case, two point will be modified
2474
if ((c1 != null) && (c2 != null)) {
2475                // if they are correct do them
2476
if (isCorrectDrawableRamp(clone1, false)
2477                        && isCorrectDrawableRamp(clone2, false)) {
2478                    c1.getEnd().y = YAxisValue;
2479                    c2.getStart().y = YAxisValue;
2480                } else {
2481                    // this.setCoordinateEditionPoint(this.pointSelected);
2482
return;
2483                }
2484            }
2485            // only the first one need to be modified
2486
else if (c1 != null) {
2487                if (isCorrectDrawableRamp(clone1, false)) {
2488                    c1.getEnd().y = YAxisValue;
2489                } else {
2490                    // this.setCoordinateEditionPoint(this.pointSelected);
2491
return;
2492                }
2493            }
2494            // only the second one need to be modified
2495
else if (c2 != null) {
2496                if (isCorrectDrawableRamp(clone2, false)) {
2497                    c2.getStart().y = YAxisValue;
2498                } else {
2499                    // this.setCoordinateEditionPoint(this.pointSelected);
2500
return;
2501                }
2502            }
2503            this.pointSelected.y = YAxisValue;
2504        }
2505        // redraw the canvas
2506
this.drawableCanvas.redraw();
2507    }
2508}
Popular Tags