From 18e708d2855950b2ae95e650c74bda4be9b7ebe8 Mon Sep 17 00:00:00 2001 From: kske Date: Mon, 9 Sep 2019 06:14:37 +0200 Subject: [PATCH] Added LogPanel to GamePane --- src/dev/kske/chess/ui/GamePane.java | 15 ++++++++++----- src/dev/kske/chess/ui/LogPanel.java | 14 ++++++++++---- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/dev/kske/chess/ui/GamePane.java b/src/dev/kske/chess/ui/GamePane.java index 338ee9a..7a4c6cc 100644 --- a/src/dev/kske/chess/ui/GamePane.java +++ b/src/dev/kske/chess/ui/GamePane.java @@ -25,6 +25,7 @@ public class GamePane extends JComponent { private JButton btnRestart, btnSwapColors; private BoardPane boardPane; + private LogPanel logPanel; private Game game; private Color activeColor; @@ -89,11 +90,14 @@ public class GamePane extends JComponent { letterPanel.add(letterLabel); } - // TODO: LogPanel - // LogPanel logPanel = new LogPanel(game.getBoard().getLog()); - // GridBagConstraints gbc_logPanel = new GridBagConstraints(); - // - // add(logPanel, gbc_logPanel); + // Initialize LogPanel + logPanel = new LogPanel(); + GridBagConstraints gbc_logPanel = new GridBagConstraints(); + gbc_logPanel.anchor = GridBagConstraints.EAST; + 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; btnSwapColors.setEnabled(game.getPlayers().get(Color.WHITE) instanceof NaturalPlayer ^ game.getPlayers().get(Color.BLACK) instanceof NaturalPlayer); + logPanel.setLog(game.getBoard().getLog()); } } diff --git a/src/dev/kske/chess/ui/LogPanel.java b/src/dev/kske/chess/ui/LogPanel.java index 3a9d8e3..96a7058 100644 --- a/src/dev/kske/chess/ui/LogPanel.java +++ b/src/dev/kske/chess/ui/LogPanel.java @@ -36,9 +36,7 @@ public class LogPanel extends JPanel implements Subscribable { /** * Create the frame. */ - public LogPanel(Log log) { - this.log = log; - + public LogPanel() { setBorder(new EmptyBorder(5, 5, 5, 5)); setLayout(new BorderLayout(0, 0)); @@ -47,7 +45,6 @@ public class LogPanel extends JPanel implements Subscribable { add(new JScrollPane(mtable), BorderLayout.CENTER); EventBus.getInstance().register(this); - handle(null); } @Override @@ -57,6 +54,8 @@ public class LogPanel extends JPanel implements Subscribable { @Override public void handle(Event event) { + if (log == null) return; + final List moves = log.getLoggedMoves(); String[][] data = new String[moves.size() / 2 + moves.size() % 2][2]; 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" })); } + + public Log getLog() { return log; } + + public void setLog(Log log) { + this.log = log; + handle(null); + } }