source: src/main/java/genius/gui/tournament/BilateralOptionsModel.java@ 230

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

Initial import : Genius 9.0.0

File size: 2.5 KB
Line 
1package genius.gui.tournament;
2
3import java.util.ArrayList;
4
5import javax.swing.event.ListDataEvent;
6import javax.swing.event.ListDataListener;
7
8import genius.core.listener.DefaultListenable;
9import genius.core.repository.MultiPartyProtocolRepItem;
10import genius.core.repository.ParticipantRepItem;
11import genius.core.repository.ProfileRepItem;
12import genius.gui.negosession.ContentProxy;
13import genius.gui.panels.BooleanModel;
14import genius.gui.panels.SingleSelectionModel;
15import genius.gui.panels.SubsetSelectionModel;
16
17/**
18 * Stores special options that apply when there are exactly 2 agents per
19 * session.
20 */
21public class BilateralOptionsModel extends DefaultListenable<BilateralOptionsModel> {
22
23 private BooleanModel playBothSides = new BooleanModel(true);
24
25 private final SubsetSelectionModel<ProfileRepItem> profileModelB;
26 private final SubsetSelectionModel<ParticipantRepItem> partyModelB;
27
28 // not owned by us, just for getting notified.
29 private SingleSelectionModel<MultiPartyProtocolRepItem> protocolModel;
30
31 public BilateralOptionsModel(SingleSelectionModel<MultiPartyProtocolRepItem> protocolModel) {
32 this.protocolModel = protocolModel;
33 profileModelB = new SubsetSelectionModel<ProfileRepItem>(ContentProxy.fetchProfiles());
34
35 partyModelB = new SubsetSelectionModel<>(new ArrayList<ParticipantRepItem>());
36 updateSubmodels();
37
38 protocolModel.addListDataListener(new ListDataListener() {
39
40 @Override
41 public void intervalRemoved(ListDataEvent e) {
42 // ignore, added will be called as well.
43 }
44
45 @Override
46 public void intervalAdded(ListDataEvent e) {
47 updateSubmodels();
48 }
49
50 @Override
51 public void contentsChanged(ListDataEvent e) {
52 updateSubmodels();
53 }
54 });
55
56 }
57
58 /**
59 * @return boolean model. true if selected agents play on both sides. If
60 * false, parties for both sides can be selected explicitly. Note
61 * that it depends on the protocol what "both sides" means.
62 */
63 public BooleanModel getPlayBothSides() {
64 return playBothSides;
65 }
66
67 /**
68 *
69 * @return the side B profile model
70 */
71 public SubsetSelectionModel<ProfileRepItem> getProfileModelB() {
72 return profileModelB;
73 }
74
75 /**
76 *
77 * @return the side B party model.
78 */
79 public SubsetSelectionModel<ParticipantRepItem> getPartyModelB() {
80 return partyModelB;
81 }
82
83 /**
84 * Update the models after a protocol change.
85 *
86 * @param protocol
87 * the new protocol.
88 */
89 private void updateSubmodels() {
90 MultiPartyProtocolRepItem protocol = protocolModel.getSelection();
91 partyModelB.setAllItems(ContentProxy.fetchPartiesForProtocol(protocol));
92 }
93
94}
Note: See TracBrowser for help on using the repository browser.