<Swing Dev> 6179357: Generics: JList: Constructors & Model
Florian Brunner
fbrunnerlist at gmx.ch
Sun Feb 1 22:28:17 UTC 2009
Hi,
I'm working now on the constructor and model-property of JList:
Here the constructors I how I suggest to change them:
----------------------------------------
public JList(final Object[] listData)
{
this (
new AbstractListModel() {
public int getSize() { return listData.length; }
public Object getElementAt(int i) { return listData[i]; }
}
);
}
--->
public JList(final E[] listData)
{
this (
new AbstractListModel<E>() {
public int getSize() { return listData.length; }
public E getElementAt(int i) { return listData[i]; }
}
);
}
----------------------------------------
public JList() {
this (
new AbstractListModel() {
public int getSize() { return 0; }
public Object getElementAt(int i) { return "No Data Model"; }
}
);
}
--->
public JList() {
this (
new AbstractListModel<E>() {
public int getSize() { return 0; }
public E getElementAt(int i) { throw new IndexOutOfBoundsException("No Data Model"); }
}
);
}
----------------------------------------
public JList(final Vector<?> listData) {
this (
new AbstractListModel() {
public int getSize() { return listData.size(); }
public Object getElementAt(int i) { return listData.elementAt(i); }
}
);
}
--->
public JList(final Vector<? extends E> listData) {
this (
new AbstractListModel<E>() {
public int getSize() { return listData.size(); }
public E getElementAt(int i) { return listData.elementAt(i); }
}
);
}
While we could define the signature also like this:
public JList(final Vector<E> listData)
there is now reason to limit the input - except maybe for consistency (see next constructor)
----------------------------------------
public JList(ListModel dataModel)
{
if (dataModel == null) {
throw new IllegalArgumentException("dataModel must be non null");
}
// Register with the ToolTipManager so that tooltips from the
// renderer show through.
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
toolTipManager.registerComponent(this);
layoutOrientation = VERTICAL;
this.dataModel = dataModel;
selectionModel = createSelectionModel();
setAutoscrolls(true);
setOpaque(true);
updateUI();
}
--->
public JList(ListModel<E> dataModel)
{
if (dataModel == null) {
throw new IllegalArgumentException("dataModel must be non null");
}
// Register with the ToolTipManager so that tooltips from the
// renderer show through.
ToolTipManager toolTipManager = ToolTipManager.sharedInstance();
toolTipManager.registerComponent(this);
layoutOrientation = VERTICAL;
this.dataModel = dataModel;
selectionModel = createSelectionModel();
setAutoscrolls(true);
setOpaque(true);
updateUI();
}
We could define the signature also like this:
public JList(ListModel<? extends E> dataModel)
but then we would have to define the dataModel-field also with:
private ListModel<? extends E> dataModel
as well as the model-property. I don't think this would be a good idea and thus define the signature
as:
public JList(ListModel<E> dataModel)
What do you think?
-Florian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/swing-dev/attachments/20090201/7c416d78/attachment.html>
More information about the swing-dev
mailing list