01: package org.conform.wings.editor;
02:
03: import java.util.HashSet;
04: import java.util.Set;
05:
06: import javax.swing.event.ChangeEvent;
07: import javax.swing.event.ChangeListener;
08: import javax.swing.event.EventListenerList;
09:
10: public class DefaultSubSetModel implements SubSetModel {
11: Set wholeSet;
12: Set includedSubSet;
13: EventListenerList listeners = new EventListenerList();
14:
15: public Set getWholeSet() {
16: return wholeSet;
17: }
18:
19: public void setWholeSet(Set wholeSet) {
20: this .wholeSet = wholeSet;
21: fireChange();
22: }
23:
24: public Set getIncludedSubSet() {
25: return includedSubSet;
26: }
27:
28: public void setIncludedSubSet(Set includedSubSet) {
29: this .includedSubSet = includedSubSet;
30: fireChange();
31: }
32:
33: public Set getExcludedSubSet() {
34: Set excludedSet = new HashSet();
35: excludedSet.addAll(wholeSet);
36: excludedSet.removeAll(includedSubSet);
37: return excludedSet;
38: }
39:
40: public void setExcludedSubSet(Set excludedSet) {
41: includedSubSet = new HashSet();
42: includedSubSet.addAll(wholeSet);
43: includedSubSet.removeAll(excludedSet);
44: }
45:
46: public void include(Object object) {
47: includedSubSet.add(object);
48: fireChange();
49: }
50:
51: public void exclude(Object object) {
52: includedSubSet.remove(object);
53: fireChange();
54: }
55:
56: public boolean isIncluded(Object object) {
57: return includedSubSet.contains(object);
58: }
59:
60: public boolean isExcluded(Object object) {
61: return !isIncluded(object);
62: }
63:
64: protected void fireChange() {
65: ChangeEvent event = new ChangeEvent(this );
66: Object[] listeners = this .listeners
67: .getListeners(ChangeListener.class);
68: for (int i = 0; i < listeners.length; i++) {
69: ChangeListener listener = (ChangeListener) listeners[i];
70: listener.stateChanged(event);
71: }
72: }
73:
74: public void addChangeListener(ChangeListener listener) {
75: listeners.add(ChangeListener.class, listener);
76: }
77:
78: public void removeChangeListener(ChangeListener listener) {
79: listeners.remove(ChangeListener.class, listener);
80: }
81: }
|