import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;

import javax.swing.border.EmptyBorder;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.TitledBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import javax.swing.border.LineBorder;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.net.URL;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.imageio.ImageIO;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.util.List;
import java.awt.*;

import java.awt.*;
import java.beans.DefaultPersistenceDelegate;
import java.beans.Encoder;
import java.beans.Statement;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Reader;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;

import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreeNode;


public class jdialog06 extends JDialog 
{
	private boolean close_Jdialog = false;
	private TreeModel model;
	private List<TreeNode[]> expanded;
	private JButton btn_load_tree;
	private JButton btn_save_tree;
	private JButton btn_load_table;
	private JButton btn_save_table;
	
	public jdialog06(JFrame f, boolean modal) 
	{
	       super(f, modal);
	       
	       // fermer la fenetre
	       addWindowListener(new java.awt.event.WindowAdapter() 
	       {
	           public void windowClosing(java.awt.event.WindowEvent e) 
	           {
	        	   dispose();
	           }
	       });
	      
	       init();
     
	}
  
	private void init()
	{
		  	setResizable( false );
		  	
			setBounds(100, 100, 926, 550);
			setTitle("Jtable et Progress bar...");
			getContentPane().setLayout(null);
	     	
			ImageIcon icon = null;
			icon = createImageIcon("resources/settings.png", "");
			setIconImage( icon.getImage() );
			

			
//		    table = new JTable(tableModel);
//		    table.setRowHeight(30);
//		    table.setFont(new Font("Serif", Font.BOLD, 20));
		    
		    //table.setEnabled(false);
	    
//		    scrollPane.setViewportView(table);

		    /*******************/
	        
//	        JScrollPane scrollPane=new JScrollPane(table);
//	        scrollPane.setBounds(294, 39, 532, 159);
	        
//	        getContentPane().add(scrollPane);

	       
			
		    /*******************/
				
			
			// Table
			final JTable table = new JTable();
			
			JScrollPane scrollPane = new JScrollPane();
			scrollPane.setBounds(294, 39, 532, 159);
			getContentPane().add(scrollPane);
			scrollPane.setViewportView(table);

			// Model for Table
			DefaultTableModel model = new DefaultTableModel() 
			{

				public Class<?> getColumnClass(int column) 
				{
					switch (column) {
					case 0:
						return Boolean.class;
					case 1:
						return String.class;
					case 2:
						return String.class;
					case 3:
						return String.class;
					case 4:
						return String.class;
					case 5:
						return String.class;
					case 6:
						return String.class;
					default:
						return String.class;
					}
				}
			};
			table.setModel(model);

			model.addColumn("Select");
			model.addColumn("CustomerID");
			model.addColumn("Name");
			model.addColumn("Email");
			model.addColumn("CountryCode");
			model.addColumn("Budget");
			model.addColumn("Used");

			// Data Row
			for (int i = 0; i <= 10; i++) {
				model.addRow(new Object[0]);
				model.setValueAt(false, i, 0);
				model.setValueAt("Row"+ (i+1), i, 1);
				model.setValueAt("Data Col 2", i, 2);
				model.setValueAt("Data Col 3", i, 3);
				model.setValueAt("Data Col 4", i, 4);
				model.setValueAt("Data Col 5", i, 5);
				model.setValueAt("Data Col 6", i, 6);
			}

			// Get Row Selected
			JButton btnGetRowSelected = new JButton("Get Row Selected");
			btnGetRowSelected.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {

					for (int i = 0; i < table.getRowCount(); i++) {
						Boolean chked = Boolean.valueOf(table.getValueAt(i, 0)
								.toString());
						String dataCol1 = table.getValueAt(i, 1).toString();
						if (chked) {
							JOptionPane.showMessageDialog(null, dataCol1);
						}
					}
				}

			});
			btnGetRowSelected.setBounds(224, 149, 131, 23);
			getContentPane().add(btnGetRowSelected);

		
			
		
			/*******************/
		
			
		
			/*******************/
			
			JSeparator separator = new JSeparator();
			separator.setBounds(240, 302, 440, 2);
			getContentPane().add(separator);
		
			/*******************/
		
			JButton btn_ok = new JButton("OK");
			btn_ok.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent arg0) 
				{
					close_Jdialog = false;
					System.out.println("Btn Cancel  \n");
					dispose();
				}
			});
			btn_ok.setBounds(135, 391, 89, 23);
			getContentPane().add(btn_ok);
	
			/*******************/
			
			JButton btn_cancel = new JButton("Cancel");
			btn_cancel.addActionListener(new ActionListener() 
			{
				public void actionPerformed(ActionEvent e) 
				{
					close_Jdialog = false;
					System.out.println("Btn Cancel  \n");
					dispose();
				}
			});
			btn_cancel.setBounds(359, 391, 89, 23);
			getContentPane().add(btn_cancel);
		
	}
    
	public ImageIcon createImageIcon(String path,  String description) 
	{
		URL imgURL = getClass().getResource(path);

		if (imgURL != null)
		{
  			return new ImageIcon(imgURL, description);
		} 
		else 
		{
			System.err.println("Couldn't find file: " + path);
			return null;
		}
	}
  
}




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