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;
|
1842 |
mathias |
4 |
|
200 |
gduche |
5 |
import com.google.gwt.core.client.GWT;
|
1842 |
mathias |
6 |
import com.google.gwt.dom.client.DivElement;
|
|
|
7 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
8 |
import com.google.gwt.event.dom.client.ClickHandler;
|
437 |
aurelien |
9 |
import com.google.gwt.event.dom.client.LoadEvent;
|
|
|
10 |
import com.google.gwt.event.dom.client.LoadHandler;
|
1842 |
mathias |
11 |
import com.google.gwt.event.dom.client.MouseOutEvent;
|
|
|
12 |
import com.google.gwt.event.dom.client.MouseOutHandler;
|
|
|
13 |
import com.google.gwt.event.dom.client.MouseOverEvent;
|
|
|
14 |
import com.google.gwt.event.dom.client.MouseOverHandler;
|
1556 |
aurelien |
15 |
import com.google.gwt.event.logical.shared.ResizeEvent;
|
|
|
16 |
import com.google.gwt.event.logical.shared.ResizeHandler;
|
200 |
gduche |
17 |
import com.google.gwt.uibinder.client.UiBinder;
|
|
|
18 |
import com.google.gwt.uibinder.client.UiField;
|
1556 |
aurelien |
19 |
import com.google.gwt.user.client.Timer;
|
|
|
20 |
import com.google.gwt.user.client.Window;
|
200 |
gduche |
21 |
import com.google.gwt.user.client.ui.Composite;
|
575 |
gduche |
22 |
import com.google.gwt.user.client.ui.HTML;
|
200 |
gduche |
23 |
import com.google.gwt.user.client.ui.Image;
|
|
|
24 |
import com.google.gwt.user.client.ui.Widget;
|
|
|
25 |
|
308 |
gduche |
26 |
public class DetailImageVue extends Composite implements DetailImagePresenteur.Vue {
|
200 |
gduche |
27 |
|
|
|
28 |
// Gestion d'UiBinder
|
|
|
29 |
interface Binder extends UiBinder<Widget, DetailImageVue> {
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
private static Binder binder = GWT.create(Binder.class);
|
|
|
33 |
|
|
|
34 |
@UiField
|
|
|
35 |
protected Image photoPrincipale;
|
|
|
36 |
|
|
|
37 |
@UiField
|
1842 |
mathias |
38 |
protected HTML superpositionImage;
|
|
|
39 |
|
|
|
40 |
@UiField
|
575 |
gduche |
41 |
protected HTML texteAlternatif;
|
200 |
gduche |
42 |
|
308 |
gduche |
43 |
public DetailImageVue() {
|
200 |
gduche |
44 |
initWidget(binder.createAndBindUi(this));
|
437 |
aurelien |
45 |
photoPrincipale.addLoadHandler(new LoadHandler() {
|
|
|
46 |
@Override
|
|
|
47 |
public void onLoad(LoadEvent event) {
|
1556 |
aurelien |
48 |
setTailleOptimale();
|
437 |
aurelien |
49 |
}
|
|
|
50 |
});
|
1556 |
aurelien |
51 |
Window.addResizeHandler(new ResizeHandler() {
|
|
|
52 |
|
|
|
53 |
Timer resizeTimer = new Timer() {
|
|
|
54 |
@Override
|
|
|
55 |
public void run() {
|
|
|
56 |
setTailleOptimale();
|
|
|
57 |
}
|
|
|
58 |
};
|
|
|
59 |
|
|
|
60 |
@Override
|
|
|
61 |
public void onResize(ResizeEvent event) {
|
|
|
62 |
resizeTimer.cancel();
|
|
|
63 |
resizeTimer.schedule(250);
|
|
|
64 |
}
|
|
|
65 |
});
|
200 |
gduche |
66 |
}
|
308 |
gduche |
67 |
|
436 |
benjamin |
68 |
public void chargerImage(org.tela_botanica.del.client.modeles.Image imageCourante) {
|
|
|
69 |
setUrlImage(imageCourante.getUrlFormat("L"));
|
1963 |
mathias |
70 |
setAltImage(imageCourante.getObservation().getAuteur() + " - " + imageCourante.getObservation().getNomRetenu());
|
1842 |
mathias |
71 |
setTitle("Cliquer pour ouvrir l'image originale dans un nouvel onglet");
|
1393 |
aurelien |
72 |
setTexteAlternatif("<strong> "+I18n.getVocabulary().imageNumero()+""+ imageCourante.getIdImage() +" - "+ imageCourante.getObservation().getNomRetenuFormateReferentiel() + " " + I18n.getVocabulary().par() + " " + imageCourante.getObservation().getAuteur() + "</strong><br />"
|
577 |
gduche |
73 |
+ I18n.getVocabulary().publiee() + " "+ imageCourante.getObservation().getDateReleve() + " - " + imageCourante.getObservation().getLocaliteAvecIdFormatee());
|
1842 |
mathias |
74 |
final String urlImageOriginale = imageCourante.getUrlFormat("O");
|
|
|
75 |
|
|
|
76 |
// ouvre l'image originale dans un nouvel onglet, en attendant un futur outil de zoom
|
|
|
77 |
superpositionImage.addClickHandler(new ClickHandler() {
|
|
|
78 |
@Override
|
|
|
79 |
public void onClick(ClickEvent event) {
|
|
|
80 |
Window.open(urlImageOriginale, "_blank", "");
|
|
|
81 |
}
|
|
|
82 |
});
|
436 |
benjamin |
83 |
}
|
|
|
84 |
|
308 |
gduche |
85 |
public void setUrlImage(String urlImage) {
|
436 |
benjamin |
86 |
photoPrincipale.setUrl(urlImage);
|
308 |
gduche |
87 |
}
|
|
|
88 |
|
1963 |
mathias |
89 |
// définit le "alt" sur l'image (ajouté pour l'intégration aux réseaux sociaux)
|
|
|
90 |
public void setAltImage(String altImage) {
|
|
|
91 |
photoPrincipale.setAltText(altImage);
|
|
|
92 |
}
|
|
|
93 |
|
308 |
gduche |
94 |
public void setTexteAlternatif(String texteAlternatif) {
|
575 |
gduche |
95 |
this.texteAlternatif.setHTML(texteAlternatif);
|
308 |
gduche |
96 |
}
|
1556 |
aurelien |
97 |
|
|
|
98 |
public void setTailleOptimale() {
|
1563 |
aurelien |
99 |
|
1556 |
aurelien |
100 |
double fenetreH = Window.getClientHeight();
|
|
|
101 |
double fenetreW = Window.getClientWidth();
|
|
|
102 |
|
|
|
103 |
double photoH = photoPrincipale.getHeight();
|
|
|
104 |
double photoW = photoPrincipale.getWidth();
|
|
|
105 |
|
1563 |
aurelien |
106 |
double rapport = 0;
|
1556 |
aurelien |
107 |
double reduction = 150;
|
|
|
108 |
|
1563 |
aurelien |
109 |
if(photoH > (fenetreH - reduction) || photoW > (fenetreW - reduction)) {
|
|
|
110 |
|
|
|
111 |
if(photoH >= (fenetreH - reduction)) {
|
1556 |
aurelien |
112 |
rapport = photoW/photoH;
|
|
|
113 |
photoH = fenetreH-reduction;
|
|
|
114 |
photoW = photoH*rapport;
|
1563 |
aurelien |
115 |
}
|
|
|
116 |
|
|
|
117 |
if(photoW >= (fenetreW - reduction)) {
|
1556 |
aurelien |
118 |
rapport = photoH/photoW;
|
|
|
119 |
photoW = fenetreW-reduction;
|
|
|
120 |
photoH = photoW*rapport;
|
|
|
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
setWidth(photoW+"px");
|
|
|
125 |
setHeight(photoH+"px");
|
|
|
126 |
}
|
200 |
gduche |
127 |
}
|