Sfoglia il codice sorgente

Add generics to some models.

pull/111/head
Greg Holmes 9 anni fa
parent
commit
c5d5dff1a0

+ 3
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/ComboBoxWidthModifier.java Vedi File

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.addons.ui_swing;
24 24
 
25
+import java.awt.Container;
25 26
 import java.awt.Dimension;
26 27
 
27 28
 import javax.swing.JComboBox;
@@ -37,12 +38,12 @@ public class ComboBoxWidthModifier implements PopupMenuListener {
37 38
 
38 39
     @Override
39 40
     public void popupMenuWillBecomeVisible(final PopupMenuEvent e) {
40
-        final JComboBox<?> box = (JComboBox) e.getSource();
41
+        final JComboBox<?> box = (JComboBox<?>) e.getSource();
41 42
         final Object comp = box.getUI().getAccessibleChild(box, 0);
42 43
         if (!(comp instanceof JPopupMenu)) {
43 44
             return;
44 45
         }
45
-        final JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
46
+        final JComponent scrollPane = (JComponent) ((Container) comp).getComponent(0);
46 47
         final Dimension size = new Dimension(box.getPreferredSize().width,
47 48
                 scrollPane.getPreferredSize().height);
48 49
         scrollPane.setPreferredSize(size);

+ 4
- 4
ui_swing/src/com/dmdirc/addons/ui_swing/components/expandingsettings/AddOptionPanel.java Vedi File

@@ -35,6 +35,7 @@ import javax.swing.JComboBox;
35 35
 import javax.swing.JComponent;
36 36
 import javax.swing.JLabel;
37 37
 import javax.swing.JPanel;
38
+import javax.swing.MutableComboBoxModel;
38 39
 
39 40
 import net.miginfocom.swing.MigLayout;
40 41
 
@@ -115,7 +116,7 @@ public class AddOptionPanel extends JPanel implements ActionListener {
115 116
      * @param setting Setting to add
116 117
      */
117 118
     protected void addOption(final JComponent setting) {
118
-        ((DefaultComboBoxModel<Object>) addOptionComboBox.getModel()).addElement(setting);
119
+        ((MutableComboBoxModel<Object>) addOptionComboBox.getModel()).addElement(setting);
119 120
         addOptionButton.setEnabled(true);
120 121
         addOptionComboBox.setEnabled(true);
121 122
     }
@@ -126,8 +127,7 @@ public class AddOptionPanel extends JPanel implements ActionListener {
126 127
      * @param setting Setting to add
127 128
      */
128 129
     protected void delOption(final JComponent setting) {
129
-        ((DefaultComboBoxModel) addOptionComboBox.getModel())
130
-                .removeElement(setting);
130
+        ((MutableComboBoxModel<Object>) addOptionComboBox.getModel()).removeElement(setting);
131 131
         if (addOptionComboBox.getModel().getSize() == 0) {
132 132
             addOptionComboBox.setEnabled(false);
133 133
             addOptionButton.setEnabled(false);
@@ -165,7 +165,7 @@ public class AddOptionPanel extends JPanel implements ActionListener {
165 165
                 addOptionComboBox.setEnabled(false);
166 166
                 addOptionButton.setEnabled(false);
167 167
             }
168
-            switchInputField(((JComponent) addOptionComboBox.getSelectedItem()));
168
+            switchInputField((JComponent) addOptionComboBox.getSelectedItem());
169 169
         } else if (e.getSource() == addOptionButton) {
170 170
             parent.addCurrentOption((JComponent) addOptionComboBox.getSelectedItem());
171 171
             delOption((JComponent) addOptionComboBox.getSelectedItem());

+ 1
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actioneditor/ActionTriggersPanel.java Vedi File

@@ -262,7 +262,7 @@ public class ActionTriggersPanel extends JPanel implements ActionListener,
262 262
      */
263 263
     private void addList(final List<ActionType> list) {
264 264
         comboChange = true;
265
-        ((DefaultComboBoxModel) triggerItem.getModel()).removeAllElements();
265
+        ((DefaultComboBoxModel<Object>) triggerItem.getModel()).removeAllElements();
266 266
         Collections.sort(list, new ActionTypeComparator());
267 267
         for (final ActionType entry : list) {
268 268
             if (compatibleTriggers.isEmpty()

+ 2
- 2
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java Vedi File

@@ -256,7 +256,7 @@ public class ActionsManagerDialog extends StandardDialog implements
256 256
      * @param selectedGroup Newly selected group
257 257
      */
258 258
     private void reloadGroups(final ActionGroup selectedGroup) {
259
-        ((DefaultListModel) groups.getModel()).clear();
259
+        ((DefaultListModel<ActionGroup>) groups.getModel()).clear();
260 260
         for (ActionGroup group : ActionManager.getActionManager().getGroupsMap().values()) {
261 261
             ((DefaultListModel<ActionGroup>) groups.getModel()).addElement(group);
262 262
         }
@@ -374,7 +374,7 @@ public class ActionsManagerDialog extends StandardDialog implements
374 374
         new StandardQuestionDialog(this, ModalityType.APPLICATION_MODAL, "Confirm deletion",
375 375
                 "Are you sure you wish to delete the '" + group +
376 376
                         "' group and all actions within it?", () -> {
377
-            int location = ((DefaultListModel) groups.getModel())
377
+            int location = ((DefaultListModel<ActionGroup>) groups.getModel())
378 378
                     .indexOf(ActionManager.getActionManager().getOrCreateGroup(group));
379 379
             ActionManager.getActionManager().deleteGroup(group);
380 380
             reloadGroups();

+ 6
- 5
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/channelsetting/ChannelListModesPane.java Vedi File

@@ -56,6 +56,7 @@ import javax.swing.JList;
56 56
 import javax.swing.JPanel;
57 57
 import javax.swing.JScrollPane;
58 58
 import javax.swing.ListCellRenderer;
59
+import javax.swing.MutableComboBoxModel;
59 60
 import javax.swing.event.ListSelectionEvent;
60 61
 import javax.swing.event.ListSelectionListener;
61 62
 
@@ -188,7 +189,7 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
188 189
             addListModeButton.setEnabled(true);
189 190
         }
190 191
 
191
-        final DefaultComboBoxModel<String> model = (DefaultComboBoxModel<String>) listModesMenu.
192
+        final MutableComboBoxModel<String> model = (MutableComboBoxModel<String>) listModesMenu.
192 193
                 getModel();
193 194
         for (char mode : listModesArray) {
194 195
             String modeText = mode + " list";
@@ -249,8 +250,8 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
249 250
         for (int i = 0; i < listModesArray.length;
250 251
                 i++) {
251 252
             final char mode = listModesArray[i];
252
-            final Enumeration<?> values = ((DefaultListModel) listModesPanels.get(i).getModel()).
253
-                    elements();
253
+            final Enumeration<?> values = ((DefaultListModel<ChannelListModeItem>) listModesPanels
254
+                    .get(i).getModel()).elements();
254 255
             final List<ChannelListModeItem> listItems = existingListItems.get(mode);
255 256
 
256 257
             for (ChannelListModeItem listItem : listItems) {
@@ -306,7 +307,7 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
306 307
         final int selectedIndex = listModesMenu.getSelectedIndex();
307 308
         final JList<ChannelListModeItem> removeList = listModesPanels.get(selectedIndex);
308 309
         for (ChannelListModeItem mode : removeList.getSelectedValuesList()) {
309
-            ((DefaultListModel) removeList.getModel()).removeElement(mode);
310
+            ((DefaultListModel<ChannelListModeItem>) removeList.getModel()).removeElement(mode);
310 311
         }
311 312
         updateModeCount();
312 313
     }
@@ -338,7 +339,7 @@ public final class ChannelListModesPane extends JPanel implements ActionListener
338 339
     @Override
339 340
     public void valueChanged(final ListSelectionEvent event) {
340 341
         if (!event.getValueIsAdjusting()) {
341
-            final int selected = ((JList) event.getSource()).getSelectedIndex();
342
+            final int selected = ((JList<?>) event.getSource()).getSelectedIndex();
342 343
             if (selected == -1) {
343 344
                 removeListModeButton.setEnabled(false);
344 345
             } else {

+ 7
- 11
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/prefs/SwingPreferencesDialog.java Vedi File

@@ -41,8 +41,6 @@ import com.dmdirc.ui.IconManager;
41 41
 import java.awt.Window;
42 42
 import java.awt.event.ActionEvent;
43 43
 import java.awt.event.ActionListener;
44
-import java.util.Collection;
45
-import java.util.List;
46 44
 import java.util.concurrent.ExecutionException;
47 45
 
48 46
 import javax.inject.Inject;
@@ -53,6 +51,7 @@ import javax.swing.JButton;
53 51
 import javax.swing.JList;
54 52
 import javax.swing.JScrollPane;
55 53
 import javax.swing.ListSelectionModel;
54
+import javax.swing.ScrollPaneConstants;
56 55
 import javax.swing.WindowConstants;
57 56
 import javax.swing.event.ListSelectionEvent;
58 57
 import javax.swing.event.ListSelectionListener;
@@ -151,7 +150,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
151 150
     private void setPrefsManager(final PreferencesDialogModel manager) {
152 151
         this.manager = manager;
153 152
 
154
-        ((DefaultListModel) tabList.getModel()).clear();
153
+        ((DefaultListModel<PreferencesCategory>) tabList.getModel()).clear();
155 154
         mainPanel.setCategory(null);
156 155
 
157 156
         final int count = countCategories(manager.getCategories());
@@ -172,7 +171,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
172 171
         ListScroller.register(tabList);
173 172
         final JScrollPane tabListScrollPane = new JScrollPane(tabList);
174 173
         tabListScrollPane.setHorizontalScrollBarPolicy(
175
-                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
174
+                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
176 175
 
177 176
         setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
178 177
         setTitle("Preferences");
@@ -185,9 +184,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
185 184
         getOkButton().addActionListener(this);
186 185
         getCancelButton().addActionListener(this);
187 186
 
188
-        final MigLayout layout
189
-                = new MigLayout("pack, hmin min(80sp, 700), " + "hmax min(700, 80sp)");
190
-        setLayout(layout);
187
+        setLayout(new MigLayout("pack, hmin min(80sp, 700), " + "hmax min(700, 80sp)"));
191 188
         add(tabListScrollPane, "w 150!, growy, pushy");
192 189
         add(mainPanel, "wrap, w 480!, pushy, growy, pushy");
193 190
         add(getLeftButton(), "span, split, right");
@@ -197,7 +194,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
197 194
     /**
198 195
      * Adds the categories from the preferences manager, clearing existing categories first.
199 196
      */
200
-    private void addCategories(final List<PreferencesCategory> categories) {
197
+    private void addCategories(final Iterable<PreferencesCategory> categories) {
201 198
         UIUtilities.invokeLater(() -> {
202 199
             tabList.removeListSelectionListener(this);
203 200
             for (PreferencesCategory category : categories) {
@@ -222,8 +219,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
222 219
      *
223 220
      * @since 0.6.3m1rc3
224 221
      */
225
-    protected int countCategories(
226
-            final Collection<PreferencesCategory> categories) {
222
+    private int countCategories(final Iterable<PreferencesCategory> categories) {
227 223
         int count = 0;
228 224
 
229 225
         for (PreferencesCategory cat : categories) {
@@ -297,7 +293,7 @@ public final class SwingPreferencesDialog extends StandardDialog implements
297 293
 
298 294
     @Override
299 295
     public void dispose() {
300
-        synchronized (SwingPreferencesDialog.this) {
296
+        synchronized (this) {
301 297
             if (!worker.isDone()) {
302 298
                 worker.cancel(true);
303 299
             }

+ 1
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/profiles/ProfileManagerDialogLinker.java Vedi File

@@ -81,7 +81,7 @@ public class ProfileManagerDialogLinker {
81 81
         });
82 82
         listModel.addListSelectionListener(e -> model.setSelectedProfile(list.getSelectedValue()));
83 83
         model.addPropertyChangeListener("profiles", evt -> {
84
-            ((DefaultListModel) list.getModel()).clear();
84
+            ((DefaultListModel<Profile>) list.getModel()).clear();
85 85
             for (Profile profile : model.getProfiles()) {
86 86
                 ((DefaultListModel<Profile>) list.getModel()).addElement(profile);
87 87
             }

+ 1
- 1
ui_swing/src/com/dmdirc/addons/ui_swing/dialogs/serversetting/PerformTab.java Vedi File

@@ -141,7 +141,7 @@ public class PerformTab extends JPanel implements ActionListener {
141 141
 
142 142
     @Override
143 143
     public void actionPerformed(final ActionEvent e) {
144
-        final PerformDescription perform = (PerformDescription) ((JComboBox) e.getSource()).
144
+        final PerformDescription perform = (PerformDescription) ((JComboBox<?>) e.getSource()).
145 145
                 getSelectedItem();
146 146
         performPanel.switchPerform(perform);
147 147
     }

Loading…
Annulla
Salva