Subversion Repositories eFlore/Applications.del

Rev

Rev 2080 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
638 aurelien 1
package org.tela_botanica.del.client.composants.votes.moyennevotes;
9 benjamin 2
 
1583 mathias 3
import java.util.HashMap;
4
 
9 benjamin 5
import org.cobogw.gwt.user.client.ui.Rating;
1084 gduche 6
import org.tela_botanica.del.client.composants.votes.barrerepartition.InfoBulleAnim;
423 gduche 7
import org.tela_botanica.del.client.i18n.I18n;
9 benjamin 8
 
66 gduche 9
import com.google.gwt.core.client.GWT;
1583 mathias 10
import com.google.gwt.dom.client.DivElement;
11
import com.google.gwt.dom.client.SpanElement;
423 gduche 12
import com.google.gwt.event.dom.client.HasClickHandlers;
1095 gduche 13
import com.google.gwt.event.dom.client.HasMouseMoveHandlers;
1583 mathias 14
import com.google.gwt.i18n.client.NumberFormat;
66 gduche 15
import com.google.gwt.uibinder.client.UiBinder;
16
import com.google.gwt.uibinder.client.UiField;
1583 mathias 17
import com.google.gwt.user.client.Window;
423 gduche 18
import com.google.gwt.user.client.ui.Button;
9 benjamin 19
import com.google.gwt.user.client.ui.Composite;
66 gduche 20
import com.google.gwt.user.client.ui.FocusPanel;
423 gduche 21
import com.google.gwt.user.client.ui.HasText;
629 aurelien 22
import com.google.gwt.user.client.ui.HasWidgets;
66 gduche 23
import com.google.gwt.user.client.ui.Label;
1084 gduche 24
import com.google.gwt.user.client.ui.Panel;
66 gduche 25
import com.google.gwt.user.client.ui.Widget;
9 benjamin 26
 
