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

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

Initial import : Genius 9.0.0

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