Added LogPanel to GamePane

This commit is contained in:
Kai S. K. Engelbart 2019-09-09 06:14:37 +02:00
parent 37cf7dcab2
commit 8d23315481
2 changed files with 20 additions and 9 deletions

View File

@ -25,6 +25,7 @@ public class GamePane extends JComponent {
private JButton btnRestart, btnSwapColors; private JButton btnRestart, btnSwapColors;
private BoardPane boardPane; private BoardPane boardPane;
private LogPanel logPanel;
private Game game; private Game game;
private Color activeColor; private Color activeColor;
@ -89,11 +90,14 @@ public class GamePane extends JComponent {
letterPanel.add(letterLabel); letterPanel.add(letterLabel);
} }
// TODO: LogPanel // Initialize LogPanel
// LogPanel logPanel = new LogPanel(game.getBoard().getLog()); logPanel = new LogPanel();
// GridBagConstraints gbc_logPanel = new GridBagConstraints(); GridBagConstraints gbc_logPanel = new GridBagConstraints();
// gbc_logPanel.anchor = GridBagConstraints.EAST;
// add(logPanel, gbc_logPanel); gbc_logPanel.fill = GridBagConstraints.VERTICAL;
gbc_logPanel.gridx = 2;
gbc_logPanel.gridy = 1;
add(logPanel, gbc_logPanel);
} }
/** /**
@ -117,5 +121,6 @@ public class GamePane extends JComponent {
this.game = game; this.game = game;
btnSwapColors.setEnabled(game.getPlayers().get(Color.WHITE) instanceof NaturalPlayer btnSwapColors.setEnabled(game.getPlayers().get(Color.WHITE) instanceof NaturalPlayer
^ game.getPlayers().get(Color.BLACK) instanceof NaturalPlayer); ^ game.getPlayers().get(Color.BLACK) instanceof NaturalPlayer);
logPanel.setLog(game.getBoard().getLog());
} }
} }

View File

@ -36,9 +36,7 @@ public class LogPanel extends JPanel implements Subscribable {
/** /**
* Create the frame. * Create the frame.
*/ */
public LogPanel(Log log) { public LogPanel() {
this.log = log;
setBorder(new EmptyBorder(5, 5, 5, 5)); setBorder(new EmptyBorder(5, 5, 5, 5));
setLayout(new BorderLayout(0, 0)); setLayout(new BorderLayout(0, 0));
@ -47,7 +45,6 @@ public class LogPanel extends JPanel implements Subscribable {
add(new JScrollPane(mtable), BorderLayout.CENTER); add(new JScrollPane(mtable), BorderLayout.CENTER);
EventBus.getInstance().register(this); EventBus.getInstance().register(this);
handle(null);
} }
@Override @Override
@ -57,6 +54,8 @@ public class LogPanel extends JPanel implements Subscribable {
@Override @Override
public void handle(Event<?> event) { public void handle(Event<?> event) {
if (log == null) return;
final List<LoggedMove> moves = log.getLoggedMoves(); final List<LoggedMove> moves = log.getLoggedMoves();
String[][] data = new String[moves.size() / 2 + moves.size() % 2][2]; String[][] data = new String[moves.size() / 2 + moves.size() % 2][2];
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
@ -65,4 +64,11 @@ public class LogPanel extends JPanel implements Subscribable {
} }
mtable.setModel(new DefaultTableModel(data, new String[] { "White", "Black" })); mtable.setModel(new DefaultTableModel(data, new String[] { "White", "Black" }));
} }
public Log getLog() { return log; }
public void setLog(Log log) {
this.log = log;
handle(null);
}
} }