content: package com.chess.gui;
  
  import java.awt.BorderLayout;
  import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.GridLayout;
  import java.awt.Image;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Comparator;
  import java.util.List;
  import javax.imageio.ImageIO;
  import javax.swing.ImageIcon;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.border.EtchedBorder;
  
  import com.chess.engine.board.Move;
  import com.chess.engine.pieces.Piece;
  import com.chess.gui.Table.MoveLog;
  
  class TakenPiecesPanel extends JPanel {
  
      private final JPanel northPanel;
      private final JPanel southPanel;
  
      private static final long serialVersionUID = 1L;
      private static final Color PANEL_COLOR = Color.decode("0xFDF5E6");
      private static final Dimension TAKEN_PIECES_PANEL_DIMENSION = new Dimension(40, 80);
      private static final EtchedBorder PANEL_BORDER = new EtchedBorder(EtchedBorder.RAISED);
  
      public TakenPiecesPanel() {
          super(new BorderLayout());
          setBackground(Color.decode("0xFDF5E6"));
          setBorder(PANEL_BORDER);
          this.northPanel = new JPanel(new GridLayout(8, 2));
          this.southPanel = new JPanel(new GridLayout(8, 2));
          this.northPanel.setBackground(PANEL_COLOR);
          this.southPanel.setBackground(PANEL_COLOR);
          add(this.northPanel, BorderLayout.NORTH);
          add(this.southPanel, BorderLayout.SOUTH);
          setPreferredSize(TAKEN_PIECES_PANEL_DIMENSION);
      }
  
      public void redo(final MoveLog moveLog) {
          southPanel.removeAll();
          northPanel.removeAll();
          
          final List<Piece> whiteTakenPieces = new ArrayList<>();
          final List<Piece> blackTakenPieces = new ArrayList<>();
          
          for(final Move move : moveLog.getMoves()) {
              if(move.isAttack()) {
                  final Piece takenPiece = move.getAttackedPiece();
                  if(takenPiece.getPieceAllegiance().isWhite()) {
                      whiteTakenPieces.add(takenPiece);
                  } else if(takenPiece.getPieceAllegiance().isBlack()){
                      blackTakenPieces.add(takenPiece);
                  } else {
                      throw new RuntimeException("Should not reach here!");
                  }
              }
          }
  
          whiteTakenPieces.sort(Comparator.comparingInt(Piece::getPieceValue));
          blackTakenPieces.sort(Comparator.comparingInt(Piece::getPieceValue));
          
          for (final Piece takenPiece : whiteTakenPieces) {
              try {
                  final BufferedImage image = ImageIO.read(new File("art/holywarriors/"
                          + takenPiece.getPieceAllegiance().toString().substring(0, 1) + "" + takenPiece.toString()
                          + ".gif"));
                  final ImageIcon ic = new ImageIcon(image);
                  final JLabel imageLabel = new JLabel(new ImageIcon(ic.getImage().getScaledInstance(
                          ic.getIconWidth() - 15, ic.getIconWidth() - 15, Image.SCALE_SMOOTH)));
                  this.southPanel.add(imageLabel);
              }
              catch (final IOException e) {
                  throw new RuntimeException(e);
              }
          }
  
          for (final Piece takenPiece : blackTakenPieces) {
              try {
                  final BufferedImage image = ImageIO.read(new File("art/holywarriors/"
                          + takenPiece.getPieceAllegiance().toString().substring(0, 1) + "" + takenPiece.toString()
                          + ".gif"));
                  final ImageIcon ic = new ImageIcon(image);
                  final JLabel imageLabel = new JLabel(new ImageIcon(ic.getImage().getScaledInstance(
                          ic.getIconWidth() - 15, ic.getIconWidth() - 15, Image.SCALE_SMOOTH)));
                  this.northPanel.add(imageLabel);
              } catch (final IOException e) {
                  throw new RuntimeException(e);
              }
          }
          validate();
      }
  }