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


public class OrientOptionPane{

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

        public OrientOptionPane(){

        }

        private JLabel colorOneLabel = new javax.swing.JLabel();
        private JPanel colorOnePanel = new javax.swing.JPanel();

        private JLabel colorTwoLabel = new javax.swing.JLabel();
        private JPanel colorTwoPanel = new javax.swing.JPanel();

        private JLabel colorThreeLabel = new javax.swing.JLabel();
        private JPanel colorThreePanel = new javax.swing.JPanel();

        private JLabel triQuantityLabel = new javax.swing.JLabel();
        private JTextField triQuantityField = new javax.swing.JTextField();

        private JLabel yptLabel = new javax.swing.JLabel();
        private JTextField yptField = new javax.swing.JTextField();

        private JLabel xOffsetLabel = new javax.swing.JLabel();
        private JTextField xOffsetField = new javax.swing.JTextField();

        private JSlider colorTwoSlider = new javax.swing.JSlider();
        private JSlider colorThreeSlider = new javax.swing.JSlider();
        private JSlider yptSlider = new javax.swing.JSlider();
        private JSlider triQuantitySlider = new javax.swing.JSlider();
        private JSlider xOffsetSlider = new javax.swing.JSlider();
        private JButton DrawButton = new javax.swing.JButton();
        private JButton generateButton = new javax.swing.JButton();
        private JButton colorOneButton = new javax.swing.JButton();
        private JButton colorTwoButton = new javax.swing.JButton();
        private JButton colorThreeButton = new javax.swing.JButton();

        private JColorChooser chooser = new JColorChooser();

        public JScrollPane orientPaneLoad(){

               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.Orient.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);

               colorTwoLabel.setText("Color Two");
               colorTwoLabel.setPreferredSize(new java.awt.Dimension(150, 20));
               OptionPanel.add(colorTwoLabel, java.awt.BorderLayout.CENTER);

               colorTwoPanel.setPreferredSize(new java.awt.Dimension(30, 20));
               colorTwoPanel.setBackground(opart1.Orient.colorTwo);
               OptionPanel.add(colorTwoPanel, java.awt.BorderLayout.CENTER);

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

               OptionPanel.add(colorTwoButton, BorderLayout.CENTER);

               colorThreeLabel.setText("Color Three");
               colorThreeLabel.setPreferredSize(new java.awt.Dimension(150, 20));
               OptionPanel.add(colorThreeLabel, java.awt.BorderLayout.CENTER);

               colorThreePanel.setPreferredSize(new java.awt.Dimension(30, 20));
               colorThreePanel.setBackground(opart1.Orient.colorThree);
               OptionPanel.add(colorThreePanel, java.awt.BorderLayout.CENTER);

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

               OptionPanel.add(colorThreeButton, BorderLayout.CENTER);



               yptLabel.setText("Y Point");
               yptLabel.setPreferredSize(new java.awt.Dimension(130, 20));
               OptionPanel.add(yptLabel, java.awt.BorderLayout.CENTER);

               yptField.setText("1000");
               yptField.setPreferredSize(new java.awt.Dimension(50, 20));
               OptionPanel.add(yptField, java.awt.BorderLayout.CENTER);

               yptSlider.setBackground(new java.awt.Color(153, 153, 255));
               yptSlider.setForeground(new java.awt.Color(0, 51, 51));
               yptSlider.setMajorTickSpacing(500);
               yptSlider.setPaintLabels(true);
               yptSlider.setPaintTicks(true);
               yptSlider.setMaximum(2000);
               yptSlider.setMinimum(0);
               yptSlider.setValue(1000);
               yptSlider.setPreferredSize(new java.awt.Dimension(180, 50));
               yptSlider.addMouseListener(new MouseAdapter() {

               public void mouseReleased(MouseEvent evt) {
                      yptSliderMouseReleased(evt);
                      }
               });
               OptionPanel.add(yptSlider, java.awt.BorderLayout.CENTER);

               triQuantityLabel.setText("Triangle Quantity");
               triQuantityLabel.setPreferredSize(new java.awt.Dimension(130, 20));
               OptionPanel.add(triQuantityLabel, java.awt.BorderLayout.CENTER);

