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;
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;
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 = "";
}
}
- @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()));
};
}
- @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);
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++) {
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;
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));
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
* @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;
/**
private int hoveredIndex;
private List<T> items = new ArrayList<T>();
- private JList list;
+ private JList6<T> list;
/**
* Create a new {@link ListModel}.
* @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);
}
/**
* @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);
*
* @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;
hoverable.setHovered(model.isHovered(index));
}
- return (Component) item;
+ return item;
}
};
}