1 | package genius.gui.boaparties;
|
---|
2 |
|
---|
3 | import java.awt.BorderLayout;
|
---|
4 | import java.awt.GridLayout;
|
---|
5 |
|
---|
6 | import javax.swing.JOptionPane;
|
---|
7 | import javax.swing.JPanel;
|
---|
8 |
|
---|
9 | import genius.core.boaframework.AcceptanceStrategy;
|
---|
10 | import genius.core.boaframework.BOA;
|
---|
11 | import genius.core.boaframework.OMStrategy;
|
---|
12 | import genius.core.boaframework.OfferingStrategy;
|
---|
13 | import genius.core.boaframework.OpponentModel;
|
---|
14 | import genius.core.exceptions.InstantiateException;
|
---|
15 | import genius.core.repository.boa.BoaPartyRepItem;
|
---|
16 | import genius.core.repository.boa.BoaRepItem;
|
---|
17 | import genius.core.repository.boa.BoaWithSettingsRepItem;
|
---|
18 | import genius.core.repository.boa.ParameterList;
|
---|
19 | import genius.gui.panels.LabelAndComponent;
|
---|
20 | import genius.gui.panels.TextPanel;
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * panel that allows user to set properties that will later be used to generate
|
---|
24 | * {@link BoaPartyRepItem}s.
|
---|
25 | */
|
---|
26 | @SuppressWarnings("serial")
|
---|
27 | public class BoaPartyPanel extends JPanel {
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * show panel that edits the given BoaPartyModel
|
---|
31 | *
|
---|
32 | * @param model
|
---|
33 | * the {@link BoaPartyModel} to edit.
|
---|
34 | */
|
---|
35 | public BoaPartyPanel(BoaPartyModel model) {
|
---|
36 | setLayout(new BorderLayout());
|
---|
37 |
|
---|
38 | add(new LabelAndComponent("Name", new TextPanel(model.getNameModel())), BorderLayout.NORTH);
|
---|
39 |
|
---|
40 | JPanel strategies = new JPanel(new GridLayout(2, 2, 40, 50));
|
---|
41 | strategies.add(new BoaComponentPanel<>(model.getOfferingModel(), "Bidding Strategy"));
|
---|
42 | strategies.add(new BoaComponentPanel<>(model.getAcceptanceModel(), "Acceptance Strategy"));
|
---|
43 | strategies.add(new BoaComponentPanel<>(model.getOpponentModel(), "Opponent Model"));
|
---|
44 | strategies.add(new BoaComponentPanel<>(model.getOmStrategiesModel(), "Opponent Model Strategy"));
|
---|
45 | add(strategies, BorderLayout.CENTER);
|
---|
46 |
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Test function.
|
---|
51 | *
|
---|
52 | * @param args
|
---|
53 | * @throws InstantiateException
|
---|
54 | */
|
---|
55 | public static void main(String[] args) throws InstantiateException {
|
---|
56 |
|
---|
57 | // make specific settings, to check the proper value is selected
|
---|
58 | BoaWithSettingsRepItem<OfferingStrategy> boa1 = makeSettings("resources.boa.Offering2");
|
---|
59 | BoaWithSettingsRepItem<AcceptanceStrategy> boa2 = makeSettings("resources.boa.Acceptance2");
|
---|
60 | BoaWithSettingsRepItem<OpponentModel> boa3 = makeSettings("resources.boa.OpponentModel1");
|
---|
61 | BoaWithSettingsRepItem<OMStrategy> boa4 = makeSettings("resources.boa.OMStrategy1");
|
---|
62 | BoaPartyRepItem partyitem = new BoaPartyRepItem("test party", boa1, boa2, boa3, boa4);
|
---|
63 | BoaPartyModel model = new BoaPartyModel(partyitem);
|
---|
64 |
|
---|
65 | int result = JOptionPane.showConfirmDialog(null, new BoaPartyPanel(model), "test model",
|
---|
66 | JOptionPane.OK_CANCEL_OPTION);
|
---|
67 | System.out.println("result=" + result + ":" + model);
|
---|
68 | }
|
---|
69 |
|
---|
70 | // for testing
|
---|
71 | private static <T extends BOA> BoaWithSettingsRepItem<T> makeSettings(String classname) {
|
---|
72 | BoaRepItem<T> item = new BoaRepItem<T>(classname);
|
---|
73 | ParameterList parameters = new ParameterList();
|
---|
74 | return new BoaWithSettingsRepItem<T>(item, parameters);
|
---|
75 | }
|
---|
76 |
|
---|
77 | }
|
---|