629 aurelien 27
public class MoyenneVoteVue extends Composite implements MoyenneVotePresenteur.Vue {
9 benjamin 28
 
66 gduche 29
	// Annotation can be used to change the name of the associated xml file
30
	// @UiTemplate("MoyenneVoteVue.ui.xml")
31
	interface MyUiBinder extends UiBinder<Widget, MoyenneVoteVue> {
32
	}
33
 
34
	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
423 gduche 35
	private Rating votes;
36
	private int valeurOrigine;
1084 gduche 37
	private InfoBulleAnim animerVotePrisEnCompte;
1092 gduche 38
	private InfoBulleAnim animerVoteModifie;
1471 aurelien 39
	private InfoBulleAnim animerVoteSupprime;
423 gduche 40
 
66 gduche 41
	@UiField
42
	FocusPanel voter;
43
 
44
	@UiField
1583 mathias 45
	Panel votePrisEnCompte, voteModifie, voteSupprime, zoneFleur, panneauDetailVotes;
1084 gduche 46
 
47
	@UiField
1583 mathias 48
	Label nbVotes, protocole, noteGenerale/*, nbPoints*/, zoneVoter, lienPanneauFermer;
66 gduche 49
 
423 gduche 50
	@UiField
1471 aurelien 51
	Button boutonAnnuler;
1583 mathias 52
 
1095 gduche 53
	@UiField
1583 mathias 54
	// pour le panneau de détail des votes
55
	SpanElement pdvMoyenneArithmetique, pdvMoyennePonderee, pdvMediane, pdvNbPoints,
56
				votants5, votants4, votants3, votants2, votants1;
57
	@UiField
58
	DivElement barre5, barre4, barre3, barre2, barre1;
1095 gduche 59
 
1583 mathias 60
	public static final double TAILLE_MAX_BARRE = 135; // si "int", peut faire foirer les divisions
61
 
629 aurelien 62
	public MoyenneVoteVue() {
66 gduche 63
		initWidget(uiBinder.createAndBindUi(this));
423 gduche 64
		votes = new Rating(0, 5);
65
		votes.setReadOnly(false);
66
		voter.add(votes);
67
		masquerBoutonAnnuler();
1583 mathias 68
		masquerPanneauDetailVotes();
1084 gduche 69
		votePrisEnCompte.setVisible(false);
70
		animerVotePrisEnCompte = new InfoBulleAnim(votePrisEnCompte);
1092 gduche 71
		animerVoteModifie = new InfoBulleAnim(voteModifie);
1471 aurelien 72
		animerVoteSupprime = new InfoBulleAnim(voteSupprime);
423 gduche 73
	}
74
 
75
	public HasClickHandlers getBoutonAnnuler() {
76
		return boutonAnnuler;
77
	}
78
 
79
	public HasText getNbVotes() {
80
		return nbVotes;
81
	}
82
 
1583 mathias 83
	public HasClickHandlers getLienNbVotes() {
84
		return nbVotes;
1566 mathias 85
	}
86
 
1583 mathias 87
	/*public HasText getNbPoints() {
88
		return nbPoints;
89
	}*/
90
 
423 gduche 91
	public HasClickHandlers getVotes() {
92
		return votes;
93
	}
94
 
629 aurelien 95
	public int getValeurVote() {
96
		return votes.getValue();
97
	}
423 gduche 98
 
99
	public void afficherBoutonAnnuler() {
100
		boutonAnnuler.setVisible(true);
101
	}
102
 
103
	public void masquerBoutonAnnuler() {
104
		boutonAnnuler.setVisible(false);
105
	}
106
 
1566 mathias 107
	public void afficherNbVotes() {
423 gduche 108
		nbVotes.setVisible(true);
109
	}
1583 mathias 110
 
1566 mathias 111
	public void masquerNbVotes() {
423 gduche 112
		nbVotes.setVisible(false);
113
	}
1583 mathias 114
 
115
	/*public void afficherNbPoints() {
116
		nbPoints.setVisible(true);
117
	}*/
118
 
119
	/*public void masquerNbPoints() {
120
		nbPoints.setVisible(false);
121
	}*/
423 gduche 122
 
1583 mathias 123
	public void afficherPanneauDetailVotes() {
124
		panneauDetailVotes.setVisible(true);
1566 mathias 125
	}
126
 
1583 mathias 127
	public void masquerPanneauDetailVotes() {
128
		panneauDetailVotes.setVisible(false);
1566 mathias 129
	}
1583 mathias 130
 
131
	public Panel getPanneauDetailVotes() {
132
		return panneauDetailVotes;
133
	}
134
 
135
	public HasClickHandlers getLienPanneauFermer() {
136
		return lienPanneauFermer;
137
	}
138
 
423 gduche 139
	public void reinitialiserVotes() {
140
		votes.setValue(valeurOrigine);
141
	}
1583 mathias 142
 
143
	public void rafraichir(int voteUtilisateur, int nombreVotes, int nombrePoints, double moyenneArithmetique, double mediane, HashMap<Integer,Integer> occurrencesParNote, double moyennePonderee) {
1088 gduche 144
		valeurOrigine = voteUtilisateur;
1086 gduche 145
		String valeurVote = nombreVotes+" "+I18n.getVocabulary().nbVotes();
146
		if (nombreVotes > 1) {
147
			valeurVote += "s";
148
		}
1583 mathias 149
		/*String valeurPoints = ", "+Math.max(0, nombrePoints)+" "+I18n.getVocabulary().nbPoints();
1566 mathias 150
		if (nombrePoints > 1) {
151
			valeurPoints += "s";
1583 mathias 152
		}*/
1086 gduche 153
		nbVotes.setText(valeurVote);
1583 mathias 154
		//nbPoints.setText(valeurPoints);
155
		pdvNbPoints.setInnerHTML("" + nombrePoints);
1088 gduche 156
		votes.setValue(voteUtilisateur);
1583 mathias 157
		rafraichirPanneauDetail(moyennePonderee, moyenneArithmetique, mediane, occurrencesParNote, nombreVotes);
9 benjamin 158
	}
629 aurelien 159
 
1583 mathias 160
	// si la chose est nulle, on retourne 0
161
	private int nullCestZero(Integer chose) {
162
		if (chose == null) {
163
			return 0;
164
		} else {
165
			return chose;
166
		}
167
	}
168
 
169
	// try {
170
	//   codeConcisEtEfficace();
171
	// } catch (ShitLanguageException e) {
172
	//   codeCracra();
173
	// }
174
	private void rafraichirPanneauDetail(double moyennePonderee, double moyenneArithmetique, double mediane, HashMap<Integer,Integer> occurrencesParNote, int nombreVotes) {
175
		// stats
176
		NumberFormat df = NumberFormat.getFormat("0.###");
177
		this.pdvMoyennePonderee.setInnerHTML("" + df.format(moyennePonderee));
178
		this.pdvMoyenneArithmetique.setInnerHTML("" + df.format(moyenneArithmetique));
179
		this.pdvMediane.setInnerHTML("" + df.format(mediane));
180
		// détail des votes
181
		double	tailleBarre1 = 0,
182
				tailleBarre2 = 0,
183
				tailleBarre3 = 0,
184
				tailleBarre4 = 0,
185
				tailleBarre5 = 0;
186
		// on peut pas mettre des attributs dans une variable ? Quelle idée aussi de faire
187
		// du Web avec un langage statique... du coup codre cracra, ça vous fera les pieds
188
		if (nombreVotes > 0) {
189
			if (occurrencesParNote.get(1) != null) {
190
				tailleBarre1 = (int) (occurrencesParNote.get(1) * TAILLE_MAX_BARRE / nombreVotes);
191
			}
192
			if (occurrencesParNote.get(2) != null) {
193
				tailleBarre2 = (int) (occurrencesParNote.get(2) * TAILLE_MAX_BARRE / nombreVotes);
194
			}
195
			if (occurrencesParNote.get(3) != null) {
196
				tailleBarre3 = (int) (occurrencesParNote.get(3) * TAILLE_MAX_BARRE / nombreVotes);
197
			}
198
			if (occurrencesParNote.get(4) != null) {
199
				tailleBarre4 = (int) (occurrencesParNote.get(4) * TAILLE_MAX_BARRE / nombreVotes);
200
			}
201
			if (occurrencesParNote.get(5) != null) {
202
				tailleBarre5 = (int) (occurrencesParNote.get(5) * TAILLE_MAX_BARRE / nombreVotes);
203
			}
204
		}
205
		this.barre1.setAttribute("style", "width: " + tailleBarre1 + "px;");
206
		this.barre2.setAttribute("style", "width: " + tailleBarre2 + "px;");
207
		this.barre3.setAttribute("style", "width: " + tailleBarre3 + "px;");
208
		this.barre4.setAttribute("style", "width: " + tailleBarre4 + "px;");
209
		this.barre5.setAttribute("style", "width: " + tailleBarre5 + "px;");
210
		this.votants1.setInnerHTML("" + nullCestZero(occurrencesParNote.get(1)));
211
		this.votants2.setInnerHTML("" + nullCestZero(occurrencesParNote.get(2)));
212
		this.votants3.setInnerHTML("" + nullCestZero(occurrencesParNote.get(3)));
213
		this.votants4.setInnerHTML("" + nullCestZero(occurrencesParNote.get(4)));
214
		this.votants5.setInnerHTML("" + nullCestZero(occurrencesParNote.get(5)));
215
	}
216
 
629 aurelien 217
	@Override
218
	public void ajouterAuParent(HasWidgets composite) {
219
		composite.add(this);
220
	}
1084 gduche 221
 
222
	@Override
223
	public void afficherVotePrisEnCompte() {
224
		votePrisEnCompte.setStyleName("votePrisEnCompteOui");
225
		animerVotePrisEnCompte.run(2000);
226
	}
1085 gduche 227
 
228
	public HasWidgets getZoneFleur() {
229
		return zoneFleur;
230
	}
1086 gduche 231
 
232
	public HasText getZoneProtocole() {
233
		return protocole;
234
	}
1088 gduche 235
 
236
	public void setNoteGenerale(int note) {
237
		noteGenerale.setText(" : " + note);
238
	}
1092 gduche 239
 
1266 aurelien 240
	@Override
241
	public void setNoteGeneraleToolTip(double valeurVoteTotalPrecise) {
242
		double valeurArrondie = (double)Math.round(valeurVoteTotalPrecise * 1000) / 1000;
243
		zoneFleur.setTitle(I18n.getVocabulary().votesMoyennePrecise()+valeurArrondie);
244
	}
245
 
1092 gduche 246
	public void afficherVoteModifie() {
247
		voteModifie.setStyleName("votePrisEnCompteOui");
248
		animerVoteModifie.run(2000);
249
	}
1095 gduche 250
 
1471 aurelien 251
	@Override
252
	public void afficherVoteSupprime() {
253
		voteSupprime.setStyleName("voteSupprime");
254
		animerVoteSupprime.run(2000);
255
	}
256
 
1095 gduche 257
	public HasMouseMoveHandlers getZoneVoter() {
258
		return zoneVoter;
259
	}
260
 
261
	public void masquerZoneVoter() {
262
		zoneVoter.setVisible(false);
263
	}
1471 aurelien 264
 
265
	@Override
266
	public void desactiverInteractionVote() {
267
		votes.setReadOnly(true);
268
		boutonAnnuler.setEnabled(false);
269
		boutonAnnuler.addStyleName("elementMasque");
270
		votes.addStyleName("elementMasque");
271
	}
272
 
273
	@Override
274
	public void activerInteractionVote() {
275
		votes.setReadOnly(false);
276
		boutonAnnuler.setEnabled(true);
277
		boutonAnnuler.removeStyleName("elementMasque");
278
		votes.removeStyleName("elementMasque");
279
	}
2080 aurelien 280
 
281
	@Override
282
	public void afficherMessageVoteIdentifie(boolean peutVoter) {
283
		String message = I18n.getVocabulary().votez();
284
		if(!peutVoter) {
285
			message = I18n.getVocabulary().identifiezVousPourVoter();
286
		}
287
		zoneVoter.getElement().setInnerHTML("<span>"+message+" !</span>");
288
	}
9 benjamin 289
}