source: src/main/java/genius/gui/tournamentvars/ProtocolVarUI.java@ 84

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

Initial import : Genius 9.0.0

File size: 1.9 KB
Line 
1package genius.gui.tournamentvars;
2
3import java.awt.Frame;
4import java.awt.Panel;
5import java.util.ArrayList;
6
7import javax.swing.BoxLayout;
8import javax.swing.ButtonGroup;
9import javax.swing.JRadioButton;
10
11import genius.core.repository.ProtocolRepItem;
12import genius.core.repository.Repository;
13import genius.core.repository.RepositoryFactory;
14import 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 */
22public 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
60class ProtocolRadioButton extends JRadioButton {
61 public ProtocolRepItem protocolRepItem;
62
63 public ProtocolRadioButton(ProtocolRepItem protocolRepItem) {
64 super("" + protocolRepItem.getName());
65 this.protocolRepItem = protocolRepItem;
66 }
67}
Note: See TracBrowser for help on using the repository browser.