

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.geom.Ellipse2D;
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.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
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 
{

  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);
	
	    
  StatusPanel stPanel = new StatusPanel();
  //private JPanel qqq= new JPanel();  
	  
  private draw qqq= new draw();  
	  
  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();
	
  // declaration du menu
  private JMenuBar    menuBar = new JMenuBar(); 
  private JMenuItem   nouveau;
  private JMenuItem   ouvrir;
  private JMenuItem   sauver;
  private JMenuItem   exporter;
  private JMenuItem   imprimer;
  private JMenuItem   quitter;
  private JMenuItem   export_JPEG;
  private JMenuItem   export_PNG;
  private JMenuItem   export_CLIPBOARD;
  private JMenuItem   apropos;
	    
   public split01() 
    {
         
      setTitle("GUI ");
      setSize(800,700);
      setLocation(200,0);
       
      Container cp = getContentPane();
      
      cp.add(stPanel,BorderLayout.SOUTH);
      
      MyMousePositionsListener mPosAdpt =  new MyMousePositionsListener(stPanel);
    		   qqq.addMouseMotionListener(mPosAdpt);
    		  
    		  MyMouseListener MAdpt = new MyMouseListener(stPanel);
    		  qqq.addMouseListener(MAdpt);
       
     // 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);
       
       myArea.setEditable(false); 
       
      mySplitePane=new JSplitPane(JSplitPane.VERTICAL_SPLIT, qqq ,myControlArea);
      
      mySplitePane.setResizeWeight(0.85);
      mySplitePane.setEnabled( false );
      
      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")     ;
                
          }
          public void windowDeactivated(WindowEvent e) {
          }
          public void windowDeiconified(WindowEvent e) {
          }
          public void windowIconified(WindowEvent e) {
          }
          public void windowOpened(WindowEvent e) {
          }
      }); 
       
     
        //.dispose();
   /////////////     setJMenuBar(myJM);
      
      
      JMenuBar menuBar = new JMenuBar();

      JMenu menu = new JMenu("File");
      menuBar.add(menu);

      nouveau = new JMenuItem("Nouveau");
      //nouveau.addActionListener(this);
      menu.add(nouveau);
              
      ouvrir = new JMenuItem("Ouvrir");
      //ouvrir.addActionListener(this);
      menu.add(ouvrir);
              
      sauver = new JMenuItem("Sauver");
      //sauver.addActionListener(this);
      menu.add(sauver);
      
      JMenu submenu = new JMenu("Exporter");
      menu.add(submenu);
              
      export_JPEG =  new JMenuItem("JPEG");
      //export_JPEG.addActionListener(this);
      submenu.add(export_JPEG);
              
             
      export_PNG =  new JMenuItem("PNG");
      //export_PNG.addActionListener(this);
      submenu.add(export_PNG);
      
      export_CLIPBOARD =  new JMenuItem("CLIPBOARD");
      //export_CLIPBOARD.addActionListener(this);
      submenu.add(export_CLIPBOARD);
              
      imprimer = new JMenuItem("Imprimer");
      //imprimer.addActionListener(this);
      menu.add(imprimer);

      menu.addSeparator();
               
      quitter = new JMenuItem("Quitter");
      //quitter.addActionListener(this);
      menu.add(quitter);
              
      JMenu menu2 = new JMenu("?");
      menuBar.add(menu2);

      apropos = new JMenuItem("A propos");
      //apropos.addActionListener(this);
      menu2.add(apropos);
      
      setJMenuBar(menuBar);
      
      setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
      setSize( 1000, 800 );
      setVisible( true );
      
      
      
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      setVisible(true);
       
       
    }
      
  
    public static void main(String[] args)  
    {
        new split01();
    }
  
}

/********************************************************/

class draw extends JPanel
{
	
    public draw()
    {
    	split01.myArea.setText("[ INFO ]: Init GUI : OK" + "\n");
    	
    	DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
    	Date date = new Date();
    	dateFormat.format(date);
   	
    	split01.myArea.append(dateFormat.format(date) + "\n");
    }
	
