package audiobook;

import java.awt.dnd.DropTargetDropEvent;
import java.beans.PropertyChangeEvent;
import java.util.concurrent.ExecutionException;
import other.Strings.AdvancedFileNameQuoteProcessor;
import other.Strings.M4aTagQuoteProcessor;
import Applications.Application;
import Dating.Time;
import Files.FileActions;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetAdapter;
import java.awt.dnd.DropTargetListener;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileFilter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
import javax.swing.SwingWorker;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.filechooser.FileNameExtensionFilter;
import other.Strings.FileNameQuoteProcessor;
import other.Strings.FilepathQuoteProcessor;
import other.Strings.NumberQuoteProcessor;
import other.Strings.QuoteProcessor;
import swing.Beans.MultipleInputPane;

/**
 * This class extends all methods to create an audiobook. It Also contains information about the Main Window shown on startup.
 * @author Kim
 */
public class MainWindow extends javax.swing.JFrame {

    /** Creates new form MainWindow
     */
    public MainWindow() {
        initComponents();
        initDragAndDrop();
    }

    /**
     * Initializes the <code>DropTargetAdapter</code> and the <code>DropTargets</code> to enable special drag and drop features
     * @see DropTargetAdapter 
     * @see DropTarget
     */
    private void initDragAndDrop() {
        coverFieldDrop = new DropTargetAdapter() {

            @Override
            public void drop(DropTargetDropEvent dtde) {
                try {
                    Transferable tr = dtde.getTransferable();
                    DataFlavor[] flavors = tr.getTransferDataFlavors();
                    //Checking Dragged Objects for their Flavour Type
                    //Only accept Files
                    for (int i = 0; i < flavors.length; i++) {
                        if (flavors[i].isFlavorJavaFileListType()) {
                            dtde.acceptDrop(dtde.getDropAction());
                            List files = (List) tr.getTransferData(flavors[i]);
                            File imageFile = (File) files.get(0);
                            if (imageFile.isDirectory()) {
                                dtde.rejectDrop();
                                return;
                            }
                            //Setting dropped File as active Cover
                            if (imageFile.getName().toLowerCase().endsWith(".jpg".toLowerCase()) || imageFile.getName().toLowerCase().endsWith(".png".toLowerCase())) {
                                Main.currBook.setImageFile(imageFile);
                                CoverField.setText(imageFile.getPath());
                                dtde.dropComplete(true);
                                CoverField.repaint();
                            } else {
                                JOptionPane.showMessageDialog(null, "Die Datei kann nicht als Cover verwendet werden. Die Formate .jpg und .png werden unterstützt.", "Fehler", JOptionPane.ERROR_MESSAGE);
                                dtde.rejectDrop();
                            }
                            return;
                        }
                    }
                } catch (Throwable t) {
                }
                dtde.rejectDrop();
            }
        };
        listDrop = new DropTargetAdapter() {

            @Override
            public void drop(DropTargetDropEvent dtde) {
                try {
                    Transferable tr = dtde.getTransferable();
                    DataFlavor[] flavors = tr.getTransferDataFlavors();
                    //Only accept dropped *.m4a Files or Filders
                    for (int i = 0; i < flavors.length; i++) {
                        if (flavors[i].isFlavorJavaFileListType()) {
                            dtde.acceptDrop(dtde.getDropAction());
                            List<File> files = (List<File>) tr.getTransferData(flavors[i]);
                            boolean unsupportedFile = false;
                            //Import useable files to audiobook data
                            for (File file : files) {
                                if (file.isDirectory() || file.getName().endsWith(".m4a")) {
                                    load(file);
                                } else {
                                    unsupportedFile = true;
                                }
                            }
                            if (unsupportedFile) {
                                JOptionPane.showMessageDialog(null, "Es werden nur *.m4a Dateien unterstützt. Konvertieren Sie diese z.B. über iTunes", "Achtung", JOptionPane.WARNING_MESSAGE);
                            }
                            updateChaptersList();
                            dtde.dropComplete(true);
                            return;
                        }
                    }
                } catch (Exception ex) {
                }
                dtde.rejectDrop();
            }
        };
        targetDirDrop = new DropTargetAdapter() {

            @Override
            public void drop(DropTargetDropEvent dtde) {
                try {
                    Transferable tr = dtde.getTransferable();
                    DataFlavor[] flavors = tr.getTransferDataFlavors();
                    //Accepting only directories
                    for (int i = 0; i < flavors.length; i++) {
                        if (flavors[i].isFlavorJavaFileListType()) {
                            dtde.acceptDrop(dtde.getDropAction());
                            List files = (List) tr.getTransferData(flavors[i]);
                            File dir = (File) files.get(0);
                            if (!dir.isDirectory()) {
                                dtde.rejectDrop();
                                return;
                            }
                            //Set dropped Folder as active target foleder
                            Main.currBook.setTargetFolder(dir);
                            FolderField.setText(dir.getPath());
                            dtde.dropComplete(true);
                            FolderField.repaint();
                            checkPOD();
                            return;
                        }
                    }
                } catch (Throwable t) {
                    t.printStackTrace();
                }
                dtde.rejectDrop();
            }
        };
        mainDrop = new DropTargetAdapter() {

            @Override
            public void drop(DropTargetDropEvent dtde) {
                try {
                    Transferable tr = dtde.getTransferable();
                    DataFlavor[] flavors = tr.getTransferDataFlavors();
                    //Checking Dragged Objects for their Flavour Type
                    //Only accept POD Files
                    for (int i = 0; i < flavors.length; i++) {
                        if (flavors[i].isFlavorJavaFileListType()) {
                            dtde.acceptDrop(dtde.getDropAction());
                            List files = (List) tr.getTransferData(flavors[i]);
                            File file = (File) files.get(0);
                            if (!file.getName().toLowerCase().endsWith("POD".toLowerCase()) || file.isDirectory()) {
                                dtde.rejectDrop();
                                return;
                            }
                            //Load dropped File
                            loadPODFile(file);
                            return;
                        }
                    }
                } catch (Throwable t) {
                }
                dtde.rejectDrop();
            }
        };
        //Activating drag-and-drop
        DropTarget listTarget = new DropTarget(ChaptersList, listDrop);
        DropTarget coverFieldTarget = new DropTarget(CoverField, coverFieldDrop);
        DropTarget targetDirTarget = new DropTarget(FolderField, targetDirDrop);
        DropTarget mainTarget = new DropTarget(this, mainDrop);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup = new javax.swing.ButtonGroup();
        openFilesButton = new javax.swing.JButton();
        FilesScrollPane = new javax.swing.JScrollPane();
        ChaptersList = new javax.swing.JList();
        upButton = new javax.swing.JButton();
        downButton = new javax.swing.JButton();
        removeButton = new javax.swing.JButton();
        ChapterPropPanel = new javax.swing.JPanel();
        TitleLabel = new javax.swing.JLabel();
        titleField = new javax.swing.JTextField();
        FileLabel = new javax.swing.JLabel();
        fileField = new javax.swing.JTextField();
        BookPropPanel = new javax.swing.JPanel();
        CoverLabel = new javax.swing.JLabel();
        CoverField = new javax.swing.JTextField();
        SearchCoverButton = new javax.swing.JButton();
        createAudiobookButton = new javax.swing.JButton();
        TargetDirLabel = new javax.swing.JLabel();
        FolderField = new javax.swing.JTextField();
        SearchFolderButton = new javax.swing.JButton();
        CopyRadioButton = new javax.swing.JRadioButton();
        moveRadioButton = new javax.swing.JRadioButton();
        createPodFileButton = new javax.swing.JButton();
        NameField = new javax.swing.JTextField();
        editTagsButton = new javax.swing.JButton();
        RemoveCoverButton = new javax.swing.JButton();
        NameTagLabel = new javax.swing.JLabel();
        NameTag = new javax.swing.JLabel();
        ArtistTagLabel = new javax.swing.JLabel();
        ArtistTag = new javax.swing.JLabel();
        AlbumTagLabel = new javax.swing.JLabel();
        AlbumTag = new javax.swing.JLabel();
        DeleteFiles = new javax.swing.JCheckBox();
        useProfile = new javax.swing.JButton();
        SortButton = new javax.swing.JButton();
        menuBar = new javax.swing.JMenuBar();
        FileMenu = new javax.swing.JMenu();
        openFilesMenuItem = new javax.swing.JMenuItem();
        loadPODFileMenuItem = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        ExitMenuItem = new javax.swing.JMenuItem();
        SpecialMenu = new javax.swing.JMenu();
        createChapterProfileMenuItem = new javax.swing.JMenuItem();
        HelpMenu = new javax.swing.JMenu();
        AboutMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Audiobook Maker");
        setIconImage(new ImageIcon(Main.class.getResource("audiobook_icon.png")).getImage());
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        openFilesButton.setText("Dateien öffnen");
        openFilesButton.setToolTipText("Dateien zum Hörbuch hinzufügen");
        openFilesButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openFilesButtonActionPerformed(evt);
            }
        });

        ChaptersList.setModel(new DefaultListModel());
        ChaptersList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                ChaptersListValueChanged(evt);
            }
        });
        ChaptersList.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                ChaptersListKeyPressed(evt);
            }
        });
        FilesScrollPane.setViewportView(ChaptersList);

        upButton.setText("nach oben");
        upButton.setToolTipText("Ausgewähltes Kapitel nach oben bewegen");
        upButton.setEnabled(false);
        upButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                upButtonActionPerformed(evt);
            }
        });

        downButton.setText("nach unten");
        downButton.setToolTipText("Ausgewähltes Kapitel nach unten bewegen");
        downButton.setEnabled(false);
        downButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downButtonActionPerformed(evt);
            }
        });

        removeButton.setText("Entfernen");
        removeButton.setToolTipText("Ausgewähltes Kapitel entfernen");
        removeButton.setEnabled(false);
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeButtonActionPerformed(evt);
            }
        });

        ChapterPropPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Kapitel-Eigenschaften"));

        TitleLabel.setText("Titel:");

        titleField.setEditable(false);
        titleField.setToolTipText("Namen für ausgewähltes Kapitel angeben");
        titleField.setDragEnabled(true);
        titleField.getDocument().addDocumentListener(new DocumentListener() {
            public void changedUpdate(DocumentEvent e){
                renameChapter();
            }

            public void removeUpdate(DocumentEvent e){
                renameChapter();
            }

            public void insertUpdate(DocumentEvent e){
                renameChapter();
            }
        });
        titleField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                titleFieldActionPerformed(evt);
            }
        });

        FileLabel.setText("Datei:");

        fileField.setEditable(false);

        javax.swing.GroupLayout ChapterPropPanelLayout = new javax.swing.GroupLayout(ChapterPropPanel);
        ChapterPropPanel.setLayout(ChapterPropPanelLayout);
        ChapterPropPanelLayout.setHorizontalGroup(
            ChapterPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ChapterPropPanelLayout.createSequentialGroup()
                .addGroup(ChapterPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(TitleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(FileLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(ChapterPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(fileField, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)
                    .addComponent(titleField, javax.swing.GroupLayout.DEFAULT_SIZE, 565, Short.MAX_VALUE)))
        );
        ChapterPropPanelLayout.setVerticalGroup(
            ChapterPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ChapterPropPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ChapterPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FileLabel)
                    .addComponent(fileField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(6, 6, 6)
                .addGroup(ChapterPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TitleLabel)
                    .addComponent(titleField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(127, Short.MAX_VALUE))
        );

        BookPropPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Hörbuch-Eigenschaften"));

        CoverLabel.setText("Cover:");

        CoverField.setEditable(false);

        SearchCoverButton.setText("...");
        SearchCoverButton.setToolTipText("Cover-Datei suchen");
        SearchCoverButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchCoverButtonActionPerformed(evt);
            }
        });

        createAudiobookButton.setText("Hörbuch erstellen");
        createAudiobookButton.setToolTipText(".m4b Datei erstellen (vorher muss eine .POD Datei erstellt werden)");
        createAudiobookButton.setEnabled(false);
        createAudiobookButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createAudiobookButtonActionPerformed(evt);
            }
        });

        TargetDirLabel.setText("Ordner:");

        FolderField.setEditable(false);

        SearchFolderButton.setText("Suchen...");
        SearchFolderButton.setToolTipText("Zielordner für die Dateien auswählen");
        SearchFolderButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SearchFolderButtonActionPerformed(evt);
            }
        });

        buttonGroup.add(CopyRadioButton);
        CopyRadioButton.setSelected(true);
        CopyRadioButton.setText("Dateien kopieren");
        CopyRadioButton.setToolTipText("Audiodateien in den Zielordner kopieren");

        buttonGroup.add(moveRadioButton);
        moveRadioButton.setText("Dateien verschieben");
        moveRadioButton.setToolTipText("Audiodateien in den Zielordner verschieben");

        createPodFileButton.setText(".POD Datei erstellen");
        createPodFileButton.setToolTipText("");
        createPodFileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createPodFileButtonActionPerformed(evt);
            }
        });

        NameField.setText("Name");
        NameField.setToolTipText("Namen für das Hörbuch auswählen");
        NameField.getDocument().addDocumentListener(new DocumentListener() {
            public void changedUpdate(DocumentEvent e){
                checkPOD();
            }

            public void removeUpdate(DocumentEvent e){
                checkPOD();
            }

            public void insertUpdate(DocumentEvent e){
                checkPOD();
            }
        });

        editTagsButton.setText("Tags bearbeiten");
        editTagsButton.setToolTipText("Tags für das Hörbuch eingeben. ACHTUNG: funktioniert noch nicht unbedingt bei iTunes");
        editTagsButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editTagsButtonActionPerformed(evt);
            }
        });

        RemoveCoverButton.setText("Löschen");
        RemoveCoverButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RemoveCoverButtonActionPerformed(evt);
            }
        });

        NameTagLabel.setText("Name: ");

        NameTag.setText("...");

        ArtistTagLabel.setText("Interpret: ");

        ArtistTag.setText("...");

        AlbumTagLabel.setText("Album: ");

        AlbumTag.setText("...");

        DeleteFiles.setText("Dateien löschen");
        DeleteFiles.setToolTipText("Dateien nach erstellen des Hörbuches aus Zielordner löschen (Sie werden nicht mehr benötigt)");

        javax.swing.GroupLayout BookPropPanelLayout = new javax.swing.GroupLayout(BookPropPanel);
        BookPropPanel.setLayout(BookPropPanelLayout);
        BookPropPanelLayout.setHorizontalGroup(
            BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(BookPropPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, BookPropPanelLayout.createSequentialGroup()
                        .addComponent(NameField, javax.swing.GroupLayout.DEFAULT_SIZE, 225, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(createPodFileButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(createAudiobookButton))
                    .addGroup(BookPropPanelLayout.createSequentialGroup()
                        .addGroup(BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(TargetDirLabel)
                            .addComponent(CoverLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, BookPropPanelLayout.createSequentialGroup()
                                .addComponent(CoverField, javax.swing.GroupLayout.DEFAULT_SIZE, 305, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(SearchCoverButton))
                            .addComponent(FolderField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(RemoveCoverButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(SearchFolderButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addGroup(BookPropPanelLayout.createSequentialGroup()
                        .addComponent(CopyRadioButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(moveRadioButton)
                        .addGap(18, 18, 18)
                        .addComponent(DeleteFiles)
                        .addContainerGap(132, Short.MAX_VALUE))
                    .addGroup(BookPropPanelLayout.createSequentialGroup()
                        .addComponent(editTagsButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(NameTagLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(NameTag)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ArtistTagLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ArtistTag)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(AlbumTagLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(AlbumTag)
                        .addGap(165, 165, 165))))
        );
        BookPropPanelLayout.setVerticalGroup(
            BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(BookPropPanelLayout.createSequentialGroup()
                .addGroup(BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CoverLabel)
                    .addComponent(CoverField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(RemoveCoverButton)
                    .addComponent(SearchCoverButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(TargetDirLabel)
                    .addComponent(FolderField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(SearchFolderButton))
                .addGap(18, 18, 18)
                .addGroup(BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(CopyRadioButton)
                    .addComponent(moveRadioButton)
                    .addComponent(DeleteFiles))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(editTagsButton)
                    .addComponent(NameTagLabel)
                    .addComponent(NameTag)
                    .addComponent(ArtistTagLabel)
                    .addComponent(ArtistTag)
                    .addComponent(AlbumTagLabel)
                    .addComponent(AlbumTag))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(BookPropPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(createAudiobookButton)
                    .addComponent(createPodFileButton)
                    .addComponent(NameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        useProfile.setText("Kapitelprofil anwenden");
        useProfile.setToolTipText("Namen der ausgewählten Kapitel automatisch bearbeiten");
        useProfile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                useProfileActionPerformed(evt);
            }
        });

        SortButton.setText("Sortieren");
        SortButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                SortButtonActionPerformed(evt);
            }
        });

        FileMenu.setText("Datei");
        FileMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openFilesButtonActionPerformed(evt);
            }
        });

        openFilesMenuItem.setText("Dateien öffnen");
        FileMenu.add(openFilesMenuItem);

        loadPODFileMenuItem.setText("POD Datei laden");
        loadPODFileMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loadPODFileMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(loadPODFileMenuItem);
        FileMenu.add(jSeparator1);

        ExitMenuItem.setText("Beenden");
        ExitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ExitMenuItemActionPerformed(evt);
            }
        });
        FileMenu.add(ExitMenuItem);

        menuBar.add(FileMenu);

        SpecialMenu.setText("Spezial");

        createChapterProfileMenuItem.setText("Kapitelprofil Editor");
        createChapterProfileMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createChapterProfileMenuItemActionPerformed(evt);
            }
        });
        SpecialMenu.add(createChapterProfileMenuItem);

        menuBar.add(SpecialMenu);

        HelpMenu.setText("Hilfe");
        HelpMenu.setToolTipText("");

        AboutMenuItem.setText("Über");
        AboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AboutMenuItemActionPerformed(evt);
            }
        });
        HelpMenu.add(AboutMenuItem);

        menuBar.add(HelpMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(useProfile, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(SortButton))
                    .addComponent(FilesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(removeButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(downButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(upButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(openFilesButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(BookPropPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(ChapterPropPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(FilesScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(useProfile)
                            .addComponent(SortButton)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(openFilesButton)
                                .addGap(47, 47, 47)
                                .addComponent(upButton)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(downButton)
                                .addGap(18, 18, 18)
                                .addComponent(removeButton))
                            .addComponent(BookPropPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(ChapterPropPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * Opens a Filechooser dialog to choose a Folder or Files to load.
     * @param evt Auto Generated Event; not used
     */
    private void openFilesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openFilesButtonActionPerformed
        JFileChooser chooser = new JFileChooser(Main.lastDir);
        chooser.addChoosableFileFilter(new FileNameExtensionFilter("Mpeg 4 audio files(*.m4a)", "m4a"));
        chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setMultiSelectionEnabled(true);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            Main.lastDir = chooser.getCurrentDirectory();
            //Load all selected files and foders
            for (File file : chooser.getSelectedFiles()) {
                load(file);
            }
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
        updateChaptersList();
    }//GEN-LAST:event_openFilesButtonActionPerformed

    /**
     * loads an audiofile to this active project. If the file is a folder every subfolder's audiofile and subfolder will be loaded
     * @param f a file
     */
    private void load(File f) {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        if (f.isDirectory()) {
            //load all subfolder's *.m4a files and folders
            FileFilter filter = new FileFilter() {

                @Override
                public boolean accept(File pathname) {
                    return pathname.isDirectory() || pathname.getName().toLowerCase().endsWith(".m4a".toLowerCase());
                }
            };
            for (File file : f.listFiles(filter)) {
                load(file);
            }
        } else {
            //add a new chapter with an audiofile
            Chapter c = new Chapter();
            c.setFile(f);
            c.setTitle(f.getName());
            //Read the audiofile's length
            boolean error = false;
            try {
                c.calculateTime();
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(this, "Beim Laden der Datei\"" + f.getPath() + "\" ist ein Fehler aufgetreten. Diese Datei wurde NICHT geladen", "Fehler", JOptionPane.ERROR_MESSAGE);
                error = true;
            }
            if (!error) {
                Main.currBook.add(c);
            }
        }
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }

    /**
     * Moves the selected chapter up
     * @param evt Auto Generated Event; not used
     */
    private void upButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upButtonActionPerformed
        if (ChaptersList.getSelectedIndices()[0] <= 0) {
            return;
        }
        List<Chapter> tmpChapters = new ArrayList<>();
        int[] indices = ChaptersList.getSelectedIndices();
        for (int i = indices.length - 1; i >= 0; i--) {
            tmpChapters.add(Main.currBook.remove(indices[i]));
        }
        List<Chapter> chapters = new ArrayList<>();
        for (int i = tmpChapters.size() - 1; i >= 0; i--) {
            chapters.add(tmpChapters.get(i));

        }
        for (int i = 0; i < chapters.size(); i++) {
            Chapter chapter = chapters.get(i);
            Main.currBook.add(indices[i] - 1, chapter);
        }
        updateChaptersList();
        int[] select = new int[indices.length];
        for (int i = 0; i < indices.length; i++) {
            int j = indices[i];
            select[i] = j - 1;
        }
        ChaptersList.setSelectedIndices(select);
    }//GEN-LAST:event_upButtonActionPerformed

    /**
     * Moves the selected chapter down
     * @param evt Auto Generated Event; not used
     */
    private void downButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downButtonActionPerformed
        if (ChaptersList.getSelectedIndices()[ChaptersList.getSelectedIndices().length - 1] >= Main.currBook.size() - 1) {
            return;
        }
        List<Chapter> tmpChapters = new ArrayList<>();
        int[] indices = ChaptersList.getSelectedIndices();
        for (int i = indices.length - 1; i >= 0; i--) {
            tmpChapters.add(Main.currBook.remove(indices[i]));
        }
        List<Chapter> chapters = new ArrayList<>();
        for (int i = tmpChapters.size() - 1; i >= 0; i--) {
            chapters.add(tmpChapters.get(i));

        }
        for (int i = 0; i < chapters.size(); i++) {
            Chapter chapter = chapters.get(i);
            Main.currBook.add(indices[i] + 1, chapter);
        }
        updateChaptersList();
        int[] select = new int[indices.length];
        for (int i = 0; i < indices.length; i++) {
            int j = indices[i];
            select[i] = j + 1;
        }
        ChaptersList.setSelectedIndices(select);
    }//GEN-LAST:event_downButtonActionPerformed

    /**
     * Called when the List's selection was changed. Enables/disables the buttons
     * @param evt Auto Generated Event; not used
     */
    private void ChaptersListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_ChaptersListValueChanged
        if (ChaptersList.getSelectedIndex() == -1 || ChaptersList.getSelectedIndices().length > 1) {
            upButton.setEnabled(false);
            downButton.setEnabled(false);
            removeButton.setEnabled(false);
            titleField.setEditable(false);
        } else {
            upButton.setEnabled(true);
            downButton.setEnabled(true);
            removeButton.setEnabled(true);
            titleField.setEditable(true);
            try {
                fileField.setText(Main.currBook.get(ChaptersList.getSelectedIndex()).getFile().getPath());
            } catch (NullPointerException ex) {
                fileField.setText("");
            }
            try {
                titleField.setText(Main.currBook.get(ChaptersList.getSelectedIndex()).getTitle());
            } catch (NullPointerException ex) {
                titleField.setText("");
            }
        }
    }//GEN-LAST:event_ChaptersListValueChanged

    /**
     * Removes the selected chapter
     * @param evt Auto Generated Event; not used
     */
    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
        int index;
        for (int i = ChaptersList.getSelectedIndices().length - 1; i >= 0; i--) {
            index = ChaptersList.getSelectedIndices()[i];
            Main.currBook.remove(index);
        }
        updateChaptersList();
    }//GEN-LAST:event_removeButtonActionPerformed

    /**
     * Opens a filechooser dialog to select a imagefile to use as cover
     * @param evt Auto Generated Event; not used
     */
    private void SearchCoverButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchCoverButtonActionPerformed
        JFileChooser chooser = new JFileChooser(Main.lastDir);
        chooser.setMultiSelectionEnabled(false);
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.addChoosableFileFilter(new FileNameExtensionFilter("Image Files(*.jpg, *.png)", "jpg", "jpeg", "png"));
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            Main.lastDir = chooser.getCurrentDirectory();
            Main.currBook.setImageFile(chooser.getSelectedFile());
            CoverField.setText(chooser.getSelectedFile().getPath());
        }
    }//GEN-LAST:event_SearchCoverButtonActionPerformed

    /**
     * Opens a filechooser dialog to select a target folder for the files
     * @param evt Auto Generated Event; not used
     */
    private void SearchFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SearchFolderButtonActionPerformed
        JFileChooser chooser = new JFileChooser();
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setMultiSelectionEnabled(false);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            Main.currBook.setTargetFolder(chooser.getSelectedFile());
            FolderField.setText(chooser.getSelectedFile().getPath());
        }
        checkPOD();
    }//GEN-LAST:event_SearchFolderButtonActionPerformed

    /**
     * Creates the .POD File
     * @param evt Auto Generated Event; not used
     */
    private void createPodFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createPodFileButtonActionPerformed
        createPODFile();
    }//GEN-LAST:event_createPodFileButtonActionPerformed

    public void createPODFile() {
        //<editor-fold defaultstate="collapsed" desc="Checking for errors">
        boolean isError = false;
        String errorText = "<html><head></head><body>Beim Erstellen der .POD Datei sind folgende Fehler aufgetreten;<ul>";
        //No target folder selected
        if (FolderField.getText().equals("")) {
            errorText = errorText.concat("<li>Es wurde kein Ordner angegeben</li>");
            isError = true;
        }
        //No name typed
        if (NameField.getText().equals("")) {
            errorText = errorText.concat("<li>Es wurde kein Dateiname angegeben</li>");
            isError = true;
        }
        //No files loaded
        if (!(Main.currBook.size() > 0)) {
            errorText = errorText.concat("<li>Es wurden keine Dateien ausgewählt</li>");
            isError = true;
        }
        if (isError) {
            errorText = errorText.concat("</ul>Der Prozess konnte nicht abgeschlossen werden</body></html>");
            JOptionPane.showMessageDialog(this, errorText, "Fehler", JOptionPane.ERROR_MESSAGE);
            return;
        }
        //</editor-fold>
        //If no cover is selected let the user confirm to proceed
        if (CoverField.getText().equals("") && JOptionPane.showConfirmDialog(this, "Es wurde kein Cover ausgewählt. Fortfahren?", "Fortfahren?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.NO_OPTION) {
            return;
        }

        SwingWorker<Boolean, Boolean> worker = new SwingWorker<Boolean, Boolean>() {

            @Override
            protected Boolean doInBackground() throws Exception {
                //<editor-fold defaultstate="collapsed" desc="Copy or move files (Old version)">
                /*if (CopyRadioButton.isSelected()) {
                //Copy Files
                dialog.ActionLabel.setText("Dateien kopieren...");
                for (Chapter chapter : Main.currBook) {
                dialog.MessageLabel.setText("Datei: " + chapter.getFile().getPath());
                dialog.validate();
                dialog.repaint();
                boolean success = true;
                if (!Files.FileActions.isInside(Main.currBook.getTargetFolder(), chapter.getFile())) {
                File newFile = new File(Main.currBook.getTargetFolder().getPath() + "/" + chapter.getFile().getName());
                success = Files.FileActions.fastCopy(chapter.getFile(), newFile);
                chapter.setFile(newFile);
                }
                dialog.progressBar.setValue(dialog.progressBar.getValue() + 1);
                dialog.validate();
                dialog.repaint();
                if (!success) {
                if (JOptionPane.showConfirmDialog(null, "Beim Kopieren der Datei \"" + chapter.getFile().getPath() + "\" ist ein Fehler aufgetreten.\n\nTrotzdem fortfahren?", "Fortfahren?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.NO_OPTION) {
                dialog.dispose();
                return;
                }
                }
                }
                //Copy Cover
                if (Main.currBook.getImageFile() != null) {
                dialog.MessageLabel.setText("Datei: " + Main.currBook.getImageFile().getPath());
                dialog.validate();
                dialog.repaint();
                boolean success = true;
                if (!Files.FileActions.isInside(Main.currBook.getTargetFolder(), Main.currBook.getImageFile())) {
                File newFile = new File(Main.currBook.getTargetFolder().getPath() + "/" + Main.currBook.getImageFile().getName());
                success = Files.FileActions.fastCopy(Main.currBook.getImageFile(), newFile);
                Main.currBook.setImageFile(newFile);
                }
                dialog.progressBar.setValue(dialog.progressBar.getValue() + 1);
                dialog.validate();
                dialog.repaint();
                if (!success) {
                JOptionPane.showMessageDialog(null, "Beim Kopieren des Covers ist ein Fehler aufgetreten. Der Prozess kann nicht fortgeführt werden", "Fehler", JOptionPane.ERROR_MESSAGE);
                dialog.dispose();
                return;
                
                }
                }
                
                } else if (moveRadioButton.isSelected()) {
                //Move Files
                dialog.ActionLabel.setText("Dateien verschieben...");
                for (Chapter chapter : Main.currBook) {
                dialog.MessageLabel.setText("Datei: " + chapter.getFile());
                File newFile = new File(Main.currBook.getTargetFolder().getPath() + "/" + chapter.getFile().getName());
                boolean success = chapter.getFile().renameTo(newFile);
                chapter.setFile(newFile);
                dialog.progressBar.setValue(dialog.progressBar.getValue() + 1);
                if (!success) {
                if (JOptionPane.showConfirmDialog(null, "Beim Verschieben der Datei \"" + chapter.getFile().getPath() + "\" ist ein Fehler aufgetreten.\n\nTrotzdem fortfahren?", "Fortfahren?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.NO_OPTION) {
                dialog.dispose();
                return;
                }
                }
                }
                //Move Cover
                if (Main.currBook.getImageFile() != null) {
                dialog.MessageLabel.setText("Datei: " + Main.currBook.getImageFile().getPath());
                File newFile = new File(Main.currBook.getTargetFolder().getPath() + "/" + Main.currBook.getImageFile().getName());
                boolean success = Main.currBook.getImageFile().renameTo(newFile);
                Main.currBook.setImageFile(newFile);
                dialog.progressBar.setValue(dialog.progressBar.getValue() + 1);
                if (!success) {
                JOptionPane.showMessageDialog(null, "Beim Verschieben des Covers ist ein Fehler aufgetreten. Der Prozess kann nicht forgeführt werden.", "Fehler", JOptionPane.ERROR_MESSAGE);
                dialog.dispose();
                return;
                }
                }
                
                }*/
                //</editor-fold>

                int max = Main.currBook.size();
                if (Main.currBook.getImageFile() != null) {
                    max++;
                }
                firePropertyChange("Maximum", 0, max);

                //<editor-fold defaultstate="collapsed" desc="Copy or Move Files (Used version)">
                if (CopyRadioButton.isSelected()) {
                    firePropertyChange("ActionLabel", null, "Dateien Kopieren...");
                } else if (moveRadioButton.isSelected()) {
                    firePropertyChange("ActionLabel", null, "Dateien verschieben...");
                } else {
                    return Boolean.FALSE;
                }

                for (int i = 0; i < Main.currBook.size(); i++) {
                    Chapter chapter = Main.currBook.get(i);
                    firePropertyChange("MessageLabel", null, "Datei: " + chapter.getFile().getPath());
                    File newFile = new File(Main.currBook.getTargetFolder().getPath() + "/" + chapter.getFile().getName());
                    boolean success;
                    if (CopyRadioButton.isSelected()) {
                        success = FileActions.fastCopy(chapter.getFile(), newFile);
                    } else {
                        success = chapter.getFile().renameTo(newFile);
                    }
                    chapter.setFile(newFile);
                    firePropertyChange("ProgressValue", 0, i + 1);
                    if (!success) {
                        firePropertyChange("Error", null, "Beim Kopieren/Verschieben der Datei \"" + chapter.getFile().getPath() + "\" ist ein Fehler aufgetreten.");
                        return Boolean.FALSE;
                    }
                }
                if (Main.currBook.getImageFile() != null) {
                    firePropertyChange("MessageLabel", null, "Datei: " + Main.currBook.getImageFile().getPath());
                    File newFile = new File(Main.currBook.getTargetFolder().getPath() + "/" + Main.currBook.getImageFile().getName());
                    boolean success;
                    if (CopyRadioButton.isSelected()) {
                        success = FileActions.fastCopy(Main.currBook.getImageFile(), newFile);
                    } else {
                        success = Main.currBook.getImageFile().renameTo(newFile);
                    }
                    Main.currBook.setImageFile(newFile);
                    firePropertyChange("ProgressValue", 0, max);
                    if (!success) {
                        firePropertyChange("Error", null, "Beim Kopieren/Verschieben der Datei \"" + Main.currBook.getImageFile().getPath() + "\" ist ein Fehler aufgetreten.");
                        return Boolean.FALSE;
                    }
                }
                //</editor-fold>

                //<editor-fold defaultstate="collapsed" desc="Removing illeagl characters from filenames">
                firePropertyChange("ProgressValue", 0, 0);
                firePropertyChange("ActionLabel", null, "Sonderzeichen entfernen...");
                for (int i = 0; i < Main.currBook.size(); i++) {
                    Chapter chapter = Main.currBook.get(i);
                    firePropertyChange("MessageLabel", null, "Datei: " + chapter.getFile().getPath());
                    File newFile = new File(chapter.getFile().getParent() + "/" + chapter.getFile().getName().replaceAll("[^A-Z^a-z^0-9^_^-^.^ ]", ""));
                    if (newFile.getName().equalsIgnoreCase(".m4a")) {
                        newFile = new File(newFile.getParent() + "/Kapitel" + (i + 1) + ".m4a");
                    }
                    if (!chapter.getFile().renameTo(newFile)) {
                        firePropertyChange("Error", null, "Die Datei " + chapter.getFile().getPath() + " enthält nicht zulässige Zeichen.");
                        //JOptionPane.showMessageDialog(null, "Die Datei " + chapter.getFile().getPath() + " enthält nicht zulässige Zeichen.", "Fehler", JOptionPane.ERROR_MESSAGE);
                        return Boolean.FALSE;
                    }
                    chapter.setFile(newFile);
                    firePropertyChange("ProgressValue", 0, i + 1);
                }
                if (Main.currBook.getImageFile() != null) {
                    File newFile = new File(Main.currBook.getImageFile().getParent() + "/" + Main.currBook.getImageFile().getName().replaceAll("[^A-Z^a-z^0-9^_^-^.^ ]", ""));
                    if (newFile.getName().equalsIgnoreCase(Files.FileActions.getExtention(newFile))) {
                        newFile = new File(newFile.getParent() + "/Cover" + Files.FileActions.getExtention(newFile));
                    }
                    if (!Main.currBook.getImageFile().renameTo(newFile)) {
                        firePropertyChange("Error", null, "Die Datei " + Main.currBook.getImageFile().getPath() + " enthält nicht zulässige Zeichen.");
                        //JOptionPane.showMessageDialog(null, "Die Coverdatei enthält nicht zulässige Zeichen.", "Fehler", JOptionPane.ERROR_MESSAGE);
                        return Boolean.FALSE;
                    }
                    Main.currBook.setImageFile(newFile);
                    firePropertyChange("ProgressValue", 0, max);
                }
                //</editor-fold>

                //<editor-fold defaultstate="collapsed" desc="Writing .POD File">
                firePropertyChange("ProgressValue", 0, 0);
                firePropertyChange("ActionLabel", "", "Script erstellen...");
                FileWriter FWriter = null;
                File PODfile = new File(Main.currBook.getTargetFolder().getPath() + "/" + NameField.getText() + ".POD");
                try {
                    FWriter = new FileWriter(PODfile);
                    BufferedWriter writer = new BufferedWriter(FWriter);

                    //Write head
                    writer.write("[Podcast]\n\n");
                    writer.write("altfolder1=" + Main.currBook.getTargetFolder().getName() + "\n");
                    writer.write("basename=" + NameField.getText() + "\n");
                    writer.write("audiobook=true\n");
                    if (Main.currBook.getImageFile() != null) {
                        writer.write("artwork=" + Main.currBook.getImageFile().getName() + "\n");
                        ImageIcon icon = new ImageIcon(Main.currBook.getImageFile().getPath());
                        writer.write("imgwidth=" + icon.getIconWidth() + "\n");
                        writer.write("imgheight=" + icon.getIconHeight() + "\n");
                    }
                    writer.write("editpointcount=" + Main.currBook.size() + "\n");
                    firePropertyChange("ProgressValue", null, 1);

                    //Write a block for each chapter
                    Time startTime = new Time(false);
                    for (int i = 1; i <= Main.currBook.size(); i++) {
                        Chapter chapter = Main.currBook.get(i - 1);
                        writer.write("\n\n[Editpoint_" + i + "]\n");
                        if (Main.currBook.getImageFile() != null) {
                            writer.write("image=" + Main.currBook.getImageFile().getName() + "\n");
                        }
                        writer.write("audiofile=" + chapter.getFile().getName() + "\n");
                        writer.write("chapter=" + chapter.getTitle() + "\n");
                        writer.write("start=" + startTime.toString() + ".00\n");
                        startTime.add(chapter.getTime());
                        firePropertyChange("ProgressValue", 0, i + 1);
                    }

                    //Write Metadata (not neccessary)
                    if (Main.currBook.getAlbum() != null || Main.currBook.getName() != null || Main.currBook.getArtist() != null) {
                        writer.write("\n[metadata]\n");
                    }
                    if (Main.currBook.getName() != null) {
                        writer.write("©nam=" + Main.currBook.getName() + "\n");
                    }
                    if (Main.currBook.getArtist() != null) {
                        writer.write("©ART=" + Main.currBook.getArtist() + "\n");
                    }
                    if (Main.currBook.getAlbum() != null) {
                        writer.write("©alb=" + Main.currBook.getAlbum());
                    }

                    writer.close();
                    FWriter.close();
                } catch (IOException ex) {
                    //JOptionPane.showMessageDialog(null, "Beim Erstellen der .POD Datei ist ein Fehler aufgetreten. Der Prozess konnte nicht abgeschlossen werden.", "Fehler", JOptionPane.ERROR_MESSAGE);
                    firePropertyChange("Error", null, "Beim Erstellen des Skriptes ist ein Fehler aufgetreten.");
                    try {
                        //remove POD file on error to not let create the user an impossible audiobook
                        PODfile.delete();
                    } catch (Exception exc) {
                    }
                    return Boolean.FALSE;
                }
                //</editor-fold>

                return Boolean.TRUE;
            }

            @Override
            protected void done() {
                try {
                    firePropertyChange("Finish", null, get());
                } catch (InterruptedException | ExecutionException ex) {
                    ex.printStackTrace();
                }
            }
        };

        final ProgressDialog dialog = new ProgressDialog(this, true);
        worker.addPropertyChangeListener(dialog);
        dialog.progressBar.setValue(0);
        dialog.ActionLabel.setText("");
        dialog.MessageLabel.setText("");

        worker.execute();

        dialog.setVisible(true);
    }

    /**
     * Lets SSA create the audiobook file
     * @param evt Auto Generated Event; not used
     */
    private void createAudiobookButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createAudiobookButtonActionPerformed
        //<editor-fold defaultstate="collapsed" desc="Checking for errors">
        boolean isError = false;
        String errorText = "<html><head></head><body>Beim Erstellen des Hörbuchs sind folgende Fehler aufgetreten;<ul>";
        //No target folder
        if (FolderField.getText().equals("")) {
            errorText = errorText.concat("<li>Es wurde kein Ordner angegeben</li>");
            isError = true;
        }
        //No name typed
        if (NameField.getText().equals("")) {
            errorText = errorText.concat("<li>Es wurde kein Dateiname angegeben</li>");
            isError = true;
        }
        if (isError) {
            errorText = errorText.concat("</ul>Der Prozess konnte nicht abgeschlossen werden</body></html>");
            JOptionPane.showMessageDialog(this, errorText, "Fehler", JOptionPane.ERROR_MESSAGE);
            return;
        }
        //Check if the POD file exists; should already be done --> checkPOD();
        final File PODfile = new File(Main.currBook.getTargetFolder().getPath() + "/" + NameField.getText() + ".POD");
        if (!PODfile.exists()) {
            JOptionPane.showMessageDialog(this, "Die .POD Datei \"" + PODfile.getPath() + "\" wurde nicht gefunden", "Fehler", JOptionPane.ERROR_MESSAGE);
            return;
        }
        //</editor-fold>

        SwingWorker worker = new SwingWorker() {

            @Override
            protected Object doInBackground() throws Exception {
                ProcessBuilder builder = new ProcessBuilder("SSA", PODfile.getName()).redirectErrorStream(true);
                builder.directory(Main.currBook.getTargetFolder());
                builder.redirectErrorStream(true);
                final Process p = builder.start();
//                new Thread() {
//
//                    public void run() {
                try {
                    //BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
                    //String line;
                    int i;
                    while ((i = p.getInputStream().read()) != -1) {

                        System.out.println(i);
                    }
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
//                    }
//                }.start();
                return p.exitValue();
            }

            @Override
            protected void done() {
                System.out.println("done");
            }
        };
        worker.execute();

        /*//<editor-fold defaultstate="collapsed" desc="Creating logfile">
        File logFile = new File(Main.currBook.getTargetFolder().getPath() + "/SSA Log.txt");
        if (logFile.exists()) {
        logFile.delete();
        }
        
        logFile.createNewFile();
        BufferedWriter writer = new BufferedWriter(new FileWriter(logFile));
        //Writing the SSA output to the logfile
        writer.write("SSA Output: " + "\n");
        BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
        String line;
        while ((line = reader.readLine()) != null) {
        writer.write("\n" + line);
        }
        writer.write("\n\n\nErgebnis=" + p.exitValue());
        reader.close();
        writer.close();
        //</editor-fold>*/

        /*       //<editor-fold defaultstate="collapsed" desc="Creating Audiobook">
        //Create new ProcessBuilder to use SSA
        ProcessBuilder builder = new ProcessBuilder("SSA", PODfile.getName()).redirectErrorStream(true);
        builder.directory(Main.currBook.getTargetFolder());
        try {
        Process p = builder.start();
        p.waitFor();
        
        //<editor-fold defaultstate="collapsed" desc="Removing files">
        if (DeleteFiles.isSelected()) {
        dialog.setTitle("Aufräumen");
        dialog.ActionLabel.setText("Dateien löschen: ");
        dialog.MessageLabel.setText("");
        dialog.progressBar.setIndeterminate(false);
        dialog.progressBar.setMaximum(Main.currBook.size());
        dialog.progressBar.setValue(0);
        for (Chapter chapter : Main.currBook) {
        dialog.MessageLabel.setText("Datei: " + chapter.getFile().getPath());
        if (!chapter.getFile().delete()) {
        JOptionPane.showMessageDialog(null, "Beim löschen der Datei " + chapter.getFile().getPath() + " ist ein Fehler aufgetreten", "Fehler", JOptionPane.ERROR_MESSAGE);
        }
        dialog.progressBar.setValue(dialog.progressBar.getValue() + 1);
        dialog.validate();
        dialog.repaint();
        }
        }
        //</editor-fold>
        
        JOptionPane.showMessageDialog(null, "Das Hörbuch wurde erfolgreich im Ordner \"" + PODfile.getParent() + "\" erstellt", "Beendet", JOptionPane.INFORMATION_MESSAGE);
        } catch (IOException ex) {
        JOptionPane.showMessageDialog(null, "Beim Erstellen des Hörbuches ist ein Fehler aufgetreten. Der Prozess konnte nicht abgeschlossen werden.", "Fehler", JOptionPane.ERROR_MESSAGE);
        } catch (InterruptedException ex) {
        JOptionPane.showMessageDialog(null, "Der Prozess wurde abgebrochen.", "Fehler", JOptionPane.ERROR_MESSAGE);
        }
        //</editor-fold>*/
    }//GEN-LAST:event_createAudiobookButtonActionPerformed

    /**
     * Lets the user choose a text file to auto rename every selected chapter
     * @param evt Auto Generated Event; not used
     */
private void useProfileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_useProfileActionPerformed
    //Creating preview component
    final JTextArea preview = new JTextArea();
    preview.setEditable(false);
    preview.setLineWrap(true);
    preview.setWrapStyleWord(true);
    preview.setPreferredSize(new Dimension(250, 100));
    File userDir = new File(System.getProperty("user.dir"));
    File profileFolder = new File(userDir.getPath() + "/Profile");
    JFileChooser chooser = new JFileChooser(profileFolder.exists() ? profileFolder : userDir);
    chooser.setMultiSelectionEnabled(false);
    chooser.setAccessory(preview);
    chooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY, new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            try {
                BufferedReader reader = new BufferedReader(new FileReader((File) evt.getNewValue()));
                preview.setText("");
                String line = "";
                while ((line = reader.readLine()) != null) {
                    if (line.startsWith("#")) {
                        preview.append(line.replaceFirst("#", "") + "\n");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        try {
            FileReader FReader = new FileReader(chooser.getSelectedFile());
            BufferedReader reader = new BufferedReader(FReader);

            String profile = "";
            while ((profile = reader.readLine()).startsWith("#")) {
            }
            //Using profile
            useChapterProfile(profile);
            FReader.close();
            reader.close();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}//GEN-LAST:event_useProfileActionPerformed

    /**
     * Renames every loaded Chapter by a single-line String containing <code>QuoteProcessor</code> compatible code.
     * @param profile a single Line String
     * @see NumberQuoteProcessor
     * @see M4aTagQuoteProcessor
     * @see FileNameQuoteProcessor
     * @see AdvancedFileNameQuoteProcessor
     * @see FilepathQuoteProcessor
     * @see QuoteProcessor
     */
    public void useChapterProfile(String profile) {
        if (profile == null || profile == "") {
            return;
        }
        //Creating QuoteProcessor instances
        NumberQuoteProcessor numbQuote = new NumberQuoteProcessor();
        FileNameQuoteProcessor fileNameQuote = new FileNameQuoteProcessor();
        FilepathQuoteProcessor filePathQuote = new FilepathQuoteProcessor();
        AdvancedFileNameQuoteProcessor advancedQuote = new AdvancedFileNameQuoteProcessor();
        M4aTagQuoteProcessor m4aQuote = new M4aTagQuoteProcessor();

        //if no chapter is selected, select all
        if (ChaptersList.getSelectedIndex() == -1) {
            ChaptersList.setSelectionInterval(0, Main.currBook.size() - 1);
        }
        //Applying profile to each loaded and selected chapter
        for (int i : ChaptersList.getSelectedIndices()) {
            Chapter chapter = Main.currBook.get(i);
            numbQuote.setNumber(i + 1);
            fileNameQuote.setFile(chapter.getFile());
            advancedQuote.setFile(chapter.getFile());
            filePathQuote.setFile(chapter.getFile());
            m4aQuote.setFile(chapter.getFile());
            String newTitle = profile;
            newTitle = numbQuote.replaceAll(newTitle);
            newTitle = fileNameQuote.replaceAll(newTitle);
            newTitle = advancedQuote.replaceAll(newTitle);
            newTitle = filePathQuote.replaceAll(newTitle);
            newTitle = m4aQuote.replaceAll(newTitle);
            chapter.setTitle(newTitle);
        }

        updateChaptersList();
    }

    /**
     * Calls the exit method
     * @param evt Auto Generated Event; not used
     */
private void ExitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExitMenuItemActionPerformed
    Main.mainObj.exit();
}//GEN-LAST:event_ExitMenuItemActionPerformed

    /**
     * Calls the exit method
     * @param evt Auto Generated Event; not used
     */
private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
    Main.mainObj.exit();
}//GEN-LAST:event_formWindowClosing

    /**
     * Opens the a new Chapter editor window
     * @param evt Auto Generated Event; not used
     */
private void createChapterProfileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createChapterProfileMenuItemActionPerformed
    ChapterProfileCreator window = new ChapterProfileCreator();
    window.setLocation(Application.getScreenCenterFor(window));
    window.setVisible(true);
}//GEN-LAST:event_createChapterProfileMenuItemActionPerformed

    /**
     * Removes the loaded cover
     * @param evt Auto Generated Event; not used
     */
private void RemoveCoverButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RemoveCoverButtonActionPerformed
    Main.currBook.setImageFile(null);
    CoverField.setText("");
}//GEN-LAST:event_RemoveCoverButtonActionPerformed

    /**
     * Opens a <code>MultipleInputPane</code> to edit tags
     * @param evt Auto Generated Event; not used
     * @see MultipleInputPane
     */
