Subversion Repositories eFlore/Applications.del

Rev

Rev 1566 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1566 Rev 1583
1
package org.tela_botanica.del.client.composants.votes.moyennevotes;
1
package org.tela_botanica.del.client.composants.votes.moyennevotes;
-
 
2
 
-
 
3
import java.util.HashMap;
2
 
4
 
3
import org.cobogw.gwt.user.client.ui.Rating;
5
import org.cobogw.gwt.user.client.ui.Rating;
4
import org.tela_botanica.del.client.composants.votes.barrerepartition.InfoBulleAnim;
6
import org.tela_botanica.del.client.composants.votes.barrerepartition.InfoBulleAnim;
5
import org.tela_botanica.del.client.i18n.I18n;
7
import org.tela_botanica.del.client.i18n.I18n;
6
 
8
 
7
import com.google.gwt.core.client.GWT;
9
import com.google.gwt.core.client.GWT;
-
 
10
import com.google.gwt.dom.client.DivElement;
-
 
11
import com.google.gwt.dom.client.SpanElement;
8
import com.google.gwt.event.dom.client.HasClickHandlers;
12
import com.google.gwt.event.dom.client.HasClickHandlers;
9
import com.google.gwt.event.dom.client.HasMouseMoveHandlers;
13
import com.google.gwt.event.dom.client.HasMouseMoveHandlers;
-
 
14
import com.google.gwt.i18n.client.NumberFormat;
10
import com.google.gwt.uibinder.client.UiBinder;
15
import com.google.gwt.uibinder.client.UiBinder;
11
import com.google.gwt.uibinder.client.UiField;
16
import com.google.gwt.uibinder.client.UiField;
-
 
17
import com.google.gwt.user.client.Window;
12
import com.google.gwt.user.client.ui.Button;
18
import com.google.gwt.user.client.ui.Button;
13
import com.google.gwt.user.client.ui.Composite;
19
import com.google.gwt.user.client.ui.Composite;
14
import com.google.gwt.user.client.ui.FocusPanel;
20
import com.google.gwt.user.client.ui.FocusPanel;
15
import com.google.gwt.user.client.ui.HasText;
21
import com.google.gwt.user.client.ui.HasText;
16
import com.google.gwt.user.client.ui.HasWidgets;
22
import com.google.gwt.user.client.ui.HasWidgets;
17
import com.google.gwt.user.client.ui.Label;
23
import com.google.gwt.user.client.ui.Label;
18
import com.google.gwt.user.client.ui.Panel;
24
import com.google.gwt.user.client.ui.Panel;
19
import com.google.gwt.user.client.ui.Widget;
25
import com.google.gwt.user.client.ui.Widget;
20
 
26
 
