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 jdialog05 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 jdialog05(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() );
			
/*			JScrollPane scrollPane = new JScrollPane();
			scrollPane.setBounds(294, 39, 532, 159);
			getContentPane().add(scrollPane);
/*			
			String[] columnNames =  {"Test", "Descrition" , "rien"};
	     
		  
		    Object[][] data = {	{ "", "", ""}  };
		    
			tableModel = new DefaultTableModel(data, columnNames)
			{
		        @Override
		        public boolean isCellEditable(int row, int column)
		        {
		            // make read only fields except column 0,13,14
		            return column == 1 || column == 2 ;
		        }
		    };
			
		    table = new JTable(tableModel);
		    table.setRowHeight(30);
		    table.setFont(new Font("Serif", Font.BOLD, 20));
		    
		    //table.setEnabled(false);
	    
		    scrollPane.setViewportView(table);
*/
		    /*******************/
		
		   // this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        TABLE_MODEL mod=new TABLE_MODEL();
	        JTable table=new JTable(mod);
	        
	        table.setRowHeight(30);
		    table.setFont(new Font("Serif", Font.BOLD, 20));
	        
	        mod.addRow("dctr1.doc");
	        mod.addRow("java.txt");
	        mod.addRow("dctr3.doc");
	        mod.addRow("dctr4.doc");
	        mod.addRow("dctr5.doc");
	        
	        UIManager.put("ProgressBar.selectionForeground", Color.red);
	        UIManager.put("ProgressBar.selectionBackground", Color.green);
	        
//	        scrollPane.setViewportView(table);
	        
	        table.getColumnModel().getColumn(0).setCellRenderer(new CELL_RENDERER());
	        table.getColumnModel().getColumn(0).setCellEditor(new TableCellEditor() {
	            @Override
	            public boolean stopCellEditing() {
	                return false;
	            }
	            @Override
	            public boolean shouldSelectCell(EventObject arg0) {
	                return false;
	            }
	            @Override
	            public void removeCellEditorListener(CellEditorListener arg0) {}
	            @Override
	            public boolean isCellEditable(EventObject arg0) {
	                 return false;
	            }
	            @Override
	            public Object getCellEditorValue() {
	                return null;
	            }
	            @Override
	            public void cancelCellEditing() {}
	            @Override
	            public void addCellEditorListener(CellEditorListener arg0) {    }   
	            @Override
	            public Component getTableCellEditorComponent(JTable table, Object value,
	                    boolean isSelected, int row, int column) {
	                return null;
	            }
	        });
	     
	        JProgressBar progressBar1=(JProgressBar)table.getValueAt(0, 0);
	        progressBar1.setStringPainted(true);
	        progressBar1.setBorderPainted(false);
	        progressBar1.setValue(10);
	        table.repaint();
	        
	        JProgressBar progressBar2=(JProgressBar)table.getValueAt(1, 0);
	        progressBar2.setStringPainted(true);
	        progressBar2.setBorderPainted(false);
	        progressBar2.setValue(45);
	        table.repaint();
	        
	        JProgressBar progressBar3=(JProgressBar)table.getValueAt(2, 0);
	        progressBar3.setStringPainted(true);
	        progressBar3.setValue(25);
	    
	        //progressBar3.setForeground(Color.blue);
	        //progressBar3.setBackground(Color.red);
	        progressBar3.setBorderPainted(false);
	        table.repaint();
	        
	        JProgressBar progressBar4=(JProgressBar)table.getValueAt(3, 0);
	        progressBar4.setStringPainted(true);
	        progressBar4.setBorderPainted(false);
	        progressBar4.setValue(98);
	        table.repaint();
	        
	        JScrollPane scrollPane=new JScrollPane(table);
	        scrollPane.setBounds(294, 39, 532, 159);
	        
	        getContentPane().add(scrollPane);

	       
			
		    /*******************/
				
			
		
			/*******************/
		
			
		
			/*******************/
			
			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;
		}
	}
  
}

class TABLE_MODEL extends DefaultTableModel
{
    public TABLE_MODEL()
    {
        addColumn("Progress");
        addColumn("Archivo");
    }
    
    public void addRow(String value)
    {
        Object rowData[]={new JProgressBar(),value};
        addRow(rowData);
    }
}

class CELL_RENDERER implements TableCellRenderer
{
    @Override
    public Component getTableCellRendererComponent(JTable arg0,  Object arg1, boolean arg2, boolean arg3, int arg4, int arg5) 
    {
        try
        {
        	return (JProgressBar)arg1;
        }
        
        catch (Exception e) {}
     
        return (JProgressBar)arg1;
    }
}

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