Reworked PgnController and PgnGui

TestingBranch
Justin 2025-06-24 01:01:26 +02:00
parent 5770d13cdc
commit 6d3154d0e3
2 changed files with 59 additions and 30 deletions

View File

@ -65,7 +65,8 @@ public class PgnController {
public void updateGuiBoard() { public void updateGuiBoard() {
BoardDTO board = engine.getBoardAsDTO(); BoardDTO board = engine.getBoardAsDTO();
gui.updateBoard(board); gui.updateBoard(board);
gui.updateMoveList(engine.getMoveListStringsGrouped()); gui.updateMoveList(engine.getMoveListStringsGrouped());
gui.setOpeningLabel(engine.getOpeningName());
} }
private void resetFieldBackground(int row, int col) { private void resetFieldBackground(int row, int col) {

View File

@ -3,6 +3,7 @@ package de.hs_mannheim.informatik.chess.view;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Color; import java.awt.Color;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font; import java.awt.Font;
import java.awt.GridBagConstraints; import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import java.awt.GridBagLayout;
@ -10,6 +11,7 @@ import java.awt.GridLayout;
import java.awt.Insets; import java.awt.Insets;
import java.util.List; import java.util.List;
import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.BoxLayout;
import javax.swing.JButton; import javax.swing.JButton;
import javax.swing.JFrame; import javax.swing.JFrame;
@ -33,6 +35,8 @@ public class PgnGui {
JButton btnNext = new JButton(">"); JButton btnNext = new JButton(">");
JButton btnLast = new JButton(">|"); JButton btnLast = new JButton(">|");
private JLabel openingLabel;
Color LIGHT = new Color(0xe0e1dd); Color LIGHT = new Color(0xe0e1dd);
Color DARK = new Color(0x778da9); Color DARK = new Color(0x778da9);
@ -124,37 +128,57 @@ public class PgnGui {
return boardPanel; return boardPanel;
} }
public JPanel chessPanel(JPanel panel) { public JPanel chessPanel(JPanel boardPanel) {
JPanel chessPanel = new JPanel(new GridBagLayout()); JPanel chessPanel = new JPanel(new BorderLayout());
GridBagConstraints board = new GridBagConstraints(); chessPanel.setBackground(new Color(0x1b263b));
chessPanel.setBackground(new Color(0x1b263b));
board.gridx = 0;
board.gridy = 0;
board.weightx = 0.7;
board.weighty = 1.0;
board.insets = new Insets(0, 0, 0, 0);
//oben, links, unten, rechts
board.fill = GridBagConstraints.BOTH;
chessPanel.add(panel);
// Button unten rechts
flipBoardButton = new JButton("⇵");
flipBoardButton.setPreferredSize(new Dimension(70, 70));
flipBoardButton.setFont(new Font("SansSerif", Font.BOLD, 40));
flipBoardButton.setBackground(new Color(0x5500ff));
flipBoardButton.setForeground(Color.WHITE);
flipBoardButton.setFocusPainted(false);
GridBagConstraints btn = new GridBagConstraints(); // --- Eröffnungslabel oben ---
btn.gridx = 0; openingLabel = new JLabel("Eröffnung: unbekannt", SwingConstants.CENTER);
btn.gridy = 1; openingLabel.setFont(new Font("SansSerif", Font.BOLD, 24));
btn.weightx = 0.0; openingLabel.setForeground(Color.WHITE);
btn.weighty = 0.0; openingLabel.setOpaque(true);
btn.anchor = GridBagConstraints.SOUTHEAST; openingLabel.setBackground(new Color(0x283655));
btn.insets = new Insets(10, 0, 0, 0); openingLabel.setPreferredSize(new Dimension(800, 50));
chessPanel.add(openingLabel, BorderLayout.NORTH);
chessPanel.add(flipBoardButton, btn); // --- Board in ein zentriertes Panel mit fixer Größe ---
JPanel centerPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 0, 0));
return chessPanel; centerPanel.setOpaque(false);
centerPanel.add(boardPanel);
centerPanel.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentResized(java.awt.event.ComponentEvent evt) {
int size = Math.min(centerPanel.getWidth(), centerPanel.getHeight());
boardPanel.setPreferredSize(new Dimension(size, size));
boardPanel.revalidate();
}
});
chessPanel.add(centerPanel, BorderLayout.CENTER);
// --- Dummy-Buffer für WEST und EAST ---
chessPanel.add(Box.createRigidArea(new Dimension(40, 0)), BorderLayout.WEST);
chessPanel.add(Box.createRigidArea(new Dimension(40, 0)), BorderLayout.EAST);
// --- Buttonleiste unten bauen ---
JPanel buttonRow = new JPanel();
buttonRow.setOpaque(false);
buttonRow.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT, 10, 0));
flipBoardButton = new JButton("⇵");
flipBoardButton.setPreferredSize(new Dimension(70, 70));
flipBoardButton.setFont(new Font("SansSerif", Font.BOLD, 40));
flipBoardButton.setBackground(new Color(0x5500ff));
flipBoardButton.setForeground(Color.WHITE);
flipBoardButton.setFocusPainted(false);
buttonRow.add(flipBoardButton);
chessPanel.add(buttonRow, BorderLayout.SOUTH);
return chessPanel;
} }
public JPanel statsPanel() { public JPanel statsPanel() {
@ -240,6 +264,10 @@ public class PgnGui {
this.isFlipped = flipped; this.isFlipped = flipped;
} }
public void setOpeningLabel(String text) {
openingLabel.setText("Eröffnung: " + text);
}
public JButton getBtnFirst() { return btnFirst; } public JButton getBtnFirst() { return btnFirst; }
public JButton getBtnPrev() { return btnPrev; } public JButton getBtnPrev() { return btnPrev; }
public JButton getBtnNext() { return btnNext; } public JButton getBtnNext() { return btnNext; }