21
public class MoyenneVoteVue extends Composite implements MoyenneVotePresenteur.Vue {
27
public class MoyenneVoteVue extends Composite implements MoyenneVotePresenteur.Vue {
22
 
28
 
23
	// Annotation can be used to change the name of the associated xml file
29
	// Annotation can be used to change the name of the associated xml file
24
	// @UiTemplate("MoyenneVoteVue.ui.xml")
30
	// @UiTemplate("MoyenneVoteVue.ui.xml")
25
	interface MyUiBinder extends UiBinder<Widget, MoyenneVoteVue> {
31
	interface MyUiBinder extends UiBinder<Widget, MoyenneVoteVue> {
26
	}
32
	}
27
 
33
 
28
	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
34
	private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
29
	private Rating votes;
35
	private Rating votes;
30
	private int valeurOrigine;
36
	private int valeurOrigine;
31
	private InfoBulleAnim animerVotePrisEnCompte;
37
	private InfoBulleAnim animerVotePrisEnCompte;
32
	private InfoBulleAnim animerVoteModifie;
38
	private InfoBulleAnim animerVoteModifie;
33
	private InfoBulleAnim animerVoteSupprime;
39
	private InfoBulleAnim animerVoteSupprime;
34
	
40
	
35
	@UiField
41
	@UiField
36
	FocusPanel voter;
42
	FocusPanel voter;
37
 
43
 
38
	@UiField
44
	@UiField
39
	Panel votePrisEnCompte, voteModifie, voteSupprime, zoneFleur;
45
	Panel votePrisEnCompte, voteModifie, voteSupprime, zoneFleur, panneauDetailVotes;
40
	
46
	
41
	@UiField
47
	@UiField
42
	Label nbVotes, protocole, noteGenerale, nbPoints;
48
	Label nbVotes, protocole, noteGenerale/*, nbPoints*/, zoneVoter, lienPanneauFermer;
43
 
49
 
44
	@UiField 
50
	@UiField 
45
	Button boutonAnnuler;
51
	Button boutonAnnuler;
46
	
52
 
-
 
53
	@UiField
-
 
54
	// pour le panneau de détail des votes
-
 
55
	SpanElement pdvMoyenneArithmetique, pdvMoyennePonderee, pdvMediane, pdvNbPoints,
-
 
56
				votants5, votants4, votants3, votants2, votants1;
47
	@UiField
57
	@UiField
48
	Label zoneVoter;
58
	DivElement barre5, barre4, barre3, barre2, barre1;
-
 
59
	
-
 
60
	public static final double TAILLE_MAX_BARRE = 135; // si "int", peut faire foirer les divisions
49
	
61
 
50
	public MoyenneVoteVue() {
62
	public MoyenneVoteVue() {
51
		initWidget(uiBinder.createAndBindUi(this));
63
		initWidget(uiBinder.createAndBindUi(this));
52
		votes = new Rating(0, 5);
64
		votes = new Rating(0, 5);
53
		votes.setReadOnly(false);
65
		votes.setReadOnly(false);
54
		voter.add(votes);
66
		voter.add(votes);
55
		masquerBoutonAnnuler();
67
		masquerBoutonAnnuler();
-
 
68
		masquerPanneauDetailVotes();
56
		votePrisEnCompte.setVisible(false);
69
		votePrisEnCompte.setVisible(false);
57
		animerVotePrisEnCompte = new InfoBulleAnim(votePrisEnCompte);
70
		animerVotePrisEnCompte = new InfoBulleAnim(votePrisEnCompte);
58
		animerVoteModifie = new InfoBulleAnim(voteModifie);
71
		animerVoteModifie = new InfoBulleAnim(voteModifie);
59
		animerVoteSupprime = new InfoBulleAnim(voteSupprime);
72
		animerVoteSupprime = new InfoBulleAnim(voteSupprime);
60
	}
73
	}
61
	
74
	
62
	public HasClickHandlers getBoutonAnnuler() {
75
	public HasClickHandlers getBoutonAnnuler() {
63
		return boutonAnnuler;
76
		return boutonAnnuler;
64
	}
77
	}
65
	
78
	
66
	public HasText getNbVotes() {
79
	public HasText getNbVotes() {
67
		return nbVotes;
80
		return nbVotes;
68
	}
81
	}
69
	
82
	
70
	public HasText getNbPoints() {
83
	public HasClickHandlers getLienNbVotes() {
71
		return nbPoints;
84
		return nbVotes;
-
 
85
	}
-
 
86
	
-
 
87
	/*public HasText getNbPoints() {
-
 
88
		return nbPoints;
72
	}
89
	}*/
73
	
90
	
74
	public HasClickHandlers getVotes() {
91
	public HasClickHandlers getVotes() {
75
		return votes;
92
		return votes;
76
	}
93
	}
77
	
94
	
78
	public int getValeurVote() {
95
	public int getValeurVote() {
79
		return votes.getValue();
96
		return votes.getValue();
80
	}
97
	}
81
 
98
 
82
	public void afficherBoutonAnnuler() {
99
	public void afficherBoutonAnnuler() {
83
		boutonAnnuler.setVisible(true);
100
		boutonAnnuler.setVisible(true);
84
	}
101
	}
85
	
102
	
86
	public void masquerBoutonAnnuler() {
103
	public void masquerBoutonAnnuler() {
87
		boutonAnnuler.setVisible(false);
104
		boutonAnnuler.setVisible(false);
88
	}
105
	}
89
	
106
	
90
	public void afficherNbVotes() {
107
	public void afficherNbVotes() {
91
		nbVotes.setVisible(true);
108
		nbVotes.setVisible(true);
92
	}
109
	}
93
	
110
 
94
	public void masquerNbVotes() {
111
	public void masquerNbVotes() {
95
		nbVotes.setVisible(false);
112
		nbVotes.setVisible(false);
96
	}
113
	}
97
	
114
 
98
	public void afficherNbPoints() {
115
	/*public void afficherNbPoints() {
99
		nbPoints.setVisible(true);
116
		nbPoints.setVisible(true);
100
	}
117
	}*/
101
	
118
 
102
	public void masquerNbPoints() {
119
	/*public void masquerNbPoints() {
103
		nbPoints.setVisible(false);
120
		nbPoints.setVisible(false);
-
 
121
	}*/
-
 
122
	
-
 
123
	public void afficherPanneauDetailVotes() {
-
 
124
		panneauDetailVotes.setVisible(true);
104
	}
125
	}
-
 
126
	
-
 
127
	public void masquerPanneauDetailVotes() {
-
 
128
		panneauDetailVotes.setVisible(false);
-
 
129
	}
-
 
130
 
-
 
131
	public Panel getPanneauDetailVotes() {
-
 
132
		return panneauDetailVotes;
-
 
133
	}
-
 
134
 
-
 
135
	public HasClickHandlers getLienPanneauFermer() {
-
 
136
		return lienPanneauFermer;
-
 
137
	}
105
	
138
 
106
	public void reinitialiserVotes() {
139
	public void reinitialiserVotes() {
107
		votes.setValue(valeurOrigine);
140
		votes.setValue(valeurOrigine);
108
	}
141
	}
109
	
142
 
110
	public void rafraichir(int voteUtilisateur, int nombreVotes, int nombrePoints) {
143
	public void rafraichir(int voteUtilisateur, int nombreVotes, int nombrePoints, double moyenneArithmetique, double mediane, HashMap<Integer,Integer> occurrencesParNote, double moyennePonderee) {
111
		valeurOrigine = voteUtilisateur;
144
		valeurOrigine = voteUtilisateur;
112
		String valeurVote = nombreVotes+" "+I18n.getVocabulary().nbVotes();
145
		String valeurVote = nombreVotes+" "+I18n.getVocabulary().nbVotes();
113
		if (nombreVotes > 1) {
146
		if (nombreVotes > 1) {
114
			valeurVote += "s";
147
			valeurVote += "s";
115
		}
148
		}
116
		String valeurPoints = ", "+Math.max(0, nombrePoints)+" "+I18n.getVocabulary().nbPoints();
149
		/*String valeurPoints = ", "+Math.max(0, nombrePoints)+" "+I18n.getVocabulary().nbPoints();
117
		if (nombrePoints > 1) {
150
		if (nombrePoints > 1) {
118
			valeurPoints += "s";
151
			valeurPoints += "s";
119
		}
152
		}*/
120
		nbVotes.setText(valeurVote);
153
		nbVotes.setText(valeurVote);
121
		nbPoints.setText(valeurPoints);
154
		//nbPoints.setText(valeurPoints);
-
 
155
		pdvNbPoints.setInnerHTML("" + nombrePoints);
122
		votes.setValue(voteUtilisateur);
156
		votes.setValue(voteUtilisateur);
-
 
157
		rafraichirPanneauDetail(moyennePonderee, moyenneArithmetique, mediane, occurrencesParNote, nombreVotes);
-
 
158
	}
-
 
159
 
-
 
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)));
123
	}
215
	}
