package fr.ethilvan.launcher.ui;

import java.awt.Component;
import java.awt.Cursor;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.URISyntaxException;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JToggleButton;
import javax.swing.SwingConstants;

import fr.ethilvan.launcher.Launcher;
import fr.ethilvan.launcher.util.Util;

public class OptionsDialog extends JDialog {

    private static final long serialVersionUID = -4589816185806932545L;

    public OptionsDialog(Component frame) {
        super();

        setModal(true);
        setTitle("Options");
        setLayout(new GridBagLayout());

        Insets insets = new Insets(6, 12, 6, 12);

        JToggleButton forceUpdate = new JToggleButton("Forcer la mise à jour");
        forceUpdate.setSelected(Launcher.get().getForceUpdate());
        GridBagConstraints forceUpdateC = new GridBagConstraints();
        forceUpdateC.fill = GridBagConstraints.HORIZONTAL;
        forceUpdateC.insets = insets;
        forceUpdateC.gridx = 0;
        forceUpdateC.gridy = 0;
        forceUpdateC.gridwidth = 2;
        add(forceUpdate, forceUpdateC);

        JToggleButton devMode = new JToggleButton("Mode développement");
        devMode.setSelected(Launcher.get().getOptions().isDevMode());
        GridBagConstraints devModeC = new GridBagConstraints();
        devModeC.fill = GridBagConstraints.HORIZONTAL;
        devModeC.insets = insets;
        devModeC.gridx = 0;
        devModeC.gridy = 1;
        devModeC.gridwidth = 2;
        add(devMode, devModeC);

        JLabel directoryLabel = new JLabel("Dossier du jeu : ",
                SwingConstants.RIGHT);
        GridBagConstraints directoryLabelC = new GridBagConstraints();
        directoryLabelC.fill = GridBagConstraints.HORIZONTAL;
        directoryLabelC.insets = insets;
        directoryLabelC.gridx = 0;
        directoryLabelC.gridy = 2;
        add(directoryLabel, directoryLabelC);

        final JLabel directory = new JLabel("<html><a href=\"\">"
                + Launcher.get().getGameDirectory() + "</a></html>");
        directory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        directory.addMouseListener(new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent event) {
                try {
                    Util.openURI(Launcher.get().getGameDirectory().toURI());
                } catch (IOException _) {
                } catch (URISyntaxException _) {
                }
            }
        });
        GridBagConstraints directoryC = new GridBagConstraints();
        directoryC.anchor = GridBagConstraints.LINE_END;
        directoryC.insets = insets;
        directoryC.gridx = 0;
        directoryC.gridy = 3;
        directoryC.gridwidth = 2;
        add(directory, directoryC);

        JButton done = new JButton("Terminer");
        GridBagConstraints doneC = new GridBagConstraints();
        doneC.anchor = GridBagConstraints.LAST_LINE_END;
        doneC.insets = insets;
        doneC.gridx = 1;
        doneC.gridy = 4;
        add(done, doneC);

        forceUpdate.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent event) {
                Launcher.get().setForceUpdate(
                        event.getStateChange() == ItemEvent.SELECTED);
            }
        });

        devMode.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent event) {
                Launcher.get().getOptions().setDevMode(
                        event.getStateChange() == ItemEvent.SELECTED);
                directory.setText("<html><a href=\"\">"
                        + Launcher.get().getGameDirectory() + "</a></html>");
                OptionsDialog.this.pack();
            }
        });

        done.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent event) {
                OptionsDialog.this.dispose();
            }
        });

        pack();
        setLocationRelativeTo(frame);
    }
}

@@ -854,24 +854,53 @@
   super();%0A%0A
+        setTitle(%22Options%22);%0A
         setM
@@ -918,39 +918,39 @@
 %0A        set
-Title(%22Options%22
+Resizable(false
 );%0A        s
@@ -1271,82 +1271,40 @@
 teC.
-fill = GridBagConstraints.HORIZONTAL;%0A        forceUpdateC.insets = insets
+insets = new Insets(6, 12, 6, 4)
 ;%0A  
@@ -1369,44 +1369,8 @@
  0;%0A
-        forceUpdateC.gridwidth = 2;%0A
     
@@ -1634,106 +1634,41 @@
 deC.
-fill = GridBagConstraints.HORIZONTAL;%0A        devModeC.insets = insets;%0A        devModeC.gridx = 0
+insets = new Insets(6, 4, 6, 12);
 ;%0A  
@@ -1686,17 +1686,17 @@
 deC.grid
-y
+x
  = 1;%0A  
@@ -1710,33 +1710,29 @@
 evModeC.grid
-width = 2
+y = 0
 ;%0A        ad
@@ -1956,12 +1956,14 @@
 elC.
-fill
+anchor
  = G
@@ -1984,18 +1984,18 @@
 nts.
-HORIZONTAL
+LINE_START
 ;%0A  
@@ -3018,24 +3018,674 @@
 rectoryC);%0A%0A
+        JLabel versionLabel = new JLabel(%22Version du launcher : %22);%0A        GridBagConstraints versionLabelC = new GridBagConstraints();%0A        versionLabelC.anchor = GridBagConstraints.LINE_START;%0A        versionLabelC.insets = insets;%0A        versionLabelC.gridx = 0;%0A        versionLabelC.gridy = 5;%0A        add(versionLabel, versionLabelC);%0A%0A        JLabel version = new JLabel(Launcher.VERSION);%0A        GridBagConstraints versionC = new GridBagConstraints();%0A        versionC.anchor = GridBagConstraints.FIRST_LINE_END;%0A        versionC.insets = insets;%0A        versionC.gridx = 1;%0A        versionC.gridy = 5;%0A        add(version, versionC);%0A%0A
         JBut
@@ -3853,38 +3853,57 @@
  doneC.insets = 
-insets
+new Insets(12, 12, 6, 12)
 ;%0A        doneC.
@@ -3935,17 +3935,17 @@
 gridy = 
-4
+7
 ;%0A      
@@ -3961,24 +3961,79 @@
 e, doneC);%0A%0A
+        pack();%0A        setLocationRelativeTo(frame);%0A%0A
         forc
@@ -4982,63 +4982,8 @@
  %7D);
-%0A%0A        pack();%0A        setLocationRelativeTo(frame);
 %0A   

Add version in options panel + redesign