

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JToolBar;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.table.AbstractTableModel;
  
  
 // https://www.codemiles.com/Tagging.php?mode=search&tag=%22Java+Swing%22

public class split01 extends JFrame {
     
    /** Creates a new instance of Main */
    public split01() 
    {
             start.show();  
      setTitle("DataBase Project");
      setSize(800,700);
      setLocation(200,0);
       
         
       
      Container cp=getContentPane();
      
       
       
     // myTables[0]=new VisitorTable(connection);
     // myTables[1]=new BookTable( connection);
     // myTables[2]=new AuthorTable(connection);
     // myTables[3]=new PublisherTable(connection);
     // myTables[4]=new BookStoreTable(connection);
       
      mySP[0]=new JScrollPane(myTables[0],JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        
      mySP[1]=new JScrollPane(myTables[1],JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      mySP[2]=new JScrollPane(myTables[2],JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      mySP[3]=new JScrollPane(myTables[3],JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
      mySP[4]=new JScrollPane(myTables[4],JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                    JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
       
      myToolbar =new myToolbar(tabbedPane,this,connection);
       
      tabbedPane.addTab("Vistor", mySP[0]);
        
      tabbedPane.addTab("Book", mySP[1]);
      tabbedPane.addTab("Author", mySP[2]);
      tabbedPane.addTab("Publisher", mySP[3]);
      tabbedPane.addTab("Book Store", mySP[4]);
       
       tabbedPane.addChangeListener(new ChangeListener() {
           public void stateChanged(ChangeEvent e) {
                switch(tabbedPane.getSelectedIndex())
                  {
                     // case 0:((VisitorTable)(myTables[0])).ChangeModel() ;break;      
                      //case 1:((BookTable)(myTables[1])).ChangeModel();break;
                      //case 2:((AuthorTable)(myTables[2])).ChangeModel();break;
                      //case 3:((PublisherTable)(myTables[3])).ChangeModel();break;
                      //case 4:((BookStoreTable)(myTables[4])).ChangeModel();break;
                       
                      //default :break;
                  }
                
           }
       });
      mySplitePane=new JSplitPane(JSplitPane.VERTICAL_SPLIT,tabbedPane,myControlArea);
      cp.add(myToolbar,BorderLayout.NORTH);
      cp.add(mySplitePane); 
        
         
      addWindowListener(new WindowListener() {
          public void windowActivated(WindowEvent e) {
          }
          public void windowClosed(WindowEvent e) {
          }
          public void windowClosing(WindowEvent e) {
        	  split01.myArea.append("Connection Closed !!!\n")     ;
                try {
                    if(connection!=null) {
                        connection.close();
                    }
                     
                } catch (SQLException ex) {
                    ex.printStackTrace();
                }
               
          }
          public void windowDeactivated(WindowEvent e) {
          }
          public void windowDeiconified(WindowEvent e) {
          }
          public void windowIconified(WindowEvent e) {
          }
          public void windowOpened(WindowEvent e) {
          }
      }); 
       
     
           start.dispose();
   /////////////     setJMenuBar(myJM);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
       
       
    }
      
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)  {
          
        // TODO code application logic here
         
        new split01();
    }
     
      
    public static Connection connection;
    private JTabbedPane tabbedPane=new JTabbedPane();
      
    public static JTextArea myArea=new JTextArea(1,1);
    private JScrollPane myControlArea=new JScrollPane(myArea,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS
            ,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    private JSplitPane mySplitePane;
    private JPanel[] myTables=new JPanel[5];
    private JScrollPane[] mySP=new JScrollPane[5];
    private myToolbar myToolbar ;
   /////////////// private myJMenu myJM=new myJMenu();
    public static String CompName="Casper";
    public static String Port="6666";
      private myStart start=new myStart();
}
 
 
class myToolbar extends JToolBar
{
    public myToolbar(final JTabbedPane Tabbed,final JFrame myMother,final Connection conn)
    {
      //  setLayout(null);
 
            AddImag=new ImageIcon("icons/Add.png");
             
        SearchImag=new ImageIcon("icons/Search.png");
        ModifyImag=new ImageIcon("icons/Modify.png");
        RemoveImag=new ImageIcon("icons/Remove.png");
        BorrowImag=new ImageIcon("icons/Borrow.png");
        ReturnImag=new ImageIcon("icons/Return.png");
        ReportImag=new ImageIcon("icons/Report.png");
        MasterImag=new ImageIcon("icons/Master.png"); 
         
        AddBut=new JButton("Add", AddImag);
        SearchBut=new JButton("Search",SearchImag);
        ModifyBut=new JButton("Modify",ModifyImag);
         RemoveBut=new JButton("Remove",RemoveImag);
         BorrowBut=new JButton("Borrow",BorrowImag);
         ReturnBut=new JButton("Return",ReturnImag);
         ReportBut=new JButton("Report",ReportImag);
         MasterBut=new JButton("Master",MasterImag);
          AddBut.setAlignmentY(CENTER_ALIGNMENT);
           SearchBut.setAlignmentY(CENTER_ALIGNMENT);
            ModifyBut.setAlignmentY(CENTER_ALIGNMENT);
              RemoveBut.setAlignmentY(CENTER_ALIGNMENT);
              ReturnBut.setAlignmentY(CENTER_ALIGNMENT);
                   ReportBut.setAlignmentY(CENTER_ALIGNMENT);
                   MasterBut.setAlignmentY(CENTER_ALIGNMENT);
         add(AddBut);
        add(SearchBut);
        add(ModifyBut);
        add(RemoveBut);
        add(BorrowBut);
        add(ReturnBut);
        add(ReportBut);
        add(MasterBut);
        AddBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) 
            {
                  
              
                  switch(Tabbed.getSelectedIndex())
                  {
                      //case 0:((new VisitorPanel(conn,myMother))).show();break;      
                      //case 1:(new BookPanel(conn,myMother)).show();break;
                      //case 2:(new AuthorPanel(conn,myMother)).show();break;
                      //case 3:(new PublisherPanel(conn,myMother)).show();break;
                      //case 4:(new BookStorePanel(conn,myMother)).show();break;
                       
                      //default :break;
                  }
               
            }
        });
         SearchBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                   
                 
                switch(Tabbed.getSelectedIndex())
                {
                    //case 0:(new VisitorSearch(conn,myMother)).show();break;      
                    //case 1:(new BookSearch(conn,myMother)).show();break;
                    //case 2:(new AuthorSearch(conn,myMother)).show();break;
                    //case 3:(new PublisherSearch(conn,myMother)).show();break;
                    //case 4:(new BookStoreSearch(conn,myMother)).show();break;
                     
                    default :break;
                }
                   
                 
            }
        });
         ModifyBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                  
              
                 
                switch(Tabbed.getSelectedIndex())
                {
                    //case 0:(new VisitorModifyPanel(conn,myMother)).show();break;      
                    //case 1:(new BookModifyPanel(conn,myMother)).show();break;
                    //case 2:(new AuthorModifyPanel(conn,myMother)).show();break;
                    //case 3:(new PublisherModifyPanel(conn,myMother)).show();break;
                    //case 4:(new BookStoreModifyPanel(conn,myMother)).show();break;
                     
                    //default :break;
                }
                 
            }
        });
         RemoveBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                  
              
                 
                switch(Tabbed.getSelectedIndex())
                 {
                   //  case 0:(new VisitorRemovePanel(conn,myMother)).show();break;      
                   //  case 1:(new BookRemovePanel(conn,myMother)).show();break;
                   //  case 2:(new AuthorRemovePanel(conn,myMother)).show();break;
                   //  case 3:(new PublisherRemovePanel(conn,myMother)).show();break;
                   //  case 4:(new BookStoreRemovePanel(conn,myMother)).show();break;
                      
                   //  default :break;
                 }
            }
        });
         
         BorrowBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) 
            {
               // new BorrowBookPanel(conn,myMother).show();
            }
        });
         
         ReturnBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                 
                //new ReturnedBookPanel(conn,myMother).show();
            }
        });
         
         ReportBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //new ReportPanel(conn,myMother).show();
            }
        });
        MasterBut.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //new BKStoreMaster(conn,myMother).show();
            }
        });
 
    }
     
     
 
  private JButton AddBut ;
  private JButton SearchBut ;
  private JButton ModifyBut ;
  private JButton RemoveBut ;
  private JButton BorrowBut ;
  private JButton ReturnBut ;
  private JButton ReportBut ;
  private JButton MasterBut ;
  private  Icon AddImag; 
  private  Icon SearchImag;
  private  Icon ModifyImag;
  private  Icon RemoveImag;
  private  Icon BorrowImag;
  private  Icon ReturnImag;
  private  Icon ReportImag;
  private  Icon MasterImag;
}
class myStart extends JDialog
{
    myStart()
    {
         
        setUndecorated(true);
      //  setIgnoreRepaint(true);
        setResizable(false);
        setSize(150,150);
        setLocation(400,300);
         
    }
      
    private Image Imgstart=new ImageIcon("icons/back.png").getImage();
    public void paint(Graphics g) {
        g.drawImage(Imgstart,0,0,this);
    }
}
