From 19bd7cb05c4e3f5c2d79b8fc5e17d3a634625f54 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sun, 19 Apr 2020 20:34:12 +0200 Subject: [PATCH] java 1.6 compat --- .../nikiroo/fanfix_swing/gui/BooksPanel.java | 7 +++-- .../gui/importer/ImporterFrame.java | 4 ++- .../fanfix_swing/gui/utils/ListModel.java | 29 ++++++++++++------- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java index 580cc70c..8c22de1e 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java @@ -41,7 +41,8 @@ public class BooksPanel extends ListenerPanel { private boolean seeWordCount; private boolean listMode; - private JList list; + @SuppressWarnings("rawtypes") // JList is not java 1.6 + private JList list; private ListModel data; private DelayWorker bookCoverUpdater; private String filter = ""; @@ -146,7 +147,8 @@ public class BooksPanel extends ListenerPanel { } } - private JList initList() { + @SuppressWarnings("rawtypes") // JList is not java 1.6 + private JList initList() { final JList list = new JList(); data = new ListModel(list, new BookPopup( Instance.getInstance().getLibrary(), initInformer())); @@ -252,6 +254,7 @@ public class BooksPanel extends ListenerPanel { book.getInfo()); } + @Override protected void done() { try { book.setCoverImage(get()); diff --git a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java index c3c6059f..6e8fcbe1 100644 --- a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java @@ -32,10 +32,12 @@ public class ImporterFrame extends JFrame { private ListModel data; private String filter = ""; + @SuppressWarnings("unchecked") // JList is not java 1.6 public ImporterFrame() { setLayout(new BorderLayout()); - JList list = new JList(); + @SuppressWarnings("rawtypes") // JList is not java 1.6 + JList list = new JList(); data = new ListModel(list); list.setCellRenderer(ListModel.generateRenderer(data)); diff --git a/src/be/nikiroo/fanfix_swing/gui/utils/ListModel.java b/src/be/nikiroo/fanfix_swing/gui/utils/ListModel.java index 81a8cecd..ab916e53 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/ListModel.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/ListModel.java @@ -26,7 +26,8 @@ import javax.swing.ListCellRenderer; * @param * the type of elements and items (the same type) */ -public class ListModel extends DefaultListModel { +@SuppressWarnings("rawtypes") // ListModel and JList are not java 1.6 +public class ListModel extends DefaultListModel { private static final long serialVersionUID = 1L; /** @@ -77,7 +78,7 @@ public class ListModel extends DefaultListModel { private int hoveredIndex; private List items = new ArrayList(); - private JList list; + private JList list; /** * Create a new {@link ListModel}. @@ -85,7 +86,7 @@ public class ListModel extends DefaultListModel { * @param list * the {@link JList} we will handle the data of (cannot be NULL) */ - public ListModel(JList list) { + public ListModel(JList list) { this(list, null); } @@ -97,7 +98,8 @@ public class ListModel extends DefaultListModel { * @param popup * the popup to use and keep track of (can be NULL) */ - public ListModel(final JList list, final JPopupMenu popup) { + @SuppressWarnings("unchecked") // ListModel and JList are not java 1.6 + public ListModel(final JList list, final JPopupMenu popup) { this.list = list; list.setModel(this); @@ -260,6 +262,7 @@ public class ListModel extends DefaultListModel { * 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 public void filter(Predicate filter) { clear(); for (T item : items) { @@ -326,6 +329,12 @@ public class ListModel extends DefaultListModel { } } + @SuppressWarnings("unchecked") // ListModel and JList are not java 1.6 + @Override + public T get(int index) { + return (T) super.get(index); + } + /** * Generate a {@link ListCellRenderer} that supports {@link Hoverable} * elements. @@ -339,20 +348,20 @@ public class ListModel extends DefaultListModel { * * @return a suitable, {@link Hoverable} compatible renderer */ - static public ListCellRenderer generateRenderer( + static public ListCellRenderer generateRenderer( final ListModel model) { - return new ListCellRenderer() { + return new ListCellRenderer() { @Override - public Component getListCellRendererComponent( - JList list, T item, int index, - boolean isSelected, boolean cellHasFocus) { + public Component getListCellRendererComponent(JList list, + Object item, int index, boolean isSelected, + boolean cellHasFocus) { if (item instanceof Hoverable) { Hoverable hoverable = (Hoverable) item; hoverable.setSelected(isSelected); hoverable.setHovered(model.isHovered(index)); } - return item; + return (Component) item; } }; } -- 2.27.0