package SesameGUI;
import oracle.jdeveloper.layout.XYLayout;
import javax.swing.JButton;
import oracle.jdeveloper.layout.XYConstraints;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;
import javax.swing.JCheckBox;

public class GraphPropertiesDlg extends javax.swing.JDialog
{
  private XYLayout xYLayout1 = new XYLayout();
  private JButton colors = new JButton();
  private JButton scales = new JButton();

  public GraphPropertiesDlg(java.awt.Dialog owner)
  {
    super (owner);
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }

  }

  public static void main(String[] args)
  {
    GraphPropertiesDlg graphPropertiesDlg = new GraphPropertiesDlg(null);

    graphPropertiesDlg.show();
  }

  private void jbInit() throws Exception
  {
    this.setTitle("Graph properties");
    this.getContentPane().setLayout(xYLayout1);
    this.addWindowListener(new java.awt.event.WindowAdapter()
      {
        public void windowDeactivated(WindowEvent e)
        {
          deactivated(e);
        }
      });
    xYLayout1.setWidth(203);
    xYLayout1.setHeight(155);
    colors.setText("Properties and series");
    colors.setActionCommand("colors");
    colors.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          colors_actionPerformed(e);
        }
      });
    scales.setText("Scales");
    scales.setActionCommand("scales");
    scales.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          scales_actionPerformed(e);
        }
      });
    showLegend.setText("Show legend");
    save.setText("Save");
    save.setActionCommand("save");
    save.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          save_actionPerformed(e);
        }
      });
    this.getContentPane().add(save, new XYConstraints(5, 75, 190, 25));
    this.getContentPane().add(showLegend, new XYConstraints(5, 105, 105, 25));
    this.getContentPane().add(scales, new XYConstraints(5, 40, 190, 25));
    this.getContentPane().add(colors, new XYConstraints(5, 5, 190, 25));

    this.setSize(207 , 162);
  }

  private void colors_actionPerformed(ActionEvent e)
  {
    SelectSpectrumOut    dlg = new SelectSpectrumOut (this);

    dlg.s1 = s1;
    dlg.s2 = s2;
    dlg.s3 = s3;
    dlg.s4 = s4;
    dlg.s5 = s5;
    dlg.s6 = s6;
    dlg.s7 = s7;
    dlg.s8 = s8;
    dlg.s9 = s9;

    dlg.sv = sv;

    dlg.setType (type);

    dlg.show();
  }

  private void scales_actionPerformed(ActionEvent e)
  {
    ScaleDlg      dlg = new ScaleDlg (this);

    dlg.horizontal = sv.getScaleX();
    dlg.vertical = sv.getScaleY();

    dlg.load ();

    dlg.show ();
  }

  private void save_actionPerformed(ActionEvent e)
  {
    SaveDlg      dlg = new SaveDlg (this);

    dlg.setComponent(sv);

    dlg.show ();
  }

  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 SpectrumView   sv;
  private JCheckBox showLegend = new JCheckBox();
  private JButton save = new JButton();

  private void deactivated(WindowEvent e)
  {
    sv.setShowLegend (showLegend.isSelected());
    sv.repaint(0 , 0 , 2000 , 2000);
  }

  public void load()
  {
    showLegend.setSelected(sv.getShowLegend ());
  }
}