source: src/main/java/genius/gui/panels/SubsetSelectionModel.java@ 346

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

Initial import : Genius 9.0.0

File size: 1.4 KB
Line 
1package genius.gui.panels;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.listener.DefaultListenable;
7
8/**
9 * A model for a list of Objects of given ItemType where the user can select a
10 * subset. Used for {@link SubsetSelectionPanel}. We use {@link List} here so
11 * that the order of the elements will not change (this might screw up AWT).
12 *
13 * @param <ItemType>
14 * the type of item that this model contains.
15 */
16public class SubsetSelectionModel<ItemType> extends DefaultListenable<ItemType> {
17 /**
18 * All available items that can be chosen
19 */
20 private List<ItemType> allItems;
21 private List<ItemType> selectedItems;
22
23 public SubsetSelectionModel(List<ItemType> allItems) {
24 setAllItems(allItems);
25 }
26
27 public void setAllItems(List<ItemType> allItems) {
28 this.allItems = allItems;
29 clear();
30 }
31
32 /**
33 * @param items
34 * the new selection
35 */
36 public void select(List<ItemType> items) {
37 // we might check if the selection is actually subset of allItems...
38 selectedItems = items;
39 notifyChange(null);
40 }
41
42 /**
43 * Clear the selection
44 */
45 public void clear() {
46 select(new ArrayList<ItemType>());
47 }
48
49 /**
50 * Remove items from the selection
51 *
52 * @param items
53 */
54 public void remove(List<ItemType> items) {
55 selectedItems.removeAll(items);
56 notifyChange(null);
57 }
58
59 public List<ItemType> getAllItems() {
60 return allItems;
61 }
62
63 public List<ItemType> getSelectedItems() {
64 return selectedItems;
65 }
66
67}
Note: See TracBrowser for help on using the repository browser.