124
 
216
 
125
	@Override
217
	@Override
126
	public void ajouterAuParent(HasWidgets composite) {
218
	public void ajouterAuParent(HasWidgets composite) {
127
		composite.add(this);
219
		composite.add(this);
128
	}
220
	}
129
	
221
	
130
	@Override
222
	@Override
131
	public void afficherVotePrisEnCompte() {
223
	public void afficherVotePrisEnCompte() {
132
		votePrisEnCompte.setStyleName("votePrisEnCompteOui");
224
		votePrisEnCompte.setStyleName("votePrisEnCompteOui");
133
		animerVotePrisEnCompte.run(2000);
225
		animerVotePrisEnCompte.run(2000);
134
	}
226
	}
135
	
227
	
136
	public HasWidgets getZoneFleur() {
228
	public HasWidgets getZoneFleur() {
137
		return zoneFleur;
229
		return zoneFleur;
138
	}
230
	}
139
	
231
	
140
	public HasText getZoneProtocole() {
232
	public HasText getZoneProtocole() {
141
		return protocole;
233
		return protocole;
142
	}
234
	}
143
	
235
	
144
	public void setNoteGenerale(int note) {
236
	public void setNoteGenerale(int note) {
145
		noteGenerale.setText(" : " + note);
237
		noteGenerale.setText(" : " + note);
146
	}
238
	}
