//TransSlidePanel.java

//import java.applet.Applet;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
//import java.lang.*;  
import java.net.*;
import java.awt.geom.*;

public class TransSlidePanel extends Panel implements AdjustmentListener, ItemListener{
        private Trans_State state;
	public Scrollbar slider, slider2, slider3, slider4, slider5, slider6, slider_mass, slider_mass_barrier;
	private Label vlab1, vlab2, vlab3;
	private double lineLength;
        private final Font labelfont=new Font("Sanserif",Font.PLAIN,12);
	private final Font labelfont2=new Font("Sanserif",Font.PLAIN,12);
        private final Font labelfont3=new Font("Sanserif",Font.PLAIN,11);
        public Panel slide1 = new Panel();
        public Panel slide2 = new Panel();
        public Panel slide3 = new Panel();
        
	//private static final Color bgcolor = new Color(216,216,191);
        private  static final Color bgcolor = new Color(200,255,255);
        public int shiftdown = 15;
        public int yplus = 0;//200;
        public Checkbox ch1, ch2, ch3, ch4, ch5, ch6, trace;
        public CheckboxGroup cbc1, cbc2, cbc3;
        
	private static final Color tinta = new Color(236,236,221);
	private boolean Is_Millimeter;
	public int SCROLLMIN=0, SCROLLMAX=351, SCROLLMAXW = 101, SCROLLMINW = 5, SCROLLMAX_TIME = 5001;
        public int SCROLLMIN_Lambda = 300, SCROLLMAX_Lambda = 751;
	public TransSlidePanel(Trans_State state){
		super();	
		setLayout(null);
		setBackground(Color.white);
                //setBackground(bgcolor);
                                
                this.state = state;
                
                CheckboxGroup cbc1 = new CheckboxGroup();
                ch1 = new Checkbox("Horizontal Plane",false,cbc1);
                ch1.setForeground(Color.red.darker());
                ch2 = new Checkbox("Vertical Plane",true,cbc1);
                ch2.setForeground(Color.blue.darker());
                add(ch1); add(ch2); 
                
                trace = new Checkbox("Current Animation",false);
                
                CheckboxGroup cbc2 = new CheckboxGroup();
                ch3 = new Checkbox("Smooth Palette",true,cbc2);
                ch3.setForeground(Color.blue);
                ch4 = new Checkbox("Coarse  Palette",false,cbc2);
                ch4.setForeground(Color.red);
                //add(ch3); add(ch4);
                
                CheckboxGroup cbc3 = new CheckboxGroup();
                ch5 = new Checkbox("32 levels",true,cbc3);
                ch5.setForeground(Color.red);
                ch6 = new Checkbox("16 levels",false,cbc3);
                ch6.setForeground(Color.red);
                //add(ch5); add(ch6); 
                ch5.setVisible(false);
                ch6.setVisible(false);
                
		vlab1 = new Label("100.0",Label.LEFT);
		vlab1.setFont(labelfont);
		
		vlab2 = new Label("mm",Label.LEFT);
		vlab3 = new Label("mils",Label.LEFT);
		
		vlab2.setFont(labelfont2);
		vlab3.setFont(labelfont2);
		
		vlab1.setBackground(Color.white);
		vlab2.setBackground(Color.white);
		
		slider3 = new Scrollbar(Scrollbar.HORIZONTAL,20,1,SCROLLMINW,SCROLLMAXW);// width of barrier
		//slider3.setBlockIncrement(10);	
		slider3.addAdjustmentListener(this);
                slider3.setBackground(new Color(230,230,255));
		
                
                lineLength=100.0;
		Is_Millimeter = true;		 		
	    
		add(slider3);
                ch1.setBounds(5,50,140,18);
                ch2.setBounds(145,50,120,18);
		
                ch3.setBounds(30,60,120,15);
                ch4.setBounds(30,77,110,15);
		
                ch5.setBounds(165,60,70,15);
                ch6.setBounds(165,77,70,15);
		
                trace.setBounds(30,75,150,20); 
                trace.setForeground(Color.black);
                add(trace);
                
                slider3.setBounds(28,22,220,15);	
		slider3.setBackground(Color.white);
                
                    slide3.setBackground(Color.cyan);
		    add(slide3);
		    slide3.setBounds(27,21,222,17);
		    slide2.setBackground(Color.black);
		    add(slide2);
		    slide2.setBounds(26,20,224,19);
                    
                slider3.addAdjustmentListener(this);       
        }
	
	
	public void paint(Graphics g){
		//g.setColor(bgcolor);
		//g.fill3DRect(0,0,getSize().width-1,getSize().height-1,true);
            
            g.clearRect(0,0,getSize().width-1,getSize().height-1);
		
		//Draw the background	
		g.setColor(Color.black);
		g.drawLine(0,getSize().height-1,getSize().width-1,getSize().height-1);
		g.drawLine(getSize().width-1,0,getSize().width-1,getSize().height-1);
		//g.setColor(Color.white);
		
		g.drawLine(0,0,getSize().width-1,0);
		g.drawLine(0,0,0,getSize().height-1);

            int plus = 44;
                        
            Graphics2D g2d = (Graphics2D)g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
            
            double range;
            range = state.delta_lambda * state.Nx / 2;
            
            g.setColor(Color.black);
            MaestroG.Custom3("Plot Range",""," = "+MaestroA.rounder(range,2)," \u03bb",g,12,80,15);
            //g.drawLine(20,53,getSize().width-20,53);
            
            g.setColor(Color.red);
            
            if(state.IsThreshold){
                g.drawLine(150,85,130,85);
                g.drawRect(150,55,95,40);
            }
	}
        
    	public void adjustmentValueChanged(AdjustmentEvent evt){
		     
		if(evt.getSource()==slider || evt.getSource()==slider2 || evt.getSource()==slider3 ||
                   evt.getSource()==slider4 || evt.getSource()==slider5 || evt.getSource()==slider6 ||
                   evt.getSource()==slider_mass || evt.getSource()==slider_mass_barrier){
                        //System.out.println("slider = "+slider3.getValue());
                       repaint();
                }
		
	}
        
        public void itemStateChanged(ItemEvent evt){
	    ItemSelectable ie = evt.getItemSelectable();
	    
            if(evt.getSource()== trace){
                repaint();
            }
        }
        
	public synchronized void reset(){
	    
	    //slider.setValue(slider.getMaximum());
	    {
	      // vlab1.setText(""+lineLength);
	      // vlab2.setText("mm");
	    }
	    
	}
}//End of TransSlidePanel

