/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.greinet.tvtotalripper.ui;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author agreiner
 */
public class SettingsRipperPanel {
    
    /** The JPanel to visualize the settings */
    private JPanel panel;
    /** The JLabel for the download folder selection */
    private final JLabel labelDownloadFolder;
    /** The text field for the current download folder */
    private JTextField textDownloadFolder;
    /** The file chooser to select the download folder */
    private JFileChooser fileChooserDownloadFolder;
    /** The download folder */
    public static File DOWNLOADFOLDER = new File("D:/Users/Andreas/Videos/MySpass/");
    /** The JButton to open the file chooser dialog */
    private final JButton button;
    
    /**
     * Create a settings panel
     */
    public SettingsRipperPanel(){
        panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.anchor = GridBagConstraints.NORTHWEST;
        
        gbc.gridx=0;
        gbc.gridy=0;
        gbc.gridwidth=1;
        gbc.insets.bottom = 10;
        labelDownloadFolder = new JLabel("Download folder");
        labelDownloadFolder.setFont(new Font(labelDownloadFolder.getFont().getFontName(), Font.BOLD, 15));
        panel.add(labelDownloadFolder, gbc);
        
        gbc.gridx=0;
        gbc.gridy=1;
        gbc.gridwidth=8;
        gbc.insets.left = 20;
        textDownloadFolder = new JTextField(DOWNLOADFOLDER.getAbsolutePath());
        textDownloadFolder.setEditable(false);
        textDownloadFolder.setPreferredSize(new Dimension(500, 30));
        panel.add(textDownloadFolder,gbc);
        
        gbc.gridx=8;
        gbc.gridy=1;
        gbc.gridwidth=1;
        gbc.insets.left = 0;
        button = new JButton("...");
        panel.add(button,gbc);
        
        fileChooserDownloadFolder = new JFileChooser(DOWNLOADFOLDER);
        fileChooserDownloadFolder.setDialogTitle("Select download folder");
        fileChooserDownloadFolder.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        fileChooserDownloadFolder.setAcceptAllFileFilterUsed(false);
        
        
        button.addActionListener(e -> {
            int value = fileChooserDownloadFolder.showOpenDialog(panel);
            
            if (value == JFileChooser.APPROVE_OPTION){
                DOWNLOADFOLDER = fileChooserDownloadFolder.getSelectedFile();
                textDownloadFolder.setText(DOWNLOADFOLDER.getAbsolutePath());
            }
            
        });
    }

    /**
     * Get the JPanel
     * @return  the JPanel
     */
    public JPanel getPanel() {
        return panel;
    }
    
}
