From: Niki Roo Date: Sun, 26 Apr 2020 12:28:42 +0000 (+0200) Subject: ListModel: JList constructors were bad X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=b489d80493bc7595051ae0087cd9cf5c90d6b2a5;p=fanfix-jexer.git ListModel: JList constructors were bad --- diff --git a/ui/ListModel.java b/ui/ListModel.java index 52fa816..e349dee 100644 --- a/ui/ListModel.java +++ b/ui/ListModel.java @@ -80,52 +80,68 @@ public class ListModel extends DefaultListModel6 { private int hoveredIndex; private List items = new ArrayList(); - private JList6 list; private boolean keepSelection = true; + @SuppressWarnings("rawtypes") // JList not compatible Java 1.6 + private JList list; + /** * Create a new {@link ListModel}. * * @param list - * the {@link JList} we will handle the data of (cannot be NULL) + * the {@link JList6} we will handle the data of (cannot be NULL) */ - @SuppressWarnings({ "unchecked", "rawtypes" }) // not compatible Java 1.6 - public ListModel(JList list) { - this((JList6) list); + @SuppressWarnings("rawtypes") // JList not compatible Java 1.6 + public ListModel(JList6 list) { + this((JList) list); } /** * Create a new {@link ListModel}. * * @param list - * the {@link JList} we will handle the data of (cannot be NULL) + * the {@link JList6} we will handle the data of (cannot be NULL) * @param popup * the popup to use and keep track of (can be NULL) */ - @SuppressWarnings({ "unchecked", "rawtypes" }) // not compatible Java 1.6 - public ListModel(final JList list, final JPopupMenu popup) { - this((JList6) list, popup); + @SuppressWarnings("rawtypes") // JList not compatible Java 1.6 + public ListModel(final JList6 list, final JPopupMenu popup) { + this((JList) list, popup); } /** * Create a new {@link ListModel}. + *

+ * Note that you must take care of passing a {@link JList} that only handles + * elements of the type of this {@link ListModel} -- you can also use + * {@link ListModel#ListModel(JList6)} instead. * * @param list - * the {@link JList6} we will handle the data of (cannot be NULL) + * the {@link JList} we will handle the data of (cannot be NULL, + * must only contain elements of the type of this + * {@link ListModel}) */ - public ListModel(JList6 list) { + @SuppressWarnings("rawtypes") // JList not compatible Java 1.6 + public ListModel(JList list) { this(list, null); } /** * Create a new {@link ListModel}. + *

+ * Note that you must take care of passing a {@link JList} that only handles + * elements of the type of this {@link ListModel} -- you can also use + * {@link ListModel#ListModel(JList6, JPopupMenu)} instead. * * @param list - * the {@link JList6} we will handle the data of (cannot be NULL) + * the {@link JList} we will handle the data of (cannot be NULL, + * must only contain elements of the type of this + * {@link ListModel}) * @param popup * the popup to use and keep track of (can be NULL) */ - public ListModel(final JList6 list, final JPopupMenu popup) { + @SuppressWarnings({ "unchecked", "rawtypes" }) // JList not in Java 1.6 + public ListModel(final JList list, final JPopupMenu popup) { this.list = list; list.setModel(this); @@ -313,7 +329,7 @@ public class ListModel extends DefaultListModel6 { * the filter will be copied as an element (can be NULL, in that * case all items will be copied as elements) */ - @SuppressWarnings("unchecked") // ListModel and JList are not java 1.6 + @SuppressWarnings("unchecked") // JList not compatible Java 1.6 public void filter(Predicate filter) { ListSnapshot snapshot = null; @@ -388,7 +404,7 @@ public class ListModel extends DefaultListModel6 { } } - @SuppressWarnings("unchecked") // ListModel and JList are not java 1.6 + @SuppressWarnings("unchecked") // JList not compatible Java 1.6 @Override public T get(int index) { return (T) super.get(index);