From b433b0b070531d563e0f54cc8a23603718e059ed Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 22 Apr 2020 20:11:39 +0200 Subject: [PATCH] use nikiroo-utils compat --- .../nikiroo/fanfix_swing/gui/BooksPanel.java | 29 +++++------- .../gui/importer/ImporterFrame.java | 6 +-- .../fanfix_swing/gui/utils/ListModel.java | 47 ++++++++++++++----- 3 files changed, 51 insertions(+), 31 deletions(-) diff --git a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java index 20b6886b..a2462fa5 100644 --- a/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java +++ b/src/be/nikiroo/fanfix_swing/gui/BooksPanel.java @@ -14,8 +14,6 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ExecutionException; -import javax.swing.JList; -import javax.swing.ListCellRenderer; import javax.swing.ListSelectionModel; import javax.swing.SwingWorker; @@ -31,6 +29,8 @@ import be.nikiroo.fanfix_swing.gui.book.BookPopup.Informer; import be.nikiroo.fanfix_swing.gui.utils.DelayWorker; import be.nikiroo.fanfix_swing.gui.utils.ListModel; import be.nikiroo.fanfix_swing.gui.utils.ListModel.Predicate; +import be.nikiroo.utils.compat.JList6; +import be.nikiroo.utils.compat.ListCellRenderer6; import be.nikiroo.fanfix_swing.gui.utils.ListenerPanel; import be.nikiroo.fanfix_swing.gui.utils.UiHelper; @@ -41,8 +41,7 @@ public class BooksPanel extends ListenerPanel { private boolean seeWordCount; private boolean listMode; - @SuppressWarnings("rawtypes") // JList is not java 1.6 - private JList list; + private JList6 list; private ListModel data; private DelayWorker bookCoverUpdater; private String filter = ""; @@ -195,9 +194,8 @@ public class BooksPanel extends ListenerPanel { } } - @SuppressWarnings("rawtypes") // JList is not java 1.6 - private JList initList() { - final JList list = new JList(); + private JList6 initList() { + final JList6 list = new JList6(); data = new ListModel(list, new BookPopup( Instance.getInstance().getLibrary(), initInformer())); @@ -268,22 +266,21 @@ public class BooksPanel extends ListenerPanel { }; } - @SuppressWarnings("rawtypes") // ListCellRenderer is not java 1.6 - private ListCellRenderer generateRenderer() { - return new ListCellRenderer() { + private ListCellRenderer6 generateRenderer() { + return new ListCellRenderer6() { @Override - public Component getListCellRendererComponent(JList list, - Object value, int index, boolean isSelected, + public Component getListCellRendererComponent(JList6 list, + BookInfo value, int index, boolean isSelected, boolean cellHasFocus) { BookLine book = books.get(value); if (book == null) { if (listMode) { - book = new BookLine((BookInfo) value, seeWordCount); + book = new BookLine(value, seeWordCount); } else { - book = new BookBlock((BookInfo) value, seeWordCount); + book = new BookBlock(value, seeWordCount); startUpdateBookCover((BookBlock) book); } - books.put((BookInfo) value, book); + books.put(value, book); } book.setSelected(isSelected); @@ -323,7 +320,7 @@ public class BooksPanel extends ListenerPanel { this.listMode = listMode; books.clear(); list.setLayoutOrientation( - listMode ? JList.VERTICAL : JList.HORIZONTAL_WRAP); + listMode ? JList6.VERTICAL : JList6.HORIZONTAL_WRAP); StringBuilder longString = new StringBuilder(); for (int i = 0; i < 20; i++) { diff --git a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java index 6e8fcbe1..7db93374 100644 --- a/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java +++ b/src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java @@ -12,7 +12,6 @@ import java.net.URL; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; -import javax.swing.JList; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.ListSelectionModel; @@ -27,17 +26,16 @@ import be.nikiroo.fanfix_swing.gui.SearchBar; import be.nikiroo.fanfix_swing.gui.utils.ListModel; import be.nikiroo.fanfix_swing.gui.utils.ListModel.Predicate; import be.nikiroo.utils.Progress; +import be.nikiroo.utils.compat.JList6; public class ImporterFrame extends JFrame { private ListModel data; private String filter = ""; - @SuppressWarnings("unchecked") // JList is not java 1.6 public ImporterFrame() { setLayout(new BorderLayout()); - @SuppressWarnings("rawtypes") // JList is not java 1.6 - JList list = new JList(); + JList6 list = new JList6(); 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 ab916e53..6f9c1961 100644 --- a/src/be/nikiroo/fanfix_swing/gui/utils/ListModel.java +++ b/src/be/nikiroo/fanfix_swing/gui/utils/ListModel.java @@ -8,11 +8,14 @@ import java.util.ArrayList; import java.util.Collection; import java.util.List; -import javax.swing.DefaultListModel; import javax.swing.JList; import javax.swing.JPopupMenu; import javax.swing.ListCellRenderer; +import be.nikiroo.utils.compat.DefaultListModel6; +import be.nikiroo.utils.compat.JList6; +import be.nikiroo.utils.compat.ListCellRenderer6; + /** * A {@link javax.swing.ListModel} that can maintain 2 lists; one with the * actual data (the elements), and a second one with the items that are @@ -26,8 +29,7 @@ import javax.swing.ListCellRenderer; * @param * the type of elements and items (the same type) */ -@SuppressWarnings("rawtypes") // ListModel and JList are not java 1.6 -public class ListModel extends DefaultListModel { +public class ListModel extends DefaultListModel6 { private static final long serialVersionUID = 1L; /** @@ -78,7 +80,7 @@ public class ListModel extends DefaultListModel { private int hoveredIndex; private List items = new ArrayList(); - private JList list; + private JList6 list; /** * Create a new {@link ListModel}. @@ -86,8 +88,9 @@ public class ListModel extends DefaultListModel { * @param list * the {@link JList} we will handle the data of (cannot be NULL) */ + @SuppressWarnings({ "unchecked", "rawtypes" }) // not compatible Java 1.6 public ListModel(JList list) { - this(list, null); + this((JList6) list); } /** @@ -98,8 +101,30 @@ public class ListModel extends DefaultListModel { * @param popup * the popup to use and keep track of (can be NULL) */ - @SuppressWarnings("unchecked") // ListModel and JList are not java 1.6 + @SuppressWarnings({ "unchecked", "rawtypes" }) // not compatible Java 1.6 public ListModel(final JList list, final JPopupMenu popup) { + this((JList6) list, popup); + } + + /** + * Create a new {@link ListModel}. + * + * @param list + * the {@link JList6} we will handle the data of (cannot be NULL) + */ + public ListModel(JList6 list) { + this(list, null); + } + + /** + * Create a new {@link ListModel}. + * + * @param list + * 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) + */ + public ListModel(final JList6 list, final JPopupMenu popup) { this.list = list; list.setModel(this); @@ -348,12 +373,12 @@ public class ListModel extends DefaultListModel { * * @return a suitable, {@link Hoverable} compatible renderer */ - static public ListCellRenderer generateRenderer( + static public ListCellRenderer6 generateRenderer( final ListModel model) { - return new ListCellRenderer() { + return new ListCellRenderer6() { @Override - public Component getListCellRendererComponent(JList list, - Object item, int index, boolean isSelected, + public Component getListCellRendererComponent(JList6 list, + T item, int index, boolean isSelected, boolean cellHasFocus) { if (item instanceof Hoverable) { Hoverable hoverable = (Hoverable) item; @@ -361,7 +386,7 @@ public class ListModel extends DefaultListModel { hoverable.setHovered(model.isHovered(index)); } - return (Component) item; + return item; } }; } -- 2.27.0