private void editTagsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editTagsButtonActionPerformed
    MultipleInputPane pane = new MultipleInputPane("Name: ", "Interpret: ", "Album: ");
    pane.setText(0, Main.currBook.getName());
    pane.setText(1, Main.currBook.getArtist());
    pane.setText(2, Main.currBook.getAlbum());
    pane.showDialog(this, "Eingabe", JOptionPane.PLAIN_MESSAGE);
    Main.currBook.setName(pane.getText(0));
    Main.currBook.setArtist(pane.getText(1));
    Main.currBook.setAlbum(pane.getText(2));
    NameTag.setText(Main.currBook.getName().equals("") ? "..." : Main.currBook.getName());
    AlbumTag.setText(Main.currBook.getAlbum().equals("") ? "..." : Main.currBook.getAlbum());
    ArtistTag.setText(Main.currBook.getArtist().equals("") ? "..." : Main.currBook.getArtist());
    pack();
}//GEN-LAST:event_editTagsButtonActionPerformed

    /**
     * Shows an about box
     * @param evt Auto Generated Event; not used
     */
private void AboutMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AboutMenuItemActionPerformed
    Main.mainObj.showAboutBox();
}//GEN-LAST:event_AboutMenuItemActionPerformed

    /**
     * Sorts all chapters alphabetical
     * @param evt Auto Generated Event; not used
     */
