//======================================================
// Numerical Analysis package in java
// Plot (Çizim ) programı
// Dr. Turhan Coban
// =====================================================
/*
 * Swing version.
 */

import java.lang.Integer;
import java.awt.*;
import java.awt.event.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.*;
import javax.swing.*;
//import Plot2D;
//import PlotShapesSW;
//import BasicWindowMonitor;

public class PlotWindowSWF_2000 extends JFrame implements ItemListener,ActionListener
{
    f2 ff=new f2();
	boolean inAnApplet = true;
    final static String KONTROLPANEL = "Kontrol sayfası";
    final static String    PLOTPANEL = "Plot sayfası   ";
    Plot2D jta;
    JLabel promptXmin;      // Label prompt in Xmin field
    JLabel promptXmax;      // Label prompt in Xmax field
    JLabel promptYmin;      // Label prompt in Ymin field
    JLabel promptYmax;      // Label prompt in Ymax field
    JLabel promptLabel;     // Label prompt Plot Label
    JLabel promptXLabel;    // Label prompt Plot XLabel
    JLabel promptYLabel;    // Label prompt Plot YLabel
    JLabel promptXntic;      // Label prompt in Xmin field
    JLabel promptYntic;      // Label prompt in Xmax field
    JLabel promptXgridon;    // Label prompt in Ymin field
    JLabel promptYgridon;    // Label prompt in Ymax field
    JTextField inputXmin;    // input field Xmin
    JTextField inputXmax;    // input field Xmax
    JTextField inputYmin;    // input field Ymin
    JTextField inputYmax;    // input field Ymax
    JTextField inputLabel;   // input field Label
    JTextField inputXLabel;  // input field XLabel
    JTextField inputYLabel;  // input field YLabel
    JTextField inputXntic;   // input field xntic
    JTextField inputYntic;   // input field yntic
    JCheckBox inputXgridon;  // input field xgridon
    JCheckBox inputYgridon;  // input field ygridon
    JButton printButton;

    public PlotWindowSWF_2000()
    {
    super("Plot çizimi");
    Container contentPane = getContentPane();
    JTabbedPane tabbedPane = new JTabbedPane();
        promptXmin=new JLabel("Xmin ");
        inputXmin=new JTextField(5);
        promptXmax=new JLabel("Xmax ");
        inputXmax=new JTextField(5);
        promptYmin=new JLabel("Ymin ");
        inputYmin=new JTextField(5);
        promptYmax=new JLabel("Ymax ");
        inputYmax=new JTextField(5);
        //*******
        promptLabel=new  JLabel("           Plot başlığı     : ");
        promptXLabel=new JLabel("           x ekseni başlığı : ");
        promptYLabel=new JLabel("           y ekseni başlığı : ");
        inputLabel=new JTextField(30);
        inputXLabel=new JTextField(30);
        inputYLabel=new JTextField(30);
        //*******
        promptXntic=new JLabel("X tik no");
        inputXntic=new JTextField(5);
        promptYntic=new  JLabel("Y tik no");
        inputYntic=new JTextField(5);
        promptXgridon=new JLabel("X grid (küçük kare)");
        inputXgridon=new JCheckBox(" ");
        promptYgridon=new JLabel("Y grid (küçük kare)");
        inputYgridon=new JCheckBox(" ");
        //*******
        JPanel pane1 = new JPanel()
        {
        public Dimension getPrefferedSize()
        {
            Dimension size=super.getPreferredSize();
            size.width=800;
            return size;
        }
        };
        JPanel mpane=new JPanel();
        mpane.setLayout(new GridLayout(1,8));
        mpane.add(promptXmin);
        mpane.add(inputXmin);
        mpane.add(promptXmax);
        mpane.add(inputXmax);
        mpane.add(promptYmin);
        mpane.add(inputYmin);
        mpane.add(promptYmax);
        mpane.add(inputYmax);
        pane1.add(mpane,BorderLayout.NORTH);
        JPanel xpane=new JPanel();
        xpane.setLayout(new GridLayout(1,8));
        xpane.add(promptXntic);
        xpane.add(inputXntic);
        xpane.add(promptYntic);
        xpane.add(inputYntic);
        xpane.add(promptXgridon);
        xpane.add(inputXgridon);
        xpane.add(promptYgridon);
        xpane.add(inputYgridon);
        pane1.add(xpane,BorderLayout.NORTH);
        //********
        JPanel lpane=new JPanel();
        lpane.setLayout(new GridLayout(3,2));
        lpane.add(promptLabel);
        lpane.add(inputLabel);
        lpane.add(promptXLabel);
        lpane.add(inputXLabel);
        lpane.add(promptYLabel);
        lpane.add(inputYLabel);
        pane1.add(lpane,BorderLayout.SOUTH);
        //*********
        inputXmin.addActionListener(this);
        inputXmax.addActionListener(this);
        inputYmin.addActionListener(this);
        inputYmax.addActionListener(this);
        inputLabel.addActionListener(this);
        inputXLabel.addActionListener(this);
        inputYLabel.addActionListener(this);
        inputXntic.addActionListener(this);
        inputYntic.addActionListener(this);
        inputXgridon.addItemListener(this);
        inputYgridon.addItemListener(this);
        jta=new Plot2D();
        inputXmin.setText(Double.toString(jta.p1.xmin));
        inputXmax.setText(Double.toString(jta.p1.xmax));
        inputYmin.setText(Double.toString(jta.p1.ymin));
        inputYmax.setText(Double.toString(jta.p1.ymax));
        inputXntic.setText(Integer.toString(jta.p1.xntic));
        inputYntic.setText(Integer.toString(jta.p1.yntic));
        inputLabel.setText(jta.p1.label);
        inputXLabel.setText(jta.p1.xlabel);
        inputYLabel.setText(jta.p1.ylabel);
        printButton=new JButton("Yazdır");
        JPanel pane2 = new JPanel();
        pane2.setLayout(new BorderLayout());
        pane2.add(jta);
        pane1.add(printButton,BorderLayout.SOUTH);
        printButton.addActionListener(this);
        tabbedPane.addTab(PLOTPANEL,    pane2);
        tabbedPane.addTab(KONTROLPANEL, pane1);
        contentPane.add(  tabbedPane, BorderLayout.CENTER);
    }


