Просмотр исходного кода

EventBus logging for the prefs dialog.

Also fix a couple of things IDEA complained about.

Change-Id: Ief34d2fb73a8b62dfbe0edf468667de592053583
Reviewed-on: http://gerrit.dmdirc.com/3710
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
changes/10/3710/2
Greg Holmes 9 лет назад
Родитель
Сommit
b1a8a15f15

+ 10
- 12
src/com/dmdirc/addons/ui_swing/dialogs/prefs/CategoryLabel.java Просмотреть файл

@@ -25,6 +25,8 @@ package com.dmdirc.addons.ui_swing.dialogs.prefs;
25 25
 import com.dmdirc.config.prefs.PreferencesCategory;
26 26
 import com.dmdirc.ui.IconManager;
27 27
 
28
+import com.google.common.eventbus.EventBus;
29
+
28 30
 import java.awt.Dimension;
29 31
 
30 32
 import javax.annotation.Nullable;
@@ -43,8 +45,6 @@ public class CategoryLabel extends JLabel {
43 45
 
44 46
     /** Serial version UID. */
45 47
     private static final long serialVersionUID = -1659415238166842265L;
46
-    /** Panel gap. */
47
-    private final int padding = (int) (1.5 * PlatformDefaults.getUnitValueX("related").getValue());
48 48
     /** Parent list. */
49 49
     @Nullable
50 50
     private final JList<? extends PreferencesCategory> parentList;
@@ -59,15 +59,15 @@ public class CategoryLabel extends JLabel {
59 59
      * @param index       Index of this label
60 60
      */
61 61
     public CategoryLabel(final IconManager iconManager,
62
+            final EventBus eventBus,
62 63
             @Nullable final JList<? extends PreferencesCategory> parentList,
63 64
             final PreferencesCategory category, final int numCats,
64 65
             final int index) {
65
-        super();
66
-
67 66
         this.parentList = parentList;
67
+        final int padding = (int) (1.5 * PlatformDefaults.getUnitValueX("related").getValue());
68 68
 
69 69
         setText(category.getTitle());
70
-        new IconLoader(iconManager, this, category.getIcon()).execute();
70
+        new IconLoader(iconManager, eventBus, this, category.getIcon()).execute();
71 71
 
72 72
         int level = 0;
73 73
         PreferencesCategory temp = category;
@@ -80,8 +80,11 @@ public class CategoryLabel extends JLabel {
80 80
                 + padding));
81 81
         setBorder(BorderFactory.createEmptyBorder(padding / 2, padding + level
82 82
                 * 18, padding / 2, padding));
83
-        setBackground(parentList.getBackground());
84
-        setForeground(parentList.getForeground());
83
+
84
+        if (parentList != null) {
85
+            setBackground(parentList.getBackground());
86
+            setForeground(parentList.getForeground());
87
+        }
85 88
         setOpaque(true);
86 89
         setToolTipText(null);
87 90
 
@@ -105,11 +108,6 @@ public class CategoryLabel extends JLabel {
105 108
         }
106 109
     }
107 110
 
108
-    /**
109
-     * {@inheritDoc}
110
-     *
111
-     * @param icon New icon
112
-     */
113 111
     @Override
114 112
     public void setIcon(final Icon icon) {
115 113
         super.setIcon(icon);

+ 13
- 5
src/com/dmdirc/addons/ui_swing/dialogs/prefs/CategoryPanel.java Просмотреть файл

@@ -32,6 +32,8 @@ import com.dmdirc.addons.ui_swing.components.text.TextLabel;
32 32
 import com.dmdirc.config.prefs.PreferencesCategory;
33 33
 import com.dmdirc.ui.IconManager;
34 34
 
35
+import com.google.common.eventbus.EventBus;
36
+
35 37
 import java.awt.Component;
36 38
 import java.util.Collections;
37 39
 import java.util.HashMap;
@@ -73,35 +75,41 @@ public class CategoryPanel extends JPanel {
73 75
     private LoggingSwingWorker<JPanel, Object> worker;
74 76
     /** Prefs component factory. */
75 77
     private final PrefsComponentFactory factory;
78
+    /** The event bus to post errors to. */
79
+    private final EventBus eventBus;
76 80
 
77 81
     /**
78 82
      * Instantiates a new category panel.
79 83
      *
84
+     * @param eventBus    The event bus to post errors to
80 85
      * @param factory     Prefs component factory instance
81 86
      * @param iconManager Icon manager
82 87
      */
83 88
     @Inject
84 89
     public CategoryPanel(
90
+            final EventBus eventBus,
85 91
             final PrefsComponentFactory factory,
86 92
             @GlobalConfig final IconManager iconManager) {
87
-        this(factory, iconManager, null);
93
+        this(eventBus, factory, iconManager, null);
88 94
     }
89 95
 
90 96
     /**
91 97
      * Instantiates a new category panel.
92 98
      *
99
+     * @param eventBus    The event bus to post errors to
93 100
      * @param factory     Prefs component factory instance
94 101
      * @param iconManager Icon manager
95 102
      * @param category    Initial category
96 103
      */
97
-    public CategoryPanel(final PrefsComponentFactory factory,
104
+    public CategoryPanel(
105
+            final EventBus eventBus, final PrefsComponentFactory factory,
98 106
             final IconManager iconManager,
99 107
             final PreferencesCategory category) {
100 108
         super(new MigLayout("fillx, wrap, ins 0"));
101 109
         this.factory = factory;
110
+        this.eventBus = eventBus;
102 111
 
103
-        panels = Collections.synchronizedMap(
104
-                new HashMap<PreferencesCategory, JPanel>());
112
+        panels = Collections.synchronizedMap(new HashMap<PreferencesCategory, JPanel>());
105 113
 
106 114
         loading = new JPanel(new MigLayout("fillx"));
107 115
         loading.add(new TextLabel("Loading..."));
@@ -214,7 +222,7 @@ public class CategoryPanel extends JPanel {
214 222
                 }
215 223
             });
216 224
 
217
-            worker = new PrefsCategoryLoader(factory, this, category);
225
+            worker = new PrefsCategoryLoader(factory, eventBus, this, category);
218 226
             worker.execute();
219 227
         } else {
220 228
             categoryLoaded(category);

+ 10
- 6
src/com/dmdirc/addons/ui_swing/dialogs/prefs/IconLoader.java Просмотреть файл

@@ -23,10 +23,12 @@
23 23
 package com.dmdirc.addons.ui_swing.dialogs.prefs;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
26
+import com.dmdirc.events.UserErrorEvent;
26 27
 import com.dmdirc.logger.ErrorLevel;
27
-import com.dmdirc.logger.Logger;
28 28
 import com.dmdirc.ui.IconManager;
29 29
 
30
+import com.google.common.eventbus.EventBus;
31
+
30 32
 import java.util.concurrent.ExecutionException;
31 33
 
32 34
 import javax.swing.Icon;
@@ -38,6 +40,8 @@ public class IconLoader extends LoggingSwingWorker<Icon, Void> {
38 40
 
39 41
     /** Category this icon will be used for. */
40 42
     private final CategoryLabel label;
43
+    /** The event bus to post errors to. */
44
+    private final EventBus eventBus;
41 45
     /** Icon to load. */
42 46
     private final String icon;
43 47
     /** Icon manager. */
@@ -48,14 +52,14 @@ public class IconLoader extends LoggingSwingWorker<Icon, Void> {
48 52
      * loaded in the background.
49 53
      *
50 54
      * @param iconManager Icon manager
55
+     * @param eventBus    The event bus to post errors to
51 56
      * @param label       Label to load category for
52
-     * @param icon        Icon to load1111
57
+     * @param icon        Icon to load
53 58
      */
54
-    public IconLoader(final IconManager iconManager,
59
+    public IconLoader(final IconManager iconManager, final EventBus eventBus,
55 60
             final CategoryLabel label, final String icon) {
56
-        super();
57
-
58 61
         this.iconManager = iconManager;
62
+        this.eventBus = eventBus;
59 63
         this.label = label;
60 64
         this.icon = icon;
61 65
     }
@@ -72,7 +76,7 @@ public class IconLoader extends LoggingSwingWorker<Icon, Void> {
72 76
         } catch (InterruptedException ex) {
73 77
             //Ignore
74 78
         } catch (ExecutionException ex) {
75
-            Logger.appError(ErrorLevel.LOW, ex.getMessage(), ex);
79
+            eventBus.post(new UserErrorEvent(ErrorLevel.LOW, ex, ex.getMessage(), ""));
76 80
         }
77 81
 
78 82
     }

+ 8
- 2
src/com/dmdirc/addons/ui_swing/dialogs/prefs/PreferencesListCellRenderer.java Просмотреть файл

@@ -25,6 +25,8 @@ package com.dmdirc.addons.ui_swing.dialogs.prefs;
25 25
 import com.dmdirc.config.prefs.PreferencesCategory;
26 26
 import com.dmdirc.ui.IconManager;
27 27
 
28
+import com.google.common.eventbus.EventBus;
29
+
28 30
 import java.awt.Component;
29 31
 import java.awt.Font;
30 32
 import java.util.HashMap;
@@ -48,18 +50,22 @@ public class PreferencesListCellRenderer extends JLabel implements
48 50
     private final IconManager iconManager;
49 51
     /** Label map. */
50 52
     private final Map<PreferencesCategory, JLabel> labelMap;
53
+    /** The event bus to post errors to. */
54
+    private final EventBus eventBus;
51 55
 
52 56
     /**
53 57
      * Instantiates a new prefs list cell renderer.
54 58
      *
55 59
      * @param iconManager Icon manager to load icons
60
+     * @param eventBus    The event bus to post errors to
56 61
      * @param numCats     Number of categories in the list
57 62
      */
58
-    public PreferencesListCellRenderer(final IconManager iconManager,
63
+    public PreferencesListCellRenderer(final IconManager iconManager, final EventBus eventBus,
59 64
             final int numCats) {
60 65
         labelMap = new HashMap<>();
61 66
         this.numCats = numCats;
62 67
         this.iconManager = iconManager;
68
+        this.eventBus = eventBus;
63 69
     }
64 70
 
65 71
     @Override
@@ -67,7 +73,7 @@ public class PreferencesListCellRenderer extends JLabel implements
67 73
             final PreferencesCategory value, final int index, final boolean isSelected,
68 74
             final boolean cellHasFocus) {
69 75
         if (!labelMap.containsKey(value)) {
70
-            labelMap.put(value, new CategoryLabel(iconManager,
76
+            labelMap.put(value, new CategoryLabel(iconManager, eventBus,
71 77
                     list, value, numCats, index));
72 78
         }
73 79
         final JLabel label = labelMap.get(value);

+ 10
- 5
src/com/dmdirc/addons/ui_swing/dialogs/prefs/PrefsCategoryLoader.java Просмотреть файл

@@ -30,8 +30,10 @@ import com.dmdirc.addons.ui_swing.components.text.TextLabel;
30 30
 import com.dmdirc.config.prefs.PreferencesCategory;
31 31
 import com.dmdirc.config.prefs.PreferencesSetting;
32 32
 import com.dmdirc.config.prefs.PreferencesType;
33
+import com.dmdirc.events.UserErrorEvent;
33 34
 import com.dmdirc.logger.ErrorLevel;
34
-import com.dmdirc.logger.Logger;
35
+
36
+import com.google.common.eventbus.EventBus;
35 37
 
36 38
 import java.util.concurrent.Callable;
37 39
 import java.util.concurrent.ExecutionException;
@@ -67,20 +69,23 @@ public class PrefsCategoryLoader extends LoggingSwingWorker<JPanel, Object> {
67 69
     private final PreferencesCategory category;
68 70
     /** Prefs component factory instance. */
69 71
     private final PrefsComponentFactory factory;
72
+    /** The event bus to post the errors to. */
73
+    private final EventBus eventBus;
70 74
 
71 75
     /**
72 76
      * Instantiates a new preferences category loader.
73 77
      *
74 78
      * @param factory       Prefs component factory instance
79
+     * @param eventBus      The event bus to post errors ro
75 80
      * @param categoryPanel Parent Category panel
76 81
      * @param category      Preferences Category to load
77 82
      */
78 83
     public PrefsCategoryLoader(final PrefsComponentFactory factory,
84
+            final EventBus eventBus,
79 85
             final CategoryPanel categoryPanel,
80 86
             final PreferencesCategory category) {
81
-        super();
82
-
83 87
         this.factory = factory;
88
+        this.eventBus = eventBus;
84 89
         this.categoryPanel = categoryPanel;
85 90
         this.category = category;
86 91
 
@@ -119,7 +124,8 @@ public class PrefsCategoryLoader extends LoggingSwingWorker<JPanel, Object> {
119 124
         } catch (InterruptedException ex) {
120 125
             panel = errorCategory;
121 126
         } catch (ExecutionException ex) {
122
-            Logger.appError(ErrorLevel.MEDIUM, "Error loading prefs panel", ex);
127
+            eventBus.post(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
128
+                    "Error loading prefs panel", ""));
123 129
             panel = errorCategory;
124 130
         }
125 131
         return panel;
@@ -275,7 +281,6 @@ public class PrefsCategoryLoader extends LoggingSwingWorker<JPanel, Object> {
275 281
      *
276 282
      * @since 0.6.3m1
277 283
      * @param category   The category to be added
278
-     * @param namePrefix Category name prefix
279 284
      */
280 285
     private JPanel addCategory(final PreferencesCategory category) {
281 286
         final JPanel panel = UIUtilities.invokeAndWait(

+ 15
- 39
src/com/dmdirc/addons/ui_swing/dialogs/prefs/SwingPreferencesDialog.java Просмотреть файл

@@ -33,10 +33,12 @@ import com.dmdirc.addons.ui_swing.injection.DialogProvider;
33 33
 import com.dmdirc.addons.ui_swing.injection.MainWindow;
34 34
 import com.dmdirc.config.prefs.PreferencesCategory;
35 35
 import com.dmdirc.config.prefs.PreferencesDialogModel;
36
+import com.dmdirc.events.UserErrorEvent;
36 37
 import com.dmdirc.logger.ErrorLevel;
37
-import com.dmdirc.logger.Logger;
38 38
 import com.dmdirc.ui.IconManager;
39 39
 
40
+import com.google.common.eventbus.EventBus;
41
+
40 42
 import java.awt.Window;
41 43
 import java.awt.event.ActionEvent;
42 44
 import java.awt.event.ActionListener;
@@ -76,14 +78,14 @@ public final class SwingPreferencesDialog extends StandardDialog implements
76 78
     private PreferencesDialogModel manager;
77 79
     /** Manager loading swing worker. */
78 80
     private final LoggingSwingWorker<PreferencesDialogModel, Void> worker;
79
-    /** Panel size. */
80
-    private int panelSize = 500;
81 81
     /** The provider to use for restart dialogs. */
82 82
     private final DialogProvider<SwingRestartDialog> restartDialogProvider;
83 83
     /** The provider to use to produce a category panel. */
84 84
     private final Provider<CategoryPanel> categoryPanelProvider;
85 85
     /** Icon manager to retrieve icons from. */
86 86
     private final IconManager iconManager;
87
+    /** The event bus to post errors to. */
88
+    private final EventBus eventBus;
87 89
 
88 90
     /**
89 91
      * Creates a new instance of SwingPreferencesDialog.
@@ -93,6 +95,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
93 95
      * @param restartDialogProvider The provider to use for restart dialogs.
94 96
      * @param dialogModelProvider   The provider to use to get a dialog model.
95 97
      * @param categoryPanelProvider The provider to use to produce a category panel.
98
+     * @param eventBus              The event bus to post errors to.
96 99
      */
97 100
     @Inject
98 101
     public SwingPreferencesDialog(
@@ -100,12 +103,14 @@ public final class SwingPreferencesDialog extends StandardDialog implements
100 103
             @GlobalConfig final IconManager iconManager,
101 104
             @ForSettings final DialogProvider<SwingRestartDialog> restartDialogProvider,
102 105
             final Provider<PreferencesDialogModel> dialogModelProvider,
103
-            final Provider<CategoryPanel> categoryPanelProvider) {
106
+            final Provider<CategoryPanel> categoryPanelProvider,
107
+            final EventBus eventBus) {
104 108
         super(parentWindow, ModalityType.MODELESS);
105 109
 
106 110
         this.iconManager = iconManager;
107 111
         this.restartDialogProvider = restartDialogProvider;
108 112
         this.categoryPanelProvider = categoryPanelProvider;
113
+        this.eventBus = eventBus;
109 114
 
110 115
         initComponents();
111 116
 
@@ -119,8 +124,8 @@ public final class SwingPreferencesDialog extends StandardDialog implements
119 124
                     prefsManager = dialogModelProvider.get();
120 125
                 } catch (IllegalArgumentException ex) {
121 126
                     mainPanel.setError(ex.getMessage());
122
-                    Logger.appError(ErrorLevel.HIGH, "Unable to load the" + "preferences dialog.",
123
-                            ex);
127
+                    eventBus.post(new UserErrorEvent(ErrorLevel.HIGH, ex,
128
+                            "Unable to load the preferences dialog", ""));
124 129
                 }
125 130
                 return prefsManager;
126 131
             }
@@ -136,7 +141,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
136 141
                     } catch (InterruptedException ex) {
137 142
                         //Ignore
138 143
                     } catch (ExecutionException ex) {
139
-                        Logger.appError(ErrorLevel.MEDIUM, ex.getMessage(), ex);
144
+                        eventBus.post(new UserErrorEvent(ErrorLevel.MEDIUM, ex, ex.getMessage(), ""));
140 145
                     }
141 146
                 }
142 147
             }
@@ -151,7 +156,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
151 156
         mainPanel.setCategory(null);
152 157
 
153 158
         final int count = countCategories(manager.getCategories());
154
-        tabList.setCellRenderer(new PreferencesListCellRenderer(iconManager, count));
159
+        tabList.setCellRenderer(new PreferencesListCellRenderer(iconManager, eventBus, count));
155 160
 
156 161
         addCategories(manager.getCategories());
157 162
     }
@@ -282,22 +287,11 @@ public final class SwingPreferencesDialog extends StandardDialog implements
282 287
             final int index = tabList.getSelectedIndex();
283 288
             tabList.scrollRectToVisible(tabList.getCellBounds(index, index));
284 289
             selected = node;
285
-            if (selected != null) {
286
-                selected.fireCategorySelected();
287
-            }
290
+            selected.fireCategorySelected();
288 291
             mainPanel.setCategory(selected);
289 292
         }
290 293
     }
291 294
 
292
-    /**
293
-     * Returns the selected category.
294
-     *
295
-     * @return Selected category
296
-     */
297
-    protected PreferencesCategory getSelectedCategory() {
298
-        return selected;
299
-    }
300
-
301 295
     public void saveOptions() {
302 296
         if (manager != null && manager.save()) {
303 297
             dispose();
@@ -305,28 +299,10 @@ public final class SwingPreferencesDialog extends StandardDialog implements
305 299
         }
306 300
     }
307 301
 
308
-    /**
309
-     * Gets the maximum panel size.
310
-     *
311
-     * @return Max panel size
312
-     */
313
-    public int getPanelHeight() {
314
-        return panelSize;
315
-    }
316
-
317
-    /**
318
-     * Sets the panel size to the specified value.
319
-     *
320
-     * @param panelSize New panel size
321
-     */
322
-    protected void setPanelHeight(final int panelSize) {
323
-        this.panelSize = panelSize;
324
-    }
325
-
326 302
     @Override
327 303
     public void dispose() {
328 304
         synchronized (SwingPreferencesDialog.this) {
329
-            if (worker != null && !worker.isDone()) {
305
+            if (!worker.isDone()) {
330 306
                 worker.cancel(true);
331 307
             }
332 308
             if (manager != null) {

+ 12
- 7
src/com/dmdirc/addons/ui_swing/dialogs/prefs/UpdateConfigPanel.java Просмотреть файл

@@ -26,16 +26,18 @@ import com.dmdirc.ClientModule.GlobalConfig;
26 26
 import com.dmdirc.ClientModule.UserConfig;
27 27
 import com.dmdirc.addons.ui_swing.components.PackingTable;
28 28
 import com.dmdirc.config.prefs.PreferencesInterface;
29
+import com.dmdirc.events.UserErrorEvent;
29 30
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 31
 import com.dmdirc.interfaces.config.ConfigChangeListener;
31 32
 import com.dmdirc.interfaces.config.ConfigProvider;
32 33
 import com.dmdirc.interfaces.config.IdentityController;
33 34
 import com.dmdirc.logger.ErrorLevel;
34
-import com.dmdirc.logger.Logger;
35 35
 import com.dmdirc.updater.UpdateChannel;
36 36
 import com.dmdirc.updater.UpdateChecker;
37 37
 import com.dmdirc.updater.manager.CachingUpdateManager;
38 38
 
39
+import com.google.common.eventbus.EventBus;
40
+
39 41
 import java.awt.event.ActionEvent;
40 42
 import java.awt.event.ActionListener;
41 43
 
@@ -64,8 +66,6 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
64 66
     private JScrollPane scrollPane;
65 67
     /** Component table model. */
66 68
     private UpdateTableModel tableModel;
67
-    /** Component table. */
68
-    private PackingTable table;
69 69
     /** Check now button. */
70 70
     private JButton checkNow;
71 71
     /** Update channel. */
@@ -78,6 +78,8 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
78 78
     private final CachingUpdateManager updateManager;
79 79
     /** Controller to pass to the update checker. */
80 80
     private final IdentityController identityController;
81
+    /** The event bus to post errors to. */
82
+    private final EventBus eventBus;
81 83
 
82 84
     /**
83 85
      * Instantiates a new update config panel.
@@ -86,17 +88,20 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
86 88
      * @param globalConfig       The configuration to read global settings from.
87 89
      * @param updateManager      The manager to read update information from.
88 90
      * @param identityController Controller to pass to the update checker.
91
+     * @param eventBus           The event bus to post the errors to
89 92
      */
90 93
     @Inject
91 94
     public UpdateConfigPanel(
92 95
             @UserConfig final ConfigProvider userConfig,
93 96
             @GlobalConfig final AggregateConfigProvider globalConfig,
94 97
             final CachingUpdateManager updateManager,
95
-            final IdentityController identityController) {
98
+            final IdentityController identityController,
99
+            final EventBus eventBus) {
96 100
         this.userConfig = userConfig;
97 101
         this.globalConfig = globalConfig;
98 102
         this.updateManager = updateManager;
99 103
         this.identityController = identityController;
104
+        this.eventBus = eventBus;
100 105
 
101 106
         initComponents();
102 107
         addListeners();
@@ -126,7 +131,7 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
126 131
         enable = new JCheckBox();
127 132
         scrollPane = new JScrollPane();
128 133
         tableModel = new UpdateTableModel(updateManager, updateManager.getComponents());
129
-        table = new PackingTable(tableModel, scrollPane);
134
+        final PackingTable table = new PackingTable(tableModel, scrollPane);
130 135
         checkNow = new JButton("Check now");
131 136
         checkNow.setEnabled(globalConfig.getOptionBool("updater", "enable"));
132 137
         updateChannel = new JComboBox<>(new DefaultComboBoxModel<>(UpdateChannel.values()));
@@ -136,8 +141,8 @@ public class UpdateConfigPanel extends JPanel implements ActionListener,
136 141
         try {
137 142
             channel = UpdateChannel.valueOf(globalConfig.getOption("updater", "channel"));
138 143
         } catch (IllegalArgumentException e) {
139
-            Logger.userError(ErrorLevel.LOW, "Invalid setting for update "
140
-                    + "channel, defaulting to none.");
144
+            eventBus.post(new UserErrorEvent(ErrorLevel.LOW, e,
145
+                    "Invalid setting for update channel, defaulting to none.", ""));
141 146
         }
142 147
         updateChannel.setSelectedItem(channel);
143 148
         scrollPane.setViewportView(table);

Загрузка…
Отмена
Сохранить