//ControlPanel3D.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class ControlPanel3D extends Panel implements ActionListener {
    private NewGuide_State state;
    
    private static final Color bgcolor = new Color(236,236,221);
    private static final Color circolor = Color.black;
    
    private Font labfont;
    private Font labfont2;
    private Font normalfont;
    private Font labfont3, labfont4;
    
    public int ScrollMax = 360; 
    public int offset;
    private Label titlelabel;
    private Label lab1, lab2, lab3, lab4, lab5, lab6, lab7;
    private Label ulab1, ulab2, ulab3, ulab4, ulab5, ulab6;
    public TextField text1, text2, text3, text4, text5, text6, text7, text8;
    //public Scrollbar slider1, slider2, slider3, slider5;
    public JSlider slider1;
    //public Checkbox ch1, ch2, ch3, cg1, cg2, cg3, cg4, cg5, cg6;
    //public Checkbox cplot1, cplot2, cplot3;
    //public CheckboxGroup cplot;
    public boolean show_spher1, show_spher2, show_spher3;
    public boolean show_cart1, show_cart2, show_cart3, show_cart4, show_cart5;
    public boolean show_2D_plots, show_polar_plots, show_data;

    //public  Button b1, b2, b3, b5;
    public  Button bupdate;
    
    private Image im;
    private Graphics buf;
    
    public Button bSpher1, bSpher2, bSpher3, bCart1, bCart2, bCart3, bCart4, bCart5;
    public Button bplot1, bplot2, bplot3;
        public Panel pSpher1 = new Panel();
        public Panel pSpher2 = new Panel();
        public Panel pSpher3 = new Panel();
        public Panel pCart1 = new Panel();
        public Panel pCart2 = new Panel();
        public Panel pCart3 = new Panel();
        public Panel pCart4 = new Panel();
        public Panel pCart5 = new Panel();
        public Panel pPlot1 = new Panel();
        public Panel pPlot2 = new Panel();
        public Panel pPlot3 = new Panel();
        
    public Panel ps1, ps2;
  
    public ControlPanel3D(NewGuide_State state){
	super();
	setLayout(null);
	setBackground(bgcolor);
	this.state = state;
        
        offset = state.s20;
        
        labfont = new Font("SanSerif",Font.PLAIN,state.font12);
        labfont2 = new Font("Serif",Font.BOLD,state.font12);
        labfont3 = new Font("SanSerif",Font.PLAIN,state.font11);
        labfont4 = new Font("SanSerif",Font.PLAIN,state.font10);
        normalfont = new Font("SanSerif",Font.PLAIN,state.font14);
    
	titlelabel = new Label("Radiation Plots",Label.CENTER);
	titlelabel.setFont(new Font("SanSerif",Font.BOLD,state.font16));
	add(titlelabel);
	titlelabel.setBounds(state.s10,state.s2,state.s200+state.s80,state.s18);
	titlelabel.setForeground(Color.blue);

	/*
	CheckboxGroup chgroup1 = new CheckboxGroup();
	ch1 = new Checkbox("",true,chgroup1);
        ch2 = new Checkbox("",false,chgroup1);
	ch3 = new Checkbox("",false,chgroup1);
	cg1 = new Checkbox("",false,chgroup1);
        cg2 = new Checkbox("",false,chgroup1);
	cg3 = new Checkbox("",false,chgroup1);
	cg4 = new Checkbox("",false,chgroup1);
        cg5 = new Checkbox("",false,chgroup1);
        
        
	CheckboxGroup cplot = new CheckboxGroup();
	cplot1 = new Checkbox("2D plots",true,cplot);
        cplot2 = new Checkbox("Polar plots",false,cplot);
	cplot3 = new Checkbox("Data",false,cplot);
        cplot1.setFont(labfont3);
	cplot2.setFont(labfont3);
	cplot3.setFont(labfont3);
	*/
	show_2D_plots = true;
	show_polar_plots = false;
	show_data = false;
	
	show_spher1 = true;
	show_spher2 = false;
	show_spher3 = false;
	show_cart1 = false;
	show_cart2 = false;
	show_cart3 = false;
	show_cart4 = false;
	show_cart5 = false;

	slider1 = new JSlider(0,ScrollMax); //changes phi
	//slider1 = new Scrollbar(Scrollbar.HORIZONTAL,0,1,0,ScrollMax+1);//changes phi
	slider1.setValue(45);
	add(slider1);
	
	slider1.setBounds(state.s84,state.s165,state.s198,state.s15);
	/*
        slider1.setBackground(Color.white);
	Panel ps9 = new Panel();
	    ps9.setBackground(Color.cyan);
	    add(ps9);
	    ps9.setBounds(state.s84-1,state.s165-1,state.s198+2,state.s15+2);
	    
	Panel ps10 = new Panel();
	    ps10.setBackground(Color.black);
	    add(ps10);
	    ps10.setBounds(state.s84-2,state.s165-2,state.s198+4,state.s15+4);
	*/
	    /*  NO!!! USING boolean vars and bplot1 - 3 INSTEAD
             also never setting bounds for these, so causing rogue text
                problems (and cut-off radio button) with cheerpj (on browser)

	ch1.setBackground(bgcolor);
	ch2.setBackground(bgcolor);
	ch3.setBackground(bgcolor);
	cg1.setBackground(bgcolor);
	cg2.setBackground(bgcolor);
	cg3.setBackground(bgcolor);
	cg4.setBackground(bgcolor);
	cg5.setBackground(bgcolor);
	
	ch1.setFont(labfont2);
	ch2.setFont(labfont2);
	ch2.setFont(labfont2);
	cg1.setFont(labfont2);
	cg2.setFont(labfont2);
	cg3.setFont(labfont2);
	cg4.setFont(labfont2);
	cg5.setFont(labfont2);
	
	add(ch1);
	add(ch2);
	add(ch3);
	add(cg1);
	add(cg2);
	add(cg3);
	add(cg4);
	add(cg5);
	    
	add(cplot1);
	add(cplot2);
	add(cplot3);
	*/
	//======================================================================
	//ch1.setBounds(state.s85,state.s46,state.s22,state.s20);
	//ch2.setBounds(state.s155,state.s46,state.s22,state.s20);
	//ch3.setBounds(state.s85,state.s66,state.s22,state.s20);
	//cg1.setBounds(state.s85,state.s86,state.s22,state.s20);
	//cg2.setBounds(state.s155,state.s86,state.s22,state.s20);
	//cg3.setBounds(state.s200+state.s25,state.s86,state.s22,state.s20);
	//cg4.setBounds(state.s85,state.s106,state.s22,state.s20);
	//cg5.setBounds(state.s155,state.s106,state.s22,state.s20);
        
        //======================================================================
        //bSpher1 = new Button(" X "); 
        state.ignition();
        if(state.IsMac){
            bSpher1 = new Button(" \u2714 ");
        }
        else{
            bSpher1 = new Button(" \u2713 ");
        }
        bSpher1.setBackground(Color.white);
        bSpher1.setForeground(Color.red);
        bSpher1.setFont(labfont4);
	add(bSpher1);
	bSpher1.setBounds(state.s85,state.s48,state.s22,state.s14);	
	pSpher1 = new Panel();
	    pSpher1.setBackground(Color.red);
	    add(pSpher1);
	    pSpher1.setBounds(state.s85-1,state.s48-1,state.s22+2,state.s14+2);
        
        bSpher2 = new Button(""); 
        bSpher2.setBackground(Color.white);
        bSpher2.setForeground(Color.gray);
        bSpher2.setFont(labfont4);
	add(bSpher2);
	bSpher2.setBounds(state.s155,state.s48,state.s22,state.s14);	
        pSpher2 = new Panel();
	    pSpher2.setBackground(Color.gray);
	    add(pSpher2);
	    pSpher2.setBounds(state.s155-1,state.s48-1,state.s22+2,state.s14+2);
        
        bSpher3 = new Button(""); 
        bSpher3.setBackground(Color.white);
        bSpher3.setForeground(Color.gray);
        bSpher3.setFont(labfont4);
	add(bSpher3);
	bSpher3.setBounds(state.s85,state.s68,state.s22,state.s14);	
	pSpher3 = new Panel();
	    pSpher3.setBackground(Color.gray);
	    add(pSpher3);
	    pSpher3.setBounds(state.s85-1,state.s68-1,state.s22+2,state.s14+2);
        
        bCart1 = new Button(""); 
        bCart1.setBackground(Color.white);
        bCart1.setForeground(Color.gray);
        bCart1.setFont(labfont4);
	add(bCart1);
	bCart1.setBounds(state.s85,state.s88,state.s22,state.s14);	
	pCart1 = new Panel();
	    pCart1.setBackground(Color.gray);
	    add(pCart1);
	    pCart1.setBounds(state.s85-1,state.s88-1,state.s22+2,state.s14+2);
        
        bCart2 = new Button(""); 
        bCart2.setBackground(Color.white);
        bCart2.setForeground(Color.gray);
        bCart2.setFont(labfont4);
	add(bCart2);
	bCart2.setBounds(state.s155,state.s88,state.s22,state.s14);	
	pCart2 = new Panel();
	    pCart2.setBackground(Color.gray);
	    add(pCart2);
	    pCart2.setBounds(state.s155-1,state.s88-1,state.s22+2,state.s14+2);
        
        bCart3 = new Button(""); 
        bCart3.setBackground(Color.white);
        bCart3.setForeground(Color.gray);
        bCart3.setFont(labfont4);
	add(bCart3);
	bCart3.setBounds(state.s200+state.s25,state.s88,state.s22,state.s14);	
	pCart3 = new Panel();
	    pCart3.setBackground(Color.gray);
	    add(pCart3);
	    pCart3.setBounds(state.s200+state.s25-1,state.s88-1,state.s22+2,state.s14+2);
        
        bCart4 = new Button(""); 
        bCart4.setBackground(Color.white);
        bCart4.setForeground(Color.gray);
        bCart4.setFont(labfont4);
	add(bCart4);
	bCart4.setBounds(state.s85,state.s108,state.s22,state.s14);	
	pCart4 = new Panel();
	    pCart4.setBackground(Color.gray);
	    add(pCart4);
	    pCart4.setBounds(state.s85-1,state.s108-1,state.s22+2,state.s14+2);
        
        bCart5 = new Button(""); 
        bCart5.setBackground(Color.white);
        bCart5.setForeground(Color.gray);
        bCart5.setFont(labfont4);
	add(bCart5);
	bCart5.setBounds(state.s155,state.s108,state.s22,state.s14);	
	pCart5 = new Panel();
	    pCart5.setBackground(Color.gray);
	    add(pCart5);
	    pCart5.setBounds(state.s155-1,state.s108-1,state.s22+2,state.s14+2);
        
        //======================================================================
        //cplot1.setBounds(state.s25,state.s20,state.s90,state.s20);
	//cplot2.setBounds(state.s120,state.s20,state.s105,state.s20);
	//cplot3.setBounds(state.s200+state.s25,state.s20,state.s65,state.s20);
        //======================================================================
        bplot1 = new Button("  2D Plots ");
        bplot2 = new Button("Polar Plots");
        bplot3 = new Button("   Data    ");
        bplot1.setFont(labfont3);
        bplot2.setFont(labfont3);
        bplot3.setFont(labfont3);
        bplot1.setBounds(state.s10,state.s22,state.s80,state.s15);
	bplot2.setBounds(state.s108,state.s22,state.s80,state.s15);
	bplot3.setBounds(state.s200+state.s5,state.s22,state.s80,state.s15);
        bplot1.setBackground(Color.white);
        bplot2.setBackground(Color.white);
        bplot3.setBackground(Color.white);
        bplot1.setForeground(Color.black);
        bplot2.setForeground(Color.black);
        bplot3.setForeground(Color.black);
        add(bplot1); add(bplot2); add(bplot3);
        
	pPlot1 = new Panel();
	    pPlot1.setBackground(Color.black);
	    add(pPlot1);
	    pPlot1.setBounds(state.s10-2,state.s22-2,state.s80+4,state.s15+4);
	    
	pPlot2 = new Panel();
	    pPlot2.setBackground(bgcolor);
	    add(pPlot2);
	    pPlot2.setBounds(state.s108-2,state.s22-2,state.s80+4,state.s15+4);
	
        pPlot3 = new Panel();
	    pPlot3.setBackground(bgcolor);
	    add(pPlot3);
	    pPlot3.setBounds(state.s200+state.s5-2,state.s22-2,state.s80+4,state.s15+4);
	
	lab1 = new Label("Spherical",Label.LEFT);
	lab2 = new Label("Cartesian",Label.LEFT);
	lab1.setFont(labfont);
	lab2.setFont(labfont);
	lab1.setForeground(Color.black);
	lab2.setForeground(Color.black);
	lab1.setBounds(state.s10,state.s46,state.s100,state.s14); 
	lab2.setBounds(state.s10,state.s86,state.s100,state.s14); 
	
	lab3 = new Label("Distance R = ",Label.RIGHT);
	lab3.setFont(labfont3);
	lab3.setForeground(Color.blue);
	text3 = new TextField(""+state.point_distance,8);
        text3.setFont(labfont3);
	ulab3 = new Label(" [  ]",Label.LEFT);
        ulab3.setForeground(Color.blue);
	
	lab3.setBounds(state.s15,state.s137,state.s80,state.s20);
	text3.setBounds(state.s100,state.s137,state.s80,state.s20);
	ulab3.setBounds(state.s180,state.s140,state.s30,state.s20);
	
	add(lab1);
	add(lab2);
	add(lab3);
	add(text3);
	
        Panel ptext3 = new Panel();
	    ptext3.setBackground(Color.black);
	    add(ptext3);
	    ptext3.setBounds(state.s100-1,state.s137-1,state.s80+2,state.s20+2);
        
	// update
	bupdate = new Button("Update"); bupdate.setBackground(Color.white);
        bupdate.setFont(labfont3);
	add(bupdate);
	bupdate.setBounds(state.s200+state.s20,state.s139,state.s62,state.s16);	
	Panel pupdate = new Panel();
	    pupdate.setBackground(Color.cyan);
	    add(pupdate);
	    pupdate.setBounds(state.s200+state.s20-1,state.s139-1,state.s62+2,state.s16+2);
	    
	Panel pupdate2 = new Panel();
	    pupdate2.setBackground(Color.black);
	    add(pupdate2);
	    pupdate2.setBounds(state.s200+state.s20-2,state.s139-2,state.s62+4,state.s16+4);
	   	
	//Listeners
	/*  ADJUSTMENTLISTENER AND ITEMLISTENER NOT USED
	slider1.addAdjustmentListener(this);
	ch1.addItemListener(this);
	ch2.addItemListener(this);
	ch3.addItemListener(this);
	cg1.addItemListener(this);
	cg2.addItemListener(this);
	cg3.addItemListener(this);
	cg4.addItemListener(this);
	cg5.addItemListener(this);
	cplot1.addItemListener(this);
	cplot2.addItemListener(this);
	*/
	bupdate.addActionListener(this);
        bSpher1.addActionListener(this);
        bSpher2.addActionListener(this);
        bSpher3.addActionListener(this);
        bCart1.addActionListener(this);
        bCart2.addActionListener(this);
        bCart3.addActionListener(this);
        bCart4.addActionListener(this);
        bCart5.addActionListener(this);
        bplot1.addActionListener(this);
        bplot2.addActionListener(this);
        bplot3.addActionListener(this);
    }
    
    public void paint(Graphics g){
	    if(im == null){
		im = createImage(getSize().width,getSize().height);
		buf = im.getGraphics();
		drawCanvas(buf);
	    }
	    else{
		drawCanvas(buf);
	    }
	    g.drawImage(im,0,0,null);
	    slider1.requestFocusInWindow();
    }

    //Addition to reduce flicker new routine
    public void update(Graphics g){		// added to avoid clearing
	//paint(g);
	// Do this instead, or else the slider disappears!!!
        g.setColor(bgcolor);
	g.fillRect(state.s28,state.s177-state.s14,state.s50,state.s14);
	g.setColor(Color.blue);
	g.drawString("= "+slider1.getValue()+"\u00b0",state.s28,state.s177);	
    }
    
    public void drawCanvas(Graphics g){
	Graphics2D g2d = (Graphics2D)g;
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                
	g.setColor(bgcolor);
	g.fillRect(0,0,getSize().width,getSize().height);
        
        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);
	
	g.setColor(Color.blue);
	g.setFont(new Font("Serif",Font.PLAIN,state.font14)); 
	g.drawString("\u03c6",state.s15,state.s177);
	g.setFont(new Font("Serif",Font.PLAIN,state.font13)); 
	g.drawString("= "+slider1.getValue()+".0\u00b0",state.s28,state.s177);
	
        g.setColor(Color.blue);
	g.drawRect(state.s5,state.s132,state.s200+state.s85,state.s58);
	
        g.setColor(Color.red);
	g.drawLine(state.s7,state.s43,getSize().width - state.s7, state.s43);
        
	g.setColor(Color.red);
	// CHANGE ==============================================================
        MaestroG.subscripterSymbol("| E","\u03b8"," |",g,state.font12,state.s115,state.s59);
	MaestroG.subscripter2("| E","R"," |",g,state.font12,state.s185,state.s59);
	g.setColor(Color.blue);
	MaestroG.subscripterSymbol("| H","\u03c6"," |",g,state.font12,state.s115,state.s79);
	
        g.setColor(Color.red);
	MaestroG.subscripter2("| E","x"," |",g,state.font12,state.s115,state.s99);
	MaestroG.subscripter2("| E","y"," |",g,state.font12,state.s185,state.s99);
	MaestroG.subscripter2("| E","z"," |",g,state.font12,state.s200+state.s55,state.s99);
	g.setColor(Color.blue);
	MaestroG.subscripter2("| H","x"," |",g,state.font12,state.s115,state.s119);
	MaestroG.subscripter2("| H","y"," |",g,state.font12,state.s185,state.s119);
	//======================================================================
        
	g.setColor(Color.blue); 
	   
	g.setFont(new Font("Serif",Font.PLAIN,state.font14));
	g.drawString("\u03bb",state.s185,state.s153);
	g.setFont(new Font("Serif",Font.PLAIN,state.font14));
	//drawCircle(80,80,10,circolor,g);
    }
    
    public void drawCircle(int x, int y, int radius, Color c, Graphics g){
		g.setColor(c);
		g.drawOval(x-radius,y-radius,2*radius,2*radius);
    }
    
    public void fillCircle(int x, int y, int radius, Color c, Graphics g){
		g.setColor(c);
		g.fillOval(x-radius,y-radius,2*radius,2*radius);
    }
    
    public void reset(){
                pSpher1.setBackground(Color.red);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                
                bSpher1.setForeground(Color.red);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                
                //bSpher1.setLabel(" X ");
                if(state.IsMac){
                    bSpher1.setLabel(" \u2714 ");
                }
                else{
                    bSpher1.setLabel(" \u2713 ");
                }
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                
                pPlot1.setBackground(Color.black);
                pPlot2.setBackground(bgcolor);
                pPlot3.setBackground(bgcolor);
                
                repaint();
    }


    private void redraw_button_panels() {
	pSpher1.repaint();
	pSpher2.repaint();
	pSpher3.repaint();
	pCart1.repaint();
	pCart2.repaint();
	pCart3.repaint();
	pCart4.repaint();
	pCart5.repaint();
    }


    private void redraw_plotbtn_panels() {
	pPlot1.repaint();
	pPlot2.repaint();
	pPlot3.repaint();
    }
    
    
    public void actionPerformed(ActionEvent evt){
            if(evt.getSource() == bSpher1){
	        pSpher1.setBackground(Color.red);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);

		redraw_button_panels();

                bSpher1.setForeground(Color.red);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                
                //bSpher1.setLabel(" X ");
                if(state.IsMac){
                    bSpher1.setLabel(" \u2714 ");
                }
                else{
                    bSpher1.setLabel(" \u2713 ");
                }
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
                
                //repaint();
            }
            else if(evt.getSource() == bSpher2){
                pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.red);
                pSpher3.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);

		redraw_button_panels();		
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.red);
                bSpher3.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                //bSpher2.setLabel(" X ");
                if(state.IsMac){
                    bSpher2.setLabel(" \u2714 ");
                }
                else{
                    bSpher2.setLabel(" \u2713 ");
                }
                bSpher3.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");

            }
            else if(evt.getSource() == bSpher3){
                pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.blue);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
		
		redraw_button_panels();		
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.blue);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                //bSpher3.setLabel(" X ");
                if(state.IsMac){
                    bSpher3.setLabel(" \u2714 ");
                }
                else{
                    bSpher3.setLabel(" \u2713 ");
                }
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");

		repaint();
            }
            else if(evt.getSource() == bCart1){
                pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pCart1.setBackground(Color.red);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                
		redraw_button_panels();

                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bCart1.setForeground(Color.red);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                //bCart1.setLabel(" X ");
                if(state.IsMac){
                    bCart1.setLabel(" \u2714 ");
                }
                else{
                    bCart1.setLabel(" \u2713 ");
                }
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
            }
            else if(evt.getSource() == bCart2){
                pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.red);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                
		redraw_button_panels();
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.red);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bCart1.setLabel("");
                if(state.IsMac){
                    bCart2.setLabel(" \u2714 ");
                }
                else{
                    bCart2.setLabel(" \u2713 ");
                }
                //bCart2.setLabel(" X ");
                bCart3.setLabel("");
                bCart4.setLabel("");
                bCart5.setLabel("");
            }
            else if(evt.getSource() == bCart3){
                pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.red);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.gray);
                
		redraw_button_panels();
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.red);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                //bCart3.setLabel(" X ");
                if(state.IsMac){
                    bCart3.setLabel(" \u2714 ");
                }
                else{
                    bCart3.setLabel(" \u2713 ");
                }
                bCart4.setLabel("");
                bCart5.setLabel("");
            }
            else if(evt.getSource() == bCart4){
                pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.blue);
                pCart5.setBackground(Color.gray);
                
		redraw_button_panels();
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.blue);
                bCart5.setForeground(Color.gray);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                //bCart4.setLabel(" X ");
                if(state.IsMac){
                    bCart4.setLabel(" \u2714 ");
                }
                else{
                    bCart4.setLabel(" \u2713 ");
                }
                bCart5.setLabel("");
            }
            else if(evt.getSource() == bCart5){
                pSpher1.setBackground(Color.gray);
                pSpher2.setBackground(Color.gray);
                pSpher3.setBackground(Color.gray);
                pCart1.setBackground(Color.gray);
                pCart2.setBackground(Color.gray);
                pCart3.setBackground(Color.gray);
                pCart4.setBackground(Color.gray);
                pCart5.setBackground(Color.blue);
                
		redraw_button_panels();
                
                bSpher1.setForeground(Color.gray);
                bSpher2.setForeground(Color.gray);
                bSpher3.setForeground(Color.gray);
                bCart1.setForeground(Color.gray);
                bCart2.setForeground(Color.gray);
                bCart3.setForeground(Color.gray);
                bCart4.setForeground(Color.gray);
                bCart5.setForeground(Color.blue);
                
                bSpher1.setLabel("");
                bSpher2.setLabel("");
                bSpher3.setLabel("");
                bCart1.setLabel("");
                bCart2.setLabel("");
                bCart3.setLabel("");
                bCart4.setLabel("");
                //bCart5.setLabel(" X ");
                if(state.IsMac){
                    bCart5.setLabel(" \u2714 ");
                }
                else{
                    bCart5.setLabel(" \u2713 ");
                }
                
            }
            else if(evt.getSource() == bplot1){
                pPlot1.setBackground(Color.black);
                pPlot2.setBackground(bgcolor);
                pPlot3.setBackground(bgcolor);
		redraw_plotbtn_panels();
            }
            else if(evt.getSource() == bplot2){
                pPlot1.setBackground(bgcolor);
                pPlot2.setBackground(Color.black);
                pPlot3.setBackground(bgcolor);
		redraw_plotbtn_panels();
            }
            else if(evt.getSource() == bplot3){
                pPlot1.setBackground(bgcolor);
                pPlot2.setBackground(bgcolor);
                pPlot3.setBackground(Color.black);
		redraw_plotbtn_panels();
            }
	
    }//End of actionPerformed()
    
}