    public void itemStateChanged(ItemEvent e)
    {
    inputXmin.setText(Double.toString(jta.p1.xmin));
    inputXmax.setText(Double.toString(jta.p1.xmax));
    inputYmin.setText(Double.toString(jta.p1.ymin));
    inputYmax.setText(Double.toString(jta.p1.ymax));
    inputXntic.setText(Integer.toString(jta.p1.xntic));
    inputYntic.setText(Integer.toString(jta.p1.yntic));
    Object source=e.getItemSelectable();
    if(source==inputXgridon)
    {
     if (e.getStateChange() == ItemEvent.DESELECTED)
     {
     jta.p1.xgridon=0;
     }
     else
     {
      jta.p1.xgridon=1;
     }
    }
    else if(source==inputYgridon)
    {
     if (e.getStateChange() == ItemEvent.DESELECTED)
     {
     jta.p1.ygridon=0;
     }
     else
     {
      jta.p1.ygridon=1;
     }
    }
    inputLabel.setText(jta.p1.label);
    inputXLabel.setText(jta.p1.xlabel);
    inputYLabel.setText(jta.p1.ylabel);
    jta.p1.addFunction(ff,0.0,20.0,20);
    jta.yenidenciz();
    }

    public void actionPerformed(ActionEvent e)
    {
    if (e.getSource()==printButton )
    {
    jta.yazdir();
    }
    Double valXmin=new Double(inputXmin.getText());
    jta.p1.xmin=valXmin.doubleValue();
    Double valXmax=new Double(inputXmax.getText());
    jta.p1.xmax=valXmax.doubleValue();
    Double valYmin=new Double(inputYmin.getText());
    jta.p1.ymin=valYmin.doubleValue();
    Double valYmax=new Double(inputYmax.getText());
    //*****
    Integer valXntic=new Integer(inputXntic.getText());
    jta.p1.xntic=valXntic.intValue();
    Integer valYntic=new Integer(inputYntic.getText());
    jta.p1.yntic=valYntic.intValue();
    //*****
    jta.p1.ymax=valYmax.doubleValue();
    jta.p1.label=inputLabel.getText();
    jta.p1.xlabel=inputXLabel.getText();
    jta.p1.ylabel=inputYLabel.getText();
    jta.yenidenciz();
    }

      public static void main(String[] args)
      {
      PlotWindowSWF_2000 pencere= new PlotWindowSWF_2000();
      pencere.addWindowListener(new BasicWindowMonitor());
      pencere.setSize(600,600);
      pencere.setVisible(true);
      }
}

