소스 검색

Switch pluginPanel to use a table not a list, same for themes.

Fixes CLIENT-171

Depends-On:Iecb3ea2067a398bb7ce26a8803f5678ec38e73b9
Change-Id: Ic451ad093b870ce9a69f64aa28049020fe02dc3b
Reviewed-on: http://gerrit.dmdirc.com/1793
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.5
Greg Holmes 13 년 전
부모
커밋
661689c05b

+ 5
- 4
src/com/dmdirc/addons/ui_swing/SwingController.java 파일 보기

@@ -32,10 +32,11 @@ import com.dmdirc.addons.ui_swing.components.frames.CustomFrame;
32 32
 import com.dmdirc.addons.ui_swing.components.frames.CustomInputFrame;
33 33
 import com.dmdirc.addons.ui_swing.components.frames.QueryFrame;
34 34
 import com.dmdirc.addons.ui_swing.components.frames.ServerFrame;
35
-import com.dmdirc.addons.ui_swing.components.pluginpanel.PluginPanel;
35
+import com.dmdirc.addons.ui_swing.components.addonpanel.AddonPanel;
36
+import com.dmdirc.addons.ui_swing.components.addonpanel.PluginPanel;
37
+import com.dmdirc.addons.ui_swing.components.addonpanel.ThemePanel;
36 38
 import com.dmdirc.addons.ui_swing.components.statusbar.FeedbackNag;
37 39
 import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
38
-import com.dmdirc.addons.ui_swing.components.themepanel.ThemePanel;
39 40
 import com.dmdirc.addons.ui_swing.dialogs.DialogKeyListener;
40 41
 import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
41 42
 import com.dmdirc.addons.ui_swing.dialogs.StandardMessageDialog;
