Browse Source

Fixes issue 3777: Addon browser needs to show feedback when installing/finished

Change-Id: Ie0a8c56c2ef8eb65c4d7154f91bd87f46de6fd95
Reviewed-on: http://gerrit.dmdirc.com/883
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
tags/0.6.4
Gregory Holmes 14 years ago
parent
commit
ce166549b3

+ 8
- 2
src/com/dmdirc/addons/ui_swing/components/addonbrowser/AddonInfoLabel.java View File

@@ -27,6 +27,7 @@ import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27 27
 
28 28
 import java.awt.Color;
29 29
 import java.awt.Font;
30
+import java.awt.Window;
30 31
 
31 32
 import javax.swing.BorderFactory;
32 33
 import javax.swing.JButton;
@@ -47,15 +48,20 @@ public class AddonInfoLabel extends JPanel {
47 48
      * objects being unserialized with the new class).
48 49
      */
49 50
     private static final long serialVersionUID = 1;
51
+    /** Addon info to be represented. */
50 52
     private final AddonInfo addonInfo;
53
+    /** Parent window. */
54
+    private Window parentWindow;
51 55
 
52 56
     /**
53 57
      * Creates a new addon info label to describe the specified addon info.
54 58
      *
55 59
      * @param addonInfo Addon to describe
60
+     * @param parentWindow Parent window
56 61
      */
