[1] | 1 | package genius.gui.tournament;
|
---|
| 2 |
|
---|
| 3 | import java.awt.BorderLayout;
|
---|
| 4 | import java.awt.event.ActionEvent;
|
---|
| 5 | import java.awt.event.ActionListener;
|
---|
| 6 |
|
---|
| 7 | import javax.swing.JButton;
|
---|
| 8 | import javax.swing.JFrame;
|
---|
| 9 | import javax.swing.event.ChangeEvent;
|
---|
| 10 | import javax.swing.event.ChangeListener;
|
---|
| 11 |
|
---|
| 12 | import genius.core.config.MultilateralTournamentConfiguration;
|
---|
| 13 | import genius.core.listener.Listener;
|
---|
| 14 | import genius.core.repository.MultiPartyProtocolRepItem;
|
---|
| 15 | import genius.core.repository.PartyRepItem;
|
---|
| 16 | import genius.gui.deadline.DeadlinePanel;
|
---|
| 17 | import genius.gui.panels.CheckboxPanel;
|
---|
| 18 | import genius.gui.panels.ComboboxSelectionPanel;
|
---|
| 19 | import genius.gui.panels.SpinnerPanel;
|
---|
| 20 | import genius.gui.panels.VflowPanelWithBorder;
|
---|
| 21 | import 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")
|
---|
| 35 | public 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() {
|
---|
[8] | 51 | ComboboxSelectionPanel<MultiPartyProtocolRepItem> protocolcomb = new ComboboxSelectionPanel<>(
|
---|
| 52 | "Protocol", model.getProtocolModel());
|
---|
[1] | 53 | protocolcomb.setCellRenderer(new RepItemListCellRenderer());
|
---|
[8] | 54 | ComboboxSelectionPanel<PartyRepItem> mediatorcomb = new ComboboxSelectionPanel<>(
|
---|
| 55 | "Mediator", model.getMediatorModel());
|
---|
[1] | 56 | mediatorcomb.setCellRenderer(new RepItemListCellRenderer());
|
---|
| 57 |
|
---|
| 58 | add(protocolcomb);
|
---|
| 59 | add(new DeadlinePanel(model.getDeadlineModel()));
|
---|
[8] | 60 | add(new SpinnerPanel("Nr. Tournaments",
|
---|
| 61 | model.getNumTournamentsModel()));
|
---|
| 62 | add(new SpinnerPanel("Agents per Session",
|
---|
| 63 | model.getNumAgentsPerSessionModel()));
|
---|
| 64 | add(new CheckboxPanel("Agent Repetition",
|
---|
| 65 | model.getAgentRepetitionModel()));
|
---|
| 66 | add(new CheckboxPanel("Randomize session order",
|
---|
| 67 | model.getRandomSessionOrderModel()));
|
---|
| 68 | add(new CheckboxPanel("Enable System.out print",
|
---|
| 69 | model.getEnablePrint()));
|
---|
| 70 | add(new ComboboxSelectionPanel<>("Data persistency",
|
---|
| 71 | model.getPersistentDatatypeModel()));
|
---|
[1] | 72 |
|
---|
| 73 | add(mediatorcomb);
|
---|
| 74 |
|
---|
[8] | 75 | add(new PartiesAndProfilesPanel(model.getPartyModel(),
|
---|
| 76 | model.getProfileModel()));
|
---|
[1] | 77 |
|
---|
[8] | 78 | biOptionsPanel = new BilateralOptionsPanel(
|
---|
| 79 | model.getBilateralOptionsModel());
|
---|
[1] | 80 | add(biOptionsPanel);
|
---|
| 81 |
|
---|
| 82 | add(start);
|
---|
| 83 | start.addActionListener(new ActionListener() {
|
---|
| 84 | @Override
|
---|
| 85 | public void actionPerformed(ActionEvent e) {
|
---|
| 86 | model.modelIsComplete();
|
---|
| 87 | }
|
---|
| 88 | });
|
---|
| 89 |
|
---|
[8] | 90 | model.getNumAgentsPerSessionModel()
|
---|
| 91 | .addChangeListener(new ChangeListener() {
|
---|
| 92 | @Override
|
---|
| 93 | public void stateChanged(ChangeEvent e) {
|
---|
| 94 | updateBipanelVisibility();
|
---|
| 95 | }
|
---|
[1] | 96 |
|
---|
[8] | 97 | });
|
---|
[1] | 98 | updateBipanelVisibility();
|
---|
| 99 |
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | private void updateBipanelVisibility() {
|
---|
[8] | 103 | biOptionsPanel.setVisible(
|
---|
| 104 | (Integer) model.getNumAgentsPerSessionModel().getValue() == 2);
|
---|
[1] | 105 | }
|
---|
| 106 |
|
---|
| 107 | /**
|
---|
| 108 | * simple stub to run this stand-alone (for testing).
|
---|
| 109 | *
|
---|
| 110 | * @param args
|
---|
| 111 | */
|
---|
| 112 | public static void main(String[] args) {
|
---|
| 113 | final JFrame gui = new JFrame();
|
---|
| 114 | gui.setLayout(new BorderLayout());
|
---|
| 115 | MultiTournamentModel model = new MultiTournamentModel();
|
---|
[8] | 116 | gui.getContentPane().add(new MultiTournamentSettingsPanel(model),
|
---|
| 117 | BorderLayout.CENTER);
|
---|
[1] | 118 | gui.pack();
|
---|
| 119 | gui.setVisible(true);
|
---|
| 120 |
|
---|
| 121 | model.addListener(new Listener<MultilateralTournamentConfiguration>() {
|
---|
| 122 |
|
---|
| 123 | @Override
|
---|
| 124 | public void notifyChange(MultilateralTournamentConfiguration data) {
|
---|
| 125 | System.out.println("done, with " + data);
|
---|
| 126 | gui.setVisible(false);
|
---|
| 127 | }
|
---|
| 128 | });
|
---|
| 129 | }
|
---|
| 130 | }
|
---|