FileDocCategorySizeDatePackage
SliderComp.javaAPI DocJMF 2.1.1e1786Mon May 12 12:20:52 BST 2003com.sun.media.ui

SliderComp

public class SliderComp extends BasicComp implements ActionListener

Fields Summary
float
value
float
minValue
float
maxValue
float
initialValue
Scroll
scroll
TextField
tfIndicator
private static final int
MIN
private static final int
MAX
private static final int
PAGESIZE
Constructors Summary
public SliderComp(String label, float min, float max, float initial)

    
             
	super(label);
	this.minValue = min;
	this.maxValue = max;
	this.initialValue = initial;
	this.value = initial;
	
	setLayout(new BorderLayout());
	Label lab = new Label(label, Label.LEFT);
	add("West", lab);

	scroll = new Scroll();

	add("Center", scroll);
	scroll.setActionListener(this);
	scroll.setValue(toRatio(value));
	
	//tfIndicator = new TextField(5);
	//add("East", tfIndicator);
	//tfIndicator.addActionListener(this);
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent ae)

	float scrollValue = scroll.getValue();
	value = fromRatio(scrollValue);
	//tfIndicator.setText(Float.toString(value));
	informListener();	
    
private floatfromRatio(float value)

	return value * (maxValue - minValue) + minValue;
    
public floatgetFloatValue()

	return value;
    
public intgetIntValue()

	return (int) value;
    
public voidsetValue(int value)

	this.value = (float) value;
	scroll.setValue(toRatio(value));
    
public voidsetValue(float value)

	this.value = value;
	scroll.setValue(toRatio(value));
    
private floattoRatio(float value)

	float diff = maxValue - minValue;
	return (value - minValue) / diff;