

/* Genomic Comparison Tool
   Master Thesis of computer science

   Author: Yue Lu
   Version: 1.1

*/




/* the program for display each protein's data */

import java.net.*;
import java.sql.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import javax.swing.*;

//The Panle which will show the dataset data when user click on it
public class DatabaseDataDisplay extends JPanel
{
	//constructor
   public DatabaseDataDisplay(String Name, int num)
   {

	  tableName=Name;
   	  proteinNum=""+num;

	  //use the BorderLayout to layout the JTable
	  this.setLayout(new BorderLayout());
	  this.setBackground(Color.white);
	  this.setPreferredSize(new Dimension(2000, 50));

	  try{

		 //get the instance of the database connection
		 DatabaseConnection connection=DatabaseConnection.getInstance();
		 con=connection.getConnection();

		 //get the information of the protein
         Statement stmt = con.createStatement();
         String query = "SELECT * FROM [" + tableName + "] where ID="+proteinNum;
        // System.out.println("data display"+query);
		 ResultSet rs = stmt.executeQuery(query);

		//init the datasetTableMedel

		if(model!=null) model=null;
		 model = new DataSetTableModel(rs);

		//add the JTable to the Panel
		 JTable table = new JTable(model);
		 table.setBackground(Color.white);

		 scrollPane = new JScrollPane(table);

		 this.add(scrollPane, "Center");

		 //stmt.close();
	 	// rs.close();
	     }

      catch (SQLException ex)
      {
		  System.out.println ("4"+ex);

      }

   }

	private String tableName;
	private String proteinNum;
	private Graphics g;
	private Connection con;
	private DataSetTableModel model;
	private JScrollPane scrollPane;

}
