//TransSlidePanel.java

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


public class TransSlidePanel extends Panel implements AdjustmentListener, ActionListener{
        public Scrollbar slider, slider2;
	private Label vlab1, vlab2, vlab3;
	private double lineLength = 1.50, lineLength_part1 = 1.50, lineLength_part2 = 0.0;
        private int linecounter1 = 1000;
        private int linecounter2 = 0;
        private final Font labelfont=new Font("Sanserif",Font.PLAIN,12);
        private final Font labelfontS=new Font("Serif",Font.PLAIN,12);
	private static final Color bgcolor = new Color(255,255,255);
	private static final Color tinta = new Color(236,236,236);
        private int xplus = 497;
	public Button b2a, b2b, b3a, b3b;
        
	public int SCROLLMIN=0, SCROLLMAX=1501, SCROLLMAX2 = 1000;
	public TransSlidePanel(){
		super();	
		setLayout(null);
		setBackground(tinta);
				
		vlab1 = new Label(" 0.0",Label.LEFT);
		vlab1.setFont(labelfont);
		vlab2 = new Label(" \u03bb",Label.LEFT);
		vlab2.setFont(labelfontS);
		
                // CHANGE #1 6/13/2017 =========================================
		// MODIFY LINE BELOW
                //vlab3 = new Label(" d  = ",Label.LEFT);
                vlab3 = new Label("d =",Label.LEFT);
                //==============================================================
		vlab3.setFont(labelfont);
		//vlab1.setBackground(bgcolor);
		vlab1.setBackground(Color.white);
		vlab2.setBackground(Color.white);
		vlab3.setBackground(Color.white);	
		//slider = new Scrollbar(Scrollbar.HORIZONTAL,10001,1,SCROLLMIN,SCROLLMAX);	
                slider = new Scrollbar(Scrollbar.HORIZONTAL,0,1,SCROLLMIN,SCROLLMAX);	
		slider2 = new Scrollbar(Scrollbar.HORIZONTAL,1000,1,SCROLLMIN,SCROLLMAX2);	
		slider.addAdjustmentListener(this);
		slider2.addAdjustmentListener(this);
                
		lineLength=1.0;		 		
	    
		//vlab1.setBounds(3,2,45,12);
		vlab3.setBounds(15,12,25,12);
		vlab2.setBounds(291+xplus,5,12,18);
		slider.setBounds(50,3,240+xplus,15);	
		slider2.setBounds(50,20,240+xplus,15);
                slider.setBackground(new Color(230,255,230));
                slider2.setBackground(Color.white);
                
		    
                // CHANGE  10/1/2017   =========================================
                b2a = new Button("<");
                b2a.setBackground(bgcolor);        
                b2b = new Button(">");
                b2b.setBackground(bgcolor);
                b3a = new Button("<");
                b3a.setBackground(bgcolor);
                b3b = new Button(">");
                b3b.setBackground(bgcolor);
                add(b2a); add(b2b); add(b3a); add(b3b);
                add(slider); add(slider2); add(vlab1); add(vlab2);
		add(vlab3);
                
                Panel slide1 = new Panel();
		    slide1.setBackground(Color.black);
		    add(slide1);
		    slide1.setBounds(49,2,242+xplus,17);
                Panel slide2 = new Panel();
		    slide2.setBackground(Color.black);
		    add(slide2);
		    slide2.setBounds(49,19,242+xplus,17);
                
                // CHANGE  9/27/2017 ===========================================
                b2a.setBounds(50,3,14,15);
                b2b.setBounds(276+xplus,3,14,15);
                b3a.setBounds(50,20,14,15);
                b3b.setBounds(276+xplus,20,14,15);
                //==============================================================
		//Listeners
		slider.addAdjustmentListener(this);
                // CHANGE 10/1/2017 ============================================
                b2a.addActionListener(this);
                b2b.addActionListener(this);
                b3a.addActionListener(this);
                b3b.addActionListener(this);
                //==============================================================
	}
	
	public void paint(Graphics g){
                
		g.setColor(bgcolor);
		g.fill3DRect(0,0,getSize().width-1,getSize().height-1,true);
                
                g.setColor(bgcolor.darker());
                g.fillRect(0,getSize().height-2,getSize().width,2);
                g.fillRect(getSize().width-2,0,2,getSize().height);
                g.setColor(bgcolor.brighter());
                g.fillRect(0,0,2,getSize().height-1);
                g.fillRect(0,0,getSize().width-2,2);
	}
	
    	public void adjustmentValueChanged(AdjustmentEvent evt){
	  if(evt.getSource()==slider){
		SCROLLMAX = slider.getMaximum();
		SCROLLMIN = slider.getMinimum();
		    vlab1.setText(" "+MaestroA.rounder((SCROLLMAX-SCROLLMIN-1-slider.getValue())*lineLength_part1/(SCROLLMAX-SCROLLMIN-1),5));    
	  }
	}
        
