/** * Create a listenable list that will dynamically reflect the contents of the source listenable collection.<br> * This is useful for instance when you want to put the contents of a set in a swing JList (then use new JList(new ListenableListModel(ListenableCollections.asList(yourSet)))). * @param <T> type of the elements of the collection * @param source collection that is to be adapted to a listenable list * @return source if it is already a listenable list, otherwise a new listenable list that is two-ways bound to the source collection. */ public static <T> ListenableList<T> asList(ListenableCollection<T> source) { if (source instanceof ListenableList<?>) return (ListenableList<T>)source; ListenableList<T> out = new DefaultListenableList<T>(new ArrayList<T>(source)); bind(source, out); return out; }