//  ======================================================
//  Thermodynamics package in java
//  sogutmacevrimiTable class to calculate properties of 
//  user interface (JApplet) Dr. M. Turhan Coban
//  Ege Üniversitesi Müh. Fak. Makina Böl.
//  email : Turhan.Coban@ege.edu.tr
//  File Name   : sogutmacevrimiTable.java
//  requires    : sogutmacevrimi.java, sogutmacevrimiModel.java sogut1.java
//  =====================================================

import java.io.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;

public class sogutmacevrimiTable2 extends JApplet implements ActionListener,ItemListener
{
  JTabbedPane  tabPane = new JTabbedPane();
  final static String say1 = "girdi sayfası";
  final static String say2 = "çıktı sayfası";
  String s3[]={"R134a","R22","R12","R124","R407C","R404A","R410A","R401B","R401A","R402B","R142B","R125","R718","R717","R744","R23"};
  JPanel inputPanel;
  JPanel outputPanel;
  JPanel totalPanel;
  JPanel buttonPanel;
  JLabel l1[]=new JLabel[11];           // Label prompt unit
  JLabel l2[]=new JLabel[11];           // Label prompt unit
  JTextField t1[]=new JTextField[11];
  JButton b1,b2;
  JComboBox x1;
  JTextArea output;
  JScrollPane cikisPaneli;
  JScrollPane cikisPaneli1;
  JTable jt;
  sogutmacevrimiModel2 sm;
  //sogutmacevrimi1 sc;
  String ref_name;
  String s;
  double mv;
  double p1;
  double p2;
  double ti[];
  double Patm; 
  Container c;
  Color bg;
  public void init()
  {
    ref_name="R134a";
	c=getContentPane();
    c.setLayout(new FlowLayout());
    bg=c.getBackground();
    //                  (String s1, double Q_evap,
    //                      double Tevap,double dPevap,double dTevap,
    //                      double Tcond,double dPcond,double dTcond,
    //                      double dhexpansion,double Tkompout,double etam)
    double ti1[]={17.1,73.5,42.4,32.2,15.4,14.2};
    ti=ti1;
    mv=13.8;
    p1=327.0;
    p2=1170;
    Patm=101.3;
    sm=new sogutmacevrimiModel2(ref_name,mv,ti,p1,p2,Patm);
    inputPanel=new JPanel();
    inputPanel.setLayout(new GridLayout(11,3));
    outputPanel=new JPanel();
    outputPanel.setLayout(new BorderLayout());
    totalPanel=new JPanel();
    totalPanel.setLayout(new BorderLayout());
    l1[0]=new JLabel("soğutucu akışkan adı  ");
    l1[1]=new JLabel("hacimsel debi litre/dakika  ");
    l1[2]=new JLabel("Buharlaştırıcı alet basıncı kPa");
    l1[3]=new JLabel("Yoğuşturucu alet basıncı kPa");
    l1[4]=new JLabel("ti[0] emme hattı");
    l1[5]=new JLabel("ti[1] basma hattı");
    l1[6]=new JLabel("ti[2] sıvı hattı ");
    l1[7]=new JLabel("ti[3] ısı değiştirici çıkışı-kondenser giriş");
    l1[8]=new JLabel("ti[4] genleşme hatı çıkış-evaporaör giriş");
    l1[9]=new JLabel(" ti[5] evaporatör çıkış ısı değiştiriciye giriş");
    l1[10]=new JLabel("Pa atmosfer basıncı kPa");    
    l2[0]=new JLabel("  ");
    l2[1]=new JLabel("litre/dakika");
    l2[2]=new JLabel("kPa");
    l2[3]=new JLabel("kPa");
    l2[4]=new JLabel("derece  C");
    l2[5]=new JLabel("derece C");
    l2[6]=new JLabel("derece  C");
    l2[7]=new JLabel("derece C");
    l2[8]=new JLabel("derece  C");
    l2[9]=new JLabel("derece C ");
    l2[10]=new JLabel("kPa");
    b1=new JButton("P - h Basınç - Entalpi diyagramı");
    b2=new JButton("T - s Sıcaklık - Entropi diyagramı");
    x1=new JComboBox(sm.sc.rs.isimler);  
    //x1=new JComboBox(s3);
    t1[0]= new JTextField(""+sm.sc.s);
    t1[1]= new JTextField(""+mv);
    t1[2]= new JTextField(""+p1);
    t1[3]= new JTextField(""+p2);
    t1[4]= new JTextField(""+ti[0]);
    t1[5]= new JTextField(""+ti[1]);
    t1[6]= new JTextField(""+ti[2]);
    t1[7]= new JTextField(""+ti[3]);
    t1[8]= new JTextField(""+ti[4]);
    t1[9]= new JTextField(""+ti[5]);
    t1[10]= new JTextField(""+Patm);
    inputPanel.add(l1[0]);
    inputPanel.add(x1);
    inputPanel.add(l2[0]);

    inputPanel.add(l1[1]);
    inputPanel.add(t1[1]);
    inputPanel.add(l2[1]);

    inputPanel.add(l1[2]);
    inputPanel.add(t1[2]);
    inputPanel.add(l2[2]);
    
    inputPanel.add(l1[3]);
    inputPanel.add(t1[3]);
    inputPanel.add(l2[3]);
    
    inputPanel.add(l1[4]);
    inputPanel.add(t1[4]);
    inputPanel.add(l2[4]);
    
    inputPanel.add(l1[5]);
    inputPanel.add(t1[5]);
    inputPanel.add(l2[5]);
    
    inputPanel.add(l1[6]);
    inputPanel.add(t1[6]);
    inputPanel.add(l2[6]);
    
    inputPanel.add(l1[7]);
    inputPanel.add(t1[7]);
    inputPanel.add(l2[7]);

    inputPanel.add(l1[8]);
    inputPanel.add(t1[8]);
    inputPanel.add(l2[8]);
    
    inputPanel.add(l1[9]);
    inputPanel.add(t1[9]);
    inputPanel.add(l2[9]);
    
    inputPanel.add(l1[10]);
    inputPanel.add(t1[10]);
    inputPanel.add(l2[10]);

    x1.setBackground(bg);
    t1[1].setBackground(bg);
    t1[2].setBackground(bg);
    t1[3].setBackground(bg);
    t1[4].setBackground(bg);
    t1[5].setBackground(bg);
    t1[6].setBackground(bg);
    t1[7].setBackground(bg);
    t1[8].setBackground(bg);
    t1[9].setBackground(bg);
    t1[10].setBackground(bg);
    
    l1[0].setBackground(bg);
    l1[1].setBackground(bg);
    l1[2].setBackground(bg);
    l1[3].setBackground(bg);
    l1[4].setBackground(bg);
    l1[5].setBackground(bg);
    l1[6].setBackground(bg);
    l1[7].setBackground(bg);
    l1[8].setBackground(bg);
    l1[9].setBackground(bg);
    l1[10].setBackground(bg);
    
    l2[0].setBackground(bg);
    l2[1].setBackground(bg);
    l2[2].setBackground(bg);
    l2[3].setBackground(bg);
    l2[4].setBackground(bg);
    l2[5].setBackground(bg);
    l2[6].setBackground(bg);
    l2[7].setBackground(bg);
    l2[8].setBackground(bg);
    l2[9].setBackground(bg);
    l2[10].setBackground(bg);
    
    x1.setFont(l1[0].getFont());
    t1[1].setFont(l1[0].getFont());
    t1[2].setFont(l1[0].getFont());
    t1[3].setFont(l1[0].getFont());
    t1[4].setFont(l1[0].getFont());
    t1[5].setFont(l1[0].getFont());
    t1[6].setFont(l1[0].getFont());
    t1[7].setFont(l1[0].getFont());
    t1[8].setFont(l1[0].getFont());
    t1[9].setFont(l1[0].getFont());
    t1[10].setFont(l1[0].getFont());
    
    x1.addItemListener(this);
    //t1[0].addActionListener(this);
    t1[1].addActionListener(this);
    t1[2].addActionListener(this);
    t1[3].addActionListener(this);
    t1[4].addActionListener(this);
    t1[5].addActionListener(this);
    t1[6].addActionListener(this);
    t1[7].addActionListener(this);
    t1[8].addActionListener(this);
    t1[9].addActionListener(this);
    t1[10].addActionListener(this);
    
    b1.addActionListener(this);
    b2.addActionListener(this);
    output=new JTextArea();    
    setArea();
    jt=new JTable(sm);
    jt.setBackground(bg);
    jt.setFont(l1[0].getFont());
    cikisPaneli=new JScrollPane(jt);
    output.setFont(l1[0].getFont());
    output.setForeground(l1[0].getForeground());
    outputPanel.add(output,BorderLayout.NORTH);
    outputPanel.add( cikisPaneli,BorderLayout.SOUTH);
    totalPanel.add(inputPanel,BorderLayout.NORTH);
    buttonPanel=new JPanel();
    buttonPanel.add(b1,BorderLayout.NORTH);
    buttonPanel.add(b2,BorderLayout.SOUTH);
    totalPanel.add(buttonPanel,BorderLayout.CENTER);
    tabPane.addTab(say1,totalPanel);
    tabPane.addTab(say2,outputPanel);
    c.add(tabPane);
  }

