package SesameGUI;
import oracle.jdeveloper.layout.XYLayout;
import javax.swing.JButton;
import oracle.jdeveloper.layout.XYConstraints;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowListener;
import java.awt.event.WindowEvent;

public class SpectrumGraphicPropertiesDlg extends javax.swing.JDialog
{
  private XYLayout xYLayout1 = new XYLayout();
  private JComboBox jComboBox1 = new JComboBox();
  private JLabel jLabel1 = new JLabel();
  private JLabel jLabel2 = new JLabel();
  private FloatField jTextField1 = new FloatField(1.0f , 0);
  private JButton jButton3 = new JButton();

  public SpectrumGraphicPropertiesDlg(Dialog owner)
  {
    super(owner);
    try
    {
      jbInit();
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }

  }

  private void jbInit() throws Exception
  {
    retOk = false;
    this.getContentPane().setLayout(xYLayout1);
    this.setTitle("Select graphical properties");
    this.addWindowListener(new java.awt.event.WindowAdapter()
      {
        public void windowDeactivated(WindowEvent e)
        {
          deactivated(e);
        }
      });
    xYLayout1.setWidth(430);
    xYLayout1.setHeight(62);
    jComboBox1.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          changed(e);
        }
      });
      
    jLabel1.setText("Line type:");
    jLabel2.setText("Width:");
    jButton3.setText("Color");
    jButton3.addActionListener(new ActionListener()
      {
        public void actionPerformed(ActionEvent e)
        {
          colorChooser(e);
        }
      });

    this.getContentPane().add(jButton3, new XYConstraints(345, 5, 73, 27));
    this.getContentPane().add(jTextField1, new XYConstraints(305, 10, 25, 20));
    this.getContentPane().add(jLabel2, new XYConstraints(265, 10, 40, 20));
    this.getContentPane().add(jLabel1, new XYConstraints(10, 10, 55, 20));
    this.getContentPane().add(jComboBox1, new XYConstraints(75, 10, 160, 20));

    jComboBox1.addItem("line");
    jComboBox1.addItem("line-dot");
    jComboBox1.addItem("dotted");

    setSize(433 , 72);
  }

  private void cancel(ActionEvent e)
  {
  dispose();
  }

  private void ok(ActionEvent e)
  {
  retOk = true;
  dispose();
  }

  public boolean   retOk;

  private void colorChooser(ActionEvent e)
  {
  JColorChooser       dlg = new JColorChooser ();
  Color               c;

  c = dlg.showDialog(this , "Choose color" , spec.getSpectraVisualProperties().getLineColor());

  if (c != null)
    spec.getSpectraVisualProperties().setLineColor(c);
  }

  public void setSpectrum (Spectrum sp)
  {
    spec = sp;
    
    jComboBox1.setSelectedIndex(spec.getSpectraVisualProperties().getLinePattern() - 1);
    jTextField1.setText(Integer.toString(spec.getSpectraVisualProperties().getLineThickness()));
  }
  
  Spectrum                      spec;

  private void changed(ActionEvent e)
  {
  
  }

  private void deactivated(WindowEvent e)
  {
    spec.getSpectraVisualProperties().setLineThickness(Integer.parseInt(jTextField1.getText()));
    spec.getSpectraVisualProperties().setLinePattern(jComboBox1.getSelectedIndex() + 1);
  }
}