import java.awt.*; 
import java.awt.event.*;
//import java.applet.*;
 
public class OpticalFiber1 extends Frame implements AdjustmentListener, ActionListener, ItemListener, MouseListener, WindowListener{

    private static final Color bgcolor = new Color(230,230,230);
    Instructions instructions;
    Panel instrFrame;
    TitlePanel titlepanel;
    ObliqueCanvas o_canvas;
    ObliqueOutputPanelB outputpanelB;
    ObliqueInputPanel  inputpanel;
    Oblique_State state;

public static void main(String[] args){
        int xmove = 20;
        int ymove = 41;
        OpticalFiber1 f = new OpticalFiber1();
        f.setSize(1234+xmove,700+ymove);
        f.setVisible(true);
        //f.setLayout(new FlowLayout());
        f.setLayout(null);
}

public OpticalFiber1(){
    setBackground(bgcolor);
    setLayout(null);
    
    int xmove = 10;
    int ymove = 34;

    titlepanel = new TitlePanel("Module 8.2","Multimode","Step-Index","Optical Fiber");
    instructions = new Instructions();
    state = new Oblique_State();
    o_canvas = new ObliqueCanvas(state);
    outputpanelB = new ObliqueOutputPanelB(state);
    inputpanel  = new ObliqueInputPanel(state);
    instructions.setBounds(10+xmove,374+ymove,1214,315);
    instrFrame = new Panel();
    instrFrame.setBackground(Color.black);
    instrFrame.setBounds(9+xmove,373+ymove,1216,317);
    titlepanel.setBounds(9+xmove,9+ymove,300,71);
    o_canvas.setBounds(9+xmove,85+ymove,1216,283);
    outputpanelB.setVisible(true);
    outputpanelB.setBounds(10+xmove,374+ymove,1214,315);
    inputpanel.setBounds(314+xmove,10+ymove,911,70);
    
    Panel p0 = new Panel();
        p0.setBackground(Color.cyan);
	//add(p0);
	p0.setBounds(3+xmove,3+ymove,1228,694);
	    
    Panel p00 = new Panel();
	p00.setBackground(Color.black);
	//add(p00);
	p00.setBounds(xmove,ymove,1234,700);
    
        add(instructions);
        add(outputpanelB);
        add(instrFrame);
        add(inputpanel);
        add(titlepanel);
        add(o_canvas);
        add(p0);
	add(p00); 
                
    //Listeners
    this.addWindowListener(this);
    instructions.bupdate.addActionListener(this);	
    inputpanel.slider.addAdjustmentListener(this);
    inputpanel.slider2.addAdjustmentListener(this);	
    inputpanel.slider_scale.addAdjustmentListener(this);	
    
    inputpanel.b1.addActionListener(this);
    inputpanel.c1.addItemListener(this);
    inputpanel.c2.addItemListener(this);
    //inputpanel.Instructions.addActionListener(this);
    outputpanelB.Instructions.addActionListener(this);
    outputpanelB.Dispersion.addActionListener(this);
    outputpanelB.Propagation.addActionListener(this);
   }

public void paint(Graphics g){
    
}   

    public void mouseClicked(MouseEvent evt){}
    public void mouseEntered(MouseEvent evt){}
    public void mouseExited(MouseEvent evt){}
    public void mousePressed(MouseEvent evt){}
    public void mouseReleased(MouseEvent evt){}
    
    public void start(){}
    public void stop(){}
    
    public void windowClosing(WindowEvent e) {
        dispose();
        System.exit(0);
    }
    
    public void windowOpened(WindowEvent evt){}
    
    public void windowIconified(WindowEvent evt){}
    
    public void windowClosed(WindowEvent evt){}
    
    public void windowDeiconified(WindowEvent evt){}
    
    public void windowActivated(WindowEvent evt){}
    
    public void windowDeactivated(WindowEvent evt){}
    
    
    public void adjustmentValueChanged(AdjustmentEvent evt){
        
        o_canvas.repaint();
        outputpanelB.pwocD.repaint();
        outputpanelB.pwocE.repaint();
        outputpanelB.pwocF.repaint();
        
        state.ignition();
    }
    