        public void actionPerformed(ActionEvent evt){
            if(evt.getSource()==b2a){
                slider.setValue(slider.getValue()-1);
                
            }
            else if(evt.getSource()==b2b){
                slider.setValue(slider.getValue()+1);
            }
            else if(evt.getSource()==b3a){
                slider2.setValue(slider2.getValue()-1);
            }
            else if(evt.getSource()==b3b){
                slider2.setValue(slider2.getValue()+1);
            }
        }

	
	public double getValue(){
		SCROLLMAX = slider.getMaximum();
		SCROLLMIN = slider.getMinimum();
		
		    return (MaestroA.rounder((SCROLLMAX-SCROLLMIN-1-slider.getValue())*lineLength_part1/(SCROLLMAX-SCROLLMIN-1),5));
	}
	
	public double getValue2(){
		SCROLLMAX2 = slider2.getMaximum();
		SCROLLMIN = slider2.getMinimum();
		if(lineLength < 1.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*0.0001/(double)(SCROLLMAX2-SCROLLMIN),7));
		}
		else if(lineLength >= 1.0 && lineLength < 10.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*0.001/(double)(SCROLLMAX2-SCROLLMIN),6));
		}
		else if(lineLength >= 10.0 && lineLength < 100.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*0.01/(double)(SCROLLMAX2-SCROLLMIN),5));
		}
		else if(lineLength >= 100.0 && lineLength < 1000.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*0.1/(double)(SCROLLMAX2-SCROLLMIN),4));
		}
		else if(lineLength >= 1000.0 && lineLength < 10000.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())/(double)(SCROLLMAX2-SCROLLMIN),3));
		}
		else if(lineLength >= 10000.0 && lineLength < 100000.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*10.0/(double)(SCROLLMAX2-SCROLLMIN),2));
		}
		else{
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*100.0/(double)(SCROLLMAX2-SCROLLMIN),1));
		}
		
	}
	
	public synchronized void setValue(double x){
	    slider.setValue((int)(x));
	}
	
	public synchronized void setValue2(double x){
	    slider2.setValue((int)(x));
	}
	
	public synchronized void setLineLength(double lineLength, double lineLength_part1, double lineLength_part2, int linecounter1, int linecounter2){
	    this.lineLength=lineLength;
	    this.lineLength_part1=lineLength_part1;
	    this.lineLength_part2=lineLength_part2;
	    this.linecounter1 = linecounter1;
	    this.linecounter2 = linecounter2;
	}
	
	public synchronized void reset(){
	    //vlab1.setText(" 0.0");
	    //slider.setValue(slider.getMaximum());
	    //slider2.setValue(slider2.getMaximum());
            vlab1.setText(""+lineLength);
	    slider.setValue(slider.getMinimum());
	    slider2.setValue(slider2.getMaximum()-linecounter2-1);
	}
}

