summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ComboBox.java
diff options
context:
space:
mode:
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ComboBox.java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ComboBox.java26
1 files changed, 18 insertions, 8 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ComboBox.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ComboBox.java
index 2dddd48e..cd2afbee 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ComboBox.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/ComboBox.java
@@ -10,9 +10,13 @@ import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
-@SuppressWarnings("serial")
public class ComboBox<T> extends JComboBox<T> {
+ /**
+ * Version for serialization.
+ */
+ private static final long serialVersionUID = -114503880726655740L;
+
public static abstract class ComboBoxRenderer<T> {
public abstract String renderItem(T item);
@@ -25,13 +29,15 @@ public class ComboBox<T> extends JComboBox<T> {
private final ComboBoxRenderer<T> itemRenderer;
private final ComboBox<T> me = this;
private boolean replacedRenderer = false;
+ private final Class<T> clazz;
- public ComboBox(ComboBoxRenderer<T> renderer) {
- this(null, renderer);
+ public ComboBox(ComboBoxRenderer<T> renderer, Class<T> clazz) {
+ this(null, renderer, clazz);
}
- public ComboBox(Comparator<T> equalityComparator, ComboBoxRenderer<T> renderer) {
+ public ComboBox(Comparator<T> equalityComparator, ComboBoxRenderer<T> renderer, Class<T> clazz) {
super();
+ this.clazz = clazz;
this.itemRenderer = renderer;
this.equalityComparator = equalityComparator;
}
@@ -41,7 +47,6 @@ public class ComboBox<T> extends JComboBox<T> {
* comparator given when constructing the ComboBox to determine if an entry
* should be selected.
*/
- @SuppressWarnings("unchecked")
@Override
public void setSelectedItem(Object anObject) {
if (anObject != null && equalityComparator != null) {
@@ -50,7 +55,7 @@ public class ComboBox<T> extends JComboBox<T> {
try {
for (int i = 0; i < model.getSize(); ++i) {
T element = model.getElementAt(i);
- if (equalityComparator.compare((T) anObject, element) == 0) {
+ if (equalityComparator.compare(this.clazz.cast(anObject), element) == 0) {
localObject = element;
break;
}
@@ -99,12 +104,17 @@ public class ComboBox<T> extends JComboBox<T> {
}
private class FallbackCellRenderer extends DefaultListCellRenderer {
+
+ /**
+ * Version for serialization.
+ */
+ private static final long serialVersionUID = 3441233718432775129L;
+
public FallbackCellRenderer() {
putClientProperty("html.disable", Boolean.TRUE);
putClientProperty("html", null);
}
- @SuppressWarnings("unchecked")
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
@@ -112,7 +122,7 @@ public class ComboBox<T> extends JComboBox<T> {
value = itemRenderer.getEmptyText();
} else {
try {
- value = itemRenderer.renderItem((T) value);
+ value = itemRenderer.renderItem(ComboBox.this.clazz.cast(value));
} catch (ClassCastException e) {
// Should never happen; do nothing, retain original value
}