147
	
239
	
148
	@Override
240
	@Override
149
	public void setNoteGeneraleToolTip(double valeurVoteTotalPrecise) {
241
	public void setNoteGeneraleToolTip(double valeurVoteTotalPrecise) {
150
		double valeurArrondie = (double)Math.round(valeurVoteTotalPrecise * 1000) / 1000;
242
		double valeurArrondie = (double)Math.round(valeurVoteTotalPrecise * 1000) / 1000;
151
		zoneFleur.setTitle(I18n.getVocabulary().votesMoyennePrecise()+valeurArrondie);
243
		zoneFleur.setTitle(I18n.getVocabulary().votesMoyennePrecise()+valeurArrondie);
152
	}
244
	}
153
	
245
	
154
	public void afficherVoteModifie() {
246
	public void afficherVoteModifie() {
155
		voteModifie.setStyleName("votePrisEnCompteOui");
247
		voteModifie.setStyleName("votePrisEnCompteOui");
156
		animerVoteModifie.run(2000);
248
		animerVoteModifie.run(2000);
157
	}
249
	}
158
	
250
	
159
	@Override
251
	@Override
160
	public void afficherVoteSupprime() {
252
	public void afficherVoteSupprime() {
161
		voteSupprime.setStyleName("voteSupprime");
253
		voteSupprime.setStyleName("voteSupprime");
162
		animerVoteSupprime.run(2000);
254
		animerVoteSupprime.run(2000);
163
	}
255
	}
164
	
256
	
165
	public HasMouseMoveHandlers getZoneVoter() {
257
	public HasMouseMoveHandlers getZoneVoter() {
166
		return zoneVoter;
258
		return zoneVoter;
167
	}
259
	}
168
	
260
	
169
	public void masquerZoneVoter() {
261
	public void masquerZoneVoter() {
170
		zoneVoter.setVisible(false);
262
		zoneVoter.setVisible(false);
171
	}
263
	}
172
	
264
	
173
	@Override
265
	@Override
174
	public void desactiverInteractionVote() {
266
	public void desactiverInteractionVote() {
175
		votes.setReadOnly(true);
267
		votes.setReadOnly(true);
176
		boutonAnnuler.setEnabled(false);
268
		boutonAnnuler.setEnabled(false);
177
		boutonAnnuler.addStyleName("elementMasque");
269
		boutonAnnuler.addStyleName("elementMasque");
178
		votes.addStyleName("elementMasque");
270
		votes.addStyleName("elementMasque");
179
	}
271
	}
180
	
272
	
181
	@Override
273
	@Override
182
	public void activerInteractionVote() {
274
	public void activerInteractionVote() {
183
		votes.setReadOnly(false);
275
		votes.setReadOnly(false);
184
		boutonAnnuler.setEnabled(true);
276
		boutonAnnuler.setEnabled(true);
185
		boutonAnnuler.removeStyleName("elementMasque");
277
		boutonAnnuler.removeStyleName("elementMasque");
186
		votes.removeStyleName("elementMasque");
278
		votes.removeStyleName("elementMasque");
187
	}
279
	}
188
}
280
}