Browse Source

Add generic combo box model.

Fixes issue 4230

Change-Id: I30cf8d2b3cc7e67357dd42cf0b320e1097983fba
Reviewed-on: http://gerrit.dmdirc.com/1312
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.4
Greg Holmes 14 years ago
parent
commit
b4fcfdf1bf
1 changed files with 60 additions and 0 deletions
  1. 60
    0
      src/com/dmdirc/addons/ui_swing/components/GenericComboBoxModel.java

+ 60
- 0
src/com/dmdirc/addons/ui_swing/components/GenericComboBoxModel.java View File

@@ -0,0 +1,60 @@
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;
24
+
25
+import javax.swing.ComboBoxModel;
26
+
27
+/**
28
+ * Generic combo box model, extends generic list model.
29
+ *
30
+ * @param <T> Model holds this type of object
31
+ */
32
+public class GenericComboBoxModel<T> extends GenericListModel<T> implements
33
+        ComboBoxModel {
34
+
35
+    /**
36
+     * A version number for this class. It should be changed whenever the class
37
+     * structure is changed (or anything else that would prevent serialized
38
+     * objects being unserialized with the new class).
39
+     */
40
+    private static final long serialVersionUID = 2;
41
+    /** Selected Object. */
42
+    private T selectedObject;
43
+
44
+    /** {@inheritDoc} */
45
+    @Override
46
+    @SuppressWarnings("unchecked")
47
+    public void setSelectedItem(final Object anItem) {
48
+        if ((selectedObject != null && !selectedObject.equals(anItem)) || selectedObject
49
+                == null && anItem != null) {
50
+            selectedObject = (T) anItem;
51
+            fireContentsChanged(this, -1, -1);
52
+        }
53
+    }
54
+
55
+    /** {@inheritDoc} */
56
+    @Override
57
+    public T getSelectedItem() {
58
+        return selectedObject;
59
+    }
60
+}

Loading…
Cancel
Save