<commit_before> package View;
import jade.gui.GuiEvent;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Image;
import java.awt.Point;
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.beans.PropertyChangeEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import SMA.user.UserAgent;
import Utilities.Constance;
import Utilities.CustomImgPanel;
import Utilities.ImageTimerTask;
import Utilities.OvalBorder;
import Utilities.SongFlowItem;


public class MusicSelectView extends JAgentFrame{
	private int i = 0;
	private JLabel label;
	private JLabel labelup;
	private JLabel labeldown;
	private String temptext = null;
	private List<SongFlowItem> songs = new ArrayList<SongFlowItem>();
	private int index=0;
	Timer click_task = null;
	private JLabel valider;
	
	public MusicSelectView(final File directory,UserAgent agent){
		super(agent);
		songs = SongFlowItem.loadFromDirectory(directory);
		/*String path = "src/songs.txt";
		BufferedReader br = null;
		String temp = null;
		try {
			br = new BufferedReader(new FileReader(path));
			while ((temp = br.readLine()) != null) {
				songs.add(temp);
			}
		} catch (FileNotFoundException e) {
			System.out.println("file not exite");
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if(br!=null) {
					br.close();
					br = null;
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}*/
		this.setTitle("SONGS");
		this.setSize(700,500);
		this.setLocationRelativeTo(null);		
		this.setLayout(null);
		CustomImgPanel background=new CustomImgPanel(700, 500,"src/images/musicBackground.jpg");
		this.add(background);
		background.setLayout(null);
		//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //arret du programme
		label = new JLabel(getFileName(songs.get(i+1).getLabel()));
		index=i+1;
		label.setBounds(100, 120, 500, 160);
    	label.setFont(new Font("Chalkboard", Font.PLAIN, 50));
    	label.setHorizontalAlignment(SwingConstants.CENTER);
    	label.setForeground(Color.WHITE);
    	//label.getComponent(0).getClass().getTypeName();
    	//System.out.println(label.getComponent(0).getClass().getTypeName());

		labelup = new JLabel(getFileName(songs.get(i+2).getLabel()));
		labelup.setBounds(150, 20, 400, 160);
    	labelup.setFont(new Font("Chalkboard", Font.PLAIN, 20));
    	labelup.setHorizontalAlignment(SwingConstants.CENTER);
    	labelup.setForeground(new Color(255,255,255,150));
    	
		labeldown = new JLabel(getFileName(songs.get(i).getLabel()));
		labeldown.setBounds(150, 220, 400, 160);
    	labeldown.setFont(new Font("Chalkboard", Font.PLAIN, 20));
    	labeldown.setHorizontalAlignment(SwingConstants.CENTER);
    	labeldown.setForeground(new Color(255,255,255,150));
		
/*    	ImageIcon avant = new ImageIcon("src/images/avant.jpg");
		JButton precedent = new JButton("avant");
		precedent.setBounds(100,360,100,100);
		precedent.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				selectLastMusic();
			}
		});
//    	ImageIcon next = new ImageIcon("src/images/next.png");
		JButton suivant = new JButton("next");
		suivant.setBounds(510,360,100,100);
    	suivant.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				selectNextMusic();
			}
		});*/
		valider = new JLabel(new ImageIcon("src/images/ok.png"));
		valider.setBounds(550,360,100,100);
		valider.setBorder(new OvalBorder(valider.getWidth(), valider.getHeight(), Color.GRAY));
		
		valider.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent arg0) {
				valider.setBorder(new OvalBorder(valider.getWidth(), valider.getHeight(), Color.GRAY));

				Toolkit toolkit = Toolkit.getDefaultToolkit();
				Image cursorImage = toolkit.getImage("src/images/cursor.png");
				Point cursorHotSpot = new Point(0,0);
				Cursor customCursor = toolkit.createCustomCursor(cursorImage, cursorHotSpot, "Cursor");
				setCursor(customCursor);
				if (click_task != null) {
					click_task.cancel();
					click_task = null;
				}
				
			}
			
			@Override
			public void mouseEntered(MouseEvent arg0) {
				valider.setBorder(new OvalBorder(valider.getWidth(), valider.getHeight(), new Color(153,153,255)));
				click_task = new Timer();
				click_task.schedule(new ImageTimerTask(myAgent),0,Constance.click_delay/12);
				click_task.schedule( 
				        new java.util.TimerTask() {
				            @Override
				            public void run() {
				            	GuiEvent ev = new GuiEvent(this,UserAgent.SELECT_MUSIC_EVENT);
								ev.addParameter(songs.get(index).getFile().getAbsolutePath());
								myAgent.postGuiEvent(ev);
								setVisible(false);
				            }
				        }, 
				        Constance.click_delay 
				);
				
			}
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
//		valider.addActionListener(new ActionListener(){
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				GuiEvent ev = new GuiEvent(this,UserAgent.SELECT_MUSIC_EVENT);<commit_msg>modifier select music file<commit_after> package View;
import jade.gui.GuiEvent;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Image;
import java.awt.Point;
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.beans.PropertyChangeEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import SMA.user.UserAgent;
import Utilities.Constance;
import Utilities.CustomImgPanel;
import Utilities.ImageTimerTask;
import Utilities.OvalBorder;
import Utilities.SongFlowItem;


public class MusicSelectView extends JAgentFrame{
	private int i=1;
	private JLabel label;
	private JLabel labelup;
	private JLabel labeldown;
//	private JButton precedent;
//	private JButton suivant;	
	private List<SongFlowItem> songs = new ArrayList<SongFlowItem>();
	Timer click_task = null;
	private JLabel valider;
	
