Rev 1393 | Rev 1563 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.del.client.composants.images;
import org.tela_botanica.del.client.i18n.I18n;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.LoadEvent;
import com.google.gwt.event.dom.client.LoadHandler;
import com.google.gwt.event.logical.shared.ResizeEvent;
import com.google.gwt.event.logical.shared.ResizeHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Widget;
public class DetailImageVue extends Composite implements DetailImagePresenteur.Vue {
// Gestion d'UiBinder
interface Binder extends UiBinder<Widget, DetailImageVue> {
}
private static Binder binder = GWT.create(Binder.class);
@UiField
protected Image photoPrincipale;
@UiField
protected HTML texteAlternatif;
public DetailImageVue() {
initWidget(binder.createAndBindUi(this));
photoPrincipale.addLoadHandler(new LoadHandler() {
@Override
public void onLoad(LoadEvent event) {
setTailleOptimale();
}
});
Window.addResizeHandler(new ResizeHandler() {
Timer resizeTimer = new Timer() {
@Override
public void run() {
setTailleOptimale();
}
};
@Override
public void onResize(ResizeEvent event) {
resizeTimer.cancel();
resizeTimer.schedule(250);
}
});
}
public void chargerImage(org.tela_botanica.del.client.modeles.Image imageCourante) {
setUrlImage(imageCourante.getUrlFormat("L"));
setTitle(imageCourante.getUrlFormat("L"));
setTexteAlternatif("<strong> "+I18n.getVocabulary().imageNumero()+""+ imageCourante.getIdImage() +" - "+ imageCourante.getObservation().getNomRetenuFormateReferentiel() + " " + I18n.getVocabulary().par() + " " + imageCourante.getObservation().getAuteur() + "</strong><br />"
+ I18n.getVocabulary().publiee() + " "+ imageCourante.getObservation().getDateReleve() + " - " + imageCourante.getObservation().getLocaliteAvecIdFormatee());
}
public void setUrlImage(String urlImage) {
photoPrincipale.setUrl(urlImage);
}
public void setTexteAlternatif(String texteAlternatif) {
this.texteAlternatif.setHTML(texteAlternatif);
}
public void setTailleOptimale() {
double fenetreH = Window.getClientHeight();
double fenetreW = Window.getClientWidth();
double rapport = 0;
double photoH = photoPrincipale.getHeight();
double photoW = photoPrincipale.getWidth();
double reduction = 150;
if(photoH >= (fenetreH - reduction) || photoW >= (fenetreW - reduction)) {
if(photoH > photoW) {
rapport = photoW/photoH;
photoH = fenetreH-reduction;
photoW = photoH*rapport;
} else {
rapport = photoH/photoW;
photoW = fenetreW-reduction;
photoH = photoW*rapport;
}
}
setWidth(photoW+"px");
setHeight(photoH+"px");
}
}