Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
858 jpm 1
package org.tela_botanica.client.composants;
2
 
954 jpm 3
import org.tela_botanica.client.util.UtilNombre;
4
import org.tela_botanica.client.util.UtilString;
5
 
858 jpm 6
import com.extjs.gxt.ui.client.event.Events;
7
import com.extjs.gxt.ui.client.event.Listener;
8
import com.extjs.gxt.ui.client.event.SliderEvent;
9
import com.extjs.gxt.ui.client.widget.Slider;
10
import com.extjs.gxt.ui.client.widget.form.SliderField;
11
 
12
public class ChampSliderPourcentage extends SliderField {
13
 
14
	private String message = null;
15
 
16
	public ChampSliderPourcentage(String label) {
17
		super(creerSliderPoucentage(label));
18
		message = label;
19
		this.getSlider().addListener(Events.Change, new Listener<SliderEvent>() {
20
			public void handleEvent(SliderEvent be) {
21
				int pourcent = ((Slider) be.getComponent()).getValue();
955 jpm 22
				setFieldLabel(message+" ("+pourcent+"%) ");
858 jpm 23
			}
24
		});
25
		this.setFieldLabel(message);
26
	}
27
 
28
	private static Slider creerSliderPoucentage(String message) {
29
		Slider slider = new Slider();
30
		slider.setMinValue(0);
31
		slider.setMaxValue(100);
32
		slider.setValue(0);
33
		slider.setIncrement(1);
34
		slider.setMessage("{0} "+message);
35
		return slider;
36
	}
954 jpm 37
 
38
	public String getValeur() {
39
		String valeur = "";
955 jpm 40
		int pourcentage = getSlider().getValue();
41
		if (pourcentage != 0) {
42
			valeur = UtilNombre.formaterEnEntier(pourcentage);
954 jpm 43
		}
44
		return valeur;
45
	}
46
 
47
	public void peupler(String valeur) {
48
		if (!UtilString.isEmpty(valeur)) {
955 jpm 49
			setValue(UtilString.formaterEnEntier(valeur));
954 jpm 50
		}
51
	}
858 jpm 52
}