Ver código fonte

Initial work on redesigning the plugin panel in the prefs dialog.

This iteration brings the plugin information into a panel at the bottom,
it also changes the enable button into a checkbox.  This has code added
for improvements later on but the UI elements for this commented out.

Issue CLIENT-33

Change-Id: I6835f140b74e6f8e6ab815e6277504a3aaa0ed47
Reviewed-on: http://gerrit.dmdirc.com/2147
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.7rc1
Greg Holmes 13 anos atrás
pai
commit
489f3dada1

+ 0
- 1
src/com/dmdirc/addons/ui_swing/SwingController.java Ver arquivo

@@ -502,7 +502,6 @@ public class SwingController extends BasePlugin implements UIController {
502 502
     @Override
503 503
     public void showConfig(final PreferencesDialogModel manager) {
504 504
         manager.getCategory("GUI").addSubCategory(createGeneralCategory());
505
-
506 505
     }
507 506
 
508 507
     /**

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/LockedLayer.java Ver arquivo

@@ -97,7 +97,7 @@ public class LockedLayer<T extends JComponent> extends
97 97
     private Component recentFocusOwner;
98 98
     /** Cursor to show when locked. */
99 99
     private Cursor lockedCursor = Cursor.getPredefinedCursor(
100
-            Cursor.WAIT_CURSOR);
100
+            Cursor.DEFAULT_CURSOR);
101 101
     /** Effect to apply when locked. */
102 102
     private LayerEffect[] lockedEffects = new LayerEffect[0];
103 103
     /** Focus listener. */

+ 38
- 53
src/com/dmdirc/addons/ui_swing/components/addonpanel/AddonCell.java Ver arquivo

@@ -27,18 +27,18 @@ import com.dmdirc.addons.ui_swing.components.text.TextLabel;
27 27
 import java.awt.Color;
28 28
 import java.awt.Font;
29 29
 
30
-import javax.swing.BorderFactory;
30
+import javax.swing.JLabel;
31 31
 import javax.swing.JPanel;
32 32
 import javax.swing.JSeparator;
33 33
 import javax.swing.UIManager;
34
+import javax.swing.text.StyleConstants;
34 35
 
35
-import net.miginfocom.layout.PlatformDefaults;
36 36
 import net.miginfocom.swing.MigLayout;
37 37
 
38 38
 /**
39 39
  * Renders an addon for display in the plugin panel.
40 40
  */
