56 lines
1.5 KiB
Java
56 lines
1.5 KiB
Java
package dev.kske.chess.ui;
|
|
|
|
import java.awt.Dimension;
|
|
import java.awt.event.ComponentAdapter;
|
|
import java.awt.event.ComponentEvent;
|
|
|
|
import javax.swing.JLayeredPane;
|
|
|
|
/**
|
|
* Project: <strong>Chess</strong><br>
|
|
* File: <strong>BoardPane.java</strong><br>
|
|
* Created: <strong>08.07.2019</strong><br>
|
|
* Author: <strong>Kai S. K. Engelbart</strong>
|
|
*/
|
|
public class BoardPane extends JLayeredPane {
|
|
|
|
private static final long serialVersionUID = -5415058382478806092L;
|
|
|
|
private final BoardComponent boardComponent;
|
|
private final OverlayComponent overlayComponent;
|
|
|
|
private int tileSize;
|
|
|
|
public BoardPane() {
|
|
boardComponent = new BoardComponent(this);
|
|
overlayComponent = new OverlayComponent(this);
|
|
|
|
add(boardComponent, Integer.valueOf(1));
|
|
add(overlayComponent, Integer.valueOf(2));
|
|
|
|
/*
|
|
* Add a component listener for adjusting the tile size on resizing.
|
|
* The size of the board is assumed to be 8x8, as well as the both the board and
|
|
* the tiles being square.
|
|
*/
|
|
addComponentListener(new ComponentAdapter() {
|
|
|
|
@Override
|
|
public void componentResized(ComponentEvent e) {
|
|
tileSize = getWidth() / 8;
|
|
TextureUtil.scalePieceTextures(tileSize);
|
|
}
|
|
});
|
|
setSize(getPreferredSize());
|
|
}
|
|
|
|
@Override
|
|
public Dimension getPreferredSize() { return new Dimension(480, 480); }
|
|
|
|
public BoardComponent getBoardComponent() { return boardComponent; }
|
|
|
|
public OverlayComponent getOverlayComponent() { return overlayComponent; }
|
|
|
|
public int getTileSize() { return tileSize; }
|
|
}
|