1,14 → 1,20 |
package org.tela_botanica.del.client.composants.votes.moyennevotes; |
|
import java.util.HashMap; |
|
import org.cobogw.gwt.user.client.ui.Rating; |
import org.tela_botanica.del.client.composants.votes.barrerepartition.InfoBulleAnim; |
import org.tela_botanica.del.client.i18n.I18n; |
|
import com.google.gwt.core.client.GWT; |
import com.google.gwt.dom.client.DivElement; |
import com.google.gwt.dom.client.SpanElement; |
import com.google.gwt.event.dom.client.HasClickHandlers; |
import com.google.gwt.event.dom.client.HasMouseMoveHandlers; |
import com.google.gwt.i18n.client.NumberFormat; |
import com.google.gwt.uibinder.client.UiBinder; |
import com.google.gwt.uibinder.client.UiField; |
import com.google.gwt.user.client.Window; |
import com.google.gwt.user.client.ui.Button; |
import com.google.gwt.user.client.ui.Composite; |
import com.google.gwt.user.client.ui.FocusPanel; |
36,17 → 42,23 |
FocusPanel voter; |
|
@UiField |
Panel votePrisEnCompte, voteModifie, voteSupprime, zoneFleur; |
Panel votePrisEnCompte, voteModifie, voteSupprime, zoneFleur, panneauDetailVotes; |
|
@UiField |
Label nbVotes, protocole, noteGenerale, nbPoints; |
Label nbVotes, protocole, noteGenerale/*, nbPoints*/, zoneVoter, lienPanneauFermer; |
|
@UiField |
Button boutonAnnuler; |
|
@UiField |
Label zoneVoter; |
// pour le panneau de détail des votes |
SpanElement pdvMoyenneArithmetique, pdvMoyennePonderee, pdvMediane, pdvNbPoints, |
votants5, votants4, votants3, votants2, votants1; |
@UiField |
DivElement barre5, barre4, barre3, barre2, barre1; |
|
public static final double TAILLE_MAX_BARRE = 135; // si "int", peut faire foirer les divisions |
|
public MoyenneVoteVue() { |
initWidget(uiBinder.createAndBindUi(this)); |
votes = new Rating(0, 5); |
53,6 → 65,7 |
votes.setReadOnly(false); |
voter.add(votes); |
masquerBoutonAnnuler(); |
masquerPanneauDetailVotes(); |
votePrisEnCompte.setVisible(false); |
animerVotePrisEnCompte = new InfoBulleAnim(votePrisEnCompte); |
animerVoteModifie = new InfoBulleAnim(voteModifie); |
67,10 → 80,14 |
return nbVotes; |
} |
|
public HasText getNbPoints() { |
return nbPoints; |
public HasClickHandlers getLienNbVotes() { |
return nbVotes; |
} |
|
/*public HasText getNbPoints() { |
return nbPoints; |
}*/ |
|
public HasClickHandlers getVotes() { |
return votes; |
} |
95,33 → 112,108 |
nbVotes.setVisible(false); |
} |
|
public void afficherNbPoints() { |
/*public void afficherNbPoints() { |
nbPoints.setVisible(true); |
} |
}*/ |
|
public void masquerNbPoints() { |
/*public void masquerNbPoints() { |
nbPoints.setVisible(false); |
}*/ |
|
public void afficherPanneauDetailVotes() { |
panneauDetailVotes.setVisible(true); |
} |
|
public void masquerPanneauDetailVotes() { |
panneauDetailVotes.setVisible(false); |
} |
|
public Panel getPanneauDetailVotes() { |
return panneauDetailVotes; |
} |
|
public HasClickHandlers getLienPanneauFermer() { |
return lienPanneauFermer; |
} |
|
public void reinitialiserVotes() { |
votes.setValue(valeurOrigine); |
} |
|
public void rafraichir(int voteUtilisateur, int nombreVotes, int nombrePoints) { |
public void rafraichir(int voteUtilisateur, int nombreVotes, int nombrePoints, double moyenneArithmetique, double mediane, HashMap<Integer,Integer> occurrencesParNote, double moyennePonderee) { |
valeurOrigine = voteUtilisateur; |
String valeurVote = nombreVotes+" "+I18n.getVocabulary().nbVotes(); |
if (nombreVotes > 1) { |
valeurVote += "s"; |
} |
String valeurPoints = ", "+Math.max(0, nombrePoints)+" "+I18n.getVocabulary().nbPoints(); |
/*String valeurPoints = ", "+Math.max(0, nombrePoints)+" "+I18n.getVocabulary().nbPoints(); |
if (nombrePoints > 1) { |
valeurPoints += "s"; |
} |
}*/ |
nbVotes.setText(valeurVote); |
nbPoints.setText(valeurPoints); |
//nbPoints.setText(valeurPoints); |
pdvNbPoints.setInnerHTML("" + nombrePoints); |
votes.setValue(voteUtilisateur); |
rafraichirPanneauDetail(moyennePonderee, moyenneArithmetique, mediane, occurrencesParNote, nombreVotes); |
} |
|
// si la chose est nulle, on retourne 0 |
private int nullCestZero(Integer chose) { |
if (chose == null) { |
return 0; |
} else { |
return chose; |
} |
} |
|
// try { |
// codeConcisEtEfficace(); |
// } catch (ShitLanguageException e) { |
// codeCracra(); |
// } |
private void rafraichirPanneauDetail(double moyennePonderee, double moyenneArithmetique, double mediane, HashMap<Integer,Integer> occurrencesParNote, int nombreVotes) { |
// stats |
NumberFormat df = NumberFormat.getFormat("0.###"); |
this.pdvMoyennePonderee.setInnerHTML("" + df.format(moyennePonderee)); |
this.pdvMoyenneArithmetique.setInnerHTML("" + df.format(moyenneArithmetique)); |
this.pdvMediane.setInnerHTML("" + df.format(mediane)); |
// détail des votes |
double tailleBarre1 = 0, |
tailleBarre2 = 0, |
tailleBarre3 = 0, |
tailleBarre4 = 0, |
tailleBarre5 = 0; |
// on peut pas mettre des attributs dans une variable ? Quelle idée aussi de faire |
// du Web avec un langage statique... du coup codre cracra, ça vous fera les pieds |
if (nombreVotes > 0) { |
if (occurrencesParNote.get(1) != null) { |
tailleBarre1 = (int) (occurrencesParNote.get(1) * TAILLE_MAX_BARRE / nombreVotes); |
} |
if (occurrencesParNote.get(2) != null) { |
tailleBarre2 = (int) (occurrencesParNote.get(2) * TAILLE_MAX_BARRE / nombreVotes); |
} |
if (occurrencesParNote.get(3) != null) { |
tailleBarre3 = (int) (occurrencesParNote.get(3) * TAILLE_MAX_BARRE / nombreVotes); |
} |
if (occurrencesParNote.get(4) != null) { |
tailleBarre4 = (int) (occurrencesParNote.get(4) * TAILLE_MAX_BARRE / nombreVotes); |
} |
if (occurrencesParNote.get(5) != null) { |
tailleBarre5 = (int) (occurrencesParNote.get(5) * TAILLE_MAX_BARRE / nombreVotes); |
} |
} |
this.barre1.setAttribute("style", "width: " + tailleBarre1 + "px;"); |
this.barre2.setAttribute("style", "width: " + tailleBarre2 + "px;"); |
this.barre3.setAttribute("style", "width: " + tailleBarre3 + "px;"); |
this.barre4.setAttribute("style", "width: " + tailleBarre4 + "px;"); |
this.barre5.setAttribute("style", "width: " + tailleBarre5 + "px;"); |
this.votants1.setInnerHTML("" + nullCestZero(occurrencesParNote.get(1))); |
this.votants2.setInnerHTML("" + nullCestZero(occurrencesParNote.get(2))); |
this.votants3.setInnerHTML("" + nullCestZero(occurrencesParNote.get(3))); |
this.votants4.setInnerHTML("" + nullCestZero(occurrencesParNote.get(4))); |
this.votants5.setInnerHTML("" + nullCestZero(occurrencesParNote.get(5))); |
} |
|
@Override |
public void ajouterAuParent(HasWidgets composite) { |
composite.add(this); |