	public MusicSelectView(final File directory,UserAgent agent){
		super(agent);
		songs = SongFlowItem.loadFromDirectory(directory);
		/*String path = "src/songs.txt";
		BufferedReader br = null;
		String temp = null;
		try {
			br = new BufferedReader(new FileReader(path));
			while ((temp = br.readLine()) != null) {
				songs.add(temp);
			}
		} catch (FileNotFoundException e) {
			System.out.println("file not exite");
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				if(br!=null) {
					br.close();
					br = null;
				}
			} catch (IOException e) {
				e.printStackTrace();
			}
		}*/
		this.setTitle("SONGS");
		this.setSize(700,500);
		this.setLocationRelativeTo(null);		
		this.setLayout(null);
		CustomImgPanel background=new CustomImgPanel(700, 500,"src/images/musicBackground.jpg");
		this.add(background);
		background.setLayout(null);
		//this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //arret du programme
		label = new JLabel(getFileName(songs.get(i).getLabel()));
		label.setBounds(100, 120, 500, 160);
    	label.setFont(new Font("Chalkboard", Font.PLAIN, 50));
    	label.setHorizontalAlignment(SwingConstants.CENTER);
    	label.setForeground(Color.WHITE);
    	//label.getComponent(0).getClass().getTypeName();
    	//System.out.println(label.getComponent(0).getClass().getTypeName());

		labelup = new JLabel(getFileName(songs.get(i+1).getLabel()));
		labelup.setBounds(150, 20, 400, 160);
    	labelup.setFont(new Font("Chalkboard", Font.PLAIN, 20));
    	labelup.setHorizontalAlignment(SwingConstants.CENTER);
    	labelup.setForeground(new Color(255,255,255,150));
    	
		labeldown = new JLabel(getFileName(songs.get(i-1).getLabel()));
		labeldown.setBounds(150, 220, 400, 160);
    	labeldown.setFont(new Font("Chalkboard", Font.PLAIN, 20));
    	labeldown.setHorizontalAlignment(SwingConstants.CENTER);
    	labeldown.setForeground(new Color(255,255,255,150));
		
/*    	ImageIcon avant = new ImageIcon("src/images/avant.jpg");
		JButton precedent = new JButton("avant");
		precedent.setBounds(100,360,100,100);
		precedent.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				selectLastMusic();
			}
		});
//    	ImageIcon next = new ImageIcon("src/images/next.png");
		JButton suivant = new JButton("next");
		suivant.setBounds(510,360,100,100);
    	suivant.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				selectNextMusic();
			}
		}); */
		valider = new JLabel(new ImageIcon("src/images/ok.png"));
		valider.setBounds(550,360,100,100);
		valider.setBorder(new OvalBorder(valider.getWidth(), valider.getHeight(), Color.GRAY));
		
		valider.addMouseListener(new MouseListener() {
			
			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent arg0) {
				valider.setBorder(new OvalBorder(valider.getWidth(), valider.getHeight(), Color.GRAY));

				Toolkit toolkit = Toolkit.getDefaultToolkit();
				Image cursorImage = toolkit.getImage("src/images/cursor.png");
				Point cursorHotSpot = new Point(0,0);
				Cursor customCursor = toolkit.createCustomCursor(cursorImage, cursorHotSpot, "Cursor");
				setCursor(customCursor);
				if (click_task != null) {
					click_task.cancel();
					click_task = null;
				}
				
			}
			
			@Override
			public void mouseEntered(MouseEvent arg0) {
				valider.setBorder(new OvalBorder(valider.getWidth(), valider.getHeight(), new Color(153,153,255)));
				click_task = new Timer();
				click_task.schedule(new ImageTimerTask(myAgent),0,Constance.click_delay/12);
				click_task.schedule( 
				        new java.util.TimerTask() {
				            @Override
				            public void run() {
				            	if(i==songs.size()){
				            		i=0;
				            	}
				            	System.out.println(i);
				            	GuiEvent ev = new GuiEvent(this,UserAgent.SELECT_MUSIC_EVENT);
								ev.addParameter(songs.get(i).getFile().getAbsolutePath());
								myAgent.postGuiEvent(ev);
								setVisible(false);
				            }
				        }, 
				        Constance.click_delay 
				);
				
			}
			
			@Override
			public void mouseClicked(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
		});
//		valider.addActionListener(new ActionListener(){
//			@Override
//			public void actionPerformed(ActionEvent e) {
//				GuiEvent ev = new GuiEvent(this,UserAgent.SELECT_MUSIC_EVENT);
{'fraction_non_alphanumeric': 0.1260482406847065, 'fraction_numerical': 0.023947436673294718, 'mean_word_length': 3.7177814029363785, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2962377', 'n_tokens_mistral': 4466, 'n_tokens_neox': 3673, 'n_words': 696}