 public void setArea()
 {
    String s="";
    s+="DENEYSAN EĞİTİM CİHAZLARI SAN. VE TİC. LTD. ŞTİ.   \n";
    s+="Yeni Sanayi Sitesi 12 Ekim Cad. 52.Sok. No:18A BALIKESİR\n";
    s+="telefon : 90(266)-246 10 75";
    s+="eposta : deneysan@deneysan.com  info@deneysan.com\n";
    output.setText(s);   
    sm.setValues(ref_name, mv,ti,p1,p2,Patm);	
    output.setBackground(c.getBackground());
 }

  public void itemStateChanged(ItemEvent ev)
  {
  ref_name=(String)x1.getSelectedItem();
  sm.setValues(ref_name, mv,ti,p1,p2,Patm);
  setArea();
  repaint();
  }

public void actionPerformed( ActionEvent e)
{
  if(e.getSource()==b1)
  {ref_name=(String)x1.getSelectedItem();sm.sc.plot_Ph();}
  else if(e.getSource()==b2)
  {ref_name=(String)x1.getSelectedItem();sm.sc.plot_Ts();}
    else if(e.getSource()==t1[1])
  {Double V1=new Double(t1[1].getText());
   mv=V1.doubleValue();}
  else if(e.getSource()==t1[2])
  {Double V1=new Double(t1[2].getText());
   ti[0]=V1.doubleValue();}
  else if(e.getSource()==t1[3])
  {Double V1=new Double(t1[3].getText());
   ti[1]=V1.doubleValue();}
  else if(e.getSource()==t1[4])
  {Double V1=new Double(t1[4].getText());
   ti[2]=V1.doubleValue();} 
  else if(e.getSource()==t1[5])
  {Double V1=new Double(t1[5].getText());
   ti[3]=V1.doubleValue();}
  else if(e.getSource()==t1[6])
  {Double V1=new Double(t1[6].getText());
   ti[4]=V1.doubleValue();}
  else if(e.getSource()==t1[7])
  {Double V1=new Double(t1[7].getText());
   ti[5]=V1.doubleValue();}
  else if(e.getSource()==t1[8])
  {Double V1=new Double(t1[8].getText());
    p1=V1.doubleValue();}
  else if(e.getSource()==t1[9])
  {Double V1=new Double(t1[9].getText());
    p2=V1.doubleValue();}
  else if(e.getSource()==t1[10])
  {Double V1=new Double(t1[10].getText());
    Patm=V1.doubleValue();}          
  sm.setValues(ref_name, mv,ti,p1,p2,Patm);	
  setArea();
  repaint();
  }

    public static void main(String s[])
    {   JFrame f = new JFrame("Soğutma Çevrimi");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {}
        });
        JApplet applet = new sogutmacevrimiTable2();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.pack();
        f.setSize(new Dimension(800,800));
        f.setVisible(true);
    }
}