package SesameGUI;
import javax.swing.JCheckBox;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import oracle.jdeveloper.layout.PaneLayout;
import oracle.jdeveloper.layout.PaneConstraints;
import java.awt.Dimension;
import javax.swing.JButton;
import oracle.jdeveloper.layout.XYLayout;
import oracle.jdeveloper.layout.XYConstraints;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;

public class SelectSpectrumOut extends javax.swing.JDialog
{
  private JCheckBox cb_s1 = new JCheckBox();
  private JCheckBox cb_s2 = new JCheckBox();
  private JCheckBox cb_s3 = new JCheckBox();
  private JCheckBox cb_s4 = new JCheckBox();
  private JCheckBox cb_s5 = new JCheckBox();
  private JCheckBox cb_s6 = new JCheckBox();
  private JCheckBox cb_s7 = new JCheckBox();
  private JCheckBox cb_s8 = new JCheckBox();
  private JCheckBox cb_s9 = new JCheckBox();
  private JButton btn_s1 = new JButton();
  private JButton btn_s2 = new JButton();
  private JButton btn_s3 = new JButton();
  private JButton btn_s4 = new JButton();
  private JButton btn_s5 = new JButton();
  private JButton btn_s6 = new JButton();
  private JButton btn_s7 = new JButton();
  private JButton btn_s8 = new JButton();
  private JButton btn_s9 = new JButton();
  private XYLayout xYLayout1 = new XYLayout();

  public SelectSpectrumOut(Dialog owner)
  {
    super(owner);
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }

