package genius.gui.panels; import java.util.ArrayList; import java.util.List; import genius.core.listener.DefaultListenable; /** * A model for a list of Objects of given ItemType where the user can select a * subset. Used for {@link SubsetSelectionPanel}. We use {@link List} here so * that the order of the elements will not change (this might screw up AWT). * * @param * the type of item that this model contains. */ public class SubsetSelectionModel extends DefaultListenable { /** * All available items that can be chosen */ private List allItems; private List selectedItems; public SubsetSelectionModel(List allItems) { setAllItems(allItems); } public void setAllItems(List allItems) { this.allItems = allItems; clear(); } /** * @param items * the new selection */ public void select(List items) { // we might check if the selection is actually subset of allItems... selectedItems = items; notifyChange(null); } /** * Clear the selection */ public void clear() { select(new ArrayList()); } /** * Remove items from the selection * * @param items */ public void remove(List items) { selectedItems.removeAll(items); notifyChange(null); } public List getAllItems() { return allItems; } public List getSelectedItems() { return selectedItems; } }