package opartgui;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.*;
import java.awt.geom.*;
import javax.swing.*;
import java.awt.*;

public class CataractOptionPane {
        
        private JPanel OptionPanel = new javax.swing.JPanel();
        private JScrollPane OptionPane = new JScrollPane();
        protected JFrame colorFrame;

        public CataractOptionPane(){
        }

        private JLabel colorOneLabel = new javax.swing.JLabel();
        private JPanel colorOnePanel = new javax.swing.JPanel();
        private JLabel wavelengthLabel = new javax.swing.JLabel();
        private JTextField wavelengthField = new javax.swing.JTextField();
        private JLabel ytransLabel = new javax.swing.JLabel();
        private JTextField ytransField = new javax.swing.JTextField();
        private JLabel xtransLabel = new javax.swing.JLabel();
        private JTextField xtransField = new javax.swing.JTextField();
        private JLabel waverepLabel = new javax.swing.JLabel();
        private JTextField waverepField = new javax.swing.JTextField();
        private JLabel wavedepthLabel = new javax.swing.JLabel();
        private JTextField wavedepthField = new javax.swing.JTextField();
        private JLabel wavewidthLabel = new javax.swing.JLabel();
        private JTextField wavewidthField = new javax.swing.JTextField();
        private JButton DrawButton = new javax.swing.JButton();
        private JButton colorOneButton = new javax.swing.JButton();
        private JSlider wavelengthSlider = new javax.swing.JSlider();
        private JSlider ytransSlider = new javax.swing.JSlider();
        private JSlider xtransSlider = new javax.swing.JSlider();
        private JSlider waverepSlider = new javax.swing.JSlider();
        private JSlider wavedepthSlider = new javax.swing.JSlider();
        private JSlider wavewidthSlider = new javax.swing.JSlider();

