
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;

public class DirectoryDetails implements ActionListener{

	static JTextField textField;
	static JButton button1;
	static JButton button2;
	static JButton button3;
	static JLabel label;
	static JTextArea textArea;
	static JFrame direct;
	static File file;
	// ---------------- الكود
	
	public String getDirectoryDetails(File file){
	String 	data = "";
	String type = "";
	String empty = "";

         if (file.isFile()){
		type= "type";
		empty = "";
		}
		else {
			type= "directory";
			empty = file.isAbsolute() ? "Yes" : "No" ;
		}

		data="file name \t size \t last Modification \t type \t empty \n"+file.getName()+"\t"+file.length()+"\t"+file.lastModified()+"\t"+type+"\t"+empty;
		
		
		return data ;
		
	}
	// file.length()
     // separator   اسم
     //getName  اسم
	// ------------------ نهاية الكود

 public static void main(String[] args){
 	
 	DirectoryDetails directoryDetails = new DirectoryDetails();
 	
 	JFrame direct = new JFrame();
 	direct.setSize(600, 400); 
 	direct.setLocationRelativeTo(null);   // عشان يكون الاطار بوسط الشاشه
 	direct.setVisible(true); //  عشان يظهر الاطار
 	direct.setTitle("Directory Details       by 43101226_43101707");
 	button1 = new JButton("Browse");
 	button2 = new JButton("Run");
 	button3 = new JButton("Close");
 	textArea = new JTextArea();
 	label = new JLabel("  Directory :");
 	textField = new JTextField();
 	BorderLayout layout = new BorderLayout();
 
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(1, 3, 5, 40));
    p1.add(label);
    p1.add(button1);
    p1.add(textField);
    JPanel p2 = new JPanel();
    p2.setLayout (new FlowLayout(FlowLayout.LEFT, 10, 20));
    p2.add(textArea);
    JPanel p3 = new JPanel();
    p3.setLayout(new GridLayout(1, 2, 20, 40));
    p3.add(button2);
    p3.add(button3);
    Container c = direct.getContentPane();
 	c.setLayout(layout);
 	c.add(p1, BorderLayout.NORTH);
 	c.add(p2, BorderLayout.CENTER);
 	c.add(p3, BorderLayout.SOUTH);
    //--- color
    p1.setBackground(new Color(232, 190, 212));
    p2.setBackground(new Color(232, 190, 212));
    p3.setBackground(new Color(232, 190, 212));
    button1.setBackground(new Color(205, 117, 163));
    button2.setBackground(new Color(205, 117, 163));
    button3.setBackground(new Color(205, 117, 163));
    //--- font
    Font font1 = new Font("Monospaced", Font.BOLD, 22);
    Font font2 = new Font("Serif", Font.BOLD, 18);
    Font font3 = new Font("SanSerif", Font.BOLD, 14);
    label.setFont(font1);
    button1.setFont(font2);
    button2.setFont(font2);
    button3.setFont(font2);
    textField.setFont(font3);
    //--- name the putton
    button1.setName("Browse");
    button2.setName("Run");
	button3.setName("Close");
	// اربطها مع الـ  listener
	button1.addActionListener(directoryDetails);
	button2.addActionListener(directoryDetails);
	button3.addActionListener(directoryDetails);
	
 } // end main
 
 
         //------------- وظائف الازره
		public void actionPerformed(ActionEvent e) {
		if (((JButton) e.getSource()).getName().equals("Close")) {
			System.exit(0);
		}

	else if (((JButton) e.getSource()).getName().equals("Browse")) {
			JFileChooser fc = new JFileChooser(); // create object of file
													// Browser
			 // create file variable
			fc.setDialogTitle("Open File"); // set Title
			int result = fc.showOpenDialog(direct); // make it visible
			if (result == JFileChooser.APPROVE_OPTION) { // if click ok
				file = fc.getSelectedFile();// get the selected file
				textField.setText(file.getAbsolutePath()); // update textField
			}
		}
		else if (((JButton) e.getSource()).getName().equals("Run")) {
			String deteals = getDirectoryDetails(file);
			textArea.setText(deteals); 
		}

	}
	//-------------------------------------------
    
	
}