use nikiroo-utils compat
authorNiki Roo <niki@nikiroo.be>
Wed, 22 Apr 2020 18:11:39 +0000 (20:11 +0200)
committerNiki Roo <niki@nikiroo.be>
Wed, 22 Apr 2020 18:11:39 +0000 (20:11 +0200)
src/be/nikiroo/fanfix_swing/gui/BooksPanel.java
src/be/nikiroo/fanfix_swing/gui/importer/ImporterFrame.java
src/be/nikiroo/fanfix_swing/gui/utils/ListModel.java

index 20b6886b34021bf9672a3e3aa5dd6fe8b0cea962..a2462fa57119688493949ab4707bc7c004d35b03 100644 (file)
@@ -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<BookInfo> is not java 1.6
-       private JList list;
+       private JList6<BookInfo> list;
        private ListModel<BookInfo> data;
        private DelayWorker bookCoverUpdater;
        private String filter = "";
@@ -195,9 +194,8 @@ public class BooksPanel extends ListenerPanel {
                }
        }
 
-       @SuppressWarnings("rawtypes") // JList<BookInfo> is not java 1.6
-       private JList initList() {
-               final JList list = new JList();
+       private JList6<BookInfo> initList() {
+               final JList6<BookInfo> list = new JList6<BookInfo>();
                data = new ListModel<BookInfo>(list, new BookPopup(
                                Instance.getInstance().getLibrary(), initInformer()));
 
@@ -268,22 +266,21 @@ public class BooksPanel extends ListenerPanel {
                };
        }
 
-       @SuppressWarnings("rawtypes") // ListCellRenderer<BookInfo> is not java 1.6
-       private ListCellRenderer generateRenderer() {
-               return new ListCellRenderer() {
+       private ListCellRenderer6<BookInfo> generateRenderer() {
+               return new ListCellRenderer6<BookInfo>() {
                        @Override
-                       public Component getListCellRendererComponent(JList list,
-                                       Object value, int index, boolean isSelected,
+                       public Component getListCellRendererComponent(JList6<BookInfo> 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++) {
index 6e8fcbe12c6bbb485f991f88caf004e92ad669f0..7db93374e4d8a8366e19368042affaeaec1dce76 100644 (file)
@@ -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<ImporterItem> data;
        private String filter = "";
 
-       @SuppressWarnings("unchecked") // JList<ImporterItem> is not java 1.6
        public ImporterFrame() {
                setLayout(new BorderLayout());
 
-               @SuppressWarnings("rawtypes") // JList<ImporterItem> is not java 1.6
-               JList list = new JList();
+               JList6<ImporterItem> list = new JList6<ImporterItem>();
                data = new ListModel<ImporterItem>(list);
 
                list.setCellRenderer(ListModel.generateRenderer(data));
index ab916e53f5f27a66ba7ea583f36a08262a926f4e..6f9c1961f50856a70ad17738b66fa0fb084df54d 100644 (file)
@@ -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 <T>
  *            the type of elements and items (the same type)
  */
-@SuppressWarnings("rawtypes") // ListModel<T> and JList<T> are not java 1.6
-public class ListModel<T> extends DefaultListModel {
+public class ListModel<T> extends DefaultListModel6<T> {
        private static final long serialVersionUID = 1L;
 
        /**
@@ -78,7 +80,7 @@ public class ListModel<T> extends DefaultListModel {
 
        private int hoveredIndex;
        private List<T> items = new ArrayList<T>();
-       private JList list;
+       private JList6<T> list;
 
        /**
         * Create a new {@link ListModel}.
@@ -86,8 +88,9 @@ public class ListModel<T> 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<T>) list);
        }
 
        /**
@@ -98,8 +101,30 @@ public class ListModel<T> extends DefaultListModel {
         * @param popup
         *            the popup to use and keep track of (can be NULL)
         */
-       @SuppressWarnings("unchecked") // ListModel<T> and JList<T> are not java 1.6
+       @SuppressWarnings({ "unchecked", "rawtypes" }) // not compatible Java 1.6
        public ListModel(final JList list, final JPopupMenu popup) {
+               this((JList6<T>) list, popup);
+       }
+
+       /**
+        * Create a new {@link ListModel}.
+        * 
+        * @param list
+        *            the {@link JList6} we will handle the data of (cannot be NULL)
+        */
+       public ListModel(JList6<T> 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<T> list, final JPopupMenu popup) {
                this.list = list;
                list.setModel(this);
 
@@ -348,12 +373,12 @@ public class ListModel<T> extends DefaultListModel {
         * 
         * @return a suitable, {@link Hoverable} compatible renderer
         */
-       static public <T extends Component> ListCellRenderer generateRenderer(
+       static public <T extends Component> ListCellRenderer6<T> generateRenderer(
                        final ListModel<T> model) {
-               return new ListCellRenderer() {
+               return new ListCellRenderer6<T>() {
                        @Override
-                       public Component getListCellRendererComponent(JList list,
-                                       Object item, int index, boolean isSelected,
+                       public Component getListCellRendererComponent(JList6<T> list,
+                                       T item, int index, boolean isSelected,
                                        boolean cellHasFocus) {
                                if (item instanceof Hoverable) {
                                        Hoverable hoverable = (Hoverable) item;
@@ -361,7 +386,7 @@ public class ListModel<T> extends DefaultListModel {
                                        hoverable.setHovered(model.isHovered(index));
                                }
 
-                               return (Component) item;
+                               return item;
                        }
                };
        }