    public void actionPerformed(ActionEvent evt){
        if(evt.getSource()==outputpanelB.Instructions){
                instructions.setVisible(true);
                //instrFrame.setVisible(false);
                outputpanelB.setVisible(false);
        }
        
        if(evt.getSource()==outputpanelB.Dispersion){
                outputpanelB.Dispersion.setVisible(false);
                outputpanelB.Propagation.setVisible(true);
                outputpanelB.pwocD.setVisible(false);
                outputpanelB.pwocE.setVisible(true);
                outputpanelB.pwocF.setVisible(true);
                outputpanelB.pwocD.repaint();
                outputpanelB.pwocE.repaint();
                outputpanelB.pwocF.repaint();
                
                outputpanelB.sliderT.setVisible(true);
                outputpanelB.pT.setVisible(true); 
                outputpanelB.Tlabel.setVisible(true);
        }
        if(evt.getSource()==outputpanelB.Propagation){
                outputpanelB.Dispersion.setVisible(true);
                outputpanelB.Propagation.setVisible(false);
                outputpanelB.pwocD.setVisible(true);
                outputpanelB.pwocE.setVisible(false);
                outputpanelB.pwocF.setVisible(false);
                outputpanelB.pwocD.repaint();
                outputpanelB.pwocE.repaint();
                outputpanelB.pwocF.repaint();
                
                outputpanelB.sliderT.setVisible(false);
                outputpanelB.pT.setVisible(false);
                outputpanelB.Tlabel.setVisible(false);
        }
        
        if(evt.getSource()==instructions.bupdate){
                //about.setVisible(false);
                instructions.setVisible(false);
                //instrFrame.setVisible(false);
                outputpanelB.setVisible(true);
                
                if(state.ShowWhich == 1){
                    
                    instructions.setVisible(false);
                    //instrFrame.setVisible(false);
                    outputpanelB.setVisible(true);
                    state.ShowWhich = 1;
		    o_canvas.setVisible(true);
                    state.Plot2D = false;
                }
                else if(state.ShowWhich == 2){
                    
                    state.ShowWhich = 2;
                    instructions.setVisible(false);
                    //instrFrame.setVisible(false);
                    outputpanelB.setVisible(true);
                    o_canvas.setVisible(false);
                    state.Plot2D = true;
                    state.ignition();
                }
                else if(state.ShowWhich == 3){
                    state.ShowWhich = 3;
                    o_canvas.setVisible(false);
                    state.Plot2D = false;
                    instructions.setVisible(false);
                    outputpanelB.setVisible(true);
                }
        }
        
        
	if(evt.getSource() == inputpanel.b1){
	  state.ignition();
          o_canvas.repaint();
          outputpanelB.pwocD.repaint();
          outputpanelB.pwocE.repaint();
          outputpanelB.pwocF.repaint();
          outputpanelB.repaint();
          
          inputpanel.repaint();
          //inputpanel.panelcanvas.repaint();
          
          if(inputpanel.c1.getState()){
              inputpanel.text1.setVisible(true);
              inputpanel.text2.setVisible(true);
              inputpanel.text3.setVisible(true);
              
              inputpanel.text1b.setVisible(false);
              inputpanel.text2b.setVisible(false);
              inputpanel.text3b.setVisible(false);
          }
          
          if(inputpanel.c2.getState()){
              inputpanel.text1b.setVisible(true);
              inputpanel.text2b.setVisible(true);
              inputpanel.text3b.setVisible(true);
              inputpanel.text1.setVisible(false);
              inputpanel.text2.setVisible(false);
              inputpanel.text3.setVisible(false);   
          }
	}
    }
    
    public void itemStateChanged(ItemEvent evt){
        
            ItemSelectable ie = evt.getItemSelectable();
	    
                if(ie.getSelectedObjects()[0]==" Instructions"){
		    //about.setVisible(true);
                    instructions.setVisible(true);
                    instrFrame.setVisible(true);
                    outputpanelB.setVisible(false);
                    o_canvas.setVisible(false);
                    state.Plot2D = false;
		}
	        
        if(evt.getSource() == inputpanel.c1){
              inputpanel.text1.setVisible(true);
              inputpanel.text2.setVisible(true);
              inputpanel.text3.setVisible(true);
              
              inputpanel.text1b.setVisible(false);
              inputpanel.text2b.setVisible(false);
              inputpanel.text3b.setVisible(false);
              
              state.Show_index = false;
              o_canvas.repaint();
              outputpanelB.pwocD.repaint();
              outputpanelB.pwocE.repaint();
              outputpanelB.pwocF.repaint();
              outputpanelB.repaint();
        }
        if(evt.getSource() == inputpanel.c2){
              inputpanel.text1b.setVisible(true);
              inputpanel.text2b.setVisible(true);
              inputpanel.text3b.setVisible(true);
              
              inputpanel.text1.setVisible(false);
              inputpanel.text2.setVisible(false);
              inputpanel.text3.setVisible(false);
              
              state.Show_index = true;
              o_canvas.repaint();
              outputpanelB.pwocD.repaint();
              outputpanelB.pwocE.repaint();
              outputpanelB.pwocF.repaint();
              outputpanelB.repaint();
        }         
      }
    }

 
