Subversion Repositories eFlore/Applications.del

Rev

Rev 1393 | Rev 1563 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
476 benjamin 1
package org.tela_botanica.del.client.composants.images;
200 gduche 2
 
577 gduche 3
import org.tela_botanica.del.client.i18n.I18n;
200 gduche 4
import com.google.gwt.core.client.GWT;
437 aurelien 5
import com.google.gwt.event.dom.client.LoadEvent;
6
import com.google.gwt.event.dom.client.LoadHandler;
1556 aurelien 7
import com.google.gwt.event.logical.shared.ResizeEvent;
8
import com.google.gwt.event.logical.shared.ResizeHandler;
200 gduche 9
import com.google.gwt.uibinder.client.UiBinder;
10
import com.google.gwt.uibinder.client.UiField;
1556 aurelien 11
import com.google.gwt.user.client.Timer;
12
import com.google.gwt.user.client.Window;
200 gduche 13
import com.google.gwt.user.client.ui.Composite;
575 gduche 14
import com.google.gwt.user.client.ui.HTML;
200 gduche 15
import com.google.gwt.user.client.ui.Image;
16
import com.google.gwt.user.client.ui.Widget;
17
 
308 gduche 18
public class DetailImageVue extends Composite implements DetailImagePresenteur.Vue {
200 gduche 19
 
20
	// Gestion d'UiBinder
21
	interface Binder extends UiBinder<Widget, DetailImageVue> {
22
	}
23
 
24
	private static Binder binder = GWT.create(Binder.class);
25
 
26
	@UiField
27
	protected Image photoPrincipale;
28
 
29
	@UiField
575 gduche 30
	protected HTML texteAlternatif;
200 gduche 31
 
308 gduche 32
	public DetailImageVue() {
200 gduche 33
		initWidget(binder.createAndBindUi(this));
437 aurelien 34
		photoPrincipale.addLoadHandler(new LoadHandler() {
35
			@Override
36
			public void onLoad(LoadEvent event) {
1556 aurelien 37
				setTailleOptimale();
437 aurelien 38
			}
39
		});
1556 aurelien 40
 
41
		Window.addResizeHandler(new ResizeHandler() {
42
 
43
			Timer resizeTimer = new Timer() {
44
			    @Override
45
			    public void run() {
46
			    	setTailleOptimale();
47
			    }
48
			};
49
 
50
			@Override
51
			public void onResize(ResizeEvent event) {
52
				resizeTimer.cancel();
53
			    resizeTimer.schedule(250);
54
			}
55
		});
200 gduche 56
	}
308 gduche 57
 
436 benjamin 58
	public void chargerImage(org.tela_botanica.del.client.modeles.Image imageCourante) {
59
		setUrlImage(imageCourante.getUrlFormat("L"));
60
		setTitle(imageCourante.getUrlFormat("L"));
1393 aurelien 61
		setTexteAlternatif("<strong> "+I18n.getVocabulary().imageNumero()+""+ imageCourante.getIdImage() +" - "+ imageCourante.getObservation().getNomRetenuFormateReferentiel() + " "  + I18n.getVocabulary().par() + " " + imageCourante.getObservation().getAuteur() + "</strong><br />"
577 gduche 62
				+ I18n.getVocabulary().publiee() + " "+ imageCourante.getObservation().getDateReleve() + " - " + imageCourante.getObservation().getLocaliteAvecIdFormatee());
436 benjamin 63
	}
64
 
308 gduche 65
	public void setUrlImage(String urlImage) {
436 benjamin 66
		photoPrincipale.setUrl(urlImage);
308 gduche 67
	}
68
 
69
	public void setTexteAlternatif(String texteAlternatif) {
575 gduche 70
		this.texteAlternatif.setHTML(texteAlternatif);
308 gduche 71
	}
1556 aurelien 72
 
73
	public void setTailleOptimale() {
74
		double fenetreH = Window.getClientHeight();
75
		double fenetreW = Window.getClientWidth();
76
 
77
		double rapport = 0;
78
 
79
		double photoH = photoPrincipale.getHeight();
80
		double photoW = photoPrincipale.getWidth();
81
 
82
		double reduction = 150;
83
 
84
		if(photoH >= (fenetreH - reduction) || photoW >= (fenetreW - reduction)) {
85
			if(photoH > photoW) {
86
				rapport = photoW/photoH;
87
				photoH = fenetreH-reduction;
88
				photoW = photoH*rapport;
89
			} else {
90
				rapport = photoH/photoW;
91
				photoW = fenetreW-reduction;
92
				photoH = photoW*rapport;
93
			}
94
		}
95
 
96
		setWidth(photoW+"px");
97
		setHeight(photoH+"px");
98
	}
200 gduche 99
}