From 9059d5ac4d045407d61797b385d175c7e4c70a18 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Fri, 8 Apr 2011 18:04:32 -0700 Subject: [PATCH] JList and ListModel have type parameters. Let's use 'em. (I'll fix the one client that lives in the bowels of Yohoho.) --- .../com/samskivert/swing/CollapsibleList.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/samskivert/swing/CollapsibleList.java b/src/main/java/com/samskivert/swing/CollapsibleList.java index 5b916e4d..b87c90b5 100644 --- a/src/main/java/com/samskivert/swing/CollapsibleList.java +++ b/src/main/java/com/samskivert/swing/CollapsibleList.java @@ -5,6 +5,7 @@ package com.samskivert.swing; +import java.util.List; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; @@ -15,7 +16,7 @@ import javax.swing.ListModel; * can be collapsed. Each section of a list uses a {@link JList} instance * to render the section elements. */ -public class CollapsibleList extends JPanel +public class CollapsibleList extends JPanel { /** * Constructs an empty collapsible list. @@ -31,15 +32,14 @@ public class CollapsibleList extends JPanel } /** - * Constructs a collapsible list with the supplied section labels and - * models. + * Constructs a collapsible list with the supplied section labels and models. */ - public CollapsibleList (String[] sections, ListModel[] models) + public CollapsibleList (List sections, List> models) { this(); // set up our layout manager - for (int i = 0; i < sections.length; i++) { - addSection(sections[i], models[i]); + for (int ii = 0, ll = sections.size(); ii < ll; ii++) { + addSection(sections.get(ii), models.get(ii)); } } @@ -59,10 +59,10 @@ public class CollapsibleList extends JPanel * * @return the index of the newly added section. */ - public int addSection (String label, ListModel model) + public int addSection (String label, ListModel model) { add(new JLabel(label)); - add(new JList(model)); + add(new JList(model)); return getSectionCount()-1; } @@ -78,9 +78,10 @@ public class CollapsibleList extends JPanel /** * Returns the list object associated with the specified section. */ - public JList getSectionList (int index) + public JList getSectionList (int index) { - return (JList)getComponent(index*2+1); + @SuppressWarnings("unchecked") JList list = (JList)getComponent(index*2+1); + return list; } /** @@ -88,7 +89,7 @@ public class CollapsibleList extends JPanel */ public void toggleCollapsed (int index) { - JList list = getSectionList(index); + JList list = getSectionList(index); list.setVisible(!list.isVisible()); } }