Subversion Repositories eFlore/Archives.cel-v2

Rev

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

Rev 46 Rev 47
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
2
 
2
 
3
import org.tela_botanica.client.image.ImageMediateur;
3
import org.tela_botanica.client.image.ImageMediateur;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
 
-
 
6
import com.google.gwt.user.client.Event;
5
 
7
import com.google.gwt.user.client.ui.ClickListener;
6
import com.google.gwt.user.client.ui.ClickListener;
8
import com.google.gwt.user.client.ui.Image;
-
 
9
import com.google.gwt.user.client.ui.MouseListener;
7
import com.google.gwt.user.client.ui.Image;
10
import com.google.gwt.user.client.ui.MouseListenerAdapter;
8
import com.google.gwt.user.client.ui.MouseListenerAdapter;
11
import com.google.gwt.user.client.ui.Widget;
-
 
12
import com.gwtext.client.core.EventObject;
9
import com.google.gwt.user.client.ui.Widget;
13
import com.gwtext.client.widgets.Panel;
10
import com.gwtext.client.widgets.Panel;
14
 
11
 
15
public class BarreNotationVue extends Panel implements Rafraichissable {
12
public class BarreNotationVue extends Panel implements Rafraichissable {
16
 
13
 
17
	private ImageMediateur iMediateur = null ;
14
	private ImageMediateur iMediateur = null ;
18
	private int noteEnCours = 0 ;
15
	private int noteEnCours = 0 ;
19
	private int noteMax = 0 ;
16
	private int noteMax = 0 ;
20
	private int noteCurseur = 0 ;
17
	private int noteCurseur = 0 ;
21
	private boolean estNote = false ;
18
	private boolean estNote = false ;
22
	private Image[] etoiles = null ;
19
	private Image[] etoiles = null ;
23
	
20
	
24
	private BarreNotationVue()
21
	private BarreNotationVue()
25
	{
22
	{
26
		super() ;
23
		super() ;
27
	}
24
	}
28
	
25
	
29
	public BarreNotationVue(ImageMediateur im, int noteMax)
26
	public BarreNotationVue(ImageMediateur im, int noteMax)
30
	{
27
	{
31
		iMediateur = im ;
28
		iMediateur = im ;
32
		setNoteMax(noteMax) ;
29
		setNoteMax(noteMax) ;
33
		this.setSize(200, 100) ;
30
		this.setSize(200, 100) ;
34
		this.setBodyBorder(false) ;
31
		this.setBodyBorder(false) ;
35
		this.setBorder(false) ;
32
		this.setBorder(false) ;
36
		
33
		
37
		ajouterListeners() ;
34
		ajouterListeners() ;
38
		
35
		
39
	}
36
	}
40
	
37
	
41
	public void ajouterListeners()
38
	public void ajouterListeners()
42
	{
39
	{
43
		for (int i = 0; i < etoiles.length; i++) {
40
		for (int i = 0; i < etoiles.length; i++) {
44
			
41
			
45
			noteCurseur = i ;
42
			noteCurseur = i ;
46
			
43
			
47
			etoiles[i].addMouseListener(new MouseListenerAdapter() {
44
			etoiles[i].addMouseListener(new MouseListenerAdapter() {
48
 
45
 
-
 
46
 
49
 
47
				
50
				public void onMouseEnter(Widget sender) {
48
				public void onMouseEnter(Widget sender) {
51
					
49
					
52
					Image enCours = (Image)sender ;
50
					Image enCours = (Image)sender ;
53
					int nEnCours = 0 ;
51
					int nEnCours = 0 ;
54
					
52
					
55
					for(int i = 0 ; etoiles[i] != enCours ; i++)
53
					for(int i = 0 ; etoiles[i] != enCours ; i++)
56
					{
54
					{
57
						etoiles[i].setUrl("etoile_curseur.jpg") ;
55
						etoiles[i].setUrl("etoile_curseur.jpg") ;
58
						nEnCours = i ;
56
						nEnCours = i ;
59
					}
57
					}
60
						enCours.setUrl("etoile_curseur.jpg") ;
58
						enCours.setUrl("etoile_curseur.jpg") ;
61
					
59
					
62
				}
60
				}
-
 
61
 
63
 
62
				
64
				public void onMouseLeave(Widget sender) {
63
				public void onMouseLeave(Widget sender) {
65
				
64
				
66
					afficherNote() ;
65
					afficherNote() ;
67
				}
66
				}
68
 
67
 
69
				
68
				
70
			}) ;
69
			}) ;
71
			
70
			
72
			etoiles[i].addClickListener(new ClickListener() {
71
			etoiles[i].addClickListener(new ClickListener() {
73
 
72
 
74
				public void onClick(Widget sender) {
73
				public void onClick(Widget sender) {
75
					
74
					
76
					int i = 0 ;
75
					int i = 0 ;
77
					
76
					
78
					while(etoiles[i] != (Image)sender)
77
					while(etoiles[i] != (Image)sender)
79
					{
78
					{
80
						i++ ;
79
						i++ ;
81
					}			
80
					}			
82
					
81
					
83
					noter(i) ;
82
					noter(i) ;
84
					System.out.println("Nouvelle note : "+noteEnCours);
-
 
85
					
83
					
86
				}
84
				}
87
				
85
				
88
				
86
				
89
			}) ;
87
			}) ;
90
		}
88
		}
91
		
89
		
92
	}
90
	}
93
	
91
	
94
	
92
	
95
	public void rafraichir(Object nouvelleDonnees,
93
	public void rafraichir(Object nouvelleDonnees,
96
			boolean repandreRaffraichissement) {
94
			boolean repandreRaffraichissement) {
97
		
95
		
98
		if(nouvelleDonnees instanceof String[])
96
		if(nouvelleDonnees instanceof String[])
99
		{
97
		{
100
			estNote = false ;
98
			estNote = false ;
101
			
99
			
102
			String[] note = (String[])nouvelleDonnees ;
100
			String[] note = (String[])nouvelleDonnees ;
103
			int noteInt = Integer.parseInt(note[0]) ;
101
			int noteInt = Integer.parseInt(note[0]) ;
104
			
102
	
105
			System.out.println("Note reçue : "+noteInt);
-
 
106
			if(noteInt != -1)
103
			if(noteInt != -1)
107
			{
104
			{
108
				noter(noteInt) ;
105
				noter(noteInt) ;
109
			}
106
			}
110
			else
107
			else
111
			{
108
			{
112
				noteEnCours = 0 ;
109
				noteEnCours = 0 ;
113
				afficherNote() ;
110
				afficherNote() ;
114
			}
111
			}
115
			
112
			
116
		}
113
		}
117
		
114
		
118
	}
115
	}
119
	
116
	
120
	public void noter(int note)
117
	public void noter(int note)
121
	{
118
	{
122
		noteEnCours = note ;
119
		noteEnCours = note ;
123
		estNote = true ;
120
		estNote = true ;
124
		afficherNote() ;
121
		afficherNote() ;
125
	}
122
	}
126
	
123
	
127
	public void setNoteMax(int nMax)
124
	public void setNoteMax(int nMax)
128
	{
125
	{
129
		noteMax = nMax ;
126
		noteMax = nMax ;
130
		etoiles = new Image[noteMax] ;
127
		etoiles = new Image[noteMax] ;
131
		
128
		
132
		for(int i = 0 ; i < noteMax ; i++)
129
		for(int i = 0 ; i < noteMax ; i++)
133
		{
130
		{
134
			etoiles[i] = new Image("etoile_vide.jpg") ;
131
			etoiles[i] = new Image("etoile_vide.jpg") ;
135
			this.add(etoiles[i]) ;
132
			this.add(etoiles[i]) ;
136
		}
133
		}
137
	}
134
	}
138
	
135
	
139
	public void afficherNote()
136
	public void afficherNote()
140
	{
137
	{
141
		if(estNote)
138
		if(estNote)
142
		{
139
		{
143
			for(int i = 0 ; i <= noteEnCours ; i++)
140
			for(int i = 0 ; i <= noteEnCours ; i++)
144
			{
141
			{
145
				etoiles[i].setUrl("etoile_notee.jpg") ;
142
				etoiles[i].setUrl("etoile_notee.jpg") ;
146
			}
143
			}
147
			
144
			
148
			for (int j = noteEnCours + 1 ; j < noteMax ; j++) 
145
			for (int j = noteEnCours + 1 ; j < noteMax ; j++) 
149
			{						
146
			{						
150
				etoiles[j].setUrl("etoile_vide.jpg") ;						
147
				etoiles[j].setUrl("etoile_vide.jpg") ;						
151
			}
148
			}
152
		}
149
		}
153
		else
150
		else
154
		{
151
		{
155
			for(int i = 0 ; i < noteMax ; i++)
152
			for(int i = 0 ; i < noteMax ; i++)
156
			{
153
			{
157
				etoiles[i].setUrl("etoile_vide.jpg") ;
154
				etoiles[i].setUrl("etoile_vide.jpg") ;
158
			}
155
			}
159
		}
156
		}
160
		
157
		
161
		
158
		
162
	}
159
	}
163
	
160
	
164
	public String getNote()
161
	public String getNote()
165
	{
162
	{
166
		return ""+noteEnCours ;
163
		return ""+noteEnCours ;
167
	}
164
	}
168
 
165
 
169
}
166
}