/*
  This file ships under the GNU-COPYLEFT.
  See: http://www.gnu.org/

  Changes:
  2002-11-9:
  The awt function Button.action() is depreciated.
  The buttons are now handled via eventAction-registration.

  Notes:
  2002-11-9:
  ...ups, AWT-based user interface is going to be depreciated...
  Have to switch over to the swing-based user interface.

  2002-12-8:
  Set _t to _t_min at the start of the applet.

*/

// import Plot;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Dimension;
import java.awt.Panel;
import java.awt.Button;
import java.awt.event.*;


public class PlotAnimation
    extends Plot
{
    public double delta_t_min=0.0;
    public double delta_t_max=0.0;
    public double acceleration_rate=1.5;

    public void set_t_range(double tmin, double tmax, double dt)
    {
	super.set_t_range(tmin,tmax,dt);
	delta_t_min = 0.1*dt;
	delta_t_max = 10.0*dt;
    }

     public void init()
    {
	// Zuerst Initialisierung durch Plot()
	super.init();
	// Platz fuer zusaetzliche Tasten schaffen:
	// ToDo: An tatsaechliche Tastengroesse anpassen!
	Dimension size = graph_size();
	size.height -= 40;
	
	set_graph_dimensions( new Dimension(0,0), size);
    }
   
    public PlotAnimation()
    {
	setLayout(new BorderLayout());
	Panel p = new Panel();
	p.setLayout(new FlowLayout());
	add("South", p);
	Button _button;

	// Button "Stopp" ////////////////////////////////////////////////////
	_button=new Button("Stopp");
	_button.addActionListener( new ActionListener()
	    { public void actionPerformed(ActionEvent e) {
		wave_action = NOT_RUNNING;
	    }}); // End of addActionListener
	p.add(_button); // End of Button "Stopp"

	// Button "Schritt" //////////////////////////////////////////////////
	_button=new Button("Schritt");
	_button.addActionListener( new ActionListener()
	    { public void actionPerformed(ActionEvent e) {
		wave_action = NOT_RUNNING;
		time_step();
	    }});
	p.add(_button); // End of Button "Schritt"

	// Button "Weiter" ///////////////////////////////////////////////////
	_button = new Button("Start/Weiter");
	_button.addActionListener( new ActionListener()
	    { public void actionPerformed(ActionEvent e) {
		wave_action = RUNNING;
	    }});
	p.add(_button); // End of Button "Weiter"

	// Button "Schneller" ////////////////////////////////////////////////
	_button=new Button("Schneller");
	_button.addActionListener( new ActionListener()
	    { public void actionPerformed(ActionEvent e) {
			if( delta_t < delta_t_max )
			    {
				delta_t *= acceleration_rate;
			    }		
	    }});
	p.add(_button);

	// Button "Langsamer" ////////////////////////////////////////////////
	_button=new Button("Langsamer");
	_button.addActionListener( new ActionListener()
	    { public void actionPerformed(ActionEvent e) {
			if( delta_t > delta_t_min )
			    {
				delta_t /= acceleration_rate;
			    }		
	    }});
	p.add(_button);
    }
}