               triQuantityField.setText("25");
               triQuantityField.setPreferredSize(new java.awt.Dimension(50, 20));
               OptionPanel.add(triQuantityField, java.awt.BorderLayout.CENTER);

               triQuantitySlider.setBackground(new java.awt.Color(153, 153, 255));
               triQuantitySlider.setForeground(new java.awt.Color(0, 51, 51));
               triQuantitySlider.setMajorTickSpacing(10);
               triQuantitySlider.setPaintLabels(true);
               triQuantitySlider.setPaintTicks(true);
               triQuantitySlider.setMaximum(40);
               triQuantitySlider.setMinimum(0);
               triQuantitySlider.setValue(25);
               triQuantitySlider.setPreferredSize(new java.awt.Dimension(180, 50));
               triQuantitySlider.addMouseListener(new MouseAdapter() {

               public void mouseReleased(MouseEvent evt) {
                      triQuantitySliderMouseReleased(evt);
                      }
               });

               OptionPanel.add(triQuantitySlider, java.awt.BorderLayout.CENTER);

               xOffsetLabel.setText("X Offset");
               xOffsetLabel.setPreferredSize(new java.awt.Dimension(130, 20));
               OptionPanel.add(xOffsetLabel, java.awt.BorderLayout.CENTER);

               xOffsetField.setText("1");
               xOffsetField.setPreferredSize(new java.awt.Dimension(50, 20));
               OptionPanel.add(xOffsetField, java.awt.BorderLayout.CENTER);

               xOffsetSlider.setBackground(new java.awt.Color(153, 153, 255));
               xOffsetSlider.setForeground(new java.awt.Color(0, 51, 51));
               xOffsetSlider.setMajorTickSpacing(1);
               xOffsetSlider.setPaintLabels(true);
               xOffsetSlider.setPaintTicks(true);
               xOffsetSlider.setMaximum(4);
               xOffsetSlider.setMinimum(0);
               xOffsetSlider.setValue(1);
               xOffsetSlider.setPreferredSize(new java.awt.Dimension(180, 50));
               xOffsetSlider.addMouseListener(new MouseAdapter() {

               public void mouseReleased(MouseEvent evt) {
                      xOffsetSliderMouseReleased(evt);
                      }
               });

               OptionPanel.add(xOffsetSlider, 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);

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

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

               OptionPanel.add(generateButton, java.awt.BorderLayout.CENTER);


               OptionPane.setViewportView(OptionPanel);
               return OptionPane;
        }

        public void generate(){
             opart1.Orient.generate();
        }


        public void Draw(){
                opart1.imagePanel.doDisplay(opart1.Orient.doDraw(Integer.parseInt(yptField.getText()),
        	Integer.parseInt(triQuantityField.getText()),
                Integer.parseInt(xOffsetField.getText())));
        }

        private void DrawButtonActionPerformed(java.awt.event.ActionEvent evt) {
                Draw();
        }

        private void generateButtonActionPerformed(java.awt.event.ActionEvent evt) {
                generate();
        }

        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.Orient.colorOne = selectedColor;
                     Draw();
                }
        }

        private void colorTwoButtonActionPerformed(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 {
                     colorTwoPanel.setBackground(selectedColor);
                     opart1.Orient.colorTwo = selectedColor;
                     Draw();
                }
               }

        private void colorThreeButtonActionPerformed(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 {
                     colorThreePanel.setBackground(selectedColor);
                     opart1.Orient.colorThree = selectedColor;
                     Draw();
                }

        }


        private void yptSliderMouseReleased(MouseEvent evt) {
               yptField.setText(Integer.toString(yptSlider.getValue()));
               Draw();
        }

        private void xOffsetSliderMouseReleased(MouseEvent evt) {
               xOffsetField.setText(Integer.toString(xOffsetSlider.getValue()));
               Draw();
        }

        private void triQuantitySliderMouseReleased(MouseEvent evt) {
               triQuantityField.setText(Integer.toString(triQuantitySlider.getValue()));
               Draw();
        }

}