57
-    public AddonInfoLabel(final AddonInfo addonInfo) {
62
+    public AddonInfoLabel(final AddonInfo addonInfo, final Window parentWindow) {
58 63
         this.addonInfo = addonInfo;
64
+        this.parentWindow = parentWindow;
59 65
 
60 66
         init();
61 67
     }
@@ -80,7 +86,7 @@ public class AddonInfoLabel extends JPanel {
80 86
         add(label, "wmax 100%-170, hmax 150, growy, wrap, pushy, gapleft 5");
81 87
 
82 88
         final JButton button = new JButton("Install");
83
-        button.addActionListener(new InstallListener(addonInfo));
89
+        button.addActionListener(new InstallListener(addonInfo, parentWindow));
84 90
         final boolean installed = addonInfo.isInstalled();
85 91
         add(button, "split, gapleft 5");
86 92
 

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/addonbrowser/BrowserWindow.java View File

@@ -210,7 +210,7 @@ public class BrowserWindow extends JDialog implements ActionListener {
210 210
 
211 211
         for (Map<String, String> entry : data.getKeyDomains().values()) {
212 212
             final AddonInfo info = new AddonInfo(entry);
213
-            list.getModel().addRow(new Object[]{new AddonInfoLabel(info),});
213
+            list.getModel().addRow(new Object[]{new AddonInfoLabel(info, this),});
214 214
         }
215 215
     }
216 216
 

+ 20
- 1
src/com/dmdirc/addons/ui_swing/components/addonbrowser/InstallListener.java View File

@@ -30,11 +30,13 @@ import com.dmdirc.plugins.PluginManager;
30 30
 import com.dmdirc.ui.themes.ThemeManager;
31 31
 import com.dmdirc.util.Downloader;
32 32
 
33
+import java.awt.Window;
33 34
 import java.awt.event.ActionEvent;
34 35
 import java.awt.event.ActionListener;
35 36
 
36 37
 import java.io.File;
37 38
 import java.io.IOException;
39
+import javax.swing.SwingUtilities;
38 40
 
39 41
 /**
40 42
  * Addon info install listener.
@@ -43,14 +45,18 @@ public class InstallListener implements ActionListener {
43 45
 
44 46
     /** Addon info. */
45 47
     private final AddonInfo info;
48
+    /** Parent window. */
49
+    private Window parentWindow;
46 50
 
47 51
     /**
48 52
      * Instantiates a new install listener.
49 53
      * 
50 54
      * @param info Addoninfo to install
55
+     * @param parentWindow Parent window
51 56
      */
52
-    public InstallListener(final AddonInfo info) {
57
+    public InstallListener(final AddonInfo info, final Window parentWindow) {
53 58
         this.info = info;
59
+        this.parentWindow = parentWindow;
54 60
     }
55 61
 
56 62
     /** 
@@ -60,6 +66,14 @@ public class InstallListener implements ActionListener {
60 66
      */
61 67
     @Override
62 68
     public void actionPerformed(final ActionEvent e) {
69
+        final InstallerWindow installer = new InstallerWindow(parentWindow, info);
70
+        SwingUtilities.invokeLater(new Runnable() {
71
+
72
+            @Override
73
+            public void run() {
74
+                installer.display(parentWindow);
75
+            }
76
+        });
63 77
         try {
64 78
             final File file = File.createTempFile("dmdirc-addon", ".tmp");
65 79
             file.deleteOnExit();
@@ -87,6 +101,9 @@ public class InstallListener implements ActionListener {
87 101
                         Logger.userError(ErrorLevel.MEDIUM, "Unable to "
88 102
                                 + "install addon, failed to move file: "
89 103
                                 + file.getAbsolutePath());
104
+                        installer.finished("Unable to "
105
+                                + "install addon, failed to move file: "
106
+                                + file.getAbsolutePath());
90 107
                     }
91 108
                     break;
92 109
                 case TYPE_THEME:
@@ -96,6 +113,8 @@ public class InstallListener implements ActionListener {
96 113
         } catch (IOException ex) {
97 114
             Logger.userError(ErrorLevel.MEDIUM, "Unable to download addon: "
98 115
                     + ex.getMessage(), ex);
116
+            installer.finished("Unable to download addon: " + ex.getMessage());
99 117
         }
118
+        installer.finished("");
100 119
     }
101 120
 }

+ 110
- 0
src/com/dmdirc/addons/ui_swing/components/addonbrowser/InstallerWindow.java View File

@@ -0,0 +1,110 @@
1
+/*
2
+ * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ * 
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ * 
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ * 
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.addons.ui_swing.components.addonbrowser;
24
+
25
+import com.dmdirc.addons.ui_swing.components.text.TextLabel;
26
+import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
27
+
28
+import java.awt.Dialog.ModalityType;
29
+import java.awt.Window;
30
+import java.awt.event.ActionEvent;
31
+import java.awt.event.ActionListener;
32
+
33
+import javax.swing.JDialog;
34
+import javax.swing.JProgressBar;
35
+
36
+import net.miginfocom.swing.MigLayout;
37
+
38
+/**
39
+ * A window to show the progress whilst installing an addon.
40
+ */
41
+public class InstallerWindow extends StandardDialog implements ActionListener {
42
+
43
+    /**
44
+     * A version number for this class. It should be changed whenever the class
45
+     * structure is changed (or anything else that would prevent serialized
46
+     * objects being unserialized with the new class).
47
+     */
48
+    private static final long serialVersionUID = 1;
49
+    /** Downloader progress bar. */
50
+    private final JProgressBar jpb = new JProgressBar(0, 100);
51
+    /** Parent window. */
52
+    private Window parentWindow;
53
+    /** Message label. */
54
+    private TextLabel label;
55
+    /** Addon info. */
56
+    private AddonInfo info;
57
+
58
+    /**
59
+     * Instantiates a new installer window.
60
+     *
61
+     * @param parentWindow Parent window
62
+     * @param info Assocaited addon info
63
+     */
64
+    public InstallerWindow(final Window parentWindow, final AddonInfo info) {
65
+        super(parentWindow, ModalityType.DOCUMENT_MODAL);
66
+        this.info = info;
67
+        this.parentWindow = parentWindow;
68
+        setTitle("Installing addon...");
69
+        jpb.setIndeterminate(true);
70
+        label = new TextLabel("Installing: " + info.getTitle());
71
+        getOkButton().addActionListener(this);
72
+        getCancelButton().addActionListener(this);
73
+        setLayout(new MigLayout("fill, wrap 1"));
74
+        add(label);
75
+        add(jpb, "grow");
76
+        add(getOkButton(), "split, right");
77
+        getOkButton().setEnabled(false);
78
+        setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
79
+        setIconImages(parentWindow.getIconImages());
80
+    }
81
+
82
+    /**
83
+     * {@inheritDoc}
84
+     *
85
+     * @param ae Action event
86
+     */
87
+    @Override
88
+    public void actionPerformed(final ActionEvent ae) {
89
+        dispose();
90
+    }
91
+
92
+    /**
93
+     * Tells the window the installation has finished and displays the
94
+     * appropriate message to the user.
95
+     *
96
+     * @param message Message to display (or an empty sting for success)
97
+     */
98
+    public void finished(final String message) {
99
+        if (message.isEmpty()) {
100
+            label.setText("Finished installing addon: " + info.getTitle());
101
+        } else {
102
+            label.setText("Error installing addon: " + info.getTitle() + "<br>"
103
+                    + message);
104
+        }
105
+        jpb.setIndeterminate(false);
106
+        jpb.setValue(100);
107
+        getOkButton().setEnabled(true);
108
+        pack();
109
+    }
110
+}

+ 3
- 0
src/com/dmdirc/addons/ui_swing/dialogs/StandardDialog.java View File

@@ -67,6 +67,7 @@ public class StandardDialog extends JDialog {
67 67
         if (owner != null) {
68 68
             setIconImages(owner.getIconImages());
69 69
         }
70
+        orderButtons(new JButton(), new JButton());
70 71
     }
71 72
 
72 73
     /**
@@ -81,6 +82,7 @@ public class StandardDialog extends JDialog {
81 82
         if (owner != null) {
82 83
             setIconImages(owner.getIconImages());
83 84
         }
85
+        orderButtons(new JButton(), new JButton());
84 86
     }
85 87
 
86 88
     /**
@@ -95,6 +97,7 @@ public class StandardDialog extends JDialog {
95 97
         if (owner != null) {
96 98
             setIconImages(owner.getIconImages());
97 99
         }
100
+        orderButtons(new JButton(), new JButton());
98 101
     }
99 102
 
100 103
     /**

Loading…
Cancel
Save