source: src/main/java/genius/gui/panels/ListModelAdapter.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 863 bytes
Line 
1package genius.gui.panels;
2
3import javax.swing.ListModel;
4import javax.swing.event.ListDataListener;
5
6/**
7 * Adapter to map {@link SubsetSelectionModel} to {@link ListModel}
8 *
9 * @param <ItemType>
10 */
11public class ListModelAdapter<ItemType> implements ListModel<ItemType> {
12
13 private SubsetSelectionModel<ItemType> model;
14
15 public ListModelAdapter(SubsetSelectionModel<ItemType> model) {
16 this.model = model;
17 }
18
19 @Override
20 public int getSize() {
21 return model.getAllItems().size();
22 }
23
24 @Override
25 public ItemType getElementAt(int index) {
26 return model.getAllItems().get(index);
27 }
28
29 @Override
30 public void addListDataListener(ListDataListener l) {
31 model.addListener(new ListDataListenerAdapter<ItemType>(l));
32 }
33
34 @Override
35 public void removeListDataListener(ListDataListener l) {
36 model.removeListener(new ListDataListenerAdapter<ItemType>(l));
37 }
38
39}
Note: See TracBrowser for help on using the repository browser.