package fr.ethilvan.launcher.ui;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.BoundedRangeModel;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.SwingUtilities;

public class TaskDialog extends JDialog {

    private static final long serialVersionUID = 3508184860311427900L;

    private final Component frame;
    private final JLabel label;
    private final JProgressBar progressBar;
    private final JButton close;

    public TaskDialog(Component frame) {
        super();
        this.frame = frame;

        setTitle("Downloads");
        setModal(true);
        setResizable(false);

        JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        panel.setBorder(BorderFactory.createEmptyBorder(12, 12, 12, 12));
        add(panel);

        label = new JLabel();
        GridBagConstraints labelC = new GridBagConstraints();
        labelC.insets = new Insets(0, 0, 6, 0);
        labelC.gridx = 0;
        labelC.gridy = 0;
        panel.add(label, labelC);

        progressBar = new JProgressBar();
        progressBar.setIndeterminate(true);
        GridBagConstraints progressC = new GridBagConstraints();
        progressC.gridx = 0;
        progressC.gridy = 1;
        progressC.fill = GridBagConstraints.HORIZONTAL;
        panel.add(progressBar, progressC);

        close = new JButton("Fermer");
        close.setVisible(false);
        close.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                TaskDialog.this.dispose();
            }
        });
        panel.add(close, progressC);

        pack();
        setLocationRelativeTo(frame);
    }

    public void setStatus(final String text, final BoundedRangeModel model) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                label.setText(text);
                if (model == null) {
                    progressBar.setIndeterminate(true);
                } else {
                    progressBar.setIndeterminate(false);
                    progressBar.setModel(model);
                }

                pack();
                setLocationRelativeTo(frame);
            }
        });
    }

    public void setLoginFailed() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                label.setText("Nom d'utilisateur ou mot de passe invalide");
                progressBar.setVisible(false);
                close.setVisible(true);

                pack();
                setLocationRelativeTo(frame);
            }
        });
    }
}

@@ -50,24 +50,51 @@
 .Component;%0A
+import java.awt.Dimension;%0A
 import java.
@@ -113,24 +113,24 @@
 onstraints;%0A
-
 import java.
@@ -616,43 +616,8 @@
 L;%0A%0A
-    private final Component frame;%0A
     
@@ -783,36 +783,8 @@
 r();
-%0A        this.frame = frame;
 %0A%0A  
@@ -828,32 +828,81 @@
 setModal(true);%0A
+        setMinimumSize(new Dimension(460, 120));%0A
         setResiz
@@ -1226,17 +1226,18 @@
 s(0, 0, 
-6
+20
 , 0);%0A  
@@ -1530,16 +1530,49 @@
 dy = 1;%0A
+        progressC.weightx = 1.0;%0A
         
@@ -1727,32 +1727,232 @@
 Visible(false);%0A
+        GridBagConstraints closeC = new GridBagConstraints();%0A        closeC.gridx = 0;%0A        closeC.gridy = 1;%0A        closeC.anchor = GridBagConstraints.CENTER;%0A        panel.add(close, closeC);%0A%0A
         close.ad
@@ -2141,45 +2141,8 @@
  %7D);
-%0A        panel.add(close, progressC);
 %0A%0A  
@@ -2666,79 +2666,8 @@
    %7D
-%0A%0A                pack();%0A                setLocationRelativeTo(frame);
 %0A   
@@ -2953,32 +2953,32 @@
 Visible(false);%0A
+
                 
@@ -3004,79 +3004,8 @@
 ue);
-%0A%0A                pack();%0A                setLocationRelativeTo(frame);
 %0A   

Clean up TaskDialog