Subversion Repositories eFlore/Applications.cel

Rev

Rev 298 | Rev 735 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 298 Rev 338
1
package org.tela_botanica.client.vues.observation.indicateurs;
1
package org.tela_botanica.client.vues.observation.indicateurs;
2
 
2
 
3
import org.tela_botanica.client.interfaces.Rafraichissable;
3
import org.tela_botanica.client.interfaces.Rafraichissable;
4
import org.tela_botanica.client.modeles.Configuration;
4
import org.tela_botanica.client.modeles.Configuration;
5
import org.tela_botanica.client.observation.ObservationMediateur;
5
import org.tela_botanica.client.observation.ObservationMediateur;
-
 
6
 
-
 
7
import com.google.gwt.event.dom.client.ClickEvent;
-
 
8
import com.google.gwt.event.dom.client.ClickHandler;
-
 
9
import com.google.gwt.event.dom.client.LoadEvent;
6
 
10
import com.google.gwt.event.dom.client.LoadHandler;
7
import com.google.gwt.user.client.DOM;
11
import com.google.gwt.user.client.DOM;
8
import com.google.gwt.user.client.Event;
12
import com.google.gwt.user.client.Event;
9
import com.google.gwt.user.client.Window;
13
import com.google.gwt.user.client.Window;
10
import com.google.gwt.user.client.ui.ClickListener;
14
import com.google.gwt.user.client.ui.ClickListener;
11
import com.google.gwt.user.client.ui.Image;
15
import com.google.gwt.user.client.ui.Image;
12
import com.google.gwt.user.client.ui.LoadListener;
16
import com.google.gwt.user.client.ui.LoadListener;
13
import com.google.gwt.user.client.ui.Widget;
17
import com.google.gwt.user.client.ui.Widget;
14
import com.gwtext.client.core.AnimationConfig;
18
import com.gwtext.client.core.AnimationConfig;
15
import com.gwtext.client.core.EventObject;
19
import com.gwtext.client.core.EventObject;
16
import com.gwtext.client.core.Ext;
20
import com.gwtext.client.core.Ext;
17
import com.gwtext.client.core.ExtElement;
21
import com.gwtext.client.core.ExtElement;
18
import com.gwtext.client.core.RegionPosition;
22
import com.gwtext.client.core.RegionPosition;
19
import com.gwtext.client.widgets.Panel;
23
import com.gwtext.client.widgets.Panel;
20
import com.gwtext.client.widgets.ToolTip;
24
import com.gwtext.client.widgets.ToolTip;
21
import com.gwtext.client.widgets.layout.BorderLayout;
25
import com.gwtext.client.widgets.layout.BorderLayout;
22
import com.gwtext.client.widgets.layout.BorderLayoutData;
26
import com.gwtext.client.widgets.layout.BorderLayoutData;
23
import com.gwtext.client.widgets.menu.BaseItem;
27
import com.gwtext.client.widgets.menu.BaseItem;
24
import com.gwtext.client.widgets.menu.Item;
28
import com.gwtext.client.widgets.menu.Item;
25
import com.gwtext.client.widgets.menu.Menu;
29
import com.gwtext.client.widgets.menu.Menu;
26
import com.gwtext.client.widgets.menu.event.MenuListenerAdapter;
30
import com.gwtext.client.widgets.menu.event.MenuListenerAdapter;
27
 
31
 
28
/**
32
/**
29
 * Panneau d'affichage d'une image avec des boutons précdents et suivant
33
 * Panneau d'affichage d'une image avec des boutons précdents et suivant
30
 * 
34
 * 
31
 * @author aurelien
35
 * @author aurelien
32
 * 
36
 * 
33
 */
37
 */
