move logging logic

This commit is contained in:
Love 2022-12-04 18:14:08 +01:00
parent ee2b22a572
commit f52f3e7d0d
No known key found for this signature in database
GPG Key ID: A3C10DC241C8FA9F
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package com.billenius.schack.MoveLogging;
import java.awt.Point;
import com.billenius.schack.Piece;
public class Move {
public Piece movedPiece;
public Point from;
public Point to;
public String color;
public Move(Piece movedPiece, Point from, Point to) {
this.from = from;
this.to = to;
this.color = movedPiece.isWhite() ? "White" : "Black";
this.movedPiece = movedPiece;
}
public String toString() {
return (from.x + 1) + ":" + (from.y + 1)
+ " " + '\u27F6' + " " + (to.x + 1) + ":" + (to.y + 1);
}
}

View File

@ -0,0 +1,25 @@
package com.billenius.schack.MoveLogging;
import java.awt.Component;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
public class PieceRenderer extends JLabel implements ListCellRenderer<Move> {
@Override
public Component getListCellRendererComponent(JList<? extends Move> list, Move move, int index,
boolean isSelected,
boolean cellHasFocus) {
BufferedImage image = move.movedPiece.getIcon();
ImageIcon ii = new ImageIcon(image.getScaledInstance(40, 40, java.awt.Image.SCALE_SMOOTH));
setIcon(ii);
setText(move.toString());
return this;
}
}