Browse Source

Remove warnings in actions and aliases

Change-Id: I9ad0e3a513be76b81b20163be21a35407c469ebd
Reviewed-on: http://gerrit.dmdirc.com/3167
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.8
Greg Holmes 10 years ago
parent
commit
c45bfec729

+ 5
- 12
src/com/dmdirc/addons/ui_swing/components/SortedListModel.java View File

@@ -31,13 +31,9 @@ import javax.swing.DefaultListModel;
31 31
  *
32 32
  * @param <T> Comparator type
33 33
  */
34
-public class SortedListModel<T> extends DefaultListModel {
34
+public class SortedListModel<T> extends DefaultListModel<T> {
35 35
 
36
-    /**
37
-     * A version number for this class. It should be changed whenever the class structure is changed
38
-     * (or anything else that would prevent serialized objects being unserialized with the new
39
-     * class).
40
-     */
36
+    /** A version number for this class. */
41 37
     private static final long serialVersionUID = 1L;
42 38
     /** Comparator. */
43 39
     private final Comparator<T> comparator;
@@ -53,15 +49,12 @@ public class SortedListModel<T> extends DefaultListModel {
53 49
         this.comparator = comparator;
54 50
     }
55 51
 
56
-    /** {@inheritDoc} */
57 52
     @Override
58
-    @SuppressWarnings("unchecked")
59
-    public void addElement(final Object obj) {
60
-        final T object = (T) obj;
53
+    public void addElement(final T obj) {
61 54
         boolean added = false;
62 55
         for (int i = 0; i < getSize(); i++) {
63
-            final T currentObj = (T) getElementAt(i);
64
-            if (comparator.compare(currentObj, object) > 0) {
56
+            final T currentObj = getElementAt(i);
57
+            if (comparator.compare(currentObj, obj) > 0) {
65 58
                 add(i, obj);
66 59
                 added = true;
67 60
                 break;

+ 3
- 4
src/com/dmdirc/addons/ui_swing/components/renderers/ActionComparisonCellRenderer.java View File

@@ -28,9 +28,9 @@ import javax.swing.JLabel;
28 28
 import javax.swing.ListCellRenderer;
29 29
 
30 30
 /**
31
- * Renders an action comparison in plain english.
31
+ * Renders an action comparison in plain English.
32 32
  */
33
-public final class ActionComparisonCellRenderer extends DMDircListCellRenderer {
33
+public final class ActionComparisonCellRenderer extends DMDircListCellRenderer<Object> {
34 34
 
35 35
     /**
36 36
      * A version number for this class.
@@ -42,11 +42,10 @@ public final class ActionComparisonCellRenderer extends DMDircListCellRenderer {
42 42
      *
43 43
      * @param renderer RendereParent renderer
44 44
      */
45
-    public ActionComparisonCellRenderer(final ListCellRenderer renderer) {
45
+    public ActionComparisonCellRenderer(final ListCellRenderer<? super Object> renderer) {
46 46
         super(renderer);
47 47
     }
48 48
 
49
-    /** {@inheritDoc} */
50 49
     @Override
51 50
     protected void renderValue(final JLabel label, final Object value,
52 51
             final int index, final boolean isSelected,

+ 0
- 61
src/com/dmdirc/addons/ui_swing/components/renderers/ActionGroupListCellRenderer.java View File

@@ -1,61 +0,0 @@
1
-/*
2
- * Copyright (c) 2006-2014 DMDirc Developers
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.renderers;
24
-
25
-import com.dmdirc.actions.ActionGroup;
26
-
27
-import javax.swing.JLabel;
28
-import javax.swing.ListCellRenderer;
29
-
30
-/**
31
- * Action group list cell renderer.
32
- */
33
-public class ActionGroupListCellRenderer extends DMDircListCellRenderer {
34
-
35
-    /**
36
-     * A version number for this class.
37
-     */
38
-    private static final long serialVersionUID = 1;
39
-
40
-    /**
41
-     * Creates a new instance of this renderer.
42
-     *
43
-     * @param renderer RendereParent renderer
44
-     */
45
-    public ActionGroupListCellRenderer(final ListCellRenderer renderer) {
46
-        super(renderer);
47
-    }
48
-
49
-    /** {@inheritDoc} */
50
-    @Override
51
-    protected void renderValue(final JLabel label, final Object value,
52
-            final int index, final boolean isSelected,
53
-            final boolean cellHasFocus) {
54
-        if (value instanceof ActionGroup) {
55
-            label.setText(((ActionGroup) value).getName());
56
-        } else {
57
-            label.setText(value.toString());
58
-        }
59
-    }
60
-
61
-}

+ 5
- 5
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionGroupNoDuplicatesInListValidator.java View File

@@ -29,9 +29,9 @@ import javax.swing.DefaultListModel;
29 29
 import javax.swing.JList;
30 30
 
31 31
 /**
32
- * No duplicates list validator, overriden to work with action groups.
32
+ * No duplicates list validator, overridden to work with action groups.
33 33
  */
34
-class ActionGroupNoDuplicatesInListValidator extends NoDuplicatesInListValidator {
34
+class ActionGroupNoDuplicatesInListValidator extends NoDuplicatesInListValidator<ActionGroup> {
35 35
 
36 36
     /**
37 37
      * Creates a new validator.
@@ -39,8 +39,8 @@ class ActionGroupNoDuplicatesInListValidator extends NoDuplicatesInListValidator
39 39
      * @param list  List
40 40
      * @param model Model to validate
41 41
      */
42
-    public ActionGroupNoDuplicatesInListValidator(final JList list,
43
-            final DefaultListModel model) {
42
+    public ActionGroupNoDuplicatesInListValidator(final JList<ActionGroup> list,
43
+            final DefaultListModel<ActionGroup> model) {
44 44
         super(true, list, model);
45 45
     }
46 46
 
@@ -52,7 +52,7 @@ class ActionGroupNoDuplicatesInListValidator extends NoDuplicatesInListValidator
52 52
      * @param model         Model to validate
53 53
      */
54 54
     public ActionGroupNoDuplicatesInListValidator(final boolean caseSensitive,
55
-            final JList list, final DefaultListModel model) {
55
+            final JList<ActionGroup> list, final DefaultListModel<ActionGroup> model) {
56 56
         super(caseSensitive, list, model);
57 57
     }
58 58
 

+ 13
- 21
src/com/dmdirc/addons/ui_swing/dialogs/actionsmanager/ActionsManagerDialog.java View File

@@ -35,7 +35,7 @@ import com.dmdirc.addons.ui_swing.SwingController;
35 35
 import com.dmdirc.addons.ui_swing.components.ListScroller;
36 36
 import com.dmdirc.addons.ui_swing.components.SortedListModel;
37 37
 import com.dmdirc.addons.ui_swing.components.frames.AppleJFrame;
38
-import com.dmdirc.addons.ui_swing.components.renderers.ActionGroupListCellRenderer;
38
+import com.dmdirc.addons.ui_swing.components.renderers.PropertyListCellRenderer;
39 39
 import com.dmdirc.addons.ui_swing.components.text.TextLabel;
40 40
 import com.dmdirc.addons.ui_swing.dialogs.StandardDialog;
41 41
 import com.dmdirc.addons.ui_swing.dialogs.StandardInputDialog;
@@ -73,11 +73,7 @@ public class ActionsManagerDialog extends StandardDialog implements
73 73
         ActionListener, com.dmdirc.interfaces.ActionListener,
74 74
         ListSelectionListener {
75 75
 
76
-    /**
77
-     * A version number for this class. It should be changed whenever the class structure is changed
78
-     * (or anything else that would prevent serialized objects being unserialized with the new
79
-     * class).
80
-     */
76
+    /** A version number for this class. */
81 77
     private static final long serialVersionUID = 1;
82 78
     /** Config instance. */
83 79
     private final ConfigProvider config;
@@ -90,7 +86,7 @@ public class ActionsManagerDialog extends StandardDialog implements
90 86
     /** Info label. */
91 87
     private TextLabel infoLabel;
92 88
     /** Group list. */
93
-    private JList groups;
89
+    private JList<ActionGroup> groups;
94 90
     /** Add button. */
95 91
     private JButton add;
96 92
     /** Edit button. */
@@ -123,6 +119,7 @@ public class ActionsManagerDialog extends StandardDialog implements
123 119
      * @param groupPanelFactory Factory to use to create group panels.
124 120
      */
125 121
     @Inject
122
+    @SuppressWarnings("unchecked")
126 123
     public ActionsManagerDialog(
127 124
             final MainFrame parentWindow,
128 125
             final SwingController controller,
@@ -160,7 +157,7 @@ public class ActionsManagerDialog extends StandardDialog implements
160 157
                 + " intelligently respond to various events.  Action groups are"
161 158
                 + " there for you to organise groups, add or remove them"
162 159
                 + " to suit your needs.");
163
-        groups = new JList(new SortedListModel<>(new ActionGroupNameComparator()));
160
+        groups = new JList<>(new SortedListModel<>(new ActionGroupNameComparator()));
164 161
         actions = groupPanelFactory.getActionsGroupPanel(this, null);
165 162
         info = new ActionGroupInformationPanel(null);
166 163
         settings = new HashMap<>();
@@ -179,7 +176,7 @@ public class ActionsManagerDialog extends StandardDialog implements
179 176
         actions.setBorder(BorderFactory.createTitledBorder(UIManager.getBorder(
180 177
                 "TitledBorder.border"), "Actions"));
181 178
 
182
-        groups.setCellRenderer(new ActionGroupListCellRenderer(groups.getCellRenderer()));
179
+        groups.setCellRenderer(new PropertyListCellRenderer<>(groups.getCellRenderer(), ActionGroup.class, "name"));
183 180
         groups.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
184 181
         edit.setEnabled(false);
185 182
         delete.setEnabled(false);
@@ -256,7 +253,7 @@ public class ActionsManagerDialog extends StandardDialog implements
256 253
     private void reloadGroups(final ActionGroup selectedGroup) {
257 254
         ((DefaultListModel) groups.getModel()).clear();
258 255
         for (ActionGroup group : ActionManager.getActionManager().getGroupsMap().values()) {
259
-            ((DefaultListModel) groups.getModel()).addElement(group);
256
+            ((DefaultListModel<ActionGroup>) groups.getModel()).addElement(group);
260 257
         }
261 258
         groups.setSelectedValue(selectedGroup, true);
262 259
     }
@@ -354,8 +351,7 @@ public class ActionsManagerDialog extends StandardDialog implements
354 351
      * Prompts then edits an action group.
355 352
      */
356 353
     private void editGroup() {
357
-        final String oldName =
358
-                ((ActionGroup) groups.getSelectedValue()).getName();
354
+        final String oldName = groups.getSelectedValue().getName();
359 355
         final StandardInputDialog inputDialog = new StandardInputDialog(
360 356
                 this, ModalityType.DOCUMENT_MODAL, iconManager, "Edit action group",
361 357
                 "Please enter the new name of the action group", validator) {
@@ -392,8 +388,7 @@ public class ActionsManagerDialog extends StandardDialog implements
392 388
      * Prompts then deletes an action group.
393 389
      */
394 390
     private void delGroup() {
395
-        final String group =
396
-                ((ActionGroup) groups.getSelectedValue()).getName();
391
+        final String group = groups.getSelectedValue().getName();
397 392
         new StandardQuestionDialog(this,
398 393
                 ModalityType.APPLICATION_MODAL,
399 394
                 "Confirm deletion",
@@ -436,9 +431,8 @@ public class ActionsManagerDialog extends StandardDialog implements
436 431
             return;
437 432
         }
438 433
 
439
-        changeActiveGroup((ActionGroup) groups.getSelectedValue());
440
-        if (groups.getSelectedIndex() == -1 || !((ActionGroup) groups.
441
-                getSelectedValue()).isDelible()) {
434
+        changeActiveGroup(groups.getSelectedValue());
435
+        if (groups.getSelectedIndex() == -1 || !groups.getSelectedValue().isDelible()) {
442 436
             edit.setEnabled(false);
443 437
             delete.setEnabled(false);
444 438
         } else {
@@ -457,13 +451,11 @@ public class ActionsManagerDialog extends StandardDialog implements
457 451
         if (type.equals(CoreActionType.ACTION_CREATED) || type.equals(
458 452
                 CoreActionType.ACTION_UPDATED)) {
459 453
             final Action action = (Action) arguments[0];
460
-            if (action.getGroup().equals(((ActionGroup) groups.getSelectedValue()).
461
-                    getName())) {
454
+            if (action.getGroup().equals(groups.getSelectedValue().getName())) {
462 455
                 actions.actionChanged(action);
463 456
             }
464 457
         } else {
465
-            if (arguments[0].equals(((ActionGroup) groups.getSelectedValue()).
466
-                    getName())) {
458
+            if (arguments[0].equals(groups.getSelectedValue().getName())) {
467 459
                 actions.actionDeleted((String) arguments[1]);
468 460
             }
469 461
         }

+ 8
- 15
src/com/dmdirc/addons/ui_swing/dialogs/aliases/AliasPanel.java View File

@@ -60,18 +60,14 @@ import net.miginfocom.swing.MigLayout;
60 60
  */
61 61
 public class AliasPanel extends JPanel implements ActionListener {
62 62
 
63
-    /**
64
-     * A version number for this class. It should be changed whenever the class structure is changed
65
-     * (or anything else that would prevent serialized objects being unserialized with the new
66
-     * class).
67
-     */
63
+    /** A version number for this class. */
68 64
     private static final long serialVersionUID = 2;
69 65
     /** Factory to use when creating aliases. */
70 66
     private final ActionFactory actionFactory;
71 67
     /** Name field. */
72 68
     private final ValidatingTextFieldInputField command;
73 69
     /** argument component combo box. */
74
-    private final JComboBox argumentComponent;
70
+    private final JComboBox<Object> argumentComponent;
75 71
     /** Argument number spinner. */
76 72
     private final JSpinner argumentNumber;
77 73
     /** Response field. */
@@ -99,20 +95,17 @@ public class AliasPanel extends JPanel implements ActionListener {
99 95
 
100 96
         this.actionFactory = actionFactory;
101 97
 
102
-        command = new ValidatingTextFieldInputField(
103
-                iconManager,
104
-                colourManager,
105
-                globalConfig,
106
-                new ValidatorChain<>(
98
+        @SuppressWarnings("unchecked")
99
+        final ValidatorChain<String> chain = new ValidatorChain<>(
107 100
                 new CommandNameValidator(commandController.getCommandChar()),
108
-                new FileNameValidator()));
101
+                new FileNameValidator());
102
+        command = new ValidatingTextFieldInputField(iconManager, colourManager, globalConfig, chain);
109 103
         command.setEnabled(false);
110 104
 
111
-        argumentComponent = new JComboBox(new CoreActionComparison[]{null,
105
+        argumentComponent = new JComboBox<Object>(new CoreActionComparison[]{null,
112 106
             CoreActionComparison.INT_GREATER, CoreActionComparison.INT_EQUALS,
113 107
             CoreActionComparison.INT_LESS,});
114
-        argumentNumber = new JSpinner(new SpinnerNumberModel(0, 0,
115
-                Integer.MAX_VALUE, 1));
108
+        argumentNumber = new JSpinner(new SpinnerNumberModel(0, 0, Integer.MAX_VALUE, 1));
116 109
         response = new JTextArea();
117 110
 
118 111
         argumentNumber.setEnabled(false);

Loading…
Cancel
Save