// PhiControls.java
/* A Java class for
 * SingleStub.java
 * Electromagnetic Transmission Line Applet
 * Applet without Smith Chart - Prepared by Umberto Ravaioli 
 * for 6th edition of Fundamentals of Applied Electromagnetics Book
 * June 2009 - All Rights Reserved
 */   

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

class PhiControls extends Panel implements AdjustmentListener{
	StateVars state;
	
	Scrollbar slider1;
	final int ScrollMin=0;
	final int ScrollMax=1001;
	public double phi;
	
	public PhiControls (StateVars state){
		super();
		this.state = state;
		setBackground(Color.white);
		setLayout(null);
		slider1=new Scrollbar(Scrollbar.HORIZONTAL,ScrollMax/2,1,ScrollMin,ScrollMax);
		slider1.addAdjustmentListener(this);
		add(slider1);
		
		slider1.setBounds(27,3,370,15);
		
		Panel pslider1 = new Panel();
		    pslider1.setBackground(Color.black);
		    add(pslider1);
		    pslider1.setBounds(26,2,372,17);
	    
		state.frequency_scan = state.frequency;
	}
	
	public void paint(Graphics g){
	
	    g.setColor(Color.green);
	    MaestroG.fillCircle(12,10,6,g);
	    g.setColor(Color.black);
	    MaestroG.drawCircle(12,10,6,g);
	    
	    g.drawLine(0,0,0,getSize().height);
	    g.drawLine(getSize().width-1,0,getSize().width-1,getSize().height);
	
	}

    	public void jrupdate(){
		Graphics g = getGraphics();
		
		if(slider1.getValue()>ScrollMax){
		    slider1.setValue(ScrollMax-1);
		}
		else{
		   
		}
		g.dispose();
		
	}


	public void adjustmentValueChanged(AdjustmentEvent evt){
		if(slider1.getValue()>ScrollMax){
		    state.frequency = state.frequency_maximum;
		}
		else{
		    state.frequency_scan=((double)slider1.getValue()/(double)(ScrollMax-1))*(state.frequency_maximum - state.frequency_minimum)+state.frequency_minimum;
		}
		//System.out.println(state.frequency_scan);
		jrupdate();
	}
}
