package core.gui; import core.State; import core.StateActionTable; import javax.swing.*; import java.awt.*; import java.util.ArrayList; import java.util.List; import java.util.Map; public class QTableFrame extends JFrame { private JLabel stateCountLabel; private StateActionTable stateActionTable; private List> rows; private JPanel areaWrapper; public QTableFrame(StateActionTable stateActionTable) { super("Q-Table"); this.stateActionTable = stateActionTable; rows = new ArrayList<>(10); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); setLayout(new BorderLayout()); setPreferredSize(new Dimension(500, 500)); stateCountLabel = new JLabel(); add(BorderLayout.NORTH, stateCountLabel); areaWrapper = new JPanel(); areaWrapper.setLayout(new BoxLayout(areaWrapper, BoxLayout.Y_AXIS)); for(int i = 0; i < 10; ++i) { StateActionRow a = new StateActionRow<>(); rows.add(a); areaWrapper.add(a); } add(BorderLayout.CENTER, areaWrapper); setVisible(false); pack(); } private void refreshAllTextAreas(){ for(StateActionRow row : rows){ row.refreshLabels(); } } protected void refreshQTable() { System.out.println("ref"); int stateCount = stateActionTable.getStateCount(); stateCountLabel.setText("Total states: " + stateCount); int idx = -1; for(Map.Entry> entry : stateActionTable.getFirstStateEntriesForView()) { if(++idx > rows.size() -1) break; StateActionRow row = rows.get(idx); row.setState(entry.getKey()); row.setActionValues(entry.getValue()); } refreshAllTextAreas(); } }