    visibleS1 = false;
    visibleS2 = false;
    visibleS3 = false;
    visibleS4 = false;
    visibleS5 = false;
    visibleS6 = false;
    visibleS7 = false;
    visibleS8 = false;
    visibleS9 = false;
  }

  public static void main(String[] args)
  {
    SelectSpectrumOut selectSpectrum = new SelectSpectrumOut(null);

    selectSpectrum.show();
  }

  private void jbInit() throws Exception
  {
    this.setTitle("Select components...");
    this.getContentPane().setLayout(xYLayout1);
    this.addWindowListener(new java.awt.event.WindowAdapter()
      {
        public void windowDeactivated(WindowEvent e)
        {
          deactivated(e);
        }
      });
    cb_s1.setText("Average H/V");
    cb_s1.setActionCommand("s1");
    cb_s1.setPreferredSize(new Dimension(82, 24));
    cb_s2.setText("Average H/V * Sd");
    cb_s2.setActionCommand("s2");
    cb_s2.setPreferredSize(new Dimension(82, 24));    
    cb_s3.setText("Average H/V / Sd");
    cb_s3.setActionCommand("s3");
    cb_s3.setPreferredSize(new Dimension(82, 24));
    cb_s4.setText("NS/V");
    cb_s4.setActionCommand("s4");
    cb_s4.setPreferredSize(new Dimension(82, 24));
    cb_s5.setText("NS/V * Sd");
    cb_s5.setActionCommand("s5");
    cb_s5.setPreferredSize(new Dimension(82, 24));
    cb_s6.setText("NS/V / Sd");
    cb_s6.setActionCommand("s6");
    cb_s6.setPreferredSize(new Dimension(82, 24));
    cb_s7.setText("EW/V");
    cb_s7.setActionCommand("s7");
    cb_s7.setPreferredSize(new Dimension(82, 24));
    cb_s8.setText("EW/V * Sd");
    cb_s8.setActionCommand("s8");
    cb_s8.setPreferredSize(new Dimension(82, 24));
    cb_s9.setText("EW/V / Sd");
    cb_s9.setActionCommand("s9");
    cb_s9.setPreferredSize(new Dimension(82, 24));
    btn_s1.setText("Properties");
    btn_s1.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          e_s1(e);
        }
      });
    btn_s2.setText("Properties");
    btn_s2.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          e_s2(e);
        }
      });
    btn_s3.setText("Properties");
    btn_s3.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          e_s3(e);
        }
      });
    btn_s4.setText("Properties");
    btn_s4.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          e_s4(e);
        }
      });
    btn_s5.setText("Properties");
    btn_s5.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          e_s5(e);
        }
      });
    btn_s6.setText("Properties");
    btn_s6.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          e_s6(e);
        }
      });
    btn_s7.setText("Properties");
    btn_s7.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          e_s7(e);
        }
      });
    btn_s8.setText("Properties");
    btn_s8.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          e_s8(e);
        }
      });
    btn_s9.setText("Properties");
    btn_s9.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          e_s9(e);
        }
      });
    
    this.getContentPane().add(cb_s1, new XYConstraints(0, 5, 250, 20));
    this.getContentPane().add(cb_s2, new XYConstraints(0, 30, 250, 20));
    this.getContentPane().add(cb_s3, new XYConstraints(0, 55, 250, 20));
    this.getContentPane().add(btn_s2, new XYConstraints(255, 30, 135, 20));
    this.getContentPane().add(btn_s3, new XYConstraints(255, 55, 135, 20));
    this.getContentPane().add(btn_s4, new XYConstraints(255, 80, 135, 20));

    this.getContentPane().add(cb_s4, new XYConstraints(0, 80, 250, 20));
    this.getContentPane().add(cb_s5, new XYConstraints(0, 105, 250, 20));
    this.getContentPane().add(cb_s6, new XYConstraints(0, 130, 250, 20));
    this.getContentPane().add(cb_s7, new XYConstraints(0, 155, 245, 20));
    this.getContentPane().add(cb_s8, new XYConstraints(0, 180, 245, 20));
    this.getContentPane().add(cb_s9, new XYConstraints(0, 205, 245, 20));
    this.getContentPane().add(btn_s1, new XYConstraints(255, 5, 135, 20));
    this.getContentPane().add(btn_s5, new XYConstraints(255, 105, 135, 20));
    this.getContentPane().add(btn_s6, new XYConstraints(255, 130, 135, 20));
    this.getContentPane().add(btn_s7, new XYConstraints(255, 155, 135, 20));
    this.getContentPane().add(btn_s8, new XYConstraints(255, 180, 135, 20));
    this.getContentPane().add(btn_s9, new XYConstraints(255, 205, 135, 20));

    xYLayout1.setWidth(400);
    xYLayout1.setHeight(253);

    this.setSize(403,262);
  }

  private void e_s1(ActionEvent e)
  {
    SpectrumGraphicPropertiesDlg      dlg = new SpectrumGraphicPropertiesDlg (this);

    dlg.setSpectrum (s1);

    dlg.show ();
  }

  private void e_s2(ActionEvent e)
  {
    SpectrumGraphicPropertiesDlg      dlg = new SpectrumGraphicPropertiesDlg (this);
    
    dlg.setSpectrum (s2);

    dlg.show ();
  }

  private void e_s3(ActionEvent e)
  {
    SpectrumGraphicPropertiesDlg      dlg = new SpectrumGraphicPropertiesDlg (this);

    dlg.setSpectrum (s3);

    dlg.show ();
  }

  private void e_s4(ActionEvent e)
  {
    SpectrumGraphicPropertiesDlg      dlg = new SpectrumGraphicPropertiesDlg (this);

    dlg.setSpectrum (s4);

    dlg.show ();
  }

  private void e_s5(ActionEvent e)
  {
    SpectrumGraphicPropertiesDlg      dlg = new SpectrumGraphicPropertiesDlg (this);

    dlg.setSpectrum (s5);

    dlg.show ();
  }

  private void e_s6(ActionEvent e)
  {
    SpectrumGraphicPropertiesDlg      dlg = new SpectrumGraphicPropertiesDlg (this);

    dlg.setSpectrum (s6);

    dlg.show ();
  }

  private void e_s7(ActionEvent e)
  {
    SpectrumGraphicPropertiesDlg      dlg = new SpectrumGraphicPropertiesDlg (this);

    dlg.setSpectrum (s7);

    dlg.show ();
  }

  private void e_s8(ActionEvent e)
  {
    SpectrumGraphicPropertiesDlg      dlg = new SpectrumGraphicPropertiesDlg (this);

    dlg.setSpectrum (s8);
    
    dlg.show ();
  }

  private void e_s9(ActionEvent e)
  {
    SpectrumGraphicPropertiesDlg      dlg = new SpectrumGraphicPropertiesDlg (this);

    dlg.setSpectrum (s9);

    dlg.show ();
  }

  public void setType (int t)
  {
    type = t;

    setCheck ();

    switch (type)
    {
      case    1:
        hideOthers();
        
        break;

      case    2:
        
        break;

      case    3:
        cb_s1.setText("Merged HV");
        cb_s2.setText("NS / HV");
        cb_s3.setText("EW / HV");
        
        hideOthers();
        
        break;

      case    4:
        cb_s1.setText("Spec. Vert.");
        cb_s2.setText("Spec. NS");
        cb_s3.setText("Spec. EW");

        hideOthers();
        
        break;
    }
  }

  void hideOthers()
  {
    cb_s4.hide();
    btn_s4.hide();
    cb_s5.hide();
    btn_s5.hide();
    cb_s6.hide();
    btn_s6.hide();
    cb_s7.hide();
    btn_s7.hide();
    cb_s8.hide();
    btn_s8.hide();
    cb_s9.hide();
    btn_s9.hide();
    setSize(403, 112);
  }

  private void setCheck ()
  {
    for (int i = 0 ; i < 9 ; i++)
      {
      if (sv.getSpectrum(i) == s1)
        visibleS1 = true;
      if (sv.getSpectrum(i) == s2)
        visibleS2 = true;
      if (sv.getSpectrum(i) == s3)
        visibleS3 = true;
      if (sv.getSpectrum(i) == s4)
        visibleS4 = true;
      if (sv.getSpectrum(i) == s5)
        visibleS5 = true;
      if (sv.getSpectrum(i) == s6)
        visibleS6 = true;
      if (sv.getSpectrum(i) == s7)
        visibleS7 = true;
      if (sv.getSpectrum(i) == s8)
        visibleS8 = true;
      if (sv.getSpectrum(i) == s9)
        visibleS9 = true;
      }

    cb_s1.setSelected(visibleS1);
    cb_s2.setSelected(visibleS2);
    cb_s3.setSelected(visibleS3);

    if (type == 2)
      {
      cb_s4.setSelected(visibleS4);
      cb_s5.setSelected(visibleS5);
      cb_s6.setSelected(visibleS6);
      cb_s7.setSelected(visibleS7);
      cb_s8.setSelected(visibleS8);
      cb_s9.setSelected(visibleS9);
      }
  }

  private void getCheck ()
  {
    visibleS1 = cb_s1.isSelected();
    visibleS2 = cb_s2.isSelected();
    visibleS3 = cb_s3.isSelected();
    visibleS4 = cb_s4.isSelected();
    visibleS5 = cb_s5.isSelected();
    visibleS6 = cb_s6.isSelected();
    visibleS7 = cb_s7.isSelected();
    visibleS8 = cb_s8.isSelected();
    visibleS9 = cb_s9.isSelected();
  }


  public int type;

  public Spectrum s1;
  public Spectrum s2;
  public Spectrum s3;
  public Spectrum s4;
  public Spectrum s5;
  public Spectrum s6;
  public Spectrum s7;
  public Spectrum s8;
  public Spectrum s9;

  public boolean visibleS1;
  public boolean visibleS2;
  public boolean visibleS3;
  public boolean visibleS4;
  public boolean visibleS5;
  public boolean visibleS6;
  public boolean visibleS7;
  public boolean visibleS8;
  public boolean visibleS9;

  public SpectrumView sv;

  private void deactivated(WindowEvent e)
  {
    getCheck ();
    sv.removeSpectra();

    if (visibleS1)
      sv.addSpectrum(s1);
    if (visibleS2)
      sv.addSpectrum(s2);
    if (visibleS3)
      sv.addSpectrum(s3);
    if (visibleS4)
      sv.addSpectrum(s4);
    if (visibleS5)
      sv.addSpectrum(s5);
    if (visibleS6)
      sv.addSpectrum(s6);
    if (visibleS7)
      sv.addSpectrum(s7);
    if (visibleS8)
      sv.addSpectrum(s8);
    if (visibleS9)
      sv.addSpectrum(s9);
  }
}