From: Niki Roo Date: Wed, 22 Apr 2020 18:02:49 +0000 (+0200) Subject: Java 1.6 compat helpers X-Git-Tag: fanfix-swing-0.0.1~5 X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=3540947a69f97aaf2ff97424a66b39dbfc3b93ef;p=fanfix-swing.git Java 1.6 compat helpers --- diff --git a/src/be/nikiroo/utils/compat/DefaultListModel6.java b/src/be/nikiroo/utils/compat/DefaultListModel6.java new file mode 100644 index 00000000..114ac42e --- /dev/null +++ b/src/be/nikiroo/utils/compat/DefaultListModel6.java @@ -0,0 +1,22 @@ +package be.nikiroo.utils.compat; + +import javax.swing.DefaultListModel; +import javax.swing.JList; + +/** + * Compatibility layer so I can at least get rid of the warnings of using + * {@link JList} without a parameter (and still staying Java 1.6 compatible). + *

+ * This class is merely a {@link DefaultListModel} that you can parametrise also + * in Java 1.6. + * + * @author niki + * + * @param + * the type to use + */ +@SuppressWarnings("rawtypes") // not compatible Java 1.6 +public class DefaultListModel6 extends DefaultListModel + implements ListModel6 { + private static final long serialVersionUID = 1L; +} diff --git a/src/be/nikiroo/utils/compat/JList6.java b/src/be/nikiroo/utils/compat/JList6.java new file mode 100644 index 00000000..e0aea42e --- /dev/null +++ b/src/be/nikiroo/utils/compat/JList6.java @@ -0,0 +1,84 @@ +package be.nikiroo.utils.compat; + +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.ListModel; + +/** + * Compatibility layer so I can at least get rid of the warnings of using + * {@link JList} without a parameter (and still staying Java 1.6 compatible). + *

+ * This class is merely a {@link JList} that you can parametrise also in Java + * 1.6. + * + * @author niki + * + * @param + * the type to use + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) // not compatible Java 1.6 +public class JList6 extends JList { + private static final long serialVersionUID = 1L; + + @Override + @Deprecated + /** + * @deprecated please use {@link JList6#setCellRenderer(ListCellRenderer6)} + * instead + */ + public void setCellRenderer(ListCellRenderer cellRenderer) { + setCellRenderer((ListCellRenderer6) cellRenderer); + } + + /** + * Sets the delegate that is used to paint each cell in the list. The job of + * a cell renderer is discussed in detail in the class + * level documentation. + *

+ * If the {@code prototypeCellValue} property is {@code non-null}, setting + * the cell renderer also causes the {@code fixedCellWidth} and + * {@code fixedCellHeight} properties to be re-calculated. Only one + * PropertyChangeEvent is generated however - for the + * cellRenderer property. + *

+ * The default value of this property is provided by the {@code ListUI} + * delegate, i.e. by the look and feel implementation. + *

+ * This is a JavaBeans bound property. + * + * @param cellRenderer + * the ListCellRenderer that paints list cells + * @see #getCellRenderer + * @beaninfo bound: true attribute: visualUpdate true description: The + * component used to draw the cells. + */ + public void setCellRenderer(ListCellRenderer6 cellRenderer) { + super.setCellRenderer(cellRenderer); + } + + @Override + @Deprecated + public void setModel(ListModel model) { + setModel((ListModel6) model); + } + + /** + * Sets the model that represents the contents or "value" of the list, + * notifies property change listeners, and then clears the list's selection. + *

+ * This is a JavaBeans bound property. + * + * @param model + * the ListModel that provides the list of items for + * display + * @exception IllegalArgumentException + * if model is null + * @see #getModel + * @see #clearSelection + * @beaninfo bound: true attribute: visualUpdate true description: The + * object that contains the data to be drawn by this JList. + */ + public void setModel(ListModel6 model) { + super.setModel(model); + } +} diff --git a/src/be/nikiroo/utils/compat/ListCellRenderer6.java b/src/be/nikiroo/utils/compat/ListCellRenderer6.java new file mode 100644 index 00000000..d0048498 --- /dev/null +++ b/src/be/nikiroo/utils/compat/ListCellRenderer6.java @@ -0,0 +1,65 @@ +package be.nikiroo.utils.compat; + +import java.awt.Component; + +import javax.swing.JList; +import javax.swing.ListCellRenderer; +import javax.swing.ListModel; +import javax.swing.ListSelectionModel; + +/** + * Compatibility layer so I can at least get rid of the warnings of using + * {@link JList} without a parameter (and still staying Java 1.6 compatible). + *

+ * This class is merely a {@link ListCellRenderer} that you can parametrise also + * in Java 1.6. + * + * @author niki + * + * @param + * the type to use + */ +@SuppressWarnings({ "unchecked", "rawtypes" }) // not compatible Java 1.6 +public abstract class ListCellRenderer6 implements ListCellRenderer { + @Override + @Deprecated + /** + * @deprecated please use@deprecated please use + * {@link ListCellRenderer6#getListCellRendererComponent(JList6, Object, int, boolean, boolean)} + * instead + * {@link ListCellRenderer6#getListCellRendererComponent(JList6, Object, int, boolean, boolean)} + * instead + */ + public Component getListCellRendererComponent(JList list, Object value, + int index, boolean isSelected, boolean cellHasFocus) { + return getListCellRendererComponent((JList6) list, (E) value, index, + isSelected, cellHasFocus); + } + + /** + * Return a component that has been configured to display the specified + * value. That component's paint method is then called to + * "render" the cell. If it is necessary to compute the dimensions of a list + * because the list cells do not have a fixed size, this method is called to + * generate a component on which getPreferredSize can be + * invoked. + * + * @param list + * The JList we're painting. + * @param value + * The value returned by list.getModel().getElementAt(index). + * @param index + * The cells index. + * @param isSelected + * True if the specified cell was selected. + * @param cellHasFocus + * True if the specified cell has the focus. + * @return A component whose paint() method will render the specified value. + * + * @see JList + * @see ListSelectionModel + * @see ListModel + */ + public abstract Component getListCellRendererComponent(JList6 list, + E value, int index, boolean isSelected, boolean cellHasFocus); +} diff --git a/src/be/nikiroo/utils/compat/ListModel6.java b/src/be/nikiroo/utils/compat/ListModel6.java new file mode 100644 index 00000000..a1f8c607 --- /dev/null +++ b/src/be/nikiroo/utils/compat/ListModel6.java @@ -0,0 +1,19 @@ +package be.nikiroo.utils.compat; + +import javax.swing.JList; + +/** + * Compatibility layer so I can at least get rid of the warnings of using + * {@link JList} without a parameter (and still staying Java 1.6 compatible). + *

+ * This class is merely a {@link javax.swing.ListModel} that you can parametrise + * also in Java 1.6. + * + * @author niki + * + * @param + * the type to use + */ +@SuppressWarnings("rawtypes") // not compatible Java 1.6 +public interface ListModel6 extends javax.swing.ListModel { +}