[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 |
|
---|
| 10 | import genius.core.config.MultilateralTournamentConfiguration;
|
---|
| 11 | import genius.core.listener.Listener;
|
---|
| 12 | import genius.core.repository.MultiPartyProtocolRepItem;
|
---|
| 13 | import genius.core.repository.PartyRepItem;
|
---|
| 14 | import genius.gui.deadline.DeadlinePanel;
|
---|
| 15 | import genius.gui.panels.CheckboxPanel;
|
---|
| 16 | import genius.gui.panels.ComboboxSelectionPanel;
|
---|
| 17 | import genius.gui.panels.SpinnerPanel;
|
---|
| 18 | import genius.gui.panels.VflowPanelWithBorder;
|
---|
| 19 | import 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")
|
---|
| 33 | public 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() {
|
---|
[8] | 49 | ComboboxSelectionPanel<MultiPartyProtocolRepItem> protocolcomb = new ComboboxSelectionPanel<>(
|
---|
| 50 | "Protocol", model.getProtocolModel());
|
---|
[1] | 51 | protocolcomb.setCellRenderer(new RepItemListCellRenderer());
|
---|
[8] | 52 | ComboboxSelectionPanel<PartyRepItem> mediatorcomb = new ComboboxSelectionPanel<>(
|
---|
| 53 | "Mediator", model.getMediatorModel());
|
---|
[1] | 54 | mediatorcomb.setCellRenderer(new RepItemListCellRenderer());
|
---|
| 55 |
|
---|
| 56 | add(protocolcomb);
|
---|
| 57 | add(new DeadlinePanel(model.getDeadlineModel()));
|
---|
[8] | 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()));
|
---|
[1] | 70 |
|
---|
| 71 | add(mediatorcomb);
|
---|
| 72 |
|
---|
[8] | 73 | add(new PartiesAndProfilesPanel(model.getPartyModel(),
|
---|
| 74 | model.getProfileModel()));
|
---|
[1] | 75 |
|
---|
[8] | 76 | biOptionsPanel = new BilateralOptionsPanel(
|
---|
| 77 | model.getBilateralOptionsModel());
|
---|
[1] | 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 |
|
---|
[139] | 88 | model.getNumAgentsPerSessionModel().addListener(new Listener<Number>() {
|
---|
| 89 | @Override
|
---|
| 90 | public void notifyChange(Number e) {
|
---|
| 91 | updateBipanelVisibility();
|
---|
| 92 | }
|
---|
| 93 | });
|
---|
[1] | 94 | updateBipanelVisibility();
|
---|
| 95 |
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | private void updateBipanelVisibility() {
|
---|
[8] | 99 | biOptionsPanel.setVisible(
|
---|
[139] | 100 | model.getNumAgentsPerSessionModel().getValue().intValue() == 2);
|
---|
[1] | 101 | }
|
---|
| 102 |
|
---|
| 103 | /**
|
---|
| 104 | * simple stub to run this stand-alone (for testing).
|
---|
| 105 | *
|
---|
| 106 | * @param args
|
---|
| 107 | */
|
---|
| 108 | public static void main(String[] args) {
|
---|
| 109 | final JFrame gui = new JFrame();
|
---|
| 110 | gui.setLayout(new BorderLayout());
|
---|
| 111 | MultiTournamentModel model = new MultiTournamentModel();
|
---|
[8] | 112 | gui.getContentPane().add(new MultiTournamentSettingsPanel(model),
|
---|
| 113 | BorderLayout.CENTER);
|
---|
[1] | 114 | gui.pack();
|
---|
| 115 | gui.setVisible(true);
|
---|
| 116 |
|
---|
| 117 | model.addListener(new Listener<MultilateralTournamentConfiguration>() {
|
---|
| 118 |
|
---|
| 119 | @Override
|
---|
| 120 | public void notifyChange(MultilateralTournamentConfiguration data) {
|
---|
| 121 | System.out.println("done, with " + data);
|
---|
| 122 | gui.setVisible(false);
|
---|
| 123 | }
|
---|
| 124 | });
|
---|
| 125 | }
|
---|
| 126 | }
|
---|