41
-public class AddonCell extends JPanel {
41
+public class AddonCell extends JPanel implements AddonToggleListener {
42 42
 
43 43
     /**
44 44
      * A version number for this class. It should be changed whenever the class
@@ -47,30 +47,29 @@ public class AddonCell extends JPanel {
47 47
      */
48 48
     private static final long serialVersionUID = 1;
49 49
     /** Addon toggle object. */
50
-    private final Object info;
50
+    private final AddonToggle info;
51 51
     /** Name of the addon. */
52 52
     private final TextLabel name;
53
-    /** Version of the addon. */
54
-    private final TextLabel version;
55
-    /** Author of the addon. */
56
-    private final TextLabel author;
57
-    /** Description of the addon. */
58
-    private final TextLabel desc;
53
+    /** Status label. */
54
+    private final TextLabel status;
55
+    /** Addon icon. */
56
+    private final JLabel icon;
59 57
 
60 58
     /**
61 59
      * Creates a new addon cell representing the specified addon info.
62 60
      *
63 61
      * @param info PluginInfoToggle or ThemeToggle
64 62
      */
65
-    public AddonCell(final Object info) {
63
+    public AddonCell(final AddonToggle info) {
66 64
         super();
67 65
 
68 66
         name = new TextLabel(false);
69
-        version = new TextLabel(false);
70
-        author = new TextLabel(false);
71
-        desc = new TextLabel(false);
67
+        status = new TextLabel(false);
68
+        status.setAlignment(StyleConstants.ALIGN_RIGHT);
69
+        icon = new JLabel();
72 70
 
73 71
         this.info = info;
72
+        info.addListener(this);
74 73
         init();
75 74
     }
76 75
 
@@ -78,35 +77,24 @@ public class AddonCell extends JPanel {
78 77
      * Initialises the addon cell.
79 78
      */
80 79
     private void init() {
81
-        setLayout(new MigLayout("fill, ins 3 0 0 0"));
82
-
80
+        setLayout(new MigLayout("fill, ins 0, debug"));
83 81
         Color foreground = UIManager.getColor("Table.foreground");
84
-        if (info instanceof AddonToggle) {
85
-            final AddonToggle plugin = (AddonToggle) info;
86
-
87
-            if (!plugin.getState()) {
88
-                foreground = foreground.brighter().brighter().brighter();
89
-            }
90
-
91
-            name.setText(plugin.getName());
92
-            version.setText(plugin.getVersion());
93
-            author.setText(plugin.getAuthor());
94
-            desc.setText(plugin.getDescription());
82
+        if (!info.getState()) {
83
+            foreground = foreground.brighter().brighter().brighter();
95 84
         }
96
-
85
+        name.setText(info.getName());
86
+        status.setText(info.getState() ? "Enabled" : "Disabled");
97 87
         name.setForeground(foreground);
98 88
         name.setFont(name.getFont().deriveFont(Font.BOLD));
99
-        version.setForeground(foreground);
100
-        author.setForeground(foreground);
101
-        desc.setForeground(foreground);
102
-        desc.setBorder(BorderFactory.createEmptyBorder((int) PlatformDefaults.
103
-                getPanelInsets(0).getValue(), 0, 0, 0));
104
-
105
-        add(name, "gapleft 3, wmin 50%, wmax 50%");
106
-        add(version, "wmin 25%, wmax 25%");
107
-        add(author, "gapright 3, wmin 24.9%, wmax 24.9%, alignx right");
108
-        add(desc, "newline, span, grow, pushy, gapleft 3, gapright 3, wmax 99%");
109
-        add(new JSeparator(), "newline, span, growx, pushx");
89
+        status.setForeground(foreground);
90
+
91
+        add(icon, "gaptop rel, gapbottom rel, gapleft rel, "
92
+                + "wmin 20, wmax 20");
93
+        add(name, "gaptop rel, gapbottom rel, "
94
+                + "wmin 50% - 20, wmax 50% - 20");
95
+        add(status, "gaptop rel, gapbottom rel, gapright rel, "
96
+                + "wmin 50% - 20, wmax 50% - 20");
97
+        add(new JSeparator(), "newline, spanx, growx, pushx");
110 98
     }
111 99
 
112 100
     /**
@@ -124,26 +112,23 @@ public class AddonCell extends JPanel {
124 112
      * @return true iif enabled
125 113
      */
126 114
     public boolean isToggled() {
127
-        if (info instanceof AddonToggle) {
128
-            return ((AddonToggle) info).getState();
129
-        }
130
-        return false;
115
+        return info.getState();
131 116
     }
132 117
 
133 118
     /** {@inheritDoc} */
134 119
     @Override
135
-    public void setForeground(final Color color) {
120
+    public void setForeground(final Color fg) {
136 121
         if (name != null) {
137
-            name.setForeground(color);
138
-        }
139
-        if (version != null) {
140
-            version.setForeground(color);
122
+            name.setForeground(fg);
141 123
         }
142
-        if (author != null) {
143
-            author.setForeground(color);
144
-        }
145
-        if (desc != null) {
146
-            desc.setForeground(color);
124
+        if (status != null) {
125
+            status.setForeground(fg);
147 126
         }
148 127
     }
128
+
129
+    /** {@inheritDoc} */
130
+    @Override
131
+    public void addonToggled() {
132
+        status.setText(info.getState() ? "Enabled" : "Disabled");
133
+    }
149 134
 }

+ 154
- 0
src/com/dmdirc/addons/ui_swing/components/addonpanel/AddonInfoPanel.java Ver arquivo

@@ -0,0 +1,154 @@
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.addonpanel;
24
+
25
+import com.dmdirc.addons.ui_swing.components.text.TextLabel;
26
+import com.dmdirc.util.ListenerList;
27
+
28
+import java.awt.event.ActionEvent;
29
+import java.awt.event.ActionListener;
30
+
31
+import javax.swing.JCheckBox;
32
+import javax.swing.JPanel;
33
+
34
+import net.miginfocom.swing.MigLayout;
35
+
36
+/**
37
+ * Simple panel describing an addon toggle.
38
+ */
39
+public class AddonInfoPanel extends JPanel implements ActionListener,
40
+        AddonToggleListener {
41
+
42
+    /** Java serialisation version UID. */
43
+    private static final long serialVersionUID = 1L;
44
+    /** Addon toggle. */
45
+    private AddonToggle addonToggle;
46
+    /** Plugin description text label. */
47
+    private final TextLabel description;
48
+    /** Status toggle button. */
49
+    private final JCheckBox status;
50
+    /** Label to describe status checkbox. */
51
+    private final TextLabel statusLabel;
52
+    /** Uninstall button. */
53
+    //private final JButton uninstall;
54
+    /** Should we check this addon for updates? */
55
+    private final JCheckBox update;
56
+    /** Label to describe update checkbox. */
57
+    //private final TextLabel updateLabel;
58
+    /** Listener list. */
59
+    private final ListenerList listeners;
60
+
61
+    /**
62
+     * Creates a new addon info panel.
63
+     */
64
+    public AddonInfoPanel() {
65
+        description = new TextLabel();
66
+        status = new JCheckBox();
67
+        statusLabel = new TextLabel("Enable this addon", false);
68
+        //uninstall = new JButton("Uninstall");
69
+        update = new JCheckBox();
70
+        //updateLabel = new TextLabel("Check for updates for this addon", false);
71
+        listeners = new ListenerList();
72
+
73
+        layoutComponents();
74
+        update.addActionListener(this);
75
+        status.addActionListener(this);
76
+    }
77
+
78
+    /**
79
+     * Lays out the components in this panel.
80
+     */
81
+    private void layoutComponents() {
82
+        setLayout(new MigLayout("ins 0, fill", "[65%!][]", ""));
83
+
84
+        add(description, "grow, spany 3");
85
+        add(status, "aligny top");
86
+        add(statusLabel, "grow, push, wrap");
87
+        //add(update, "aligny top");
88
+        //add(updateLabel, "grow, push, wrap, gapbottom rel");
89
+        //add(uninstall, "grow, spanx 2, wrap");
90
+    }
91
+
92
+    /**
93
+     * Sets the addon toggle this panel should display information about.
94
+     *
95
+     * @param addonToggle Addon toggle to display, or null
96
+     */
97
+    public void setAddonToggle(final AddonToggle addonToggle) {
98
+        if (this.addonToggle != null) {
99
+            this.addonToggle.removeListener(this);
100
+        }
101
+        addonToggle.addListener(this);
102
+        this.addonToggle = addonToggle;
103
+        if (addonToggle == null) {
104
+            description.setText("");
105
+        } else {
106
+            description.setText("<b>" + addonToggle.getName() + "</b> "
107
+                    + addonToggle.getVersion() + " by "
108
+                    + addonToggle.getAuthor()
109
+                    + "<br><br>" + addonToggle.getDescription());
110
+            status.setSelected(addonToggle.getState());
111
+            update.setSelected(addonToggle.getUpdateState());
112
+        }
113
+    }
114
+
115
+    /**
116
+     * Adds an addon toggle listener to this panel, this proxies whatever
117
+     * addon listener is being displayed.
118
+     *
119
+     * @param listener Listener to add
120
+     */
121
+    public void addListener(final AddonToggleListener listener) {
122
+        listeners.add(AddonToggleListener.class, listener);
123
+    }
124
+
125
+    /**
126
+     * Removes an addon toggle listener from this panel.
127
+     *
128
+     * @param listener Listener to remove
129
+     */
130
+    public void removeListener(final AddonToggleListener listener) {
131
+        listeners.remove(AddonToggleListener.class, listener);
132
+    }
133
+
134
+    /** {@inheritDoc} */
135
+    @Override
136
+    public void addonToggled() {
137
+        listeners.getCallable(AddonToggleListener.class).addonToggled();
138
+    }
139
+
140
+    /**
141
+     * {@inheritDoc}
142
+     *
143
+     * @param e Action event
144
+     */
145
+    @Override
146
+    public void actionPerformed(final ActionEvent e) {
147
+        if (e.getSource() == update) {
148
+            addonToggle.setUpdateState(update.isSelected());
149
+        } else if (e.getSource() == status) {
150
+            addonToggle.setState(status.isSelected());
151
+        }
152
+    }
153
+
154
+}

+ 53
- 76
src/com/dmdirc/addons/ui_swing/components/addonpanel/AddonPanel.java Ver arquivo

@@ -23,6 +23,7 @@
23 23
 package com.dmdirc.addons.ui_swing.components.addonpanel;
24 24
 
25 25
 import com.dmdirc.addons.ui_swing.SwingController;
26
+import com.dmdirc.addons.ui_swing.UIUtilities;
26 27
 import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
27 28
 import com.dmdirc.addons.ui_swing.components.addonbrowser.BrowserWindow;
28 29
 import com.dmdirc.addons.ui_swing.components.renderers.AddonCellRenderer;
@@ -30,16 +31,15 @@ import com.dmdirc.addons.ui_swing.components.text.TextLabel;
30 31
 import com.dmdirc.config.prefs.PreferencesInterface;
31 32
 
32 33
 import java.awt.Window;
33
-import java.awt.event.ActionEvent;
34
-import java.awt.event.ActionListener;
35
-import java.util.List;
36 34
 
37
-import javax.swing.JButton;
38 35
 import javax.swing.JLabel;
39 36
 import javax.swing.JPanel;
40 37
 import javax.swing.JScrollPane;
41 38
 import javax.swing.JTable;
42 39
 import javax.swing.ListSelectionModel;
40
+import javax.swing.event.HyperlinkEvent;
41
+import javax.swing.event.HyperlinkEvent.EventType;
42
+import javax.swing.event.HyperlinkListener;
43 43
 import javax.swing.event.ListSelectionEvent;
44 44
 import javax.swing.event.ListSelectionListener;
45 45
 import javax.swing.table.DefaultTableModel;
@@ -49,11 +49,9 @@ import net.miginfocom.swing.MigLayout;
49 49
 /**
50 50
  * Addon panel, base class for displaying and managing addons.
51 51
  */
52
-public abstract class AddonPanel extends JPanel implements
53
-        ActionListener, ListSelectionListener, PreferencesInterface {
52
+public abstract class AddonPanel extends JPanel implements AddonToggleListener,
53
+        ListSelectionListener, PreferencesInterface, HyperlinkListener {
54 54
 
55
-    /** Button to enable/disable addon. */
56
-    protected JButton toggleButton;
57 55
     /** List of addons. */
58 56
     protected JTable addonList;
59 57
     /**
@@ -68,10 +66,14 @@ public abstract class AddonPanel extends JPanel implements
68 66
     private final SwingController controller;
69 67
     /** Addon list scroll pane. */
70 68
     private JScrollPane scrollPane;
71
-    /** Currently selected addon. */
72
-    private int selectedAddon;
73 69
     /** Blurb label. */
74 70
     private TextLabel blurbLabel;
71
+    /** Get more info link. */
72
+    private TextLabel getMoreLabel;
73
+    /** Addon info panel. */
74
+    private AddonInfoPanel addonInfo;
75
+    /** Selected addon. */
76
+    private int selectedAddon = -1;
75 77
 
76 78
     /**
77 79
      * Creates a new instance of AddonPanel
@@ -87,11 +89,7 @@ public abstract class AddonPanel extends JPanel implements
87 89
         this.controller = controller;
88 90
 
89 91
         initComponents();
90
-        addListeners();
91 92
         layoutComponents();
92
-
93
-        addonList.getSelectionModel().setSelectionInterval(0, 0);
94
-        selectedAddon = 0;
95 93
     }
96 94
 
97 95
     /** Initialises the components. */
@@ -115,7 +113,6 @@ public abstract class AddonPanel extends JPanel implements
115 113
         addonList.setShowGrid(false);
116 114
         addonList.getSelectionModel().setSelectionMode(
117 115
                 ListSelectionModel.SINGLE_SELECTION);
118
-        addonList.getSelectionModel().clearSelection();
119 116
 
120 117
         scrollPane = new JScrollPane(new JLabel("Loading " + getTypeName()
121 118
                 + "..."));
@@ -124,12 +121,14 @@ public abstract class AddonPanel extends JPanel implements
124 121
         scrollPane.setVerticalScrollBarPolicy(
125 122
                 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
126 123
 
127
-        toggleButton = new JButton("Enable");
128
-        toggleButton.setEnabled(false);
129
-
130 124
         blurbLabel = new TextLabel(getTypeName().substring(0, 1).toUpperCase()
131 125
                 + getTypeName().substring(1) + " allow you to extend the "
132 126
                 + "functionality of DMDirc.");
127
+        getMoreLabel = new TextLabel(
128
+                "<a href=\"http://addons.dmdirc.com\">Get more addons</a>");
129
+        getMoreLabel.addHyperlinkListener(this);
130
+        addonInfo = new AddonInfoPanel();
131
+        addonInfo.addListener(this);
133 132
 
134 133
         /** {@inheritDoc}. */
135 134
         new LoggingSwingWorker<Object, Object>() {
@@ -145,6 +144,17 @@ public abstract class AddonPanel extends JPanel implements
145 144
             protected void done() {
146 145
                 super.done();
147 146
                 scrollPane.setViewportView(addonList);
147
+                UIUtilities.invokeLater(new Runnable() {
148
+
149
+                    /** {@inheritDoc}. */
150
+                    @Override
151
+                    public void run() {
152
+                        addonList.getSelectionModel()
153
+                                .addListSelectionListener(AddonPanel.this);
154
+                        addonList.getSelectionModel()
155
+                                .setSelectionInterval(0, 0);
156
+                    }
157
+                });
148 158
             }
149 159
         }.executeInExecutor();
150 160
     }
@@ -152,26 +162,23 @@ public abstract class AddonPanel extends JPanel implements
152 162
     /** Lays out the dialog. */
153 163
     private void layoutComponents() {
154 164
         if (controller == null) {
155
-            setLayout(new MigLayout("ins 0, fill, hmax " + 300));
165
+            setLayout(new MigLayout("ins 0, fill, hmax " + 500));
156 166
         } else {
157 167
             setLayout(new MigLayout("ins 0, fill, hmax "
158 168
                     + controller.getPrefsDialog().getPanelHeight()));
159 169
         }
160 170
 
161
-        add(blurbLabel, "wrap 10, growx, pushx");
162
-
171
+        add(blurbLabel, "wrap 5, growx, pushx");
172
+        add(getMoreLabel, "wrap 5, right");
163 173
         add(scrollPane, "wrap 5, grow, push");
164
-
165
-        add(toggleButton, "split 2, growx, pushx, sg button");
166
-
167
-        final JButton button = new JButton("Get more " + getTypeName());
168
-        button.addActionListener(this);
169
-        add(button, "growx, pushx, sg button");
174
+        add(addonInfo, "grow, push");
170 175
     }
171 176
 
172 177
     /**
173 178
      * Populates the addon list returning it when complete.
174 179
      *
180
+     * @param table Table to be populated
181
+     *
175 182
      * @return Populated table
176 183
      */
177 184
     protected abstract JTable populateList(final JTable table);
@@ -183,61 +190,25 @@ public abstract class AddonPanel extends JPanel implements
183 190
      */
184 191
     protected abstract String getTypeName();
185 192
 
186
-    /** Adds listeners to components. */
187
-    private void addListeners() {
188
-        toggleButton.addActionListener(this);
189
-        addonList.getSelectionModel().addListSelectionListener(this);
190
-    }
191
-
192
-    /**
193
-     * Invoked when an action occurs.
194
-     *
195
-     * @param e The event related to this action.
196
-     */
193
+    /** {@inheritDoc}. */
197 194
     @Override
198
-    public void actionPerformed(final ActionEvent e) {
199
-        if (e.getSource() == toggleButton && selectedAddon >= 0) {
200
-            final AddonToggle addonToggle = (AddonToggle) ((AddonCell)
201
-                    addonList.getModel().getValueAt(addonList
202
-                    .getSelectedRow(), 0)).getObject();
203
-
204
-            addonToggle.toggle();
205
-
206
-            if (addonToggle.getState()) {
207
-                toggleButton.setText("Disable");
208
-            } else {
209
-                toggleButton.setText("Enable");
210
-            }
211
-
212
-            addonList.repaint();
213
-        } else if (e.getSource() != toggleButton) {
214
-            new BrowserWindow(parentWindow);
195
+    public void valueChanged(final ListSelectionEvent e) {
196
+        final int newSelection = addonList.getSelectedRow();
197
+        if (newSelection == -1) {
198
+            addonList.getSelectionModel().setSelectionInterval(0, selectedAddon);
199
+        } else if (addonList.getModel().getRowCount() > newSelection) {
200
+            addonInfo.setAddonToggle((AddonToggle) ((AddonCell) addonList
201
+                    .getModel().getValueAt(newSelection, 0)).getObject());
215 202
         }
203
+        selectedAddon = addonList.getSelectedRow();
216 204
     }
217 205
 
218 206
     /** {@inheritDoc}. */
219 207
     @Override
220
-    public void valueChanged(final ListSelectionEvent e) {
221
-        if (!e.getValueIsAdjusting()) {
222
-            return;
223
-        }
224
-        final int selected = addonList.getSelectionModel()
225
-                .getLeadSelectionIndex();
226
-        if (selected == -1) {
227
-            return;
228
-        }
229
-        final AddonToggle addonToggle = (AddonToggle) ((AddonCell)
230
-                ((List) ((DefaultTableModel) addonList.getModel())
231
-                .getDataVector().elementAt(selected)).get(0)).getObject();
232
-        toggleButton.setEnabled(true);
233
-
234
-        if (addonToggle.getState()) {
235
-            toggleButton.setEnabled(addonToggle.isUnloadable());
236
-            toggleButton.setText("Disable");
237
-        } else {
238
-            toggleButton.setText("Enable");
208
+    public void hyperlinkUpdate(final HyperlinkEvent e) {
209
+        if (e.getEventType() == EventType.ACTIVATED) {
210
+            new BrowserWindow(parentWindow);
239 211
         }
240
-        selectedAddon = selected;
241 212
     }
242 213
 
243 214
     /** {@inheritDoc} */
@@ -246,10 +217,16 @@ public abstract class AddonPanel extends JPanel implements
246 217
         if (addonList.getRowCount() == 0) {
247 218
             return;
248 219
         }
249
-        for (int i = 1; i < addonList.getRowCount(); i++) {
220
+        for (int i = 0; i < addonList.getRowCount(); i++) {
250 221
             addonList.getModel().getColumnCount();
251 222
             ((AddonToggle) ((AddonCell) addonList.getModel()
252 223
                     .getValueAt(i, 0)).getObject()).apply();
253 224
         }
254 225
     }
226
+
227
+    /** {@inheritDoc} */
228
+    @Override
229
+    public void addonToggled() {
230
+        addonList.repaint();
231
+    }
255 232
 }

+ 98
- 16
src/com/dmdirc/addons/ui_swing/components/addonpanel/AddonToggle.java Ver arquivo

@@ -21,23 +21,33 @@
21 21
  */
22 22
 package com.dmdirc.addons.ui_swing.components.addonpanel;
23 23
 
24
+import com.dmdirc.config.IdentityManager;
24 25
 import com.dmdirc.plugins.PluginInfo;
25 26
 import com.dmdirc.plugins.PluginManager;
26 27
 import com.dmdirc.ui.themes.Theme;
27 28
 import com.dmdirc.ui.themes.ThemeManager;
29
+import com.dmdirc.updater.UpdateChecker;
30
+import com.dmdirc.updater.UpdateComponent;
31
+import com.dmdirc.util.ListenerList;
28 32
 
29 33
 /**
30 34
  * Wraps a Addon object (Theme or Plugin) with a boolean to indicate whether
31 35
  * it should be toggled or not.
32 36
  */
33
-public class AddonToggle {
37
+public final class AddonToggle {
34 38
 
35 39
     /** The PluginInfo object we're wrapping. */
36 40
     private final PluginInfo pi;
37 41
     /** The Theme object we're wrapping. */
38 42
     private final Theme theme;
39
-    /** Whether or not to toggle it. */
40
-    private boolean toggled = false;
43
+    /** Update component. */
44
+    private final UpdateComponent updateComponent;
45
+    /** Addon state. */
46
+    private boolean state;
47
+    /** Whether or nor the addon update state should be toggled. */
48
+    private boolean updateState;
49
+    /** Listener list. */
50
+    private final ListenerList listeners;
41 51
 
42 52
     /**
43 53
      * Creates a new instance of AddonToggle to wrap the specified
@@ -53,13 +63,32 @@ public class AddonToggle {
53 63
         }
54 64
         this.pi = pi;
55 65
         this.theme = theme;
66
+        listeners = new ListenerList();
67
+        state = pi.isLoaded();
68
+        updateComponent = UpdateChecker.findComponent("addon-" + getID());
69
+        if (updateComponent != null) {
70
+            updateState = UpdateChecker.isEnabled(updateComponent);
71
+        }
72
+    }
73
+
74
+    /**
75
+     * Sets the state of this adddon.
76
+     *
77
+     * @param state New state
78
+     */
79
+    public void setState(final boolean state) {
80
+        this.state = state;
81
+        triggerListener();
56 82
     }
57 83
 
58 84
     /**
59
-     * Toggles this PluginInfoToggle.
85
+     * Sets the update state of this addon.
86
+     *
87
+     * @param updateState New update state
60 88
      */
61
-    public void toggle() {
62
-        toggled ^= true;
89
+    public void setUpdateState(final boolean updateState) {
90
+        this.updateState = updateState;
91
+        triggerListener();
63 92
     }
64 93
 
65 94
     /**
@@ -69,11 +98,18 @@ public class AddonToggle {
69 98
      * @return True if the plugin is or should be loaded, false otherwise.
70 99
      */
71 100
     public boolean getState() {
101
+        return state;
102
+    }
103
+
104
+    /**
105
+     * Gets the update state of this PluginInfo, taking into account the state
106
+     * of the update toggle setting.
107
+     *
108
+     * @return True if the plugin is or should be updated, false otherwise.
109
+     */
110
+    public boolean getUpdateState() {
72 111
         if (pi != null) {
73
-            return toggled ^ pi.isLoaded();
74
-        }
75
-        if (theme != null) {
76
-            return toggled ^ theme.isEnabled();
112
+            return updateState;
77 113
         }
78 114
         return false;
79 115
     }
@@ -105,16 +141,25 @@ public class AddonToggle {
105 141
             /** {@inheritDoc} */
106 142
             @Override
107 143
             public void run() {
108
-                if (pi != null && toggled) {
109
-                    if (pi.isLoaded()) {
110
-                        pi.unloadPlugin();
111
-                    } else {
144
+                if (pi != null) {
145
+                    if (AddonToggle.this.getState()) {
112 146
                         pi.loadPlugin();
147
+                    } else {
148
+                        pi.unloadPlugin();
113 149
                     }
114 150
                     PluginManager.getPluginManager().updateAutoLoad(pi);
151
+                    if (getID() != -1) {
152
+                        if (getUpdateState()) {
153
+                            IdentityManager.getConfigIdentity().unsetOption(
154
+                                    "updater", "enable-addon-" + getID());
155
+                        } else {
156
+                            IdentityManager.getConfigIdentity().setOption(
157
+                                   "updater", "enable-addon-" + getID(), false);
158
+                        }
159
+                    }
115 160
                 }
116
-                if (theme != null && toggled) {
117
-                    if (theme.isEnabled()) {
161
+                if (theme != null) {
162
+                    if (AddonToggle.this.getState()) {
118 163
                         theme.applyTheme();
119 164
                     } else {
120 165
                         theme.removeTheme();
@@ -153,6 +198,18 @@ public class AddonToggle {
153 198
         return "Unknown addon name";
154 199
     }
155 200
 
201
+    /**
202
+     * Returns the ID of this addon. This will return -1 for any theme.
203
+     *
204
+     * @return Addon ID
205
+     */
206
+    public int getID() {
207
+        if (pi != null) {
208
+            return pi.getMetaData().getUpdaterId();
209
+        }
210
+        return -1;
211
+    }
212
+
156 213
     /**
157 214
      * Returns the friendly version of this addon.
158 215
      *
@@ -204,4 +261,29 @@ public class AddonToggle {
204 261
         return "There is an error with this addon.";
205 262
     }
206 263
 
264
+    /**
265
+     * Adds an addon toggle listener to this panel.
266
+     *
267
+     * @param listener Listener to add
268
+     */
269
+    public void addListener(final AddonToggleListener listener) {
270
+        listeners.add(AddonToggleListener.class, listener);
271
+    }
272
+
273
+    /**
274
+     * Removes an addon toggle listener from this panel.
275
+     *
276
+     * @param listener Listener to remove
277
+     */
278
+    public void removeListener(final AddonToggleListener listener) {
279
+        listeners.remove(AddonToggleListener.class, listener);
280
+    }
281
+
282
+    /**
283
+     * Triggers this listener to be called across all it's listeners.
284
+     */
285
+    public void triggerListener() {
286
+        listeners.getCallable(AddonToggleListener.class).addonToggled();
287
+    }
288
+
207 289
 }

+ 34
- 0
src/com/dmdirc/addons/ui_swing/components/addonpanel/AddonToggleListener.java Ver arquivo

@@ -0,0 +1,34 @@
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.addonpanel;
24
+
25
+/**
26
+ * Addon toggle listener.
27
+ */
28
+public interface AddonToggleListener {
29
+
30
+    /**
31
+     * Called when the addon has been toggled.
32
+     */
33
+    void addonToggled();
34
+}

+ 0
- 6
src/com/dmdirc/addons/ui_swing/components/addonpanel/PluginPanel.java Ver arquivo

@@ -85,12 +85,6 @@ public class PluginPanel extends AddonPanel implements ActionListener {
85 85
                             new AddonCell[]{
86 86
                         new AddonCell(new AddonToggle(plugin, null)), });
87 87
                 }
88
-
89
-                if (((DefaultTableModel) table.getModel()).getRowCount()
90
-                        > 0) {
91
-                    toggleButton.setEnabled(true);
92
-                }
93
-
94 88
                 table.repaint();
95 89
             }
96 90
         });

+ 0
- 5
src/com/dmdirc/addons/ui_swing/components/addonpanel/ThemePanel.java Ver arquivo

@@ -78,11 +78,6 @@ public class ThemePanel extends AddonPanel {
78 78
                         new AddonCell(new AddonToggle(null, theme)), });
79 79
                 }
80 80
 
81
-                if (((DefaultTableModel) addonList.getModel()).getRowCount()
82
-                        > 0) {
83
-                    toggleButton.setEnabled(true);
84
-                }
85
-
86 81
                 addonList.repaint();
87 82
             }
88 83
         });

+ 0
- 5
src/com/dmdirc/addons/ui_swing/components/renderers/AddonCellRenderer.java Ver arquivo

@@ -55,11 +55,6 @@ public class AddonCellRenderer implements TableCellRenderer {
55 55
                 label.setBackground(table.getSelectionBackground());
56 56
             } else {
57 57
                 label.setBackground(table.getBackground());
58
-                final Color colour = (row & 1)
59
-                        == 1 ? new Color(0xEE, 0xEE, 0xFF) : Color.WHITE;
60
-                if (!label.getBackground().equals(colour)) {
61
-                    label.setBackground(colour);
62
-                }
63 58
             }
64 59
 
65 60
             final int height = label.getPreferredSize().height;

+ 1
- 1
src/com/dmdirc/addons/ui_swing/dialogs/prefs/SwingPreferencesDialog.java Ver arquivo

@@ -82,7 +82,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
82 82
     /** Parent window. */
83 83
     private final MainFrame parentWindow;
84 84
     /** Panel size. */
85
-    private int panelSize = 300;
85
+    private int panelSize = 500;
86 86
 
87 87
     /**
88 88
      * Creates a new instance of SwingPreferencesDialog.

Carregando…
Cancelar
Salvar