import java.awt.event.*;
import java.util.ArrayList;
import javax.swing.JRadioButtonMenuItem;

public class MenuSortingListener implements ActionListener
{
	//#################################
	private MyFiles 			files;
	private MyVideos_GUI 		gui;
	private ArrayList<MyFiles.sortResult>	sortResult;

	//#################################
	public MenuSortingListener(MyFiles f) {
		sortResult = new ArrayList<>();
		files = f;
	}
	public void addGUI(MyVideos_GUI g) {
		gui = g;
	}
	//#################################
	public void actionPerformed(ActionEvent e) {
		JRadioButtonMenuItem menuItem = (JRadioButtonMenuItem)(e.getSource());
		String text = menuItem.getText();
        System.out.print("Sorting: " + text);
		switch (text) {
            case "All":         sortResult = files.getMovieBy("all");   break;
            case "Alphabetical":sortResult = files.getMovieBy("name");  break;
            case "Genres":      sortResult = files.getMovieBy("gen");   break;
            case "Year":        sortResult = files.getMovieBy("year");  break;
            case "Director":    sortResult = files.getMovieBy("dir");   break;
            default: break;
        }
        if(sortResult != null) {
            gui.cleanGridPanels();
            for (MyFiles.sortResult res : sortResult) {
                gui.addGridPanel(res.label, res.movie);
                gui.revalidate();
            }
            gui.getGridPanes();
            System.out.println("... Magic!");
        } else {
		    System.out.println("... Nothing happens!!");
        }
	}
}
