package ch.werner_randelshofer.gui;/*Copyright (C) 1999 Werner Randelshoferwerner.randelshofer@mythen.chhttp://www.mythen.ch/w.randelshofer/    Permission to use this release of MovieSlider is herebygranted without fee provided that the complete copyrightnotice and this permission notice appear in all copiesand in supporting documentation.*/import java.awt.Canvas;import java.awt.Color;import java.awt.Dimension;import java.awt.Graphics;import java.awt.Event;import ch.werner_randelshofer.gui.event.ChangeListener;import ch.werner_randelshofer.gui.event.ChangeEvent;import ch.werner_randelshofer.gui.event.EventListenerList;import ch.werner_randelshofer.gui.model.BoundedRangeModel;import ch.werner_randelshofer.gui.model.DefaultBoundedRangeModel;/**@author	Werner Randelshofer, Staldenmattweg 2, CH-6405 Immensee, Switzerland@version	1999-02-28	Created.*/public class MovieSliderextends HorizontalSlider	{	private int progressPos_;	private BoundedRangeModel progressModel_;			public MovieSlider()		{		setBackground(Color.lightGray);		setThumbWidth(8);		setThumbHeight(14);		}		public synchronized void setProgressModel(BoundedRangeModel brm)		{		if (progressModel_ != null)			{ progressModel_.removeChangeListener(this); }		progressModel_ = brm;		if (progressModel_ != null)			{ progressModel_.addChangeListener(this); }		}	public BoundedRangeModel getProgressModel()		{		return progressModel_;		}		public void update(Graphics g)		{		Dimension s = size();		int thumbWidth = getThumbWidth();		if (computeProgressPos() < progressPos_)			{			int halfThumb = thumbWidth/2;			g.setColor(getBackground());			g.fillRect(halfThumb+2,6,s.width-halfThumb-2,s.height-11);			}		g.setColor(getBackground());		g.fillRect(thumbPos_-thumbWidth/2,1,thumbWidth+1,s.height-2);		g.setColor(getForeground());		paint(g);		}	public void paint(Graphics g)		{		int thumbWidth = getThumbWidth();		int halfThumb = thumbWidth/2;		int thumbPos = computeThumbPos();		int progressPos = computeProgressPos();		thumbPos_ = thumbPos;		progressPos_ = progressPos;		Dimension s = size();				// slider border		g.drawRect(0,0,s.width-1,s.height-1);				// bar border		g.drawRect(halfThumb,4,s.width-thumbWidth-1,s.height-9);				// slider highlight		g.setColor(Color.white);		g.drawLine(1,1,s.width-2,1);		g.drawLine(1,2,1,s.height-2);				// bar highlight		g.drawLine(halfThumb+1,5,s.width-halfThumb-3,5);		g.drawLine(halfThumb+1,6,halfThumb+1,s.height-6);				// progress bar		g.setColor(Color.gray);		g.fillRect(halfThumb+2,6,progressPos,s.height-11);				// thumb		g.setColor(Color.white);		g.drawRect(thumbPos-halfThumb+1,1,thumbWidth-2,s.height-3);		g.setColor(getForeground());		g.drawRect(thumbPos-halfThumb,0,thumbWidth,s.height-1);		g.drawRect(thumbPos-halfThumb+2,2,thumbWidth-4,s.height-5);		}	protected int computeProgressPos()		{		int halfThumb = getThumbWidth() / 2;		BoundedRangeModel m = progressModel_;		int width = size().width - getThumbWidth()-3;		if (m == null)			{ return width; }		float thumbPos = m.getValue() / (float)((m.getMaximum() - m.getMinimum()));		return (int)(width * thumbPos);		}	public void stateChanged(ChangeEvent event)		{		BoundedRangeModel progress = progressModel_;		if (progress != null && event.getSource() == progress)			{			if (computeProgressPos() != progressPos_)				{ repaint(); }			}		else			{			super.stateChanged(event);			}		}	}