//PlaneWaveSlidePanel.java

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.lang.*;  

public class PlaneWaveSlidePanel extends Panel implements AdjustmentListener{
    //private static final Color bgcolor = Color.lightGray;
    private static final Color bgcolor = new Color(246,246,246);
    private static final Color labcolor1 = Color.black;
    private static final Color labcolor2 = Color.red.darker();
    public Scrollbar slider1, slider2;
    public Label lab1, lab1a, lab2, lab2a;
    private int SCROLLMIN=0, SCROLLMAX=1001;
    private PlaneWave_State state;
    private final Font labelfont=new Font("Sanserif",Font.PLAIN,11);
    private final Font labelfont2=new Font("Sanserif",Font.BOLD,11);
        
    public PlaneWaveSlidePanel(PlaneWave_State state){
	super();
	this.state = state;
	setLayout(null);
	setBackground(bgcolor);
	
	slider1 = new Scrollbar(Scrollbar.HORIZONTAL,SCROLLMIN,1,SCROLLMIN,SCROLLMAX);
	slider1.setBackground(Color.white);
        slider2 = new Scrollbar(Scrollbar.HORIZONTAL,SCROLLMAX-1,1,SCROLLMIN,SCROLLMAX);
        slider2.setBackground(Color.white);
        int reduce = 50;
        
	setForeground(labcolor1);
	lab1  = new Label("A",Label.LEFT);
        lab1a  = new Label("A",Label.RIGHT);
        
	lab1.setFont(labelfont2);
	lab1a.setFont(labelfont2);
	
        add(slider1);
	add(lab1);
	add(lab1a);
	slider1.setBounds(75,2,745-reduce,15);
	lab1.setBounds(835-reduce,1,20,15);
	lab1.setForeground(labcolor1);
	lab1a.setBounds(40,1,20,15);
	lab1a.setForeground(labcolor1);
	
	//setForeground(labcolor2);
	
	lab2  = new Label("B",Label.LEFT);
	lab2.setForeground(labcolor2);
	lab2a  = new Label("B",Label.RIGHT);
	lab2a.setForeground(labcolor2);
	
	lab2.setFont(labelfont2);
	lab2a.setFont(labelfont2);
	
        add(slider2);
	add(lab2);
	add(lab2a);
	
	slider2.setBounds(75,20,745-reduce,15);
	lab2.setBounds(835-reduce,21,20,15);
	lab2a.setBounds(40,21,20,15);
	
	Panel p1 = new Panel();
	    p1.setBackground(Color.black);
	    add(p1);
	    p1.setBounds(74,1,747-reduce,17);
	   
	Panel p2 = new Panel();
	    p2.setBackground(Color.black);
	    //add(p2);
	    p2.setBounds(73,2,747-reduce,13);
	    
	Panel p3 = new Panel();
	    p3.setBackground(Color.black);
	    add(p3);
	    p3.setBounds(74,19,747-reduce,17);
	   
	Panel p4 = new Panel();
	    p4.setBackground(Color.black);
	    //add(p4);
	    p4.setBounds(73,19,747-reduce,13);
	
	//Listeners
	slider1.addAdjustmentListener(this);	
	slider2.addAdjustmentListener(this);
    }
    
    public void adjustmentValueChanged(AdjustmentEvent evt){
	double temp, temp2;
	if(evt.getSource()==slider1){
		//setForeground(labcolor1);
		SCROLLMAX = slider1.getMaximum();
		SCROLLMIN = slider1.getMinimum();
		if(state.total_length-(SCROLLMAX-SCROLLMIN-1-slider1.getValue())*
		    state.total_length/(SCROLLMAX-SCROLLMIN-1)>state.total_length){
		    state.zpos[0] = state.total_length;
		    temp2 = state.total_length*state.wavelength;	    
		    //vlab3.setText("  "+MaestroA.rounder(state.total_length*state.wavelength,5)+" m ");
		    slider1.setValue(SCROLLMAX-1);
		}
		else{    
		    state.zpos[0] = state.total_length-(SCROLLMAX-SCROLLMIN-1-slider1.getValue())*state.total_length/(SCROLLMAX-SCROLLMIN-1);
		    temp2 = state.zpos[0]*state.wavelength;
		    //vlab3.setText("  "+MaestroA.rounder(state.zpos[0]*state.wavelength,5)+" m ");    
		}
		
	}
	else if(evt.getSource()==slider2){
		//setForeground(labcolor2);
		SCROLLMAX = slider2.getMaximum();
		SCROLLMIN = slider2.getMinimum();
		if(state.total_length-(SCROLLMAX-SCROLLMIN-1-slider2.getValue())*
		    state.total_length/(SCROLLMAX-SCROLLMIN-1)>state.total_length){
		    state.zpos[1] = state.total_length;
		    temp2 = state.total_length*state.wavelength;
		    slider2.setValue(SCROLLMAX-1);
		}
		else{    
		    state.zpos[1] = state.total_length-(SCROLLMAX-SCROLLMIN-1-slider2.getValue())*state.total_length/(SCROLLMAX-SCROLLMIN-1);
		    temp2 = state.zpos[1]*state.wavelength;   
		}   
	}
    }
    
    
    public synchronized void reset(){
	    double temp, temp2;
	    state.zpos[0] = 0.0;
	    state.zpos[1] = 1.0*state.total_length;
	    slider2.setValue(slider1.getMaximum());
	    temp2 = state.total_length*state.wavelength;
	    
	    slider1.setValue(slider2.getMinimum());
    }
}