/*
//TransSlidePanel.java

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


public class TransSlidePanel extends Panel implements AdjustmentListener{
    public Scrollbar slider, slider2;
	private Label vlab1, vlab2, vlab3;
	private double lineLength = 1.50, lineLength_part1 = 1.50, lineLength_part2 = 0.0;
        private int linecounter1 = 1000;
        private int linecounter2 = 0;
        private final Font labelfont=new Font("Sanserif",Font.PLAIN,12);
        private final Font labelfontS=new Font("Serif",Font.PLAIN,12);
	private static final Color bgcolor = new Color(255,255,255);
	private static final Color tinta = new Color(236,236,236);
        private int xplus = 497;
	
	public int SCROLLMIN=0, SCROLLMAX=1501, SCROLLMAX2 = 1000;
	public TransSlidePanel(){
		super();	
		setLayout(null);
		setBackground(tinta);
				
		vlab1 = new Label(" 0.0",Label.LEFT);
		vlab1.setFont(labelfont);
		vlab2 = new Label(" \u03bb",Label.LEFT);
		vlab2.setFont(labelfontS);
		
		// CHANGE #1 7/25/2017 =========================================
		// MODIFY LINE BELOW
                //vlab3 = new Label(" d  = ",Label.LEFT);
                vlab3 = new Label("d =",Label.LEFT);
                //==============================================================
		
		vlab3.setFont(labelfont);
		//vlab1.setBackground(bgcolor);
		vlab1.setBackground(Color.white);
		vlab2.setBackground(Color.white);
		vlab3.setBackground(Color.white);	
		//slider = new Scrollbar(Scrollbar.HORIZONTAL,10001,1,SCROLLMIN,SCROLLMAX);	
                slider = new Scrollbar(Scrollbar.HORIZONTAL,0,1,SCROLLMIN,SCROLLMAX);	
		slider2 = new Scrollbar(Scrollbar.HORIZONTAL,1000,1,SCROLLMIN,SCROLLMAX2);	
		slider.addAdjustmentListener(this);
		slider2.addAdjustmentListener(this);
                
		lineLength=1.0;		 		
	    
		add(slider);
		add(slider2);
		add(vlab1);
		add(vlab2);
		add(vlab3);
    
		//vlab1.setBounds(3,2,45,12);
		vlab3.setBounds(15,12,25,12);
		vlab2.setBounds(291+xplus,5,12,18);
		slider.setBounds(50,3,240+xplus,15);	
		slider2.setBounds(50,20,240+xplus,15);
                slider.setBackground(new Color(230,255,230));
                slider2.setBackground(Color.white);
                
		Panel slide1 = new Panel();
		    slide1.setBackground(Color.black);
		    add(slide1);
		    slide1.setBounds(49,2,242+xplus,17);
                Panel slide2 = new Panel();
		    slide2.setBackground(Color.black);
		    add(slide2);
		    slide2.setBounds(49,19,242+xplus,17);
		//Listeners
		//slider.addAdjustmentListener(this);	
	}
	
	public void paint(Graphics g){
                
		g.setColor(bgcolor);
		g.fill3DRect(0,0,getSize().width-1,getSize().height-1,true);
                
                g.setColor(bgcolor.darker());
                g.fillRect(0,getSize().height-2,getSize().width,2);
                g.fillRect(getSize().width-2,0,2,getSize().height);
                g.setColor(bgcolor.brighter());
                g.fillRect(0,0,2,getSize().height-1);
                g.fillRect(0,0,getSize().width-2,2);
	}
	
    	public void adjustmentValueChanged(AdjustmentEvent evt){
	  if(evt.getSource()==slider){
		SCROLLMAX = slider.getMaximum();
		SCROLLMIN = slider.getMinimum();
		    vlab1.setText(" "+MaestroA.rounder((SCROLLMAX-SCROLLMIN-1-slider.getValue())*lineLength_part1/(SCROLLMAX-SCROLLMIN-1),5));    
	  }
	}
	
	public double getValue(){
		SCROLLMAX = slider.getMaximum();
		SCROLLMIN = slider.getMinimum();
		
		    return (MaestroA.rounder((SCROLLMAX-SCROLLMIN-1-slider.getValue())*lineLength_part1/(SCROLLMAX-SCROLLMIN-1),5));
	}
	
	public double getValue2(){
		SCROLLMAX2 = slider2.getMaximum();
		SCROLLMIN = slider2.getMinimum();
		if(lineLength < 1.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*0.0001/(double)(SCROLLMAX2-SCROLLMIN),7));
		}
		else if(lineLength >= 1.0 && lineLength < 10.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*0.001/(double)(SCROLLMAX2-SCROLLMIN),6));
		}
		else if(lineLength >= 10.0 && lineLength < 100.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*0.01/(double)(SCROLLMAX2-SCROLLMIN),5));
		}
		else if(lineLength >= 100.0 && lineLength < 1000.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*0.1/(double)(SCROLLMAX2-SCROLLMIN),4));
		}
		else if(lineLength >= 1000.0 && lineLength < 10000.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())/(double)(SCROLLMAX2-SCROLLMIN),3));
		}
		else if(lineLength >= 10000.0 && lineLength < 100000.0){
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*10.0/(double)(SCROLLMAX2-SCROLLMIN),2));
		}
		else{
		    return (MaestroA.rounder((double)(SCROLLMAX2-SCROLLMIN-1-slider2.getValue())*100.0/(double)(SCROLLMAX2-SCROLLMIN),1));
		}
		
	}
	
	public synchronized void setValue(double x){
	    slider.setValue((int)(x));
	}
	
	public synchronized void setValue2(double x){
	    slider2.setValue((int)(x));
	}
	
	public synchronized void setLineLength(double lineLength, double lineLength_part1, double lineLength_part2, int linecounter1, int linecounter2){
	    this.lineLength=lineLength;
	    this.lineLength_part1=lineLength_part1;
	    this.lineLength_part2=lineLength_part2;
	    this.linecounter1 = linecounter1;
	    this.linecounter2 = linecounter2;
	}
	
	public synchronized void reset(){
	    //vlab1.setText(" 0.0");
	    //slider.setValue(slider.getMaximum());
	    //slider2.setValue(slider2.getMaximum());
            vlab1.setText(""+lineLength);
	    slider.setValue(slider.getMinimum());
	    slider2.setValue(slider2.getMaximum()-linecounter2-1);
	}
}
*/