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"));
|
1842 |
mathias |
70 |
//setTitle(imageCourante.getUrlFormat("L"));
|
|
|
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 |
|
|
|
89 |
public void setTexteAlternatif(String texteAlternatif) {
|
575 |
gduche |
90 |
this.texteAlternatif.setHTML(texteAlternatif);
|
308 |
gduche |
91 |
}
|
1556 |
aurelien |
92 |
|
|
|
93 |
public void setTailleOptimale() {
|
1563 |
aurelien |
94 |
|
1556 |
aurelien |
95 |
double fenetreH = Window.getClientHeight();
|
|
|
96 |
double fenetreW = Window.getClientWidth();
|
|
|
97 |
|
|
|
98 |
double photoH = photoPrincipale.getHeight();
|
|
|
99 |
double photoW = photoPrincipale.getWidth();
|
|
|
100 |
|
1563 |
aurelien |
101 |
double rapport = 0;
|
1556 |
aurelien |
102 |
double reduction = 150;
|
|
|
103 |
|
1563 |
aurelien |
104 |
if(photoH > (fenetreH - reduction) || photoW > (fenetreW - reduction)) {
|
|
|
105 |
|
|
|
106 |
if(photoH >= (fenetreH - reduction)) {
|
1556 |
aurelien |
107 |
rapport = photoW/photoH;
|
|
|
108 |
photoH = fenetreH-reduction;
|
|
|
109 |
photoW = photoH*rapport;
|
1563 |
aurelien |
110 |
}
|
|
|
111 |
|
|
|
112 |
if(photoW >= (fenetreW - reduction)) {
|
1556 |
aurelien |
113 |
rapport = photoH/photoW;
|
|
|
114 |
photoW = fenetreW-reduction;
|
|
|
115 |
photoH = photoW*rapport;
|
|
|
116 |
}
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
setWidth(photoW+"px");
|
|
|
120 |
setHeight(photoH+"px");
|
|
|
121 |
}
|
200 |
gduche |
122 |
}
|