source: src/main/java/genius/gui/tournament/MultiTournamentSettingsPanel.java@ 127

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

#28 fixed listener structures. Added Lockable interface, boolean model and integer model are now lockable. Slider now reflects state of lockable. Added test for that.

File size: 3.8 KB
Line 
1package genius.gui.tournament;
2
3import java.awt.BorderLayout;
4import java.awt.event.ActionEvent;
5import java.awt.event.ActionListener;
6
7import javax.swing.JButton;
8import javax.swing.JFrame;
9
10import genius.core.config.MultilateralTournamentConfiguration;
11import genius.core.listener.Listener;
12import genius.core.repository.MultiPartyProtocolRepItem;
13import genius.core.repository.PartyRepItem;
14import genius.gui.deadline.DeadlinePanel;
15import genius.gui.panels.CheckboxPanel;
16import genius.gui.panels.ComboboxSelectionPanel;
17import genius.gui.panels.SpinnerPanel;
18import genius.gui.panels.VflowPanelWithBorder;
19import genius.gui.renderer.RepItemListCellRenderer;
20
21/**
22 * This is the user interface for the multilateral tournament and replaces the
23 * old MultiTournamentUI.
24 * <p/>
25 * The configuration of this user interface is stored in the
26 * {@link MultilateralTournamentConfiguration} variable, which is also used by
27 * the tournament manager to run the tournaments.
28 *
29 * @author W.Pasman
30 *
31 */
32@SuppressWarnings("serial")
33public class MultiTournamentSettingsPanel extends VflowPanelWithBorder {
34
35 private MultiTournamentModel model;
36 private JButton start = new JButton("Start Tournament");
37 private BilateralOptionsPanel biOptionsPanel;
38
39 public MultiTournamentSettingsPanel(MultiTournamentModel model) {
40 super("Multilateral negotiation Tournament Setup");
41 this.model = model;
42 initPanel();
43 }
44
45 /**
46 * Load and set all the panel elements - buttons, comboboxes, etc.
47 */
48 private void initPanel() {
49 ComboboxSelectionPanel<MultiPartyProtocolRepItem> protocolcomb = new ComboboxSelectionPanel<>(
50 "Protocol", model.getProtocolModel());
51 protocolcomb.setCellRenderer(new RepItemListCellRenderer());
52 ComboboxSelectionPanel<PartyRepItem> mediatorcomb = new ComboboxSelectionPanel<>(
53 "Mediator", model.getMediatorModel());
54 mediatorcomb.setCellRenderer(new RepItemListCellRenderer());
55
56 add(protocolcomb);
57 add(new DeadlinePanel(model.getDeadlineModel()));
58 add(new SpinnerPanel("Nr. Tournaments",
59 model.getNumTournamentsModel()));
60 add(new SpinnerPanel("Agents per Session",
61 model.getNumAgentsPerSessionModel()));
62 add(new CheckboxPanel("Agent Repetition",
63 model.getAgentRepetitionModel()));
64 add(new CheckboxPanel("Randomize session order",
65 model.getRandomSessionOrderModel()));
66 add(new CheckboxPanel("Enable System.out print",
67 model.getEnablePrint()));
68 add(new ComboboxSelectionPanel<>("Data persistency",
69 model.getPersistentDatatypeModel()));
70
71 add(mediatorcomb);
72
73 add(new PartiesAndProfilesPanel(model.getPartyModel(),
74 model.getProfileModel()));
75
76 biOptionsPanel = new BilateralOptionsPanel(
77 model.getBilateralOptionsModel());
78 add(biOptionsPanel);
79
80 add(start);
81 start.addActionListener(new ActionListener() {
82 @Override
83 public void actionPerformed(ActionEvent e) {
84 model.modelIsComplete();
85 }
86 });
87
88 model.getNumAgentsPerSessionModel()
89 .addListener(new Listener<Integer>() {
90 @Override
91 public void notifyChange(Integer e) {
92 updateBipanelVisibility();
93 }
94 });
95 updateBipanelVisibility();
96
97 }
98
99 private void updateBipanelVisibility() {
100 biOptionsPanel.setVisible(
101 model.getNumAgentsPerSessionModel().getValue() == 2);
102 }
103
104 /**
105 * simple stub to run this stand-alone (for testing).
106 *
107 * @param args
108 */
109 public static void main(String[] args) {
110 final JFrame gui = new JFrame();
111 gui.setLayout(new BorderLayout());
112 MultiTournamentModel model = new MultiTournamentModel();
113 gui.getContentPane().add(new MultiTournamentSettingsPanel(model),
114 BorderLayout.CENTER);
115 gui.pack();
116 gui.setVisible(true);
117
118 model.addListener(new Listener<MultilateralTournamentConfiguration>() {
119
120 @Override
121 public void notifyChange(MultilateralTournamentConfiguration data) {
122 System.out.println("done, with " + data);
123 gui.setVisible(false);
124 }
125 });
126 }
127}
Note: See TracBrowser for help on using the repository browser.