Added LogPanel to GamePane

This commit is contained in:
Kai S. K. Engelbart 2019-09-09 06:14:37 +02:00
parent 3f2e7183dd
commit 18e708d285
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13
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 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());
}
}

View File

@ -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<LoggedMove> 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);
}
}