        public JScrollPane cataractPaneLoad(){

       //  OptionPane.setBackground(new java.awt.Color(153, 153, 255));
//         OptionPane.setBorder(new javax.swing.border.EtchedBorder());
//         OptionPane.setPreferredSize(new java.awt.Dimension(200, 600));


        OptionPanel.setBackground(new java.awt.Color(153, 153, 255));
        OptionPanel.setBorder(new javax.swing.border.EtchedBorder());
        OptionPanel.setPreferredSize(new java.awt.Dimension(200, 580));
        
        colorOneLabel.setText("Color One");
               colorOneLabel.setPreferredSize(new java.awt.Dimension(150, 20));
               OptionPanel.add(colorOneLabel, java.awt.BorderLayout.CENTER);

               colorOnePanel.setPreferredSize(new java.awt.Dimension(30, 20));
               colorOnePanel.setBackground(opart1.Cataract.colorOne);
               OptionPanel.add(colorOnePanel, java.awt.BorderLayout.CENTER);

               colorOneButton.setText("Choose Color");
               colorOneButton.setPreferredSize(new java.awt.Dimension(150, 20));
               colorOneButton.addActionListener(new ActionListener() {
               public void actionPerformed(java.awt.event.ActionEvent evt) {
                      colorOneButtonActionPerformed(evt);
                      }
               });

               OptionPanel.add(colorOneButton, BorderLayout.CENTER);

        wavelengthLabel.setText("Wavelength");
        wavelengthLabel.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(wavelengthLabel, java.awt.BorderLayout.CENTER);

        wavelengthField.setText("150");
        wavelengthField.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(wavelengthField, java.awt.BorderLayout.CENTER);

        wavelengthSlider.setBackground(new java.awt.Color(153, 153, 255));
        wavelengthSlider.setForeground(new java.awt.Color(0, 51, 51));
        wavelengthSlider.setMajorTickSpacing(100);
        wavelengthSlider.setPaintLabels(true);
        wavelengthSlider.setPaintTicks(true);
        wavelengthSlider.setMaximum(300);
        wavelengthSlider.setMinimum(0);
        wavelengthSlider.setValue(150);
        wavelengthSlider.setPreferredSize(new java.awt.Dimension(180, 50));
        wavelengthSlider.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent evt) {
                wavelengthSliderMouseReleased(evt);
            }
        });
        OptionPanel.add(wavelengthSlider, java.awt.BorderLayout.CENTER);

        ytransLabel.setText("Separation");
        ytransLabel.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(ytransLabel, java.awt.BorderLayout.CENTER);

        ytransField.setText("6");
        ytransField.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(ytransField, java.awt.BorderLayout.CENTER);

        ytransSlider.setBackground(new java.awt.Color(153, 153, 255));
        ytransSlider.setForeground(new java.awt.Color(0, 51, 51));
        ytransSlider.setMajorTickSpacing(5);
        ytransSlider.setPaintLabels(true);
        ytransSlider.setPaintTicks(true);
        ytransSlider.setMaximum(20);
        ytransSlider.setMinimum(0);
        ytransSlider.setValue(6);
        ytransSlider.setPreferredSize(new java.awt.Dimension(180, 50));
        ytransSlider.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent evt) {
                ytransSliderMouseReleased(evt);
            }
        });
        OptionPanel.add(ytransSlider, java.awt.BorderLayout.CENTER);

        xtransLabel.setText("Shear");
        xtransLabel.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(xtransLabel, java.awt.BorderLayout.CENTER);

        xtransField.setText("15");
        xtransField.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(xtransField, java.awt.BorderLayout.CENTER);

        xtransSlider.setBackground(new java.awt.Color(153, 153, 255));
        xtransSlider.setForeground(new java.awt.Color(0, 51, 51));
        xtransSlider.setMajorTickSpacing(10);
        xtransSlider.setPaintLabels(true);
        xtransSlider.setPaintTicks(true);
        xtransSlider.setMaximum(30);
        xtransSlider.setMinimum(0);
        xtransSlider.setValue(15);
        xtransSlider.setPreferredSize(new java.awt.Dimension(180, 50));
        xtransSlider.addMouseListener(new MouseAdapter() {
        
        public void mouseReleased(MouseEvent evt) {
                xtransSliderMouseReleased(evt);
            }
        });
        OptionPanel.add(xtransSlider, java.awt.BorderLayout.CENTER);

        waverepLabel.setText("Repitions");
        waverepLabel.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(waverepLabel, java.awt.BorderLayout.CENTER);

        waverepField.setText("17");
        waverepField.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(waverepField, java.awt.BorderLayout.CENTER);

        waverepSlider.setBackground(new java.awt.Color(153, 153, 255));
        waverepSlider.setForeground(new java.awt.Color(0, 51, 51));
        waverepSlider.setMajorTickSpacing(5);
        waverepSlider.setPaintLabels(true);
        waverepSlider.setPaintTicks(true);
        waverepSlider.setMaximum(30);
        waverepSlider.setMinimum(0);
        waverepSlider.setValue(17);
        waverepSlider.setPreferredSize(new java.awt.Dimension(180, 50));
        waverepSlider.addMouseListener(new MouseAdapter() {
        
        public void mouseReleased(MouseEvent evt) {
                waverepSliderMouseReleased(evt);
            }
        });
        
        OptionPanel.add(waverepSlider, java.awt.BorderLayout.CENTER);

        wavedepthLabel.setText("WaveDepth");
        wavedepthLabel.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(wavedepthLabel, java.awt.BorderLayout.CENTER);

        wavedepthField.setText("10");
        wavedepthField.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(wavedepthField, java.awt.BorderLayout.CENTER);

        wavedepthSlider.setBackground(new java.awt.Color(153, 153, 255));
        wavedepthSlider.setForeground(new java.awt.Color(0, 51, 51));
        wavedepthSlider.setMajorTickSpacing(25);
        wavedepthSlider.setPaintLabels(true);
        wavedepthSlider.setPaintTicks(true);
        wavedepthSlider.setMaximum(100);
        wavedepthSlider.setMinimum(0);
        wavedepthSlider.setValue(10);
        wavedepthSlider.setPreferredSize(new java.awt.Dimension(180, 50));
        wavedepthSlider.addMouseListener(new MouseAdapter() {
        
        public void mouseReleased(MouseEvent evt) {
                wavedepthSliderMouseReleased(evt);
            }
        });
        
        OptionPanel.add(wavedepthSlider, java.awt.BorderLayout.CENTER);

        wavewidthLabel.setText("Wave Width");
        wavewidthLabel.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(wavewidthLabel, java.awt.BorderLayout.CENTER);

        wavewidthField.setText("65");
        wavewidthField.setPreferredSize(new java.awt.Dimension(90, 20));
        OptionPanel.add(wavewidthField, java.awt.BorderLayout.CENTER);

        wavewidthSlider.setBackground(new java.awt.Color(153, 153, 255));
        wavewidthSlider.setForeground(new java.awt.Color(0, 51, 51));
        wavewidthSlider.setMajorTickSpacing(50);
        wavewidthSlider.setPaintLabels(true);
        wavewidthSlider.setPaintTicks(true);
        wavewidthSlider.setMaximum(200);
        wavewidthSlider.setMinimum(0);
        wavewidthSlider.setValue(65);
        wavewidthSlider.setPreferredSize(new java.awt.Dimension(180, 50));
        wavewidthSlider.addMouseListener(new MouseAdapter() {
        
        public void mouseReleased(MouseEvent evt) {
                wavewidthSliderMouseReleased(evt);
            }
        });
        
        OptionPanel.add(wavewidthSlider, java.awt.BorderLayout.CENTER);

        DrawButton.setBackground(new java.awt.Color(102, 102, 255));
        DrawButton.setText("Draw");
        DrawButton.setPreferredSize(new java.awt.Dimension(100, 20));
        DrawButton.addActionListener(new java.awt.event.ActionListener() {

        public void actionPerformed(java.awt.event.ActionEvent evt) {
                DrawButtonActionPerformed(evt);
            }
        });

        OptionPanel.add(DrawButton, java.awt.BorderLayout.CENTER);
        OptionPane.setViewportView(OptionPanel);
        return OptionPane;
        }
        
    public void Draw(){
                                        opart1.imagePanel.doDisplay(opart1.Cataract.doDraw(Integer.parseInt(wavelengthField.getText()),
					Integer.parseInt(ytransField.getText()),
        				Integer.parseInt(xtransField.getText()),
        				Integer.parseInt(waverepField.getText()),
        				Integer.parseInt(wavedepthField.getText()),
        				Integer.parseInt(wavewidthField.getText())));

    }

    private void DrawButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DrawButtonActionPerformed
        Draw();
    }//GEN-LAST:event_DrawButtonActionPerformed


    private void wavelengthSliderMouseReleased(MouseEvent evt) {
               wavelengthField.setText(Integer.toString(wavelengthSlider.getValue()));
               Draw();
    }

    private void ytransSliderMouseReleased(MouseEvent evt) {
               ytransField.setText(Integer.toString(ytransSlider.getValue()));
               Draw();
    }

    private void xtransSliderMouseReleased(MouseEvent evt) {
               xtransField.setText(Integer.toString(xtransSlider.getValue()));
               Draw();
    }

    private void waverepSliderMouseReleased(MouseEvent evt) {
               waverepField.setText(Integer.toString(waverepSlider.getValue()));
               Draw();
    }

    private void wavedepthSliderMouseReleased(MouseEvent evt) {
               wavedepthField.setText(Integer.toString(wavedepthSlider.getValue()));
               Draw();
    }

    private void wavewidthSliderMouseReleased(MouseEvent evt) {
               wavewidthField.setText(Integer.toString(wavewidthSlider.getValue()));
               Draw();
    }
    
    private void colorOneButtonActionPerformed(java.awt.event.ActionEvent evt) {

                colorFrame = new JFrame();
                Color selectedColor = JColorChooser.showDialog(colorFrame, "Pick A Color", opart1.Orient.colorOne);
                if(selectedColor == null) {
                                 System.out.println("No Colour Selected");
                }
                else {
                     colorOnePanel.setBackground(selectedColor);
                     opart1.Cataract.colorOne = selectedColor;
                     Draw();
                }
        }


}