	@Override
	public void paint(Graphics g) 
	{
		Graphics2D g2d = (Graphics2D) g;
		g2d.setColor(Color.RED);
		g2d.fillOval(0, 0, 30, 30);
		g2d.drawOval(0, 50, 30, 30);		
		g2d.fillRect(50, 0, 30, 30);
		g2d.drawRect(50, 50, 30, 30);

		g2d.draw(new Ellipse2D.Double(0, 100, 30, 30));
	
	}
}

/********************************************************/
 
class myToolbar extends JToolBar
{
	
	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;
	
    public myToolbar(final JTabbedPane Tabbed,final JFrame myMother,final Connection conn)
    {
      //  setLayout(null);
 
    	
    	Toolkit tk = Toolkit.getDefaultToolkit(); 
        Image ttt = tk.getImage("d:/search.pgn"); 
    	
        //AddImag=new ImageIcon("icons/Add.png");
        
        //URL imageURL=getClass().getClassLoader().getResource("images/" + iconName);
        
        //ImageIcon icon = new ImageIcon("book.jpg");
        
        //setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("Your image address")))
        
        SearchImag=new ImageIcon(ttt);
        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);
        
        SearchBut.setPreferredSize(new Dimension(140, 40));
        
        
        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();
            }
        });
 
    }
     
     
 
  
}

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);
    }
}

/********************************************************/

class StatusPanel extends JPanel 
{ 

	private JLabel posText = new JLabel("position:"); 
	private JLabel XCoord = new JLabel("0", JLabel.RIGHT); 
	private JLabel YCoord = new JLabel("0", JLabel.RIGHT); 
	private JLabel countText = new JLabel("no. of clicks"); 
	private JLabel counts = new JLabel("0", JLabel.RIGHT); 
	private JLabel dummy1 = new JLabel(); 
	private JLabel inOutText = new JLabel("mouse is in comp."); 
	private JLabel inOut = new JLabel("no", JLabel.RIGHT); 
	private JLabel dummy2 = new JLabel(); 
	private int clickCount = 0;


	public StatusPanel() 
	{
		this.setLayout(new GridLayout(3,3)); 
		this.add(posText); 
		this.add(XCoord); 
		this.add(YCoord); 
		this.add(countText); 
		this.add(counts); 
		this.add(dummy1); 
		this.add(inOutText); 
		this.add(inOut); 
		this.add(dummy2); 
	} 
		
	public void setCoordinates(int x, int y) 
	{ 
		XCoord.setText(Integer.toString(x)); 
		YCoord.setText(Integer.toString(y)); 
	} 

	public void setInOut(String str) 
	{ 
		inOut.setText(str); 
	} 

	public void incrementClickCount()
	{
		clickCount++;
		counts.setText(Integer.toString(clickCount));
	}

}

/********************************************************/

class MyMousePositionsListener implements MouseMotionListener 
{ 
	private StatusPanel statusPane; 

	public MyMousePositionsListener(StatusPanel s) 
	{ 
		statusPane = s;
	} 

	public void mouseMoved(MouseEvent evt) 
	{ 
		statusPane.setCoordinates(evt.getX(),evt.getY()); 
	} 

	public void mouseDragged(MouseEvent evt) 
	{ 
	} 
}

/********************************************************/

class MyMouseListener implements MouseListener
{
	private StatusPanel statusPane;

	public MyMouseListener(StatusPanel s)
	{
		statusPane = s;
	}

	public void mouseEntered(MouseEvent e)
	{
		statusPane.setInOut("yes");
	}

	public void mouseExited(MouseEvent e)
	{
		statusPane.setInOut("no");
		statusPane.setCoordinates(-1,-1);
	}

	public void mouseClicked(MouseEvent e)
	{
		statusPane.incrementClickCount();
	}

	public void mousePressed(MouseEvent e)
	{
	}

	public void mouseReleased(MouseEvent e)
	{
	}

 }

/********************************************************/
