<commit_before>package jfmi.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.border.SoftBevelBorder;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import java.util.Vector;

import jfmi.control.JFMIApp;
import jfmi.control.TaggedFileHandler;
import jfmi.control.FileTagHandler;
import jfmi.control.FileTaggingHandler;
import jfmi.control.TaggedFile;


/** A JFMIFrame acts as the parent Swing Component for the JFMI application's
  GUI. All other graphical components treat a JFMIFrame as their parent.
  */
public class JFMIFrame extends JFrame implements ActionListener {
	private static final String FRAME_TITLE = "JFMI";
	private static final Dimension FRAME_DIMENSION = new Dimension(800, 600);

	private JPanel contentPanel;

	// Button related
	private Box buttonBox;	// Holds buttons
	private JButton manageTagsButton;
	private JButton addFileButton;
	private JButton deleteFilesButton;

	// List related
	private JScrollPane taggedFileScroller;	// Holds the taggedFileJList
	private JList<TaggedFile> taggedFileJList;

	// Controller related
	private JFMIApp jfmiApp;

	private JFileChooser fileChooser;

	//************************************************************
	// PUBLIC INSTANCE Methods
	//************************************************************

	/** Constructs a JFMIFrame with the specified JFMIApp as its controller.
	  @param jfmiApp_ JFMIApp that will act as this instance's controller.
	  */
	public JFMIFrame(JFMIApp jfmiApp_)
	{
		// Initialize instance
		super(FRAME_TITLE);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(FRAME_DIMENSION);
		setJFMIApp(jfmiApp_);
	
		// Initialize child components
		initContentPanel();
		setContentPane(contentPanel);
		initButtonBox();
		initTagScroller();
		initFileChooser();

		add(buttonBox, BorderLayout.WEST);
		add(taggedFileScroller, BorderLayout.CENTER);

		// Do not display initially
		setVisible(false);
	}

	/** Displays a window for the user to select one or more files and/or
	  directories.
	  @return an array of selected files if the user indicated approval, else
	  		null if the user cancelled
	  */
	public File[] displayFileChooser()
	{
		int returnVal = fileChooser.showDialog(this, "Add File");

		if (returnVal == JFileChooser.APPROVE_OPTION) {
			return fileChooser.getSelectedFiles();
		} else {
			return null;
		}
	}

	/** Prompts a user to confirm an action with the specified message, and 
	  returns the user's decision.
	  @param confirmMsg the message to display to the user
	  @return true if the user confirmed
	  */
	public boolean getConfirmation(String confirmMsg)
	{
		int choice = JOptionPane.showConfirmDialog(this, confirmMsg,
											"Please Provide Confirmation",
											JOptionPane.OK_CANCEL_OPTION);

		return choice == JOptionPane.OK_OPTION;
	}

	/** Sets the list data of the taggedFileJList list. Passing a null
	  reference to the method causes an exception to be thrown.
	  @param vector Non-null Vector<TaggedFile> to be used as the list's data
	  @throws IllegalArgumentException if vector is null
	  */
	public void setTaggedFileJListData(Vector<TaggedFile> vector)
	{
		if (vector == null) {
			throw new IllegalArgumentException("vector cannot be null");
		}

		taggedFileJList.setListData(vector);	
	}


	//************************************************************
	// PRIVATE INSTANCE Methods
	//************************************************************

	/** Initializes the contentPanel field.
	  */
	private final void initContentPanel()
	{
		contentPanel = new JPanel();
		contentPanel.setLayout(new BorderLayout());
	}

	/** Initialize the buttonBox field.
	  */
	private final void initButtonBox()
	{
		// Initialize buttons
		manageTagsButton = new JButton("Manage Tags");
		manageTagsButton.addActionListener(this);
		Styles.setDefaultJButtonStyles(manageTagsButton);

		addFileButton = new JButton("Add New File");
		addFileButton.addActionListener(this);
		Styles.setDefaultJButtonStyles(addFileButton);

		deleteFilesButton = new JButton("Delete Selected Files");
		deleteFilesButton.addActionListener(this);
		Styles.setDefaultJButtonStyles(deleteFilesButton);

		// Initialize buttonBox
		buttonBox = new Box(BoxLayout.Y_AXIS);
		buttonBox.add(Box.createVerticalStrut(50));
		buttonBox.add(manageTagsButton);
		buttonBox.add(Box.createVerticalStrut(50));
		buttonBox.add(addFileButton);
		buttonBox.add(Box.createVerticalStrut(10));
		buttonBox.add(deleteFilesButton);
		buttonBox.add(Box.createVerticalStrut(50));
	}

