import javax.swing.*;
import jas.bean.*;
import jas.hist.*;

/**
 * A slider that may be embedded in a web page to control the
 * number of bins for a plot on the same page. The objectid of
 * the plot must be specified using the target property of the
 * RebinSlider.
 */
public class RebinSlider extends JSlider implements PageContextHook
{
	public RebinSlider()
	{
		// Defaults, can be overriden from the <object> tag
		this.setMaximum(200);
		this.setMinimum(10);
	}
	public void setTarget(String target)
	{
		this.target = target;
	}
	public String getTarget()
	{
		return target;
	}
	public void init(PageContext context) throws Exception
	{
		// The target is assumed to be a jas.bean.XMLPlot
		XMLPlot plot = (XMLPlot) context.getBean(target);
		JASHist hist = plot.getHist();
		int bins = hist.getXAxis().getBins();
		setValue(bins);
		this.hist = hist;
	}
	protected void fireStateChanged()
	{
		// Called when the slider is moved
		if (hist != null) hist.getXAxis().setBins(getValue());
		super.fireStateChanged();
	}
	public void destroy()
	{
	}
	private JASHist hist;
	private String target;

}