//======================================================
//  
// Soğutucu akışkanlar doyma termodinamik özellikleri
// Dr. Turhan Coban
// EGE Üniversitesi Mühendislik Fakultesi, Makina Bölümü
// turhan.coban@ege.edu.tr
// =====================================================
//  
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 java.util.Locale;
import java.text.*;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.table.*;

public class ref_CS_Table extends JApplet implements ItemListener,ActionListener
{
  Container c;
  Color bg;
  JTabbedPane tabPane = new JTabbedPane();
  JScrollPane skrolPane;
  final static String say1 = "Soğutucu akışkanlar ";
  final static String say2 = "Soğutucu akışkanlar ek bilgi     ";
  ImageIcon sogutucuakiskanlar;
  JPanel panel1;
  JPanel girisPaneli;
  JScrollPane cikisPaneli;
  JLabel l1[]=new JLabel[2];           // Label prompt unit
  JLabel l2[]=new JLabel[2];           // Label prompt unit
  JTextField t1[]=new JTextField[2];
  JComboBox  c1[]=new JComboBox[1];
  JTextArea output;
  JTable jt;
  ref_CS_Model samodel;
  //condYTOK  cond;
  double aa[]=new double[10];  // çıktı değerleri
  //Icon turkoglu_logo;
  JButton b1;
  double ts;
  String isim;
  String s1[];
  JTextArea LSK;
    public void init()
    { 
	sogutucuakiskanlar=new ImageIcon("Asogutucuakiskanlar.JPG");
    ts=0.0;
    isim="R134a"; 
	samodel=new ref_CS_Model(); 
	s1=samodel.g.liste();       
    c =getContentPane();
    panel1 = new JPanel();
 
    panel1.setBackground(c.getBackground());
    panel1.setLayout(new BorderLayout());
      //==========================
      output=new JTextArea(toString());
      output.setBackground(bg);

      l1[0]=new JLabel("soğutucu akışkan ismi : ");
      l1[0].setBorder(BorderFactory.createEtchedBorder(Color.blue,Color.yellow));
      Font fo16=l1[0].getFont();
      fo16=new Font(fo16.getFontName(),Font.BOLD,16);
      Font fo12=new Font(fo16.getFontName(),Font.BOLD,12);
      Font fo10=new Font(fo16.getFontName(),Font.BOLD,10);
      l1[0].setFont(fo12);
      output.setFont(fo12);
      //panel1.add(b1,BorderLayout.NORTH);
      panel1.add(output,BorderLayout.NORTH);
      LSK=new JTextArea(toString());
      l1[1]=new JLabel("  sıcaklık");
      l1[1].setBorder(BorderFactory.createEtchedBorder(Color.blue,Color.yellow));
      l2[0]=new JLabel(" ");
      l2[0].setBorder(BorderFactory.createEtchedBorder(Color.blue,Color.yellow));
      l2[1]=new JLabel(" derece C");
      l2[1].setBorder(BorderFactory.createEtchedBorder(Color.blue,Color.yellow));
      c1[0]=new JComboBox(s1);
       c1[0].setBorder(BorderFactory.createEtchedBorder(Color.blue,Color.yellow));
      t1[1]=new JTextField(""+ts);
      t1[1].setBorder(BorderFactory.createEtchedBorder(Color.blue,Color.yellow));
      jt=new JTable(samodel);
      girisPaneli = new JPanel();
      girisPaneli.setLayout(new GridLayout(2,3));
      girisPaneli.setBorder(BorderFactory.createLineBorder(Color.blue));
      cikisPaneli=new JScrollPane(jt);
      girisPaneli.add(l1[0]);
      girisPaneli.add(c1[0]);
      girisPaneli.add(l2[0]);
      girisPaneli.add(l1[1]);
      girisPaneli.add(t1[1]);
      girisPaneli.add(l2[1]);   
    t1[1].setBackground(bg);
    l1[0].setBackground(bg);
    l1[1].setBackground(bg);
    c1[0].setBackground(bg);
    l2[0].setBackground(bg);
    l2[1].setBackground(bg);
    jt.setBackground(bg);
    t1[1].setFont(fo12);
    jt.setFont(fo12);
    c1[0].addItemListener(this);
    t1[1].addActionListener(this);
    panel1.add(girisPaneli,BorderLayout.CENTER);   
    //cikisPaneli.add(jt,BorderLayout.NORTH);
    panel1.add(cikisPaneli,BorderLayout.SOUTH);  
    
      //==========================  
      skrolPane=new JScrollPane(panel1);
      tabPane.addTab(say1,skrolPane);
      LSK.add(output);
      tabPane.addTab(say2,LSK);
      c.add(tabPane);    
    }

    public void itemStateChanged(ItemEvent e)
    {     
	isim=(String)c1[0].getSelectedItem();
	samodel.setValues(isim,ts);
	repaint();
    }
    
    public void actionPerformed(ActionEvent e)
    {	    
	if(e.getSource()==t1[1])
	{Double V1=new Double(t1[1].getText());
     ts=V1.doubleValue();}
     samodel.setValues(ts);
     repaint();
   }
    
   public static String toString(double left, int w, int d)
   // converts a double to a string with given width and decimals.
   {
	NumberFormat df=NumberFormat.getInstance(Locale.US);
	df.setMaximumFractionDigits(d);
    df.setMinimumFractionDigits(d);
    df.setGroupingUsed(false);
    String s = df.format(left);
    while (s.length() < w)
      s = " " + s;
    if (s.length() > w)
    {
        s = "";
        for (int i=0; i<w; i++)
          s = s + "-";
    }
    return s;
    } 
    public String toString()
    {
	 String s="  SOĞUTUCU AKIŞKANLARIN DOYMA TERMOFİZİKSEL ÖZELLİKLERİ\n\n";
	 s+="  M. Turhan ÇOBAN\n";
	 s+="  EGE Üniversitesi, Mühendislik Fak. Makina Mühendisliği\n";
	 s+="  e-mail : turhan.coban@ege.edu.tr\n";    
     return s;
	}
                
    public static void main(String s[])
    {
        //main program
	    JFrame f = new JFrame("  SOĞUTUCU AKIŞKANLAR DOYMA TERMOFİZİKSEL DEĞERLERİ");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });
        JApplet applet = new ref_CS_Table();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.pack();
       // f.setSize(new Dimension(1200,600));
        f.setVisible(true);
    }    
 }

