1 | package genius.gui.tournamentvars;
|
---|
2 |
|
---|
3 | import java.awt.Frame;
|
---|
4 | import java.awt.Panel;
|
---|
5 | import java.util.ArrayList;
|
---|
6 |
|
---|
7 | import javax.swing.BoxLayout;
|
---|
8 | import javax.swing.ButtonGroup;
|
---|
9 | import javax.swing.JRadioButton;
|
---|
10 |
|
---|
11 | import genius.core.repository.ProtocolRepItem;
|
---|
12 | import genius.core.repository.Repository;
|
---|
13 | import genius.core.repository.RepositoryFactory;
|
---|
14 | import genius.gui.panels.DefaultOKCancelDialog;
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Open a UI and negotiate with user about which agents to use in tournament.
|
---|
18 | *
|
---|
19 | * @author wouter
|
---|
20 | *
|
---|
21 | */
|
---|
22 | public class ProtocolVarUI extends DefaultOKCancelDialog {
|
---|
23 |
|
---|
24 | private static final long serialVersionUID = -6106919299675060907L;
|
---|
25 | ArrayList<ProtocolRadioButton> radioButtons; // copy of what's in the panel,
|
---|
26 | // for easy check-out.
|
---|
27 |
|
---|
28 | public ProtocolVarUI(Frame owner) {
|
---|
29 | super(owner, "Protocol Variable Selector");
|
---|
30 |
|
---|
31 | }
|
---|
32 |
|
---|
33 | public Panel getPanel() {
|
---|
34 | radioButtons = new ArrayList<ProtocolRadioButton>();
|
---|
35 | Panel protocolList = new Panel();
|
---|
36 | protocolList.setLayout(new BoxLayout(protocolList, BoxLayout.Y_AXIS));
|
---|
37 | ButtonGroup group = new ButtonGroup();
|
---|
38 |
|
---|
39 | Repository<ProtocolRepItem> protocolRep = RepositoryFactory.getProtocolRepository();
|
---|
40 | for (ProtocolRepItem agt : protocolRep.getItems()) {
|
---|
41 | ProtocolRadioButton cbox = new ProtocolRadioButton((ProtocolRepItem) agt);
|
---|
42 | radioButtons.add(cbox);
|
---|
43 | protocolList.add(cbox);
|
---|
44 | cbox.setSelected(true);
|
---|
45 | group.add(cbox);
|
---|
46 | }
|
---|
47 | return protocolList;
|
---|
48 | }
|
---|
49 |
|
---|
50 | public Object ok() {
|
---|
51 | ArrayList<ProtocolRepItem> result = new ArrayList<ProtocolRepItem>();
|
---|
52 | for (ProtocolRadioButton cbox : radioButtons) {
|
---|
53 | if (cbox.isSelected())
|
---|
54 | result.add(cbox.protocolRepItem);
|
---|
55 | }
|
---|
56 | return result;
|
---|
57 | }
|
---|
58 | }
|
---|
59 |
|
---|
60 | class ProtocolRadioButton extends JRadioButton {
|
---|
61 | public ProtocolRepItem protocolRepItem;
|
---|
62 |
|
---|
63 | public ProtocolRadioButton(ProtocolRepItem protocolRepItem) {
|
---|
64 | super("" + protocolRepItem.getName());
|
---|
65 | this.protocolRepItem = protocolRepItem;
|
---|
66 | }
|
---|
67 | } |
---|