	/** Initialize the scrollPane field.
	  */
	private final void initTagScroller()
	{
		// Instantiate the taggedFileJList
		taggedFileJList = new JList<TaggedFile>();
		taggedFileJList.setLayoutOrientation(JList.VERTICAL);
		taggedFileJList.setCellRenderer(new TaggedFileJListRenderer());

		// Initialize the scroll pane<commit_msg>Added "edit" and "view" buttons to JFMIFrame<commit_after>package jfmi.gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.File;
import javax.swing.border.SoftBevelBorder;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ListSelectionModel;
import java.util.Vector;

import jfmi.control.JFMIApp;
import jfmi.control.TaggedFileHandler;
import jfmi.control.FileTagHandler;
import jfmi.control.FileTaggingHandler;
import jfmi.control.TaggedFile;


/** A JFMIFrame acts as the parent Swing Component for the JFMI application's
  GUI. All other graphical components treat a JFMIFrame as their parent.
  */
public class JFMIFrame extends JFrame implements ActionListener {
	private static final String FRAME_TITLE = "JFMI";
	private static final Dimension FRAME_DIMENSION = new Dimension(800, 600);

	private JPanel contentPanel;

	// Button related
	private Box buttonBox;	// Holds buttons
	private JButton manageTagsButton;
	private JButton addFileButton;
	private JButton editFileButton;
	private JButton viewFileButton;
	private JButton deleteFilesButton;

	// List related
	private JScrollPane taggedFileScroller;	// Holds the taggedFileJList
	private JList<TaggedFile> taggedFileJList;

	// Controller related
	private JFMIApp jfmiApp;

	private JFileChooser fileChooser;

	//************************************************************
	// PUBLIC INSTANCE Methods
	//************************************************************

	/** Constructs a JFMIFrame with the specified JFMIApp as its controller.
	  @param jfmiApp_ JFMIApp that will act as this instance's controller.
	  */
	public JFMIFrame(JFMIApp jfmiApp_)
	{
		// Initialize instance
		super(FRAME_TITLE);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setSize(FRAME_DIMENSION);
		setJFMIApp(jfmiApp_);
	
		// Initialize child components
		initContentPanel();
		setContentPane(contentPanel);
		initButtonBox();
		initTagScroller();
		initFileChooser();

		add(buttonBox, BorderLayout.WEST);
		add(taggedFileScroller, BorderLayout.CENTER);

		// Do not display initially
		setVisible(false);
	}

	/** Displays a window for the user to select one or more files and/or
	  directories.
	  @return an array of selected files if the user indicated approval, else
	  		null if the user cancelled
	  */
	public File[] displayFileChooser()
	{
		int returnVal = fileChooser.showDialog(this, "Add File");

		if (returnVal == JFileChooser.APPROVE_OPTION) {
			return fileChooser.getSelectedFiles();
		} else {
			return null;
		}
	}

	/** Prompts a user to confirm an action with the specified message, and 
	  returns the user's decision.
	  @param confirmMsg the message to display to the user
	  @return true if the user confirmed
	  */
	public boolean getConfirmation(String confirmMsg)
	{
		int choice = JOptionPane.showConfirmDialog(this, confirmMsg,
											"Please Provide Confirmation",
											JOptionPane.OK_CANCEL_OPTION);

		return choice == JOptionPane.OK_OPTION;
	}

	/** Sets the list data of the taggedFileJList list. Passing a null
	  reference to the method causes an exception to be thrown.
	  @param vector Non-null Vector<TaggedFile> to be used as the list's data
	  @throws IllegalArgumentException if vector is null
	  */
	public void setTaggedFileJListData(Vector<TaggedFile> vector)
	{
		if (vector == null) {
			throw new IllegalArgumentException("vector cannot be null");
		}

		taggedFileJList.setListData(vector);	
	}


	//************************************************************
	// PRIVATE INSTANCE Methods
	//************************************************************

	/** Initializes the contentPanel field.
	  */
	private final void initContentPanel()
	{
		contentPanel = new JPanel();
		contentPanel.setLayout(new BorderLayout());
	}

	/** Initialize the buttonBox field.
	  */
	private final void initButtonBox()
	{
		// Initialize buttons
		manageTagsButton = new JButton("Manage Tags..");
		manageTagsButton.addActionListener(this);
		Styles.setDefaultJButtonStyles(manageTagsButton);

		addFileButton = new JButton("Add New File");
		addFileButton.addActionListener(this);
		Styles.setDefaultJButtonStyles(addFileButton);

		editFileButton = new JButton("Edit File");
		editFileButton.addActionListener(this);
		Styles.setDefaultJButtonStyles(editFileButton);

		viewFileButton = new JButton("View File");
		viewFileButton.addActionListener(this);
		Styles.setDefaultJButtonStyles(viewFileButton);

		deleteFilesButton = new JButton("Delete Selected Files");
		deleteFilesButton.addActionListener(this);
		Styles.setDefaultJButtonStyles(deleteFilesButton);
		deleteFilesButton.setForeground(Styles.DANGER_COLOR);

		// Initialize buttonBox
		buttonBox = new Box(BoxLayout.Y_AXIS);
		buttonBox.add(Box.createVerticalStrut(50));
		buttonBox.add(manageTagsButton);
		buttonBox.add(Box.createVerticalStrut(50));
		buttonBox.add(addFileButton);
		buttonBox.add(Box.createVerticalStrut(10));
		buttonBox.add(editFileButton);
		buttonBox.add(Box.createVerticalStrut(10));
		buttonBox.add(viewFileButton);
		buttonBox.add(Box.createVerticalStrut(10));
		buttonBox.add(deleteFilesButton);
		buttonBox.add(Box.createVerticalStrut(50));
	}

	/** Initialize the scrollPane field.
	  */
	private final void initTagScroller()
	{
		// Instantiate the taggedFileJList
		taggedFileJList = new JList<TaggedFile>();
		taggedFileJList.setLayoutOrientation(JList.VERTICAL);
		taggedFileJList.setCellRenderer(new TaggedFileJListRenderer());

		// Initialize the scroll pane
{'fraction_non_alphanumeric': 0.12870211031609455, 'fraction_numerical': 0.0028982881985327416, 'mean_word_length': 5.007616974972796, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '331482', 'n_tokens_mistral': 3586, 'n_tokens_neox': 3245, 'n_words': 836}