/**
 * 
         -------- Copyright (C) [2012]  [Kristofer SCHWEIGER & Niklas FLORIAN1]---------

    This program is free software; you can redistribute it and/or modify it under the terms of the
 *  GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
 *  or (at your option) any later version.
    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU General Public License for more details.
 * 
    You should have received a copy of the GNU General Public License along with this program; if not, 
 *  write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA

 * 
 * For any licensing issues please contact us under following adress: Mosaik.Projekt.2012@gmail.com
 */
package gui;

import dataBase.DataBase;
import java.awt.Frame;
import java.io.File;
import javax.swing.filechooser.FileFilter;
import java.io.IOException;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.UIManager;
import mosaik.MosaikFunctions;
import org.jdesktop.application.Action;
import util.simpleIO.Out;

public class Configurations extends JDialog {

    private MosaikApp mosaik;
    private JFileChooser jFileChooser1;
    private File picturesDirectory;

    /** Creates new form Configuration */
    public Configurations(JFrame parent, Boolean modal) {
        super(parent, modal);
        mosaik = (MosaikApp) parent;

        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel4 = new javax.swing.JPanel();
        jButton8 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jButton7 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jButton9 = new javax.swing.JButton();
        jTextField7 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jButton4 = new javax.swing.JButton();
        jTextField3 = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jTextField2 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jTextField5 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jLabel10 = new javax.swing.JLabel();
        jButton11 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Einstellungen");
        setModal(true);
        setResizable(false);

        jPanel4.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel4.setName("jPanel4"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(Configurations.class, this);
        jButton8.setAction(actionMap.get("makeNewDatabase")); // NOI18N
        jButton8.setName("jButton8"); // NOI18N

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Datenbank erstellen"));
        jPanel1.setName("jPanel1"); // NOI18N

        jButton7.setAction(actionMap.get("chooseNewDatabase")); // NOI18N
        jButton7.setName("jButton7"); // NOI18N

        jLabel8.setText("Quellverzeichnis der Bilder:");
        jLabel8.setName("jLabel8"); // NOI18N

        jTextField6.setFocusable(false);
        jTextField6.setName("jTextField6"); // NOI18N

        jButton9.setAction(actionMap.get("chooseDirectory")); // NOI18N
        jButton9.setName("jButton9"); // NOI18N

        jTextField7.setFocusable(false);
        jTextField7.setName("jTextField7"); // NOI18N

        jLabel9.setText("Speicherort:");
        jLabel9.setName("jLabel9"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(80, 80, 80)
                        .addComponent(jLabel9))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel8)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 347, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton7)
                    .addComponent(jButton9))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addComponent(jLabel9)
                .addContainerGap(54, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(30, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton7)
                    .addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton9)
                    .addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addGap(18, 18, 18))
        );

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel1.setForeground(new java.awt.Color(51, 204, 0));
        jLabel1.setName("jLabel1"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(16, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(154, 154, 154)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton8, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                    .addComponent(jButton8))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel5.setName("jPanel5"); // NOI18N

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Bestehende Datenbank mit Verzeichnis verschmelzen"));
        jPanel3.setName("jPanel3"); // NOI18N

        jButton4.setAction(actionMap.get("chooseDatabaseToMergeWithDirectory")); // NOI18N
        jButton4.setName("jButton4"); // NOI18N

        jTextField3.setFocusable(false);
        jTextField3.setName("jTextField3"); // NOI18N

        jLabel5.setText("Datenbank:");
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText("Verzeichnis:");
        jLabel6.setName("jLabel6"); // NOI18N

        jTextField4.setFocusable(false);
        jTextField4.setName("jTextField4"); // NOI18N

        jButton5.setAction(actionMap.get("chooseDirectoryOfPictures")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextField4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 399, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton4, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jButton4))
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton5)
                    .addComponent(jLabel6))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton6.setAction(actionMap.get("mergeDirectoryWithExistingDatabase")); // NOI18N
        jButton6.setName("jButton6"); // NOI18N

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel2.setForeground(new java.awt.Color(51, 204, 0));
        jLabel2.setName("jLabel2"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(124, 124, 124)
                        .addComponent(jButton6, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton6)
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel6.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        jPanel6.setName("jPanel6"); // NOI18N

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Datenbank mit anderer Datenbank verschmelzen"));
        jPanel2.setName("jPanel2"); // NOI18N

        jTextField1.setFocusable(false);
        jTextField1.setName("jTextField1"); // NOI18N

        jTextField2.setFocusable(false);
        jTextField2.setName("jTextField2"); // NOI18N

        jLabel3.setText("1. Datenbank:");
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText("2. Datenbank:");
        jLabel4.setName("jLabel4"); // NOI18N

        jButton1.setAction(actionMap.get("chooseFirstDatabase")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jButton2.setAction(actionMap.get("chooseSecondDatabase")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        jButton12.setAction(actionMap.get("chooseNewDatabaseForMerge")); // NOI18N
        jButton12.setName("jButton12"); // NOI18N

        jTextField5.setFocusable(false);
        jTextField5.setName("jTextField5"); // NOI18N

        jLabel7.setText("Neue Datenbank:");
        jLabel7.setName("jLabel7"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(25, 25, 25)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel2Layout.createSequentialGroup()
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 398, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jButton1))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 398, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(jButton2))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 398, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(10, 10, 10)
                        .addComponent(jButton12)))
                .addContainerGap(6, Short.MAX_VALUE))
        );

        jPanel2Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jTextField1, jTextField2});

        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton2)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel4)
                        .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton12)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel7)
                        .addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        jButton3.setAction(actionMap.get("mergeTwoDatabases")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12));
        jLabel10.setForeground(new java.awt.Color(51, 204, 0));
        jLabel10.setName("jLabel10"); // NOI18N

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                        .addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(127, 127, 127)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jButton3)
                    .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE))
                .addContainerGap(16, Short.MAX_VALUE))
        );

        jButton11.setAction(actionMap.get("close")); // NOI18N
        jButton11.setName("jButton11"); // NOI18N

        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.TRAILING, false)
                    .addComponent(jPanel6, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton11))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(8, 8, 8)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton11)
                .addContainerGap())
        );

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

    @Action
    public void chooseNewDatabase() {
        // Overwrites the standard values of the Look and Feel Preset
        UIManager.put("FileChooser.lookInLabelText", "Speichern in:");
        UIManager.put("FileChooser.upFolderToolTipText", "Einen Ordner aufwärts in der Hierarchie");
        UIManager.put("FileChooser.newFolderToolTipText", "Neuen Ordner anlegen");
        UIManager.put("FileChooser.fileNameLabelText", "Dateiname:");
        UIManager.put("FileChooser.filesOfTypeLabelText", "Dateityp:");
        UIManager.put("FileChooser.cancelButtonText", "Abbrechen");
        UIManager.put("FileChooser.cancelButtonToolTipText ", "Aktion abbrechen");

        jFileChooser1 = new JFileChooser();
        jFileChooser1.removeChoosableFileFilter(jFileChooser1.getFileFilter());
        jFileChooser1.addChoosableFileFilter(new FileFilter() {

            @Override
            public boolean accept(File f) {
                if (f.isDirectory()) {
                    return true;
                }
                String name = f.getName();
                int i = name.lastIndexOf('.');

                if (i > 0 && i < name.length() - 1) {
                    String type = name.substring(i + 1).toLowerCase();		// shorter ;)

                    //if the file extension is "db"
                    if (type.equals("db")) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            public String getDescription() {
                return ".db";
            }
        });

        jFileChooser1.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        if (jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            File dbDirectory = jFileChooser1.getSelectedFile();
            String name = dbDirectory.getName();
            int i = name.lastIndexOf('.');

            if (i > 0 && i < name.length() - 1) {
                String type = name.substring(i + 1).toLowerCase();

                if (type.equals("db")) {
                    this.jTextField6.setText(dbDirectory.getAbsolutePath());
                    this.newDatabaseDirectory = dbDirectory;
                    jLabel1.setText("");

                    //if the file extension is not right (not "db")
                } else {
                    JOptionPane.showMessageDialog(this,
                            "Keine gültige Endung eingeben.",
                            "Tipp: Lassen Sie die Endung weg, oder schreiben sie .db hinter den Dateinamen.",
                            JOptionPane.WARNING_MESSAGE);
                }
                // if no file extension exist
            } else {
                dbDirectory = new File(dbDirectory + ".db");
                this.jTextField6.setText(dbDirectory.getAbsolutePath());
                this.newDatabaseDirectory = dbDirectory;
                jLabel1.setText("");

            }


        }
    }

    @Action
    public void chooseNewDatabaseForMerge() {
        // Overwrites the standard values of the Look and Feel Preset
        UIManager.put("FileChooser.lookInLabelText", "Speichern in:");
        UIManager.put("FileChooser.upFolderToolTipText", "Einen Ordner aufwärts in der Hierarchie");
        UIManager.put("FileChooser.newFolderToolTipText", "Neuen Ordner anlegen");
        UIManager.put("FileChooser.fileNameLabelText", "Dateiname:");
        UIManager.put("FileChooser.filesOfTypeLabelText", "Dateityp:");
        UIManager.put("FileChooser.cancelButtonText", "Abbrechen");
        UIManager.put("FileChooser.cancelButtonToolTipText ", "Aktion abbrechen");

        jFileChooser1 = new JFileChooser();
        jFileChooser1.removeChoosableFileFilter(jFileChooser1.getFileFilter());
        jFileChooser1.addChoosableFileFilter(new FileFilter() {

            @Override
            public boolean accept(File f) {
                if (f.isDirectory()) {
                    return true;
                }
                String name = f.getName();
                int i = name.lastIndexOf('.');

                if (i > 0 && i < name.length() - 1) {
                    String type = name.substring(i + 1).toLowerCase();		// shorter ;)

                    // if file extension ist "db"
                    if (type.equals("db")) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            public String getDescription() {
                return ".db";
            }
        });

        jFileChooser1.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        if (jFileChooser1.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            File dbDirectory = jFileChooser1.getSelectedFile();
            String name = dbDirectory.getName();
            int i = name.lastIndexOf('.');
            if (i > 0 && i < name.length() - 1) {
                String type = name.substring(i + 1).toLowerCase();
                //if the file extension is not right (not "db")
                if (type.equals("db")) {
                    this.jTextField5.setText(dbDirectory.getAbsolutePath());
                    this.newMergeDatabaseDirectory = dbDirectory;
                    jLabel10.setText("");

                } else {
                    JOptionPane.showMessageDialog(this,
                            "Keine gültige Endung eingeben.",
                            "Tipp: Lassen Sie die Endung weg, oder schreiben sie .db hinter den Dateinamen.",
                            JOptionPane.WARNING_MESSAGE);
                }
                // if no file extension exist
            } else {
                dbDirectory = new File(dbDirectory + ".db");
                this.jTextField5.setText(dbDirectory.getAbsolutePath());
                this.newMergeDatabaseDirectory = dbDirectory;
                jLabel10.setText("");

            }


        }
    }

    @Action
    /**
     * Opens a new Dialog to choose a directory
     */
    public void chooseDirectory() {

        JFileChooser jfc = new JFileChooser();
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            picturesDirectory = new File(jfc.getSelectedFile().getAbsolutePath());
            jTextField7.setText(picturesDirectory.getAbsolutePath());
            System.out.print(picturesDirectory);
            jLabel1.setText("");
        }



    }

    @Action
    /**
     * Makes a new Database file
     */
    public void makeNewDatabase() throws IOException, ClassNotFoundException {
        // if the filename and the chosen filepath were the same
        if (picturesDirectory != null && newDatabaseDirectory != null) {
            Out.pl("Making DB:");
// makes the database
            DataBase db = MosaikFunctions.makeDatabase(picturesDirectory);
            Out.pl("DB made:" + picturesDirectory);
// saves the database
            MosaikFunctions.storeDatabase(db, newDatabaseDirectory);
            Out.pl("DB stored.");
            jLabel1.setText("Status: Erfolgreich durchgeführt");
            mosaik.databaseDirectory = newDatabaseDirectory;  // sets the new Database as current Database

            mosaik.enableComponents2(true);
        }

//        String name = jTextField6.getText();
//        int i = name.lastIndexOf('.');
//        // if there exist a file extation
//        if (i > 0 && i < name.length() - 1) {
//            String type = name.substring(i + 1).toLowerCase();
//            // if it is equal to "db"
//            if (type.equals("db")) {
//                newDatabaseDirectory = new File(newDatabaseDirectory.getParent() + jTextField6.getText());
//            } else {
//                // if not equal to "db"
//                JOptionPane.showMessageDialog(this,
//                        "Keine gültige Endung eingeben.",
//                        "Tipp: Lassen Sie die Endung weg, oder schreiben sie .db hinter den Dateinamen.",
//                        JOptionPane.WARNING_MESSAGE);
//                return;
//            }
//
//        } else {
//
//            //   if it hasn't any file extion
//            newDatabaseDirectory = new File(newDatabaseDirectory.getParent() + jTextField6.getText() + ".db");
//        }
    }

    @Action
    public void chooseFirstDatabase() {

        chooseDatabase = new ChooseDatabase(this, true, "chooseFristDatabase", mosaik);
        chooseDatabase.setLocationRelativeTo(this);
        chooseDatabase.pack();
        chooseDatabase.setVisible(true);
        jLabel10.setText("");
    }

    @Action
    public void chooseSecondDatabase() {

        chooseDatabase = new ChooseDatabase(this, true, "chooseSecondDatabase", mosaik);
        chooseDatabase.setLocationRelativeTo(this);
        chooseDatabase.pack();
        chooseDatabase.setVisible(true);
        jLabel10.setText("");
    }

    @Action
    public void chooseDatabaseToMergeWithDirectory() {

        chooseDatabase = new ChooseDatabase(this, true, "chooseDatabaseToMergeWithDirectory", mosaik);
        chooseDatabase.setLocationRelativeTo(this);
        chooseDatabase.pack();
        chooseDatabase.setVisible(true);
        jLabel2.setText("");

    }

    @Action
    /**
     * Merges two databses to one
     */
    public void mergeTwoDatabases() throws IOException, ClassNotFoundException {

        if (firstDatabaseDirectory != null && secondDatabaseDirectory != null && newMergeDatabaseDirectory != null) {
            DataBase db1 = MosaikFunctions.loadDatabase(firstDatabaseDirectory);
            DataBase db2 = MosaikFunctions.loadDatabase(secondDatabaseDirectory);
            db1.add(db2);
            MosaikFunctions.storeDatabase(db1, newMergeDatabaseDirectory);
            Out.p("Database stored");
            mosaik.databaseDirectory = newMergeDatabaseDirectory;
            jLabel10.setText("Status: Erfolgreich durchgeführt");
        }
    }

    @Action
    public void chooseDirectoryOfPictures() {

        JFileChooser jfc = new JFileChooser();
        jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        if (jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
            directoryOfPicturesToMergeWithExistingDatabase = new File(jfc.getSelectedFile().getAbsolutePath());
            jTextField4.setText(directoryOfPicturesToMergeWithExistingDatabase.getAbsolutePath());
            jLabel2.setText("");
            System.out.print(directoryOfPicturesToMergeWithExistingDatabase);
        }

    }

    @Action
    /**
     * Merges and save an existing database with a new one that is based on a new directory.
     */
    public void mergeDirectoryWithExistingDatabase() throws IOException, ClassNotFoundException {
        if (directoryOfPicturesToMergeWithExistingDatabase != null && existingDatabaseToMergeWithDirectoryOfPictures != null) {
            DataBase db1 = MosaikFunctions.makeDatabase(directoryOfPicturesToMergeWithExistingDatabase);
            DataBase db2 = MosaikFunctions.loadDatabase(existingDatabaseToMergeWithDirectoryOfPictures);
            db1.add(db2);
            MosaikFunctions.storeDatabase(db1, existingDatabaseToMergeWithDirectoryOfPictures);
            mosaik.databaseDirectory = existingDatabaseToMergeWithDirectoryOfPictures;
            jLabel2.setText("Status: Erfolgreich durchgeführt");
        }
    }

    @Action
    public void close() {
        dispose();


    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    protected javax.swing.JTextField jTextField1;
    protected javax.swing.JTextField jTextField2;
    protected javax.swing.JTextField jTextField3;
    protected javax.swing.JTextField jTextField4;
    protected javax.swing.JTextField jTextField5;
    protected javax.swing.JTextField jTextField6;
    protected javax.swing.JTextField jTextField7;
    // End of variables declaration//GEN-END:variables
    JDialog chooseNewDatabase;
    JDialog chooseDatabase;
    File newDatabaseDirectory;
    File firstDatabaseDirectory;
    File secondDatabaseDirectory;
    File newMergeDatabaseDirectory;
    File existingDatabaseToMergeWithDirectoryOfPictures;
    File directoryOfPicturesToMergeWithExistingDatabase;
}
