//======================================================
//  
// ELBA Radiator modelling
// Dr. Turhan Coban
// EGE Üniversitesi Mühendislik Fakultesi, Makina Bölümü
// turhan.coban@ege.edu.tr
// =====================================================
// This model is developed for ECA group of companies ELBA limited 
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 java.awt.geom.*;
import javax.swing.table.*;
import javax.swing.event.*;

public class ELBATable22 extends JApplet implements ItemListener,ActionListener
{
  Container c;
  Color bg;
  JTabbedPane  tabPane = new JTabbedPane();
  final static String say1 = "Radiator Heat capacity page";
  final static String say2 = "Additional information";
  final static String say3 = " ";
  final static String say4 = " ";
  JPanel panel1;
  JPanel panel2;
  JPanel girisPaneli;
  JPanel girisPaneli1;
  JPanel girisPaneli2;
  JScrollPane cikisPaneli; 
  //Border b=BorderFactory.createRaisedBevelBorder();
  JLabel l1[]=new JLabel[8];            //  Label prompt unit
  JLabel l2[]=new JLabel[6];            //  Label prompt unit
  JSlider cap;
  JTextField t1[]=new JTextField[6];
  JComboBox c1[]=new JComboBox[3];
  JTextArea output;
  JTable jt;
  //jt.setFont(16);
  ELBAModel elbamodel;
  double aa[]=new double[10];  //condYTOK çıktı değerleri
  String s1[];
  String s2[];
  String s3[];
  //Icon elba_logo;
  JButton b1;
  int Tip;
  int H;
  int L;
  double toda;  // oda sıcaklığı
  double tgir;  // su giriş sıcaklığı
  double tcik;  //su çıkış sıcaklığı;
  double dT;
  double Q;
  String TipArray[]={"11","21","22","33"};
  String HArray[]={"300","400","500","600","700","800","900"};
  String LArray[]={"400","500","600","700","800","900","1000","1100","1200","1300","1400","1500","1600","1700","1800","1900","2000","2100","2200","2300","2400","2500","2600","2700","2800","2900","3000"};
    public void init()
    { 
    Tip=22;
    H=300;
    L=1000;
    toda=18;  // oda sıcaklığı
    tgir=60;  // su giriş sıcaklığı
    tcik=50;  //su çıkış sıcaklığı;
    dT=10;
    Q=0;
	elbamodel=new ELBAModel(Tip,H,L,toda,tgir,tcik);         
    c = getContentPane();
    panel1 = new JPanel();
    panel2 = new JPanel();
    panel1.setBackground(c.getBackground()); 
    panel2.setBackground(c.getBackground()); 
    JPanel pane1 = new JPanel()
    {
        public Dimension getPrefferedSize()
        {
            Dimension size=super.getPreferredSize();
            size.width=600;
            return size;
        }
        };

      //==========================
      //pencereleri içeriği
      //elba_logo=new ImageIcon("elba 1.1.JPG");
      //b1=new JButton(elba_logo);
      output=new JTextArea(toString());
      
      output.setBackground(bg);
      l1[0]=new JLabel("Select radiator type ");
      Font fo16=l1[0].getFont();
      fo16=new Font(fo16.getFontName(),Font.BOLD,16);
      Font fo18=new Font(fo16.getFontName(),Font.BOLD,18);
      Font fo12=new Font(fo16.getFontName(),Font.BOLD,12);
      Font fo14=new Font(fo16.getFontName(),Font.BOLD,14);
      Font fo10=new Font(fo16.getFontName(),Font.BOLD,10);
      l1[0].setFont(fo12);
      output.setFont(fo14);
      //panel1.add(b1,BorderLayout.NORTH);
      panel1.add(output,BorderLayout.CENTER);
      l1[1]=new JLabel("Select radiator height");
      l1[2]=new JLabel("Select radiator Length");
      l1[3]=new JLabel("Input room temperature                        ");
      l1[4]=new JLabel("Input radiator water inlet temperature");      
      l1[5]=new JLabel("Input radiator water exit temperature");
      l1[6]=new JLabel("INPUT DATA");
      l1[7]=new JLabel("OUTPUT DATA");
      l1[6].setFont(fo18);
      l1[7].setFont(fo18);
      l2[0]=new JLabel("");
      l2[1]=new JLabel(" mm");
      l2[2]=new JLabel(" mm");
      l2[3]=new JLabel(" degree Celcius");
      l2[4]=new JLabel(" degree Celcius");
      l2[5]=new JLabel(" degree Celcius");
      c1[0]=new JComboBox(TipArray);
      c1[1]=new JComboBox(HArray);
      c1[2]=new JComboBox(LArray);
      t1[2]=new JTextField(""+L);
      t1[3]=new JTextField(""+toda);
      t1[4]=new JTextField(""+tgir);  
      t1[5]=new JTextField(""+tcik);     
      jt=new JTable(elbamodel);
      jt.setBackground(bg);
      jt.setFont(fo12);
      girisPaneli=new JPanel();
      girisPaneli.setLayout(new BorderLayout());
      panel2.setLayout(new BorderLayout());
      girisPaneli1=new JPanel();
      girisPaneli1.setLayout(new GridLayout(6,3));
      cikisPaneli=new JScrollPane(jt);
      pane1.setLayout(new BorderLayout());
      //Tip
      //girisPaneli1.add(l1[0]);
      //girisPaneli1.add(c1[0]);
      //girisPaneli1.add(l2[0]);
      
      //H 
      girisPaneli1.add(l1[1]);
      girisPaneli1.add(c1[1]);
      girisPaneli1.add(l2[1]);
      //L
      girisPaneli1.add(l1[2]);
      girisPaneli1.add(c1[2]);
      girisPaneli1.add(l2[2]);
      //toda
      girisPaneli1.add(l1[3]);
      girisPaneli1.add(t1[3]);
      girisPaneli1.add(l2[3]);
      //tgir
      girisPaneli1.add(l1[4]);
      girisPaneli1.add(t1[4]);
      girisPaneli1.add(l2[4]);    
      //Tcik
      girisPaneli1.add(l1[5]);
      girisPaneli1.add(t1[5]);
      girisPaneli1.add(l2[5]);
         
    c1[2].setBackground(bg);
    t1[3].setBackground(bg);
    t1[4].setBackground(bg);
    t1[5].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);

