source: src/main/java/genius/gui/boaparties/BoaPartiesModel.java

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

Initial import : Genius 9.0.0

File size: 2.6 KB
Line 
1package genius.gui.boaparties;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import javax.swing.event.TableModelListener;
7import javax.swing.table.TableModel;
8
9import genius.core.boaframework.BOA;
10import genius.core.boaframework.BoaType;
11import genius.core.listener.Listener;
12import genius.core.repository.BoaPartyRepository;
13import genius.core.repository.RepositoryFactory;
14import genius.core.repository.boa.BoaPartyRepItem;
15import genius.core.repository.boa.BoaWithSettingsRepItem;
16
17/**
18 * Adapts the BoaPartyRepository to a tablemodel
19 *
20 */
21public class BoaPartiesModel implements TableModel {
22 private BoaPartyRepository repo;
23 private List<TableModelListener> listeners = new ArrayList<>();
24
25 private final static String columns[] = { "Name", BoaType.BIDDINGSTRATEGY.toString(),
26 BoaType.ACCEPTANCESTRATEGY.toString(), BoaType.OPPONENTMODEL.toString(), BoaType.OMSTRATEGY.toString() };
27
28 public BoaPartiesModel() {
29 repo = RepositoryFactory.getBoaPartyRepository();
30 repo.addListener(new Listener<BoaPartyRepItem>() {
31 @Override
32 public void notifyChange(BoaPartyRepItem data) {
33 for (TableModelListener listener : listeners) {
34 listener.tableChanged(null); // CHECK is this ok?
35 }
36 }
37 });
38 }
39
40 @Override
41 public int getRowCount() {
42 return repo.getList().getList().size();
43 }
44
45 @Override
46 public int getColumnCount() {
47 return columns.length;
48 }
49
50 @Override
51 public String getColumnName(int columnIndex) {
52 return columns[columnIndex];
53 }
54
55 @Override
56 public Class<?> getColumnClass(int columnIndex) {
57 return String.class;
58 }
59
60 @Override
61 public boolean isCellEditable(int rowIndex, int columnIndex) {
62 return false;
63 }
64
65 @Override
66 public Object getValueAt(int rowIndex, int columnIndex) {
67 BoaPartyRepItem boaparty = repo.getList().getList().get(rowIndex);
68 switch (columnIndex) {
69 case 0:
70 return boaparty.getName();
71 case 1:
72 return strategyString(boaparty, BoaType.BIDDINGSTRATEGY);
73 case 2:
74 return strategyString(boaparty, BoaType.ACCEPTANCESTRATEGY);
75 case 3:
76 return strategyString(boaparty, BoaType.OPPONENTMODEL);
77 case 4:
78 return strategyString(boaparty, BoaType.OMSTRATEGY);
79 }
80 return "-";
81 }
82
83 private String strategyString(BoaPartyRepItem boaparty, BoaType strategyType) {
84 BoaWithSettingsRepItem<? extends BOA> strategy = boaparty.getStrategy(strategyType);
85 return strategy.getBoa().getName() + strategy.getParameters();
86 }
87
88 @Override
89 public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
90
91 }
92
93 @Override
94 public void addTableModelListener(TableModelListener l) {
95 listeners.add(l);
96 }
97
98 @Override
99 public void removeTableModelListener(TableModelListener l) {
100 listeners.remove(l);
101
102 }
103}
Note: See TracBrowser for help on using the repository browser.