Implemented LogFrame, added menu item for opening it
This commit is contained in:
parent
83c6e48f03
commit
3d8877ddbd
@ -510,6 +510,11 @@ public class Board implements Cloneable {
|
||||
*/
|
||||
public Piece[][] getBoardArr() { return boardArr; }
|
||||
|
||||
/**
|
||||
* @return The move log
|
||||
*/
|
||||
public Log getLog() { return log; }
|
||||
|
||||
/**
|
||||
* @return The active color for the next move
|
||||
*/
|
||||
|
@ -69,12 +69,14 @@ public class Log implements Cloneable {
|
||||
|
||||
public Color getActiveColor() { return activeColor; }
|
||||
|
||||
public List<LoggedMove> getLoggedMoves() { return moves; }
|
||||
|
||||
public static class LoggedMove {
|
||||
|
||||
public final Move move;
|
||||
public final Piece capturedPiece;
|
||||
public final Move move;
|
||||
public final Piece capturedPiece;
|
||||
public final Position enPassant;
|
||||
public final int fullmoveCounter, halfmoveClock;
|
||||
public final int fullmoveCounter, halfmoveClock;
|
||||
|
||||
public LoggedMove(Move move, Piece capturedPiece, Position enPassant, int fullmoveCounter, int halfmoveClock) {
|
||||
this.move = move;
|
||||
|
@ -1,14 +1,17 @@
|
||||
package dev.kske.chess.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JTable;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
|
||||
import dev.kske.chess.board.Move;
|
||||
import dev.kske.chess.board.Log;
|
||||
import dev.kske.chess.board.Log.LoggedMove;
|
||||
|
||||
/**
|
||||
* Project: <strong>Chess</strong><br>
|
||||
@ -23,12 +26,16 @@ public class LogFrame extends JFrame {
|
||||
private JPanel mcontentPane;
|
||||
private JTable mtable;
|
||||
|
||||
private Log log;
|
||||
|
||||
/**
|
||||
* Create the frame.
|
||||
*/
|
||||
public LogFrame() {
|
||||
public LogFrame(Log log) {
|
||||
this.log = log;
|
||||
|
||||
setTitle("Move History");
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
||||
setBounds(100, 100, 450, 300);
|
||||
mcontentPane = new JPanel();
|
||||
mcontentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
|
||||
@ -36,12 +43,19 @@ public class LogFrame extends JFrame {
|
||||
setContentPane(mcontentPane);
|
||||
|
||||
mtable = new JTable();
|
||||
mtable.setModel(new DefaultTableModel(new Object[][] {}, new String[] { "White", "Black" }));
|
||||
mtable.setEnabled(false);
|
||||
mcontentPane.add(mtable, BorderLayout.CENTER);
|
||||
mcontentPane.add(new JScrollPane(mtable), BorderLayout.CENTER);
|
||||
update();
|
||||
}
|
||||
|
||||
public void add(Move move) {
|
||||
|
||||
// TODO: call this method after a move
|
||||
public void update() {
|
||||
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++) {
|
||||
data[i][0] = moves.get(i * 2).move.toString();
|
||||
if (i < data.length - 1) data[i][1] = moves.get(i * 2 + 1).move.toString();
|
||||
}
|
||||
mtable.setModel(new DefaultTableModel(data, new String[] { "White", "Black" }));
|
||||
}
|
||||
}
|
||||
|
@ -70,6 +70,12 @@ public class MenuBar extends JMenuBar {
|
||||
private void initToolsMenu() {
|
||||
JMenu toolsMenu = new JMenu("Tools");
|
||||
|
||||
// TODO: prevent multiple initializations
|
||||
JMenuItem showLogMenuItem = new JMenuItem("Show move log");
|
||||
showLogMenuItem
|
||||
.addActionListener((evt) -> new LogFrame(mainWindow.getGame().getBoard().getLog()).setVisible(true));
|
||||
toolsMenu.add(showLogMenuItem);
|
||||
|
||||
JMenuItem exportFENMenuItem = new JMenuItem("Export board to FEN");
|
||||
exportFENMenuItem.addActionListener((evt) -> Toolkit.getDefaultToolkit()
|
||||
.getSystemClipboard()
|
||||
|
Reference in New Issue
Block a user