    c1[0].setBackground(bg);
    c1[1].setBackground(bg);
    l2[2].setBackground(bg); 
    l2[4].setBackground(bg);
    l2[5].setBackground(bg);
    //
    c1[2].setFont(fo12);
    t1[3].setFont(fo12);
    t1[4].setFont(fo12);
    t1[5].setFont(fo12);
    jt.setFont(fo12);
    
    //c1[0].addItemListener(this);
    c1[1].addItemListener(this);
    c1[2].addItemListener(this);
    t1[3].addActionListener(this);
    t1[4].addActionListener(this);
    t1[5].addActionListener(this);
    girisPaneli.add(l1[6],BorderLayout.NORTH);
    girisPaneli.add(girisPaneli1,BorderLayout.CENTER);
    panel1.add(girisPaneli,BorderLayout.NORTH);
    panel2.add(l1[7],BorderLayout.NORTH);
    panel2.add(cikisPaneli,BorderLayout.CENTER);
    panel1.add(panel2,BorderLayout.SOUTH);  
    
   //==========================  
   tabPane.addTab(say1,panel1);
   c.add(tabPane);    
   }

    public void itemStateChanged(ItemEvent e)
    {     
	 //if(e.getSource()==c1[0])
	 //{
	 //Tip=Integer.parseInt((String)c1[0].getSelectedItem());
     //elbamodel.setValues(Tip,H,L,toda,tgir,tcik);
	 //}
     if(e.getSource()==c1[1])
	 {
	 H=Integer.parseInt((String)c1[1].getSelectedItem());
     elbamodel.setValues(Tip,H,L,toda,tgir,tcik);
     }
     if(e.getSource()==c1[2])
	 {
	 L=Integer.parseInt((String)c1[2].getSelectedItem());
     elbamodel.setValues(Tip,H,L,toda,tgir,tcik);
     }
	 repaint();
    }
    
    public void actionPerformed(ActionEvent e)
    {   
    if(e.getSource()==t1[3])
    {
    Double V1=new Double(t1[3].getText());
    toda=V1.doubleValue();
    t1[3].setText(""+toda);
    elbamodel.setValues(Tip,H,L,toda,tgir,tcik);
    } 
    else if(e.getSource()==t1[4])
    {
     Double V2=new Double(t1[4].getText());
     tgir=V2.doubleValue(); 
     t1[4].setText(""+tgir);
     elbamodel.setValues(Tip,H,L,toda,tgir,tcik);
    }     
    else if(e.getSource()==t1[5])
    {
    Double V3=new Double(t1[5].getText());
    tcik=V3.doubleValue();
    t1[5].setText(""+tcik); 
    elbamodel.setValues(Tip,H,L,toda,tgir,tcik);
    }  
   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="ECA ELBA RADIATOR CAPACITY SELECTION\n";
	 s+="Copyright : All rights of the program belongs to";
	 s+="ELBA BASINÇLI DÖKÜM SANAYİ A.Ş.\n";
	 s+="Manisa organize sanayi bölgesi 1. kısım 50. yıl cad.\n";
	 s+=" No:14 Manisa, Turkey\n";
	 s+="Tel : 0(236)2330600    \n";
	 s+="e-posta : info@elba.com.tr  www : elba.com.tr\n";    
     return s;
	}
                
    public static void main(String s[])
    {
        //main program
	    JFrame f = new JFrame("ECA ELBA Radiator selection");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {System.exit(0);}
        });
        JApplet applet = new ELBATable11();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.pack();
        f.setSize(new Dimension(1240,800));
        f.setVisible(true);
    }    
 }