@@ -631,7 +632,7 @@ public class SwingController extends Plugin implements UIController {
631 632
     /** {@inheritDoc} */
632 633
     @Override
633 634
     public PreferencesInterface getPluginPrefsPanel() {
634
-        return UIUtilities.invokeAndWait(new ReturnableThread<PluginPanel>() {
635
+        return UIUtilities.invokeAndWait(new ReturnableThread<AddonPanel>() {
635 636
 
636 637
             /** {@inheritDoc} */
637 638
             @Override
@@ -678,7 +679,7 @@ public class SwingController extends Plugin implements UIController {
678 679
             /** {@inheritDoc} */
679 680
             @Override
680 681
             public void run() {
681
-                setObject(new ThemePanel(urlHandler));
682
+                setObject(new ThemePanel(me, SwingController.this));
682 683
             }
683 684
         });
684 685
     }

+ 1
- 1
src/com/dmdirc/addons/ui_swing/components/addonbrowser/AddonInfo.java 파일 보기

@@ -36,7 +36,7 @@ import javax.swing.ImageIcon;
36 36
 /**
37 37
  * Describes an addon.
38 38
  */
39
-public class AddonInfo {    
39
+public class AddonInfo {
40 40
     private final int id;
41 41
     private final String stableDownload;
42 42
     private final String unstableDownload;

+ 143
- 0
src/com/dmdirc/addons/ui_swing/components/addonpanel/AddonCell.java 파일 보기

@@ -0,0 +1,143 @@
1
+/*
2
+ * Copyright (c) 2006-2011 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
+
27
+import java.awt.Color;
28
+import java.awt.Font;
29
+
30
+import javax.swing.BorderFactory;
31
+import javax.swing.JPanel;
32
+import javax.swing.JSeparator;
33
+import javax.swing.UIManager;
34
+
35
+import net.miginfocom.layout.PlatformDefaults;
36
+import net.miginfocom.swing.MigLayout;
37
+
38
+/**
39
+ * Renders an addon for display in the plugin panel.
40
+ */
41
+public class AddonCell extends JPanel {
42
+
43
+    /** Addon toggle object. */
44
+    private final Object info;
45
+    /** Name of the addon. */
46
+    private final TextLabel name;
47
+    /** Version of the addon. */
48
+    private final TextLabel version;
49
+    /** Author of the addon. */
50
+    private final TextLabel author;
51
+    /** Description of the addon. */
52
+    private final TextLabel desc;
53
+
54
+    /**
55
+     * Creates a new addon cell representing the specified addon info.
56
+     *
57
+     * @param info PluginInfoToggle or ThemeToggle
58
+     */
59
+    public AddonCell(final Object info) {
60
+        super();
61
+
62
+        name = new TextLabel();
63
+        version = new TextLabel();
64
+        author = new TextLabel();
65
+        desc = new TextLabel();
66
+
67
+        this.info = info;
68
+        init();
69
+    }
70
+
71
+    /**
72
+     * Initialises the addon cell.
73
+     */
74
+    private void init() {
75
+        setLayout(new MigLayout("fill, ins 3 0 0 0"));
76
+
77
+        Color foreground = UIManager.getColor("Table.foreground");
78
+        if (info instanceof AddonToggle) {
79
+            final AddonToggle plugin = (AddonToggle) info;
80
+
81
+            if (!plugin.getState()) {
82
+                foreground = foreground.brighter().brighter().brighter();
83
+            }
84
+
85
+            name.setText(plugin.getPluginInfo().getNiceName());
86
+            version.setText(plugin.getPluginInfo().getFriendlyVersion());
87
+            author.setText(plugin.getPluginInfo().getAuthor());
88
+            desc.setText(plugin.getPluginInfo().getDescription());
89
+        }
90
+
91
+        name.setForeground(foreground);
92
+        name.setFont(name.getFont().deriveFont(Font.BOLD));
93
+        version.setForeground(foreground);
94
+        author.setForeground(foreground);
95
+        desc.setForeground(foreground);
96
+        desc.setBorder(BorderFactory.createEmptyBorder((int) PlatformDefaults.
97
+                getPanelInsets(0).getValue(), 0, 0, 0));
98
+
99
+        add(name, "gapleft 3, wmin 50%, wmax 50%");
100
+        add(version, "wmin 25%, wmax 25%");
101
+        add(author, "gapright 3, wmin 24.9%, wmax 24.9%, alignx right");
102
+        add(desc, "newline, span, grow, pushy, gapleft 3, gapright 3, wmax 99%");
103
+        add(new JSeparator(), "newline, span, growx, pushx");
104
+    }
105
+
106
+    /**
107
+     * Returns the addon toggle object associated with this cell.
108
+     *
109
+     * @return Addon toggle
110
+     */
111
+    public Object getObject() {
112
+        return info;
113
+    }
114
+
115
+    /**
116
+     * Is this addon enabled or disabled?
117
+     *
118
+     * @return true iif enabled
119
+     */
120
+    public boolean isToggled() {
121
+        if (info instanceof AddonToggle) {
122
+            return ((AddonToggle) info).getState();
123
+        }
124
+        return false;
125
+    }
126
+
127
+    /** {@inheritDoc} */
128
+    @Override
129
+    public void setForeground(final Color color) {
130
+        if (name != null) {
131
+            name.setForeground(color);
132
+        }
133
+        if (version != null) {
134
+            version.setForeground(color);
135
+        }
136
+        if (author != null) {
137
+            author.setForeground(color);
138
+        }
139
+        if (desc != null) {
140
+            desc.setForeground(color);
141
+        }
142
+    }
143
+}

src/com/dmdirc/addons/ui_swing/components/pluginpanel/PluginPanel.java → src/com/dmdirc/addons/ui_swing/components/addonpanel/AddonPanel.java 파일 보기

@@ -20,45 +20,42 @@
20 20
  * SOFTWARE.
21 21
  */
22 22
 
23
-package com.dmdirc.addons.ui_swing.components.pluginpanel;
23
+package com.dmdirc.addons.ui_swing.components.addonpanel;
24 24
 
25
-import com.dmdirc.actions.ActionManager;
26
-import com.dmdirc.actions.CoreActionType;
27
-import com.dmdirc.actions.interfaces.ActionType;
28 25
 import com.dmdirc.addons.ui_swing.SwingController;
29
-import com.dmdirc.addons.ui_swing.UIUtilities;
30 26
 import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
31 27
 import com.dmdirc.addons.ui_swing.components.addonbrowser.DownloaderWindow;
32 28
 import com.dmdirc.addons.ui_swing.components.renderers.AddonCellRenderer;
33 29
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
34 30
 import com.dmdirc.config.prefs.PreferencesInterface;
35
-import com.dmdirc.plugins.PluginInfo;
36
-import com.dmdirc.plugins.PluginManager;
37 31
 
38 32
 import java.awt.Window;
39 33
 import java.awt.event.ActionEvent;
40 34
 import java.awt.event.ActionListener;
41
-import java.util.Collections;
42 35
 import java.util.List;
43 36
 
44
-import javax.swing.DefaultListModel;
45 37
 import javax.swing.JButton;
46 38
 import javax.swing.JLabel;
47
-import javax.swing.JList;
48 39
 import javax.swing.JPanel;
49 40
 import javax.swing.JScrollPane;
41
+import javax.swing.JTable;
42
+import javax.swing.ListSelectionModel;
50 43
 import javax.swing.event.ListSelectionEvent;
51 44
 import javax.swing.event.ListSelectionListener;
45
+import javax.swing.table.DefaultTableModel;
52 46
 
53 47
 import net.miginfocom.swing.MigLayout;
54 48
 
55 49
 /**
56
- * Plugin manager dialog. Allows the user to manage their plugins.
50
+ * Addon panel, base class for displaying and managing addons.
57 51
  */
58
-public final class PluginPanel extends JPanel implements
59
-        ActionListener, ListSelectionListener, PreferencesInterface,
60
-        com.dmdirc.interfaces.ActionListener {
52
+public abstract class AddonPanel extends JPanel implements
53
+        ActionListener, ListSelectionListener, PreferencesInterface {
61 54
 
55
+    /** Button to enable/disable addon. */
56
+    protected JButton toggleButton;
57
+    /** List of addons. */
58
+    protected JTable addonList;
62 59
     /**
63 60
      * A version number for this class. It should be changed whenever the class
64 61
      * structure is changed (or anything else that would prevent serialized
@@ -69,26 +66,20 @@ public final class PluginPanel extends JPanel implements
69 66
     private final Window parentWindow;
70 67
     /** Swing Controller. */
71 68
     private final SwingController controller;
72
-    /** List of plugins. */
73
-    private JList pluginList;
74
-    /** plugin list scroll pane. */
69
+    /** Addon list scroll pane. */
75 70
     private JScrollPane scrollPane;
76
-    /** Button to enable/disable plugin. */
77
-    private JButton toggleButton;
78
-    /** Currently selected plugin. */
79
-    private int selectedPlugin;
71
+    /** Currently selected addon. */
72
+    private int selectedAddon;
80 73
     /** Blurb label. */
81 74
     private TextLabel blurbLabel;
82
-    /** Do we refresh on plugin reload? */
83
-    private boolean pluginRefresh = true;
84 75
 
85 76
     /**
86
-     * Creates a new instance of PluginDialog.
77
+     * Creates a new instance of AddonPanel
87 78
      *
88 79
      * @param parentWindow Parent window
89 80
      * @param controller Swing Controller
90 81
      */
91
-    public PluginPanel(final Window parentWindow,
82
+    public AddonPanel(final Window parentWindow,
92 83
             final SwingController controller) {
93 84
         super();
94 85
 
@@ -99,16 +90,32 @@ public final class PluginPanel extends JPanel implements
99 90
         addListeners();
100 91
         layoutComponents();
101 92
 
102
-        pluginList.setSelectedIndex(0);
103
-        selectedPlugin = 0;
93
+        addonList.getSelectionModel().setSelectionInterval(0, 0);
94
+        selectedAddon = 0;
104 95
     }
105 96
 
106 97
     /** Initialises the components. */
107 98
     private void initComponents() {
108
-        pluginList = new JList(new DefaultListModel());
109
-        pluginList.setCellRenderer(new AddonCellRenderer());
99
+        addonList = new JTable(new DefaultTableModel(
100
+                new Object[]{"Addon", }, 0)) {
110 101
 
111
-        scrollPane = new JScrollPane(new JLabel("Loading plugins..."));
102
+            /** {@inheritDoc} */
103
+            @Override
104
+            public boolean isCellEditable(final int row, final int column) {
105
+                return false;
106
+            }
107
+
108
+        };
109
+        addonList.setDefaultRenderer(Object.class,
110
+                new AddonCellRenderer());
111
+        addonList.setTableHeader(null);
112
+        addonList.setShowGrid(false);
113
+        addonList.getSelectionModel().setSelectionMode(
114
+                ListSelectionModel.SINGLE_SELECTION);
115
+        addonList.getSelectionModel().clearSelection();
116
+
117
+        scrollPane = new JScrollPane(new JLabel("Loading " + getTypeName()
118
+                + "..."));
112 119
         scrollPane.setHorizontalScrollBarPolicy(
113 120
                 JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
114 121
         scrollPane.setVerticalScrollBarPolicy(
@@ -117,8 +124,9 @@ public final class PluginPanel extends JPanel implements
117 124
         toggleButton = new JButton("Enable");
118 125
         toggleButton.setEnabled(false);
119 126
 
120
-        blurbLabel = new TextLabel(
121
-                "Plugins allow you to extend the functionality of DMDirc.");
127
+        blurbLabel = new TextLabel(getTypeName().substring(0, 1).toUpperCase()
128
+                + getTypeName().substring(1) + " allow you to extend the "
129
+                + "functionality of DMDirc.");
122 130
 
123 131
         /** {@inheritDoc}. */
124 132
         new LoggingSwingWorker<Object, Object>() {
@@ -126,14 +134,14 @@ public final class PluginPanel extends JPanel implements
126 134
             /** {@inheritDoc}. */
127 135
             @Override
128 136
             protected Object doInBackground() {
129
-                return populateList();
137
+                return populateList(addonList);
130 138
             }
131 139
 
132 140
             /** {@inheritDoc}. */
133 141
             @Override
134 142
             protected void done() {
135 143
                 super.done();
136
-                scrollPane.setViewportView(pluginList);
144
+                scrollPane.setViewportView(addonList);
137 145
             }
138 146
         }.executeInExecutor();
139 147
     }
@@ -153,43 +161,29 @@ public final class PluginPanel extends JPanel implements
153 161
 
154 162
         add(toggleButton, "split 2, growx, pushx, sg button");
155 163
 
156
-        final JButton button = new JButton("Get more plugins");
164
+        final JButton button = new JButton("Get more " + getTypeName());
157 165
         button.addActionListener(this);
158 166
         add(button, "growx, pushx, sg button");
159 167
     }
160 168
 
161 169
     /**
162
-     * Populates the plugins list with plugins from the plugin manager.
170
+     * Populates the addon list returning it when complete.
163 171
      *
164
-     * @return Populated list
172
+     * @return Populated table
165 173
      */
166
-    private JList populateList() {
167
-        pluginRefresh = false;
168
-        final List<PluginInfo> list =
169
-                PluginManager.getPluginManager().getPossiblePluginInfos(true);
170
-        pluginRefresh = true;
171
-        Collections.sort(list);
174
+    protected abstract JTable populateList(final JTable table);
172 175
 
173
-        UIUtilities.invokeLater(new Runnable() {
174
-
175
-            @Override
176
-            public void run() {
177
-                ((DefaultListModel) pluginList.getModel()).clear();
178
-                for (PluginInfo plugin : list) {
179
-                    ((DefaultListModel) pluginList.getModel()).addElement(
180
-                            new PluginInfoToggle(plugin));
181
-                }
182
-                pluginList.repaint();
183
-            }
184
-        });
185
-        return pluginList;
186
-    }
176
+    /**
177
+     * Returns the name of the type of addon being handled.
178
+     *
179
+     * @return Addon type name
180
+     */
181
+    protected abstract String getTypeName();
187 182
 
188 183
     /** Adds listeners to components. */
189 184
     private void addListeners() {
190 185
         toggleButton.addActionListener(this);
191
-        pluginList.addListSelectionListener(this);
192
-        ActionManager.addListener(this, CoreActionType.PLUGIN_REFRESH);
186
+        addonList.getSelectionModel().addListSelectionListener(this);
193 187
     }
194 188
 
195 189
     /**
@@ -199,19 +193,20 @@ public final class PluginPanel extends JPanel implements
199 193
      */
200 194
     @Override
201 195
     public void actionPerformed(final ActionEvent e) {
202
-        if (e.getSource() == toggleButton && selectedPlugin >= 0) {
203
-            final PluginInfoToggle pluginInfo = (PluginInfoToggle) pluginList.
204
-                    getSelectedValue();
196
+        if (e.getSource() == toggleButton && selectedAddon >= 0) {
197
+            final AddonToggle addonToggle = (AddonToggle) ((AddonCell)
198
+                    addonList.getModel().getValueAt(addonList
199
+                    .getSelectedRow(), 0)).getObject();
205 200
 
206
-            pluginInfo.toggle();
201
+            addonToggle.toggle();
207 202
 
208
-            if (pluginInfo.getState()) {
203
+            if (addonToggle.getState()) {
209 204
                 toggleButton.setText("Disable");
210 205
             } else {
211 206
                 toggleButton.setText("Enable");
212 207
             }
213 208
 
214
-            pluginList.repaint();
209
+            addonList.repaint();
215 210
         } else if (e.getSource() != toggleButton) {
216 211
             new DownloaderWindow(parentWindow, controller);
217 212
         }
@@ -221,40 +216,37 @@ public final class PluginPanel extends JPanel implements
221 216
     @Override
222 217
     public void valueChanged(final ListSelectionEvent e) {
223 218
         if (!e.getValueIsAdjusting()) {
224
-            final int selected = ((JList) e.getSource()).getSelectedIndex();
225
-            if (selected >= 0) {
226
-                final PluginInfoToggle pluginInfo =
227
-                        (PluginInfoToggle) ((JList) e.getSource()).
228
-                        getSelectedValue();
229
-                toggleButton.setEnabled(true);
230
-
231
-                if (pluginInfo.getState()) {
232
-                    toggleButton.setEnabled(pluginInfo.getPluginInfo().
233
-                            isUnloadable());
234
-                    toggleButton.setText("Disable");
235
-                } else {
236
-                    toggleButton.setText("Enable");
237
-                }
238
-            }
239
-            selectedPlugin = selected;
219
+            return;
220
+        }
221
+        final int selected = addonList.getSelectionModel()
222
+                .getLeadSelectionIndex();
223
+        if (selected == -1) {
224
+            return;
225
+        }
226
+        final AddonToggle addonToggle = (AddonToggle) ((AddonCell)
227
+                ((List) ((DefaultTableModel) addonList.getModel())
228
+                .getDataVector().elementAt(selected)).get(0)).getObject();
229
+        toggleButton.setEnabled(true);
230
+
231
+        if (addonToggle.getState()) {
232
+            toggleButton.setEnabled(addonToggle.isUnloadable());
233
+            toggleButton.setText("Disable");
234
+        } else {
235
+            toggleButton.setText("Enable");
240 236
         }
237
+        selectedAddon = selected;
241 238
     }
242 239
 
243 240
     /** {@inheritDoc} */
244 241
     @Override
245 242
     public void save() {
246
-        for (Object pit : ((DefaultListModel) pluginList.getModel())
247
-                .toArray()) {
248
-            ((PluginInfoToggle) pit).apply();
243
+        if (addonList.getRowCount() == 0) {
244
+            return;
249 245
         }
250
-    }
251
-
252
-    /** {@inheritDoc} */
253
-    @Override
254
-    public void processEvent(final ActionType type, final StringBuffer format,
255
-            final Object... arguments) {
256
-        if (pluginRefresh) {
257
-            populateList();
246
+        for (int i = 1; i < addonList.getRowCount(); i++) {
247
+            addonList.getModel().getColumnCount();
248
+            ((AddonToggle) ((AddonCell) addonList.getModel()
249
+                    .getValueAt(i, 0)).getObject()).apply();
258 250
         }
259 251
     }
260 252
 }

src/com/dmdirc/addons/ui_swing/components/pluginpanel/PluginInfoToggle.java → src/com/dmdirc/addons/ui_swing/components/addonpanel/AddonToggle.java 파일 보기

@@ -19,74 +19,115 @@
19 19
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 20
  * SOFTWARE.
21 21
  */
22
-package com.dmdirc.addons.ui_swing.components.pluginpanel;
22
+package com.dmdirc.addons.ui_swing.components.addonpanel;
23 23
 
24 24
 import com.dmdirc.plugins.PluginInfo;
25 25
 import com.dmdirc.plugins.PluginManager;
26
+import com.dmdirc.ui.themes.Theme;
27
+import com.dmdirc.ui.themes.ThemeManager;
26 28
 
27 29
 /**
28
- * Wraps a PluginInfo object with a boolean to indicate whether it should be
29
- * toggled or not.
30
- * 
31
- * @author chris
30
+ * Wraps a Addon object (Theme or Plugin) with a boolean to indicate whether
31
+ * it should be toggled or not.
32 32
  */
33
-public class PluginInfoToggle {
34
-    
33
+public class AddonToggle {
34
+
35 35
     /** The PluginInfo object we're wrapping. */
36 36
     private final PluginInfo pi;
37
-    
37
+    /** The Theme object we're wrapping. */
38
+    private final Theme theme;
38 39
     /** Whether or not to toggle it. */
39
-    private boolean toggle = false;
40
+    private boolean toggled = false;
40 41
 
41 42
     /**
42
-     * Creates a new instance of PluginInfoToggle to wrap the specified
43
-     * PluginInfo.
44
-     * 
45
-     * @param pi The PluginInfo to be wrapped
43
+     * Creates a new instance of AddonToggle to wrap the specified
44
+     * PluginInfo or Theme.
45
+     *
46
+     * @param pi The PluginInfo to be wrapped can be null
47
+     * @param theme The Theme to be wrapped can be null
46 48
      */
47
-    public PluginInfoToggle(final PluginInfo pi) {
49
+    public AddonToggle(final PluginInfo pi, final Theme theme) {
50
+        if ((pi == null) == (theme == null)) {
51
+            throw new IllegalArgumentException("You must wrap a plugin or "
52
+                    + "a theme.");
53
+        }
48 54
         this.pi = pi;
55
+        this.theme = theme;
49 56
     }
50
-    
57
+
51 58
     /**
52 59
      * Toggles this PluginInfoToggle.
53 60
      */
54 61
     public void toggle() {
55
-        toggle = !toggle;
62
+        toggled ^= true;
56 63
     }
57
-    
64
+
58 65
     /**
59 66
      * Gets the state of this PluginInfo, taking into account the state
60 67
      * of the toggle setting.
61
-     * 
68
+     *
62 69
      * @return True if the plugin is or should be loaded, false otherwise.
63 70
      */
64 71
     public boolean getState() {
65
-        return toggle ^ pi.isLoaded();
72
+        if (pi != null) {
73
+            return toggled ^ pi.isLoaded();
74
+        }
75
+        if (theme != null) {
76
+            return toggled ^ theme.isEnabled();
77
+        }
78
+        return false;
66 79
     }
67 80
 
68 81
     /**
69 82
      * Retrieves the PluginInfo object associated with this toggle.
70
-     * 
83
+     *
71 84
      * @return This toggle's PluginInfo object.
72 85
      */
73 86
     public PluginInfo getPluginInfo() {
74 87
         return pi;
75 88
     }
76
-    
89
+
90
+    /**
91
+     * Retrieves the Theme object associated with this toggle.
92
+     *
93
+     * @return This toggle's Theme object.
94
+     */
95
+    public Theme getTheme() {
96
+        return theme;
97
+    }
98
+
77 99
     /**
78 100
      * Applies the changes to the PluginInfo, if any.
79 101
      */
80 102
     public void apply() {
81
-        if (toggle) {
103
+        if (pi != null && toggled) {
82 104
             if (pi.isLoaded()) {
83 105
                 pi.unloadPlugin();
84 106
             } else {
85 107
                 pi.loadPlugin();
86 108
             }
87
-            
88 109
             PluginManager.getPluginManager().updateAutoLoad(pi);
89 110
         }
111
+        if (theme != null && toggled) {
112
+            if (theme.isEnabled()) {
113
+                theme.applyTheme();
114
+            } else {
115
+                theme.removeTheme();
116
+            }
117
+            ThemeManager.updateAutoLoad(theme);
118
+        }
119
+    }
120
+
121
+    /**
122
+     * Is this addon unloadable?
123
+     *
124
+     * @return true iff unloadable
125
+     */
126
+    public boolean isUnloadable() {
127
+        if (pi != null) {
128
+            return pi.isUnloadable();
129
+        }
130
+        return true;
90 131
     }
91 132
 
92 133
 }

+ 109
- 0
src/com/dmdirc/addons/ui_swing/components/addonpanel/PluginPanel.java 파일 보기

@@ -0,0 +1,109 @@
1
+/*
2
+ * Copyright (c) 2006-2011 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.actions.ActionManager;
26
+import com.dmdirc.actions.CoreActionType;
27
+import com.dmdirc.actions.interfaces.ActionType;
28
+import com.dmdirc.addons.ui_swing.SwingController;
29
+import com.dmdirc.addons.ui_swing.UIUtilities;
30
+import com.dmdirc.interfaces.ActionListener;
31
+import com.dmdirc.plugins.PluginInfo;
32
+import com.dmdirc.plugins.PluginManager;
33
+
34
+import java.awt.Window;
35
+import java.util.Collections;
36
+import java.util.List;
37
+
38
+import javax.swing.JTable;
39
+import javax.swing.table.DefaultTableModel;
40
+
41
+/**
42
+ * Lists known plugins, enabling the end user to enable/disable these as well
43
+ * as download new ones.
44
+ */
45
+public class PluginPanel extends AddonPanel implements ActionListener {
46
+
47
+    /** Do we refresh on plugin reload? */
48
+    private boolean pluginRefresh = true;
49
+
50
+    /**
51
+     * Creates a new instance of PluginPanel.
52
+     *
53
+     * @param parentWindow Parent window
54
+     * @param controller Swing Controller
55
+     */
56
+    public PluginPanel(final Window parentWindow,
57
+            final SwingController controller) {
58
+        super(parentWindow, controller);
59
+
60
+        ActionManager.addListener(this, CoreActionType.PLUGIN_REFRESH);
61
+    }
62
+
63
+    /** {@inheritDoc} */
64
+    @Override
65
+    protected JTable populateList(final JTable table) {
66
+        pluginRefresh = false;
67
+        final List<PluginInfo> list =
68
+                PluginManager.getPluginManager().getPossiblePluginInfos(true);
69
+        pluginRefresh = true;
70
+        Collections.sort(list);
71
+
72
+        UIUtilities.invokeLater(new Runnable() {
73
+
74
+            /** {@inheritDoc} */
75
+            @Override
76
+            public void run() {
77
+                ((DefaultTableModel) table.getModel()).setNumRows(0);
78
+                for (PluginInfo plugin : list) {
79
+                    ((DefaultTableModel) table.getModel()).addRow(
80
+                            new AddonCell[]{
81
+                        new AddonCell(new AddonToggle(plugin, null)), });
82
+                }
83
+
84
+                if (((DefaultTableModel) table.getModel()).getRowCount()
85
+                        > 0) {
86
+                    toggleButton.setEnabled(true);
87
+                }
88
+
89
+                table.repaint();
90
+            }
91
+        });
92
+        return table;
93
+    }
94
+
95
+    /** {@inheritDoc} */
96
+    @Override
97
+    public void processEvent(final ActionType type, final StringBuffer format,
98
+            final Object... arguments) {
99
+        if (pluginRefresh) {
100
+            populateList(addonList);
101
+        }
102
+    }
103
+
104
+    /** {@inheritDoc} */
105
+    @Override
106
+    protected String getTypeName() {
107
+        return "plugins";
108
+    }
109
+}

+ 91
- 0
src/com/dmdirc/addons/ui_swing/components/addonpanel/ThemePanel.java 파일 보기

@@ -0,0 +1,91 @@
1
+/*
2
+ * Copyright (c) 2006-2011 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.SwingController;
26
+import com.dmdirc.addons.ui_swing.UIUtilities;
27
+import com.dmdirc.ui.themes.Theme;
28
+import com.dmdirc.ui.themes.ThemeManager;
29
+
30
+import java.awt.Window;
31
+import java.util.ArrayList;
32
+import java.util.Collections;
33
+import java.util.List;
34
+
35
+import javax.swing.JTable;
36
+import javax.swing.table.DefaultTableModel;
37
+
38
+/**
39
+ * Lists known themes, enabling the end user to enable/disable these as well
40
+ * as download new ones.
41
+ */
42
+public class ThemePanel extends AddonPanel {
43
+
44
+    /**
45
+     * Creates a new instance of ThemePanel.
46
+     *
47
+     * @param parentWindow Parent window
48
+     * @param controller Swing Controller
49
+     */
50
+    public ThemePanel(final Window parentWindow,
51
+            final SwingController controller) {
52
+        super(parentWindow, controller);
53
+    }
54
+
55
+    /** {@inheritDoc} */
56
+    @Override
57
+    protected JTable populateList(final JTable table) {
58
+        final List<Theme> list = new ArrayList<Theme>(ThemeManager.
59
+                getAvailableThemes().values());
60
+        Collections.sort(list);
61
+
62
+        UIUtilities.invokeLater(new Runnable() {
63
+
64
+            /** {@inheritDoc} */
65
+            @Override
66
+            public void run() {
67
+                ((DefaultTableModel) addonList.getModel()).setRowCount(0);
68
+                for (Theme theme : list) {
69
+                    ((DefaultTableModel) addonList.getModel()).addRow(
70
+                            new AddonCell[]{
71
+                        new AddonCell(new AddonToggle(null, theme)), });
72
+                }
73
+
74
+                if (((DefaultTableModel) addonList.getModel()).getRowCount()
75
+                        > 0) {
76
+                    toggleButton.setEnabled(true);
77
+                }
78
+
79
+                addonList.repaint();
80
+            }
81
+        });
82
+        return addonList;
83
+    }
84
+
85
+    /** {@inheritDoc} */
86
+    @Override
87
+    protected String getTypeName() {
88
+        return "themes";
89
+    }
90
+
91
+}

+ 31
- 64
src/com/dmdirc/addons/ui_swing/components/renderers/AddonCellRenderer.java 파일 보기

@@ -22,28 +22,19 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing.components.renderers;
24 24
 
25
-import com.dmdirc.addons.ui_swing.components.pluginpanel.PluginInfoToggle;
26
-import com.dmdirc.addons.ui_swing.components.themepanel.ThemeToggle;
25
+import com.dmdirc.addons.ui_swing.components.addonpanel.AddonCell;
27 26
 
28 27
 import java.awt.Color;
29 28
 import java.awt.Component;
30
-import java.awt.Font;
31 29
 
32
-import javax.swing.BorderFactory;
33 30
 import javax.swing.JLabel;
34
-import javax.swing.JList;
35
-import javax.swing.JPanel;
36
-import javax.swing.JSeparator;
37
-import javax.swing.ListCellRenderer;
38
-
39
-import net.miginfocom.layout.PlatformDefaults;
40
-import net.miginfocom.swing.MigLayout;
31
+import javax.swing.JTable;
32
+import javax.swing.table.TableCellRenderer;
41 33
 
42 34
 /**
43
- * Handles the rendering of the JList used for plugin and theme management.
44
- * @author chris
35
+ * Handles the rendering of the JTable used for plugin and theme management.
45 36
  */
46
-public class AddonCellRenderer extends JPanel implements ListCellRenderer {
37
+public class AddonCellRenderer implements TableCellRenderer {
47 38
 
48 39
     /**
49 40
      * A version number for this class. It should be changed whenever the class
@@ -54,61 +45,37 @@ public class AddonCellRenderer extends JPanel implements ListCellRenderer {
54 45
 
55 46
     /** {@inheritDoc} */
56 47
     @Override
57
-    public Component getListCellRendererComponent(final JList list,
58
-            final Object value, final int index, final boolean isSelected,
59
-            final boolean cellHasFocus) {
60
-
61
-        removeAll();
62
-        setLayout(new MigLayout("fill, ins 3 0 0 0"));
63
-
64
-        if (isSelected) {
65
-            setBackground(list.getSelectionBackground());
66
-        } else {
67
-            setBackground(list.getBackground());
68
-        }
69
-        final JLabel name = new JLabel(), version = new JLabel(),
70
-                author = new JLabel(), desc = new JLabel();
71
-
72
-        Color foreground = Color.BLACK;
73
-        if (value instanceof PluginInfoToggle) {
74
-            final PluginInfoToggle plugin = (PluginInfoToggle) value;
75
-
76
-            if (!plugin.getState()) {
77
-                foreground = Color.GRAY;
48
+    public Component getTableCellRendererComponent(final JTable table,
49
+            final Object value, final boolean isSelected,
50
+            final boolean hasFocus, final int row, final int column) {
51
+        if (value instanceof AddonCell) {
52
+            final AddonCell label = (AddonCell) value;
53
+
54
+            if (isSelected) {
55
+                label.setBackground(table.getSelectionBackground());
56
+            } else {
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
+                }
78 63
             }
79 64
 
80
-            name.setText(plugin.getPluginInfo().getNiceName());
81
-            version.setText(plugin.getPluginInfo().getFriendlyVersion());
82
-            author.setText(plugin.getPluginInfo().getAuthor());
83
-            desc.setText(plugin.getPluginInfo().getDescription());
84
-        } else if (value instanceof ThemeToggle) {
85
-            final ThemeToggle theme = (ThemeToggle) value;
65
+            final int height = label.getPreferredSize().height;
66
+            if (table.getRowHeight(row) != height) {
67
+                table.setRowHeight(row, height);
68
+            }
86 69
 
87
-            if (!theme.getState()) {
88
-                foreground = Color.GRAY;
70
+            if (label.isToggled()) {
71
+                label.setForeground(Color.BLACK);
72
+            } else {
73
+                label.setForeground(Color.GRAY);
89 74
             }
90 75
 
91
-            name.setText(theme.getTheme().getName());
92
-            version.setText(theme.getTheme().getVersion());
93
-            author.setText(theme.getTheme().getAuthor());
94
-            desc.setText(theme.getTheme().getDescription());
76
+            return label;
77
+        } else {
78
+            return new JLabel(value.toString());
95 79
         }
96
-
97
-        name.setForeground(foreground);
98
-        name.setFont(name.getFont().deriveFont(Font.BOLD));
99
-        version.setForeground(foreground);
100
-        version.setHorizontalAlignment(JLabel.CENTER);
101
-        author.setForeground(foreground);
102
-        desc.setForeground(foreground);
103
-        desc.setBorder(BorderFactory.createEmptyBorder((int) PlatformDefaults.
104
-                getPanelInsets(0).getValue(), 0, 0, 0));
105
-
106
-        add(name, "gapleft 3");
107
-        add(version, "pushx");
108
-        add(author, "wrap, gapright 3");
109
-        add(desc, "span 3, growx, pushx, wrap, gapleft 3, gapright 3");
110
-        add(new JSeparator(), "span 3, growx, pushx");
111
-
112
-        return this;
113 80
     }
114 81
 }

+ 16
- 4
src/com/dmdirc/addons/ui_swing/components/text/TextLabel.java 파일 보기

@@ -48,7 +48,7 @@ public class TextLabel extends JTextPane {
48 48
      */
49 49
     private static final long serialVersionUID = 1;
50 50
     /** Simple attribute set. */
51
-    private SimpleAttributeSet sas;
51
+    private final SimpleAttributeSet sas = new SimpleAttributeSet();
52 52
 
53 53
     /**
54 54
      * Creates a new instance of TextLabel.
@@ -92,7 +92,6 @@ public class TextLabel extends JTextPane {
92 92
         setHighlighter(null);
93 93
         setMargin(new Insets(0, 0, 0, 0));
94 94
 
95
-        sas = new SimpleAttributeSet();
96 95
         if (justified) {
97 96
             StyleConstants.setAlignment(sas, StyleConstants.ALIGN_JUSTIFIED);
98 97
         }
@@ -102,16 +101,29 @@ public class TextLabel extends JTextPane {
102 101
 
103 102
     /** {@inheritDoc} */
104 103
     @Override
105
-    public StyledDocument getDocument() {
104
+    public final StyledDocument getDocument() {
106 105
         return (StyledDocument) super.getDocument();
107 106
     }
108 107
 
109 108
     /** {@inheritDoc} */
110 109
     @Override
111
-    public void setText(final String t) {
110
+    public final void setText(final String t) {
112 111
         super.setText(t);
113 112
         if (t != null && !t.isEmpty()) {
114 113
             getDocument().setParagraphAttributes(0, t.length(), sas, false);
115 114
         }
116 115
     }
116
+
117
+    /** {@inheritDoc} */
118
+    @Override
119
+    public void setForeground(final Color colour) {
120
+        if (sas == null) {
121
+            return;
122
+        }
123
+        if (colour != null) {
124
+            StyleConstants.setForeground(sas, colour);
125
+            getDocument().setParagraphAttributes(0, getDocument().getLength(),
126
+                    sas, false);
127
+        }
128
+    }
117 129
 }

+ 0
- 240
src/com/dmdirc/addons/ui_swing/components/themepanel/ThemePanel.java 파일 보기

@@ -1,240 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2011 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.themepanel;
24
-
25
-import com.dmdirc.addons.ui_swing.UIUtilities;
26
-import com.dmdirc.addons.ui_swing.components.LoggingSwingWorker;
27
-import com.dmdirc.addons.ui_swing.components.renderers.AddonCellRenderer;
28
-import com.dmdirc.addons.ui_swing.components.text.TextLabel;
29
-import com.dmdirc.config.IdentityManager;
30
-import com.dmdirc.config.prefs.PreferencesInterface;
31
-import com.dmdirc.ui.core.util.URLHandler;
32
-import com.dmdirc.ui.themes.Theme;
33
-import com.dmdirc.ui.themes.ThemeManager;
34
-
35
-import java.awt.event.ActionEvent;
36
-import java.awt.event.ActionListener;
37
-import java.util.ArrayList;
38
-import java.util.Collections;
39
-import java.util.List;
40
-
41
-import javax.swing.DefaultListModel;
42
-import javax.swing.JButton;
43
-import javax.swing.JLabel;
44
-import javax.swing.JList;
45
-import javax.swing.JPanel;
46
-import javax.swing.JScrollPane;
47
-import javax.swing.event.ListSelectionEvent;
48
-import javax.swing.event.ListSelectionListener;
49
-
50
-import net.miginfocom.swing.MigLayout;
51
-
52
-/**
53
- * Theme panel. Shows users available themes and allows them to enable/disbale
54
- * them.
55
- */
56
-public final class ThemePanel extends JPanel implements
57
-        ActionListener, ListSelectionListener, PreferencesInterface {
58
-
59
-    /**
60
-     * A version number for this class. It should be changed whenever the class
61
-     * structure is changed (or anything else that would prevent serialized
62
-     * objects being unserialized with the new class).
63
-     */
64
-    private static final long serialVersionUID = 3;
65
-    /** List of themes. */
66
-    private JList themeList;
67
-    /** plugin list scroll pane. */
68
-    private JScrollPane scrollPane;
69
-    /** Button to enable/disable theme. */
70
-    private JButton toggleButton;
71
-    /** Currently selected theme. */
72
-    private int selectedTheme;
73
-    /** Blurb label. */
74
-    private TextLabel blurbLabel;
75
-    /** The URL handler to use to open links. */
76
-    private final URLHandler urlHandler;
77
-
78
-    /**
79
-     * Creates a new instance of ThemePanel.
80
-     *
81
-     * @param urlHandler A {@link URLHandler} to use to open links
82
-     */
83
-    public ThemePanel(final URLHandler urlHandler) {
84
-        super();
85
-
86
-        this.urlHandler = urlHandler;
87
-
88
-        initComponents();
89
-        addListeners();
90
-        layoutComponents();
91
-
92
-        themeList.setSelectedIndex(0);
93
-        selectedTheme = 0;
94
-    }
95
-
96
-    /** Initialises the components. */
97
-    private void initComponents() {
98
-        themeList = new JList(new DefaultListModel());
99
-        themeList.setCellRenderer(new AddonCellRenderer());
100
-
101
-        scrollPane = new JScrollPane(new JLabel("Loading plugins..."));
102
-        scrollPane.setHorizontalScrollBarPolicy(
103
-                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
104
-        scrollPane.setVerticalScrollBarPolicy(
105
-                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
106
-
107
-        toggleButton = new JButton("Enable");
108
-        toggleButton.setEnabled(false);
109
-
110
-        blurbLabel = new TextLabel("Themes alter the appearance of DMDirc");
111
-
112
-        /** {@inheritDoc}. */
113
-        new LoggingSwingWorker() {
114
-
115
-            /** {@inheritDoc}. */
116
-            @Override
117
-            protected Object doInBackground() {
118
-                return populateList();
119
-            }
120
-
121
-            /** {@inheritDoc}. */
122
-            @Override
123
-            protected void done() {
124
-                super.done();
125
-                scrollPane.setViewportView(themeList);
126
-            }
127
-        }.executeInExecutor();
128
-    }
129
-
130
-    /** Lays out the dialog. */
131
-    private void layoutComponents() {
132
-        setLayout(new MigLayout("ins 0, fill"));
133
-
134
-        add(blurbLabel, "wrap 10, growx, pushx");
135
-
136
-        add(scrollPane, "wrap 5, grow, push");
137
-
138
-        add(toggleButton, "split 2, growx, pushx, sg button");
139
-
140
-        final JButton button = new JButton("Get more themes");
141
-        button.addActionListener(this);
142
-        add(button, "growx, pushx, sg button");
143
-    }
144
-
145
-    /**
146
-     * Populates the plugins list with plugins from the plugin manager.
147
-     *
148
-     * @return Populated list
149
-     */
150
-    private JList populateList() {
151
-        final List<Theme> list = new ArrayList<Theme>(ThemeManager.
152
-                getAvailableThemes().values());
153
-        Collections.sort(list);
154
-
155
-        UIUtilities.invokeLater(new Runnable() {
156
-
157
-            /** {@inheritDoc} */
158
-            @Override
159
-            public void run() {
160
-                ((DefaultListModel) themeList.getModel()).clear();
161
-                for (Theme plugin : list) {
162
-                    ((DefaultListModel) themeList.getModel()).addElement(
163
-                            new ThemeToggle(plugin));
164
-                }
165
-
166
-                if (((DefaultListModel) themeList.getModel()).size() > 0) {
167
-                    toggleButton.setEnabled(true);
168
-                }
169
-
170
-                themeList.repaint();
171
-            }
172
-        });
173
-        return themeList;
174
-    }
175
-
176
-    /** Adds listeners to components. */
177
-    private void addListeners() {
178
-        toggleButton.addActionListener(this);
179
-        themeList.addListSelectionListener(this);
180
-    }
181
-
182
-    /**
183
-     * Invoked when an action occurs.
184
-     *
185
-     * @param e The event related to this action.
186
-     */
187
-    @Override
188
-    public void actionPerformed(final ActionEvent e) {
189
-        if (e.getSource() == toggleButton && selectedTheme >= 0) {
190
-            final ThemeToggle theme = (ThemeToggle) themeList.getSelectedValue();
191
-
192
-            theme.toggle();
193
-
194
-            if (theme.getState()) {
195
-                toggleButton.setText("Disable");
196
-            } else {
197
-                toggleButton.setText("Enable");
198
-            }
199
-
200
-            themeList.repaint();
201
-        } else if (e.getSource() != toggleButton) {
202
-            urlHandler.launchApp("http://addons.dmdirc.com/");
203
-        }
204
-    }
205
-
206
-    /** {@inheritDoc}. */
207
-    @Override
208
-    public void valueChanged(final ListSelectionEvent e) {
209
-        if (!e.getValueIsAdjusting()) {
210
-            final int selected = ((JList) e.getSource()).getSelectedIndex();
211
-            if (selected >= 0) {
212
-                final ThemeToggle theme = (ThemeToggle) ((JList) e.getSource()).
213
-                        getSelectedValue();
214
-                toggleButton.setEnabled(true);
215
-
216
-                if (theme.getState()) {
217
-                    toggleButton.setText("Disable");
218
-                } else {
219
-                    toggleButton.setText("Enable");
220
-                }
221
-            }
222
-            selectedTheme = selected;
223
-        }
224
-    }
225
-
226
-    /** {@inheritDoc} */
227
-    @Override
228
-    public void save() {
229
-        final List<String> enabled = new ArrayList<String>();
230
-
231
-        for (Object pit : ((DefaultListModel) themeList.getModel()).toArray()) {
232
-            if (((ThemeToggle) pit).getState()) {
233
-                enabled.add(((ThemeToggle) pit).getTheme().getFileName());
234
-            }
235
-        }
236
-
237
-        IdentityManager.getConfigIdentity().setOption("themes", "enabled",
238
-                enabled);
239
-    }
240
-}

+ 0
- 76
src/com/dmdirc/addons/ui_swing/components/themepanel/ThemeToggle.java 파일 보기

@@ -1,76 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2011 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
-package com.dmdirc.addons.ui_swing.components.themepanel;
23
-
24
-import com.dmdirc.ui.themes.Theme;
25
-
26
-/**
27
- * Wraps a Theme object with a boolean to indicate whether it should be
28
- * enabled or not.
29
- * 
30
- * @author chris
31
- */
32
-public class ThemeToggle {
33
-    
34
-    /** The Theme object we're wrapping. */
35
-    private final Theme theme;
36
-    
37
-    /** Whether or not to enable it. */
38
-    private boolean enable;
39
-
40
-    /**
41
-     * Creates a new instance of ThemeToggle to wrap the specified
42
-     * Theme.
43
-     * 
44
-     * @param theme The theme to be wrapped
45
-     */
46
-    public ThemeToggle(final Theme theme) {
47
-        this.theme = theme;
48
-        enable = theme.isEnabled();
49
-    }
50
-    
51
-    /**
52
-     * Toggles this theme.
53
-     */
54
-    public void toggle() {
55
-        enable = !enable;
56
-    }
57
-    
58
-    /**
59
-     * Gets the state of this ThemeToggle.
60
-     * 
61
-     * @return True if the theme is or should be loaded, false otherwise.
62
-     */
63
-    public boolean getState() {
64
-        return enable;
65
-    }
66
-
67
-    /**
68
-     * Retrieves the Theme object associated with this toggle.
69
-     * 
70
-     * @return This toggle's theme object.
71
-     */
72
-    public Theme getTheme() {
73
-        return theme;
74
-    }
75
-
76
-}

Loading…
취소
저장