34
public class MiniZoomImageVue extends Panel implements Rafraichissable {
38
public class MiniZoomImageVue extends Panel implements Rafraichissable {
35
 
39
 
36
	/**
40
	/**
37
	 * Le médiateur associé à la vue
41
	 * Le médiateur associé à la vue
38
	 */
42
	 */
39
	private ObservationMediateur oMediateur = null;
43
	private ObservationMediateur oMediateur = null;
40
	
44
	
41
	/**
45
	/**
42
	 * Le titre du panneau
46
	 * Le titre du panneau
43
	 */
47
	 */
44
	private static String titrePanneau = "Images liées";
48
	private static String titrePanneau = "Images liées";
45
 
49
 
46
	/**
50
	/**
47
	 * Panneau conteneur pour l'image
51
	 * Panneau conteneur pour l'image
48
	 */
52
	 */
49
	private Panel imageConteneur = null;
53
	private Panel imageConteneur = null;
50
	/**
54
	/**
51
	 * l'image à afficher
55
	 * l'image à afficher
52
	 */
56
	 */
53
	private Image image = new Image("");
57
	private Image image = new Image("");
54
	/**
58
	/**
55
	 * Bouton précédent
59
	 * Bouton précédent
56
	 */
60
	 */
57
	private final com.google.gwt.user.client.ui.Button prev = new com.google.gwt.user.client.ui.Button();
61
	private final com.google.gwt.user.client.ui.Button prev = new com.google.gwt.user.client.ui.Button();
58
	/**
62
	/**
59
	 * Bouton suivant
63
	 * Bouton suivant
60
	 */
64
	 */
61
	private final com.google.gwt.user.client.ui.Button suiv = new com.google.gwt.user.client.ui.Button();
65
	private final com.google.gwt.user.client.ui.Button suiv = new com.google.gwt.user.client.ui.Button();
62
 
66
 
63
	/**
67
	/**
64
	 * Taille originale Y de l'image
68
	 * Taille originale Y de l'image
65
	 */
69
	 */
66
	private int imageHeight = 0;
70
	private int imageHeight = 0;
67
 
71
 
68
	/**
72
	/**
69
	 * Taille originale X de l'image
73
	 * Taille originale X de l'image
70
	 */
74
	 */
71
	private int imageWidth = 0;
75
	private int imageWidth = 0;
72
	
76
	
73
	/**
77
	/**
74
	 * Identifiant de l'image
78
	 * Identifiant de l'image
75
	 */
79
	 */
76
	private String idImage = "0" ;
80
	private String idImage = "0" ;
77
	
81
	
78
	private String[] infosImages[] = null ;
82
	private String[] infosImages[] = null ;
79
	
83
	
80
	private int index = 0 ;
84
	private int index = 0 ;
81
 
85
 
82
	/**
86
	/**
83
	 * true pour animer les transitions
87
	 * true pour animer les transitions
84
	 */
88
	 */
85
	private boolean animerTransition = false;
89
	private boolean animerTransition = false;
86
	/**
90
	/**
87
	 * Détermine la durée de la transition
91
	 * Détermine la durée de la transition
88
	 */
92
	 */
89
	private float dureeAnimation = (float) 0.15;
93
	private float dureeAnimation = (float) 0.15;
90
	
94
	
91
	/**
95
	/**
92
	 * Booleen d'initalisation général
96
	 * Booleen d'initalisation général
93
	 */
97
	 */
94
	private boolean initialise = false;
98
	private boolean initialise = false;
95
 
99
 
96
	/**
100
	/**
97
	 * Booleen d'initalisation du conteneur d'image
101
	 * Booleen d'initalisation du conteneur d'image
98
	 */
102
	 */
99
	private boolean conteneurInitialise = false;
103
	private boolean conteneurInitialise = false;
100
	
104
	
101
	private ToolTip tp = new ToolTip("<div class=\"x-tooltip-help\"> Double cliquez pour agrandir l'image </div>") ;
105
	private ToolTip tp = new ToolTip("<div class=\"x-tooltip-help\"> Double cliquez pour agrandir l'image </div>") ;
102
	
106
	
103
	com.gwtext.client.widgets.Window imgZoom = new com.gwtext.client.widgets.Window("Agrandissement") ;
107
	com.gwtext.client.widgets.Window imgZoom = new com.gwtext.client.widgets.Window("Agrandissement") ;
104
	
108
	
105
	Image imgAgrandie = null;
109
	Image imgAgrandie = null;
106
 
110
 
107
	/**
111
	/**
108
	 * Constructeur sans argument (privé car ne doit être utilisé)
112
	 * Constructeur sans argument (privé car ne doit être utilisé)
109
	 */
113
	 */
110
	@SuppressWarnings("unused")
114
	@SuppressWarnings("unused")
111
	private MiniZoomImageVue() {
115
	private MiniZoomImageVue() {
112
		super();
116
		super();
113
	}
117
	}
114
 
118
 
115
	/**
119
	/**
116
	 * Constructeur avec argument
120
	 * Constructeur avec argument
117
	 * 
121
	 * 
118
	 * @param im
122
	 * @param im
119
	 *            le médiateur à associer à la vue
123
	 *            le médiateur à associer à la vue
120
	 */
124
	 */
121
	public MiniZoomImageVue(ObservationMediateur im) {
125
	public MiniZoomImageVue(ObservationMediateur im) {
122
		super(titrePanneau);
126
		super(titrePanneau);
123
		setId("x-view-mini-zoom-panel");
127
		setId("x-view-mini-zoom-panel");
124
		// on associe le médiateur
128
		// on associe le médiateur
125
		oMediateur = im;
129
		oMediateur = im;
126
 
130
 
127
		prev.setStylePrimaryName("x-view-zoom-button-p");
131
		prev.setStylePrimaryName("x-view-zoom-button-p");
128
		suiv.setStylePrimaryName("x-view-zoom-button-s");
132
		suiv.setStylePrimaryName("x-view-zoom-button-s");
129
 
133
 
130
		imgZoom.setCloseAction(com.gwtext.client.widgets.Window.HIDE) ;
134
		imgZoom.setCloseAction(com.gwtext.client.widgets.Window.HIDE) ;
131
		imgZoom.setConstrain(true);
135
		imgZoom.setConstrain(true);
132
		
136
		
133
		// on crée une image qui gère le double clic et la roulette de la souris
137
		// on crée une image qui gère le double clic et la roulette de la souris
134
		image = new Image() {
138
		image = new Image() {
135
 
139
 
136
			public void onBrowserEvent(Event event) {
140
			public void onBrowserEvent(Event event) {
137
 
141
 
138
				// lors d'un déplacement de la roulette
142
				// lors d'un déplacement de la roulette
139
				if (Event.ONMOUSEWHEEL == DOM.eventGetType(event)) {
143
				if (Event.ONMOUSEWHEEL == DOM.eventGetType(event)) {
140
 
144
 
141
					// on simule un clic sur le bouton précédent
145
					// on simule un clic sur le bouton précédent
142
					if (event.getMouseWheelVelocityY() >= 1) {
146
					if (event.getMouseWheelVelocityY() >= 1) {
143
						prev.click();
147
						prev.click();
144
					}
148
					}
145
 
149
 
146
					// ou suivant
150
					// ou suivant
147
					if (event.getMouseWheelVelocityY() <= -1) {
151
					if (event.getMouseWheelVelocityY() <= -1) {
148
						suiv.click();
152
						suiv.click();
149
					}
153
					}
150
				}
154
				}
151
				
155
				
152
				if(Event.ONCONTEXTMENU == DOM.eventGetType(event)) {
156
				if(Event.ONCONTEXTMENU == DOM.eventGetType(event)) {
153
					
157
					
154
					event.preventDefault() ;
158
					event.preventDefault() ;
155
					int[] xy = {event.getClientX(),event.getClientY()} ;
159
					int[] xy = {event.getClientX(),event.getClientY()} ;
156
					afficherMenu(xy) ;
160
					afficherMenu(xy) ;
157
				}
161
				}
158
				
162
				
159
				// lors du double clic
163
				// lors du double clic
160
				if (Event.ONDBLCLICK == DOM.eventGetType(event)) {
164
				if (Event.ONDBLCLICK == DOM.eventGetType(event)) {
161
					if(imgZoom.isVisible()) {
165
					if(imgZoom.isVisible()) {
162
							imgZoom.hide();
166
							imgZoom.hide();
163
					} else {
167
					} else {
164
						afficherPanneauAgrandi();
168
						afficherPanneauAgrandi();
165
					}
169
					}
166
				}
170
				}
167
			}
171
			}
168
			
172
			
169
		};
173
		};
170
		
174
		
171
		image.setPixelSize(150, 150);
175
		image.setPixelSize(150, 150);
172
		
176
		
173
		infosImages = new String[0][0] ;
177
		infosImages = new String[0][0] ;
174
 
178
 
175
		this.setHeader(true);
179
		this.setHeader(true);
176
 
180
 
177
		imageConteneur = new Panel() ;
181
		imageConteneur = new Panel() ;
178
		imageConteneur.setBorder(false);
182
		imageConteneur.setBorder(false);
179
 
183
 
180
		imageConteneur.add(image);
184
		imageConteneur.add(image);
181
		imageConteneur.setId("x-view-mini-zoom-img");
185
		imageConteneur.setId("x-view-mini-zoom-img");
182
 
186
 
183
		// il n'existe pas de méthode pour ajouter un listener pour le double
187
		// il n'existe pas de méthode pour ajouter un listener pour le double
184
		// clic sur une image
188
		// clic sur une image
185
		// alors on lui dit manuellement de capter l'évènement double clic
189
		// alors on lui dit manuellement de capter l'évènement double clic
186
		image.sinkEvents(Event.ONDBLCLICK);
190
		image.sinkEvents(Event.ONDBLCLICK);
187
		image.sinkEvents(Event.ONMOUSEWHEEL);
191
		image.sinkEvents(Event.ONMOUSEWHEEL);
188
		image.sinkEvents(Event.ONCONTEXTMENU) ;
192
		image.sinkEvents(Event.ONCONTEXTMENU) ;
189
 
193
 
190
		// l'image de base est vide
194
		// l'image de base est vide
191
		image.setUrl("");
195
		image.setUrl("");
192
 
196
 
193
		this.setLayout(new BorderLayout());
197
		this.setLayout(new BorderLayout());
194
 
198
 
195
		prev.setWidth("15%");
199
		prev.setWidth("15%");
196
		suiv.setWidth("15%");
200
		suiv.setWidth("15%");
197
 
201
 
198
		this.add(prev, new BorderLayoutData(RegionPosition.WEST));
202
		this.add(prev, new BorderLayoutData(RegionPosition.WEST));
199
		this.add(imageConteneur, new BorderLayoutData(RegionPosition.CENTER));
203
		this.add(imageConteneur, new BorderLayoutData(RegionPosition.CENTER));
200
		this.add(suiv, new BorderLayoutData(RegionPosition.EAST));
204
		this.add(suiv, new BorderLayoutData(RegionPosition.EAST));
201
 
205
 
202
		imageConteneur.setMaskDisabled(true);
206
		imageConteneur.setMaskDisabled(true);
203
		this.setBorder(false);
207
		this.setBorder(false);
204
 
208
 
205
		conteneurInitialise = true;
209
		conteneurInitialise = true;
206
		initialise = true;
210
		initialise = true;
207
 
211
 
208
		// on ajoute les listeners
212
		// on ajoute les listeners
209
		ajouterListeners();
213
		ajouterListeners();
210
 
214
 
211
	}
215
	}
212
 
216
 
213
	/**
217
	/**
214
	 * Méthode héritée de l'interface rafraichissable
218
	 * Méthode héritée de l'interface rafraichissable
215
	 * 
219
	 * 
216
	 * @param nouvelleDonnees
220
	 * @param nouvelleDonnees
217
	 *            les nouvelles données
221
	 *            les nouvelles données
218
	 * @param repandreRafraichissement
222
	 * @param repandreRafraichissement
219
	 *            le booleen qui dit si on doit répnadre l'évènement
223
	 *            le booleen qui dit si on doit répnadre l'évènement
220
	 */
224
	 */
221
	public void rafraichir(Object nouvelleDonnees,
225
	public void rafraichir(Object nouvelleDonnees,
222
			boolean repandreRafraichissement) {
226
			boolean repandreRafraichissement) {
223
 
227
 
224
		// si on reçoit une string
228
		// si on reçoit une string
225
		if (nouvelleDonnees instanceof String[][] && initialise
229
		if (nouvelleDonnees instanceof String[][] && initialise
226
				&& conteneurInitialise && ((String[][])nouvelleDonnees).length != 0) {
230
				&& conteneurInitialise && ((String[][])nouvelleDonnees).length != 0) {
227
			infosImages = (String[][]) nouvelleDonnees;
231
			infosImages = (String[][]) nouvelleDonnees;
228
			index = 0 ;
232
			index = 0 ;
229
			afficherImage() ;
233
			afficherImage() ;
230
			
234
			
231
		} else {
235
		} else {
232
			// sinon on met une image vide
236
			// sinon on met une image vide
233
			infosImages = null ;
237
			infosImages = null ;
234
			afficherImage();
238
			afficherImage();
235
			
239
			
236
		}
240
		}
237
	}
241
	}
238
 
242
 
239
	public void afficherImage()
243
	public void afficherImage()
240
	{
244
	{
241
		// c'est l'url de l'image qu'on associe à la vue
245
		// c'est l'url de l'image qu'on associe à la vue
242
		if(infosImages != null && infosImages.length != 0)
246
		if(infosImages != null && infosImages.length != 0)
243
		{
247
		{
244
			setTitle(titrePanneau+"         "+(index+1)+" / "+infosImages.length);
248
			setTitle(titrePanneau+"         "+(index+1)+" / "+infosImages.length);
245
			
249
			
246
			getImage().setUrl(convertirIdEnUrl(infosImages[index][0]));
250
			getImage().setUrl(convertirIdEnUrl(infosImages[index][0]));
247
			imageWidth = Integer.parseInt(infosImages[index][1]);
251
			imageWidth = Integer.parseInt(infosImages[index][1]);
248
			imageHeight = Integer.parseInt(infosImages[index][2]);
252
			imageHeight = Integer.parseInt(infosImages[index][2]);
249
			verifierEtRetaillerImage();
253
			verifierEtRetaillerImage();
250
			activerPanneau(true);
254
			activerPanneau(true);
251
		} else {
255
		} else {
252
			setTitle(titrePanneau);
256
			setTitle(titrePanneau);
253
			getImage().setUrl("ill_liaison.png");
257
			getImage().setUrl("ill_liaison.png");
254
			imageWidth = getImage().getWidth();
258
			imageWidth = getImage().getWidth();
255
			imageHeight = getImage().getHeight();
259
			imageHeight = getImage().getHeight();
256
			if(imgZoom.isVisible()) {
260
			if(imgZoom.isVisible()) {
257
				agrandirImage();
261
				agrandirImage();
258
			}
262
			}
259
			activerPanneau(false);
263
			activerPanneau(false);
260
		}
264
		}
261
		
265
		
262
		if(infosImages != null && infosImages.length > 1) {
266
		if(infosImages != null && infosImages.length > 1) {
263
			prev.setEnabled(true);
267
			prev.setEnabled(true);
264
			suiv.setEnabled(true);
268
			suiv.setEnabled(true);
265
		} else {
269
		} else {
266
			prev.setEnabled(false);
270
			prev.setEnabled(false);
267
			suiv.setEnabled(false);
271
			suiv.setEnabled(false);
268
		}
272
		}
269
	}
273
	}
270
 
274
 
271
	/**
275
	/**
272
	 * Active visuellement le panneau et les boutons
276
	 * Active visuellement le panneau et les boutons
273
	 */
277
	 */
274
	public void activerPanneau(boolean activer) {
278
	public void activerPanneau(boolean activer) {
275
		if(activer) {
279
		if(activer) {
276
			this.getEl().unmask();
280
			this.getEl().unmask();
277
		} else {
281
		} else {
278
			this.getEl().mask();
282
			this.getEl().mask();
279
		}
283
		}
280
	}
284
	}
281
 
285
 
282
	/**
286
	/**
283
	 * Ajoute les listeners pour la gestions d'évènement
287
	 * Ajoute les listeners pour la gestions d'évènement
284
	 */
288
	 */
285
	public void ajouterListeners() {
289
	public void ajouterListeners() {
286
 
290
 
287
		// gestion du clic sur le bouton précedent
291
		// gestion du clic sur le bouton précedent
288
		prev.addClickListener(new ClickListener() {
292
		prev.addClickHandler(new ClickHandler() {
289
 
-
 
290
			// en cas de clic
293
 
291
			public void onClick(Widget sender) {
-
 
292
				
294
			public void onClick(ClickEvent event) {
293
				if(infosImages.length != 0) {
295
				if(infosImages.length != 0) {
294
					if(index == 0)
296
					if(index == 0)
295
					{
297
					{
296
						index = infosImages.length - 1 ;
298
						index = infosImages.length - 1 ;
297
					}
299
					}
298
					else
300
					else
299
					{
301
					{
300
						index-- ;
302
						index-- ;
301
					}
303
					}
302
									
304
									
303
					afficherImage() ;
305
					afficherImage() ;
304
				}
306
				}
305
			}
307
			}
306
 
308
 
307
		});
309
		});
308
 
310
 
309
		// gestion du clic sur le bouton suivant
311
		// gestion du clic sur le bouton suivant
310
		suiv.addClickListener(new ClickListener() {
312
		suiv.addClickHandler(new ClickHandler() {
311
 
313
 
312
			// en cas de clic
314
			// en cas de clic
313
			public void onClick(Widget sender) {
315
			public void onClick(ClickEvent event) {
314
				
316
				
315
				if(infosImages.length != 0) {
317
				if(infosImages.length != 0) {
316
					if(index == infosImages.length - 1)
318
					if(index == infosImages.length - 1)
317
					{
319
					{
318
						index = 0 ;
320
						index = 0 ;
319
					}
321
					}
320
					else
322
					else
321
					{
323
					{
322
						index++ ;
324
						index++ ;
323
					}
325
					}
324
									
326
									
325
					afficherImage() ;
327
					afficherImage() ;
326
				}
328
				}
327
					
329
					
328
			}
330
			}
329
 
331
 
330
		});
332
		});
331
		
333
		
332
	}
334
	}
333
 
335
 
334
	/**
336
	/**
335
	 * Accesseur pour le médiateur
337
	 * Accesseur pour le médiateur
336
	 * 
338
	 * 
337
	 * @return le médiateur associé à la vue
339
	 * @return le médiateur associé à la vue
338
	 */
340
	 */
339
	public ObservationMediateur getIMediateur() {
341
	public ObservationMediateur getIMediateur() {
340
		return oMediateur;
342
		return oMediateur;
341
	}
343
	}
342
 
344
 
343
	/**
345
	/**
344
	 * Accesseur au conteneur de l'image
346
	 * Accesseur au conteneur de l'image
345
	 * 
347
	 * 
346
	 * @return le conteneur de l'image
348
	 * @return le conteneur de l'image
347
	 */
349
	 */
348
	public Image getImage() {
350
	public Image getImage() {
349
		return image;
351
		return image;
350
	}
352
	}
351
	
353
	
352
	/**
354
	/**
353
	 * Acesseurs pour l'identifiant de l'image
355
	 * Acesseurs pour l'identifiant de l'image
354
	 * @return l'id de l'image
356
	 * @return l'id de l'image
355
	 */
357
	 */
356
	public String getIdImage()
358
	public String getIdImage()
357
	{
359
	{
358
		return infosImages[index][0] ;
360
		return infosImages[index][0] ;
359
	}
361
	}
360
 
362
 
361
	/**
363
	/**
362
	 * Accesseur pour le bouton précédent
364
	 * Accesseur pour le bouton précédent
363
	 * 
365
	 * 
364
	 * @return le bouton précédent
366
	 * @return le bouton précédent
365
	 */
367
	 */
366
	public com.google.gwt.user.client.ui.Button getPrev() {
368
	public com.google.gwt.user.client.ui.Button getPrev() {
367
		return prev;
369
		return prev;
368
	}
370
	}
369
 
371
 
370
	/**
372
	/**
371
	 * Accesseur pour le bouton suivant
373
	 * Accesseur pour le bouton suivant
372
	 * 
374
	 * 
373
	 * @return le bouton suivant
375
	 * @return le bouton suivant
374
	 */
376
	 */
375
	public com.google.gwt.user.client.ui.Button getSuiv() {
377
	public com.google.gwt.user.client.ui.Button getSuiv() {
376
		return suiv;
378
		return suiv;
377
	}
379
	}
378
 
380
 
379
	/**
381
	/**
380
	 * Setter pour la taille de l'image
382
	 * Setter pour la taille de l'image
381
	 * 
383
	 * 
382
	 * @param x
384
	 * @param x
383
	 *            la largeur en pixels
385
	 *            la largeur en pixels
384
	 * @param y
386
	 * @param y
385
	 *            la hauteur en pixels
387
	 *            la hauteur en pixels
386
	 */
388
	 */
387
	public void setTailleImage(int x, int y) {
389
	public void setTailleImage(int x, int y) {
388
		imageHeight = y;
390
		imageHeight = y;
389
		imageWidth = x;
391
		imageWidth = x;
390
	}
392
	}
391
	
393
	
392
	/**
394
	/**
393
	 * Setteur pour l'identifiant de l'image
395
	 * Setteur pour l'identifiant de l'image
394
	 * @param id le nouvel identifiant
396
	 * @param id le nouvel identifiant
395
	 */
397
	 */
396
	public void setIdImage(String id)
398
	public void setIdImage(String id)
397
	{
399
	{
398
		idImage = id ;
400
		idImage = id ;
399
	}
401
	}
400
 
402
 
401
	/**
403
	/**
402
	 * renvoie la taille originale de l'image
404
	 * renvoie la taille originale de l'image
403
	 * 
405
	 * 
404
	 * @return un tableau de deux entiers contenant la largeur puis la hauteur
406
	 * @return un tableau de deux entiers contenant la largeur puis la hauteur
405
	 */
407
	 */
406
	public int[] getTailleImage() {
408
	public int[] getTailleImage() {
407
		int[] taille = { imageHeight, imageWidth };
409
		int[] taille = { imageHeight, imageWidth };
408
 
410
 
409
		return taille;
411
		return taille;
410
	}
412
	}
411
	
413
	
412
	/**
414
	/**
413
	 * Accesseur pour le conteneur de l'image
415
	 * Accesseur pour le conteneur de l'image
414
	 * @return le conteur de l'image
416
	 * @return le conteur de l'image
415
	 */
417
	 */
416
	public Panel getImageConteneur() {
418
	public Panel getImageConteneur() {
417
 
419
 
418
		return imageConteneur;
420
		return imageConteneur;
419
 
421
 
420
	}
422
	}
421
 
423
 
422
	public void raz() {
424
	public void raz() {
423
		
425
		
424
		infosImages = new String[0][0] ;
426
		infosImages = new String[0][0] ;
425
		getImage().setUrl("");
427
		getImage().setUrl("");
426
		
428
		
427
	}
429
	}
428
	
430
	
429
	public void supprimerLiaisonImage() {
431
	public void supprimerLiaisonImage() {
430
		
432
		
431
		if(infosImages.length > 0) {
433
		if(infosImages.length > 0) {
432
			
434
			
433
			getImage().setUrl("") ;
435
			getImage().setUrl("") ;
434
			int nouvelleTaille = infosImages.length - 1 ;
436
			int nouvelleTaille = infosImages.length - 1 ;
435
			int indexSupp = index ;
437
			int indexSupp = index ;
436
			
438
			
437
			String[][] nouveauInfosImages = new String[nouvelleTaille][3] ;
439
			String[][] nouveauInfosImages = new String[nouvelleTaille][3] ;
438
			int j = 0 ;
440
			int j = 0 ;
439
			
441
			
440
			for(int i = 0 ; i < infosImages.length ; i++) {
442
			for(int i = 0 ; i < infosImages.length ; i++) {
441
				
443
				
442
				if(i != indexSupp) {
444
				if(i != indexSupp) {
443
					
445
					
444
					nouveauInfosImages[j] = infosImages[i] ;
446
					nouveauInfosImages[j] = infosImages[i] ;
445
					j++ ;
447
					j++ ;
446
				}
448
				}
447
			}
449
			}
448
			
450
			
449
			infosImages = nouveauInfosImages ;
451
			infosImages = nouveauInfosImages ;
450
			index = 0 ;
452
			index = 0 ;
451
			
453
			
452
			afficherImage() ;
454
			afficherImage() ;
453
		}
455
		}
454
	}
456
	}
455
	
457
	
456
	public void afficherMenu(int[] xy) {
458
	public void afficherMenu(int[] xy) {
457
		
459
		
458
		Menu mn = new Menu() ;
460
		Menu mn = new Menu() ;
459
		final Item suppLiaison = new Item("Supprimer la liaison") ;
461
		final Item suppLiaison = new Item("Supprimer la liaison") ;
460
		
462
		
461
		mn.addItem(suppLiaison) ;
463
		mn.addItem(suppLiaison) ;
462
		
464
		
463
		mn.addListener(new MenuListenerAdapter() {
465
		mn.addListener(new MenuListenerAdapter() {
464
			
466
			
465
			public void onItemClick(BaseItem item, EventObject e) {
467
			public void onItemClick(BaseItem item, EventObject e) {
466
				
468
				
467
				// si c'est l'aide
469
				// si c'est l'aide
468
				if (item.equals(suppLiaison)) {
470
				if (item.equals(suppLiaison)) {
469
					// on notifie le médiateur
471
					// on notifie le médiateur
470
					getIMediateur().supprimerLiaisonObsImage() ;
472
					getIMediateur().supprimerLiaisonObsImage() ;
471
				}
473
				}
472
			}
474
			}
473
			
475
			
474
		}) ;
476
		}) ;
475
		
477
		
476
		mn.showAt(xy) ;
478
		mn.showAt(xy) ;
477
	}
479
	}
478
	
480
	
479
	public String convertirIdEnUrl(String idImg)
481
	public String convertirIdEnUrl(String idImg)
480
	{
482
	{
481
		int maxZeros = 9 - idImg.length();
483
		int maxZeros = 9 - idImg.length();
482
		
484
		
483
		for (int j = 0; j < maxZeros; j++) {
485
		for (int j = 0; j < maxZeros; j++) {
484
			idImg = "0" + idImg;
486
			idImg = "0" + idImg;
485
		}
487
		}
486
		
488
		
487
		String baseUrl = Configuration.getImageBaseUrl() ;
489
		String baseUrl = Configuration.getImageBaseUrl() ;
488
 
490
 
489
		String dossierNv1 = idImg.substring(0, 3);
491
		String dossierNv1 = idImg.substring(0, 3);
490
		String dossierNv2 = idImg.substring(3, 6);
492
		String dossierNv2 = idImg.substring(3, 6);
491
		String fichierNv = idImg.substring(6, 9);
493
		String fichierNv = idImg.substring(6, 9);
492
 
494
 
493
		String nomFichier = dossierNv1 + "_" + dossierNv2 + "_" + fichierNv;
495
		String nomFichier = dossierNv1 + "_" + dossierNv2 + "_" + fichierNv;
494
 
496
 
495
		String[] infosFichier = { nomFichier, dossierNv1, dossierNv2 };
497
		String[] infosFichier = { nomFichier, dossierNv1, dossierNv2 };
496
		
498
		
497
		String urlImg = baseUrl + infosFichier[1] + "/" + infosFichier[2] + "/M/"
499
		String urlImg = baseUrl + infosFichier[1] + "/" + infosFichier[2] + "/M/"
498
		+ infosFichier[0] + "_M.jpg";
500
		+ infosFichier[0] + "_M.jpg";
499
		
501
		
500
		return urlImg ;
502
		return urlImg ;
501
	}
503
	}
502
	
504
	
503
	/**
505
	/**
504
	 * Verifie si l'image est plus grande que le conteneur et la retaille le cas
506
	 * Verifie si l'image est plus grande que le conteneur et la retaille le cas
505
	 * echeant
507
	 * echeant
506
	 */
508
	 */
507
	public void verifierEtRetaillerImage() {
509
	public void verifierEtRetaillerImage() {
508
		
510
		
509
		// si l'image est nulle
511
		// si l'image est nulle
510
		if (image == null) {
512
		if (image == null) {
511
			// on ne fait rien
513
			// on ne fait rien
512
			return;
514
			return;
513
		}
515
		}
514
		
516
		
515
		int[] dim = calculerDimensions(getTailleImage(),300,imageConteneur.getWidth());
517
		int[] dim = calculerDimensions(getTailleImage(),300,imageConteneur.getWidth());
516
		getImage().setSize("" + dim[0] + "px",
518
		getImage().setSize("" + dim[0] + "px",
517
				"" + dim[1] + "px");
519
				"" + dim[1] + "px");
518
		
520
		
519
		doLayout();
521
		doLayout();
520
		
522
		
521
		if(imgZoom.isVisible()) {
523
		if(imgZoom.isVisible()) {
522
			agrandirImage();
524
			agrandirImage();
523
		}
525
		}
524
	}
526
	}
525
	
527
	
526
	public int[] calculerDimensions(int[] tailleXY, double tailleMax, double tailleConteneur) {
528
	public int[] calculerDimensions(int[] tailleXY, double tailleMax, double tailleConteneur) {
527
	    
529
	    
528
		float[] tailleXYf = {new Float(tailleXY[0]),new Float(tailleXY[1])} ;
530
		float[] tailleXYf = {new Float(tailleXY[0]),new Float(tailleXY[1])} ;
529
        float tailleOr = Math.min(new Float(tailleMax),new Float(tailleConteneur)) ;
531
        float tailleOr = Math.min(new Float(tailleMax),new Float(tailleConteneur)) ;
530
        float maxTaille = Math.max(tailleXYf[1],tailleXYf[0]) ;
532
        float maxTaille = Math.max(tailleXYf[1],tailleXYf[0]) ;
531
        float[] XYresize = new float[2];
533
        float[] XYresize = new float[2];
532
        
534
        
533
        if(maxTaille == tailleXY[0]) {
535
        if(maxTaille == tailleXY[0]) {
534
            float rapport = tailleXYf[1]/tailleXYf[0] ;
536
            float rapport = tailleXYf[1]/tailleXYf[0] ;
535
            XYresize[0] = tailleOr ;
537
            XYresize[0] = tailleOr ;
536
            XYresize[1] = tailleOr*rapport ;
538
            XYresize[1] = tailleOr*rapport ;
537
        }else {
539
        }else {
538
            float rapport = tailleXYf[0]/tailleXYf[1] ;
540
            float rapport = tailleXYf[0]/tailleXYf[1] ;
539
            XYresize[1] = tailleOr ;
541
            XYresize[1] = tailleOr ;
540
            XYresize[0] = tailleOr*rapport ;
542
            XYresize[0] = tailleOr*rapport ;
541
        }
543
        }
542
        
544
        
543
        int[] res = {(int)Math.round(XYresize[0]*0.85),(int)Math.round(XYresize[1]*0.85)} ;
545
        int[] res = {(int)Math.round(XYresize[0]*0.85),(int)Math.round(XYresize[1]*0.85)} ;
544
        
546
        
545
        return res;
547
        return res;
546
    }
548
    }
547
	
549
	
548
	protected void agrandirImage() {
550
	protected void agrandirImage() {
549
		
551
		
550
			String urlAgrandie = "";
552
			String urlAgrandie = "";
551
			
553
			
552
			if(infosImages == null) {
554
			if(infosImages == null) {
553
				urlAgrandie = "ill_liaison.png";
555
				urlAgrandie = "ill_liaison.png";
554
				setTailleImage(265, 270);
556
				setTailleImage(265, 270);
555
			} else {
557
			} else {
556
				urlAgrandie = convertirIdEnUrl(infosImages[index][0]).replace("_M", "_L") ;
558
				urlAgrandie = convertirIdEnUrl(infosImages[index][0]).replace("_M", "_L") ;
557
				urlAgrandie = urlAgrandie.replace("/M/", "/L/") ;
559
				urlAgrandie = urlAgrandie.replace("/M/", "/L/") ;
558
			}
560
			}
559
			
561
			
560
			if(imgAgrandie == null) {
562
			if(imgAgrandie == null) {
561
				imgAgrandie = new Image(urlAgrandie); 
563
				imgAgrandie = new Image(urlAgrandie); 
562
				imgZoom.add(imgAgrandie);
564
				imgZoom.add(imgAgrandie);
563
				
565
				
564
				imgAgrandie.addLoadListener(new LoadListener() {
-
 
565
 
-
 
566
					public void onError(Widget sender) {
-
 
567
						// TODO Auto-generated method stub
-
 
568
						
-
 
569
					}
566
				imgAgrandie.addLoadHandler(new LoadHandler() {
570
 
567
 
571
					public void onLoad(Widget sender) {
568
					public void onLoad(LoadEvent event) {
572
						int[] tailleImage = calculerDimensions(getTailleImage(),getTailleImage()[1],Window.getClientHeight()*0.75);
569
						int[] tailleImage = calculerDimensions(getTailleImage(),getTailleImage()[1],Window.getClientHeight()*0.75);
573
						ExtElement imgElement = Ext.get(imgAgrandie.getElement());
570
						ExtElement imgElement = Ext.get(imgAgrandie.getElement());
574
						if(animerTransition) {
571
						if(animerTransition) {
575
							AnimationConfig a = new AnimationConfig() ;
572
							AnimationConfig a = new AnimationConfig() ;
576
							a.setDuration((float) dureeAnimation);
573
							a.setDuration((float) dureeAnimation);
577
							imgElement.setHeight(tailleImage[1], a);
574
							imgElement.setHeight(tailleImage[1], a);
578
							imgElement.setWidth(tailleImage[0], a);
575
							imgElement.setWidth(tailleImage[0], a);
579
							
576
							
580
							ExtElement winElement = Ext.get(imgZoom.getElement());
577
							ExtElement winElement = Ext.get(imgZoom.getElement());
581
							winElement.setHeight(tailleImage[1], a);
578
							winElement.setHeight(tailleImage[1], a);
582
							winElement.setWidth(tailleImage[0], a);
579
							winElement.setWidth(tailleImage[0], a);
583
						} else {
580
						} else {
584
							imgElement.setHeight(tailleImage[1], false);
581
							imgElement.setHeight(tailleImage[1], false);
585
							imgElement.setWidth(tailleImage[0], false);
582
							imgElement.setWidth(tailleImage[0], false);
586
							
583
							
587
							ExtElement winElement = Ext.get(imgZoom.getElement());
584
							ExtElement winElement = Ext.get(imgZoom.getElement());
588
							winElement.setHeight(tailleImage[1], false);
585
							winElement.setHeight(tailleImage[1], false);
589
							winElement.setWidth(tailleImage[0], false);
586
							winElement.setWidth(tailleImage[0], false);
590
						}
587
						}
591
					}
588
					}
592
					
-
 
593
					
589
					
594
				});
590
				});
595
				
591
				
596
			} else {
592
			} else {
597
				imgAgrandie.setUrl(urlAgrandie);
593
				imgAgrandie.setUrl(urlAgrandie);
598
				imgAgrandie.setVisible(true);
594
				imgAgrandie.setVisible(true);
599
			}
595
			}
600
	}
596
	}
601
	
597
	
602
	private void afficherPanneauAgrandi() {
598
	private void afficherPanneauAgrandi() {
603
		agrandirImage();
599
		agrandirImage();
604
		imgZoom.show(this.getElement());
600
		imgZoom.show(this.getElement());
605
		imgZoom.setPosition((int)(Window.getClientWidth() - Window.getClientWidth()*0.50),(int)(Window.getClientHeight() - Window.getClientHeight()*0.85));
601
		imgZoom.setPosition((int)(Window.getClientWidth() - Window.getClientWidth()*0.50),(int)(Window.getClientHeight() - Window.getClientHeight()*0.85));
606
	}
602
	}
607
}
603
}
608
 
604