private void SortButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SortButtonActionPerformed
    Collections.sort(Main.currBook);
    updateChaptersList();
}//GEN-LAST:event_SortButtonActionPerformed

    /**
     * Called when the user presses the [Enter] Key after typing in titleField
     * @param evt Auto Generated Event; not used
     */
    private void titleFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_titleFieldActionPerformed
        ChaptersList.removeSelectionInterval(ChaptersList.getSelectedIndex(), ChaptersList.getSelectedIndex());
    }//GEN-LAST:event_titleFieldActionPerformed

    /**
     * Provides methods to react on Key actions inside the List
     * @param evt a Key Event
     */
    private void ChaptersListKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_ChaptersListKeyPressed
        //Delete
        if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
            removeButtonActionPerformed(null);
        }
    }//GEN-LAST:event_ChaptersListKeyPressed

    /**
     * Loads all available information of a POD file and sets them active
     * @param evt Auto Generated Event; not used
     */
    private void loadPODFileMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loadPODFileMenuItemActionPerformed
        //Open filechooser dialog
        JFileChooser chooser = new JFileChooser(Main.lastDir);
        chooser.addChoosableFileFilter(new FileNameExtensionFilter("*.POD Files", "POD"));
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setAcceptAllFileFilterUsed(false);
        chooser.setMultiSelectionEnabled(false);
        if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
            Main.lastDir = chooser.getCurrentDirectory();
            loadPODFile(chooser.getSelectedFile());
        }
    }//GEN-LAST:event_loadPODFileMenuItemActionPerformed

    public void loadPODFile(File podFile) {
        try {
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            //setting targetFolder
            Main.currBook.setTargetFolder(podFile.getParentFile());
            BufferedReader reader = new BufferedReader(new FileReader(podFile));
            String line = "";
            String errorText = "<html>Beim Laden folgender Dateien sind Fehler aufgetreten, sodass sie nicht geladen wurden:<br /><ul>";
            boolean error = false;
            //<editor-fold defaultstate="collapsed" desc="Reading lines">
            while (line != null) {
                if (line.startsWith("basename=")) {
                    //seting Name
                    NameField.setText(line.substring(line.indexOf("=") + 1));
                    line = reader.readLine();
                } else if (line.startsWith("[Editpoint")) {
                    //Creating a new chapter
                    Chapter newChapter = new Chapter();
                    boolean wasError = error;
                    while (!(line = reader.readLine()).startsWith("[")) {
                        if (line.startsWith("audiofile")) {
                            //Setting the chapter's file
                            File audiofile = new File(podFile.getParent() + "/" + line.substring(line.indexOf("=") + 1));
                            newChapter.setFile(audiofile);
                            //Reading the audiotrack's length
                            try {
                                newChapter.calculateTime();
                                error = false;
                            } catch (Exception ex) {
                                errorText = errorText.concat("<li>" + newChapter.getFile().getPath() + "</li>");
                                error = true;
                            }
                        } else if (line.startsWith("chapter")) {
                            //Setting the title of the chapter
                            newChapter.setTitle(line.substring(line.indexOf("=") + 1));
                        }
                    }
                    if (!error) {
                        //If there is no error add chapter to active audiobook
                        Main.currBook.add(newChapter);
                        error = wasError;
                    }

                    //Reading tag information
                } else if (line.startsWith("©nam")) {
                    Main.currBook.setName(line.substring(line.indexOf("=") + 1));
                    line = reader.readLine();
                } else if (line.startsWith("©ART")) {
                    Main.currBook.setArtist(line.substring(line.indexOf("=") + 1));
                    line = reader.readLine();
                } else if (line.startsWith("©alb")) {
                    Main.currBook.setAlbum(line.substring(line.indexOf("=") + 1));
                    line = reader.readLine();
                } else {
                    line = reader.readLine();
                }
            }
            //</editor-fold>
            if (error) {
                //Show error log
                errorText = errorText.concat("</ul>Prüfen Sie, ob die Dateien funktionsfähige *.m4a Dateien und im Ordner der POD Datei vorhanden sind.</html>");
                JOptionPane.showMessageDialog(this, errorText, "Fehler", JOptionPane.ERROR_MESSAGE);
            }

            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        repaintAll();
    }

    /**
     * Auto called. Checks wether a POD file in the target folder exists
     */
    public void checkPOD() {
        try {
            if (new File(Main.currBook.getTargetFolder().getPath() + "/" + NameField.getText() + ".POD").exists()) {
                createAudiobookButton.setEnabled(true);
            } else {
                createAudiobookButton.setEnabled(false);
            }
        } catch (Exception ex) {
            createAudiobookButton.setEnabled(false);
        }
    }

    /**
     * Auto called. Updates the Chapters List.
     */
    public void renameChapter() {
        Chapter c = Main.currBook.get(ChaptersList.getSelectedIndex());
        c.setTitle(titleField.getText());
    }

    /**
     * Creates a new <code>TreeModel</code> with all loaded chapters and sets it as active model
     */
    public void updateChaptersList() {
        DefaultListModel model = new DefaultListModel();
        for (Object chapter : Main.currBook) {
            model.addElement(chapter);
        }
        ChaptersList.setModel(model);
        ChaptersList.repaint();
    }

    /**
     * Sets data of all components by their related variables
     */
    public void repaintAll() {
        updateChaptersList();
        CoverField.setText(Main.currBook.getImageFile() == null ? "" : Main.currBook.getImageFile().getPath());
        NameTag.setText(Main.currBook.getName().equals("") ? "..." : Main.currBook.getName());
        AlbumTag.setText(Main.currBook.getAlbum().equals("") ? "..." : Main.currBook.getAlbum());
        ArtistTag.setText(Main.currBook.getArtist().equals("") ? "..." : Main.currBook.getArtist());
        FolderField.setText(Main.currBook.getTargetFolder().getPath());
        checkPOD();
    }
    //<editor-fold defaultstate="collapsed" desc="Variables declaration">
    DropTargetListener listDrop;
    DropTargetListener coverFieldDrop;
    DropTargetListener targetDirDrop;
    DropTargetListener mainDrop;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenuItem AboutMenuItem;
    private javax.swing.JLabel AlbumTag;
    private javax.swing.JLabel AlbumTagLabel;
    private javax.swing.JLabel ArtistTag;
    private javax.swing.JLabel ArtistTagLabel;
    private javax.swing.JPanel BookPropPanel;
    private javax.swing.JPanel ChapterPropPanel;
    private javax.swing.JList ChaptersList;
    private javax.swing.JRadioButton CopyRadioButton;
    private javax.swing.JTextField CoverField;
    private javax.swing.JLabel CoverLabel;
    private javax.swing.JCheckBox DeleteFiles;
    private javax.swing.JMenuItem ExitMenuItem;
    private javax.swing.JLabel FileLabel;
    private javax.swing.JMenu FileMenu;
    private javax.swing.JScrollPane FilesScrollPane;
    private javax.swing.JTextField FolderField;
    private javax.swing.JMenu HelpMenu;
    private javax.swing.JTextField NameField;
    private javax.swing.JLabel NameTag;
    private javax.swing.JLabel NameTagLabel;
    private javax.swing.JButton RemoveCoverButton;
    private javax.swing.JButton SearchCoverButton;
    private javax.swing.JButton SearchFolderButton;
    private javax.swing.JButton SortButton;
    private javax.swing.JMenu SpecialMenu;
    private javax.swing.JLabel TargetDirLabel;
    private javax.swing.JLabel TitleLabel;
    private javax.swing.ButtonGroup buttonGroup;
    private javax.swing.JButton createAudiobookButton;
    private javax.swing.JMenuItem createChapterProfileMenuItem;
    private javax.swing.JButton createPodFileButton;
    private javax.swing.JButton downButton;
    private javax.swing.JButton editTagsButton;
    private javax.swing.JTextField fileField;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenuItem loadPODFileMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JRadioButton moveRadioButton;
    private javax.swing.JButton openFilesButton;
    private javax.swing.JMenuItem openFilesMenuItem;
    private javax.swing.JButton removeButton;
    private javax.swing.JTextField titleField;
    private javax.swing.JButton upButton;
    private javax.swing.JButton useProfile;
    // End of variables declaration//GEN-END:variables
    //</editor-fold>
}
