add controlpanel

pgnReader
dstuck 2025-06-24 17:45:14 +02:00
parent 596a3a4dea
commit 039a5756ee
7 changed files with 595 additions and 442 deletions

View File

@ -30,13 +30,17 @@ public class ButtonMovePieceListener implements ActionListener {
if (this.game.isDraw()) {
this.game.stopClock();
this.sf.setBoardMode(BoardMode.finished);
this.sf.setViewPointer(this.game.getMoveList().size() - 1);
this.sf.showDraw();
} else if (this.game.isMate()) {
this.game.stopClock();
this.sf.setBoardMode(BoardMode.finished);
this.sf.setViewPointer(this.game.getMoveList().size() - 1);
this.sf.showWin(game.getActivePlayer());
}
} else {
this.sf.setBoardMode(BoardMode.normal);
}
this.sf.setCursor(null);
this.sf.erstelleBrett();

View File

@ -0,0 +1,22 @@
package de.mannheim.th.chess.controller.controlPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import de.mannheim.th.chess.domain.Game;
public class ButtonViewBackListener implements ActionListener {
private Game game;
public ButtonViewBackListener(Game game) {
this.game = game;
}
@Override
public void actionPerformed(ActionEvent e) {
this.game.setViewPointer(this.game.getViewPointer() - 1);
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,22 @@
package de.mannheim.th.chess.controller.controlPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import de.mannheim.th.chess.domain.Game;
public class ButtonViewFirstListener implements ActionListener {
private Game game;
public ButtonViewFirstListener(Game game) {
this.game = game;
}
@Override
public void actionPerformed(ActionEvent e) {
this.game.setViewPointer(0);
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,22 @@
package de.mannheim.th.chess.controller.controlPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import de.mannheim.th.chess.domain.Game;
public class ButtonViewForwardListener implements ActionListener {
private Game game;
public ButtonViewForwardListener(Game game) {
this.game = game;
}
@Override
public void actionPerformed(ActionEvent e) {
this.game.setViewPointer(this.game.getViewPointer() + 1);
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,23 @@
package de.mannheim.th.chess.controller.controlPanel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import de.mannheim.th.chess.domain.Game;
public class ButtonViewLastListener implements ActionListener {
private Game game;
public ButtonViewLastListener(Game game) {
this.game = game;
}
@Override
public void actionPerformed(ActionEvent e) {
this.game.setViewPointer(this.game.getMoveList().size() - 1);
// TODO Auto-generated method stub
}
}

View File

@ -34,6 +34,7 @@ public class Game {
private boolean rotieren, zuruecknahme;
private MoveList movelist;
private int viewPointer;
public Game() {
@ -272,11 +273,23 @@ public class Game {
return board.getFen();
}
// public Square getSelectedSquare() {
// return this.getSelectedSquare();
// }
// public Square getSelectedSquare() {
// return this.getSelectedSquare();
// }
public String getUnicodeFromMove(Move move) {
return board.getPiece(move.getTo()).getFanSymbol().toUpperCase();
}
public void setViewPointer(int i) {
this.viewPointer = i;
}
public int getViewPointer() {
return this.viewPointer;
}
public void loadView() {
// TODO: add functionality
}
}

View File

@ -36,7 +36,8 @@ import javax.swing.JTextArea;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@ -49,7 +50,7 @@ public class SpielFrame extends JFrame {
private static final long serialVersionUID = 1L;
private ArrayList<JButton> buttons = new ArrayList<>();
private HashMap<JButton, String> belegungen = new HashMap<>();
private JPanel panelLinks, panelRechts, contentPane;
private JPanel panelLinks, panelRechts, contentPane, controlPanel;
private JButton undo, undo2;
private JTextArea ausgabe;
private Game game;
@ -59,6 +60,8 @@ public class SpielFrame extends JFrame {
private BoardMode mode;
private Square selectedSquare;
private int viewPointer;
public enum BoardMode {
normal, pieceSelected, finished
}
@ -96,6 +99,8 @@ public class SpielFrame extends JFrame {
// Panel für alle Eingaben von Player 2
panelRechts.add(getUiPlayerTwo());
panelRechts.add(createControlPanel());
// Panel für Statistikanzeigen
panelRechts.add(getUiStatistik());
@ -123,7 +128,7 @@ public class SpielFrame extends JFrame {
this.setDefaultBackground();
this.setButtonsActions();
ladeBrett();
this.ladeBrett();
panelLinks.revalidate();
panelLinks.repaint();
@ -247,7 +252,8 @@ public class SpielFrame extends JFrame {
}
break;
case finished:
clearButtons();
// this.enableControlPanelButtons();
// this.viewPointer = this.game.getMoveList().size() - 1;
break;
default:
break;
@ -313,6 +319,31 @@ public class SpielFrame extends JFrame {
return result[0];
}
private JPanel createControlPanel() {
this.controlPanel = new JPanel();
this.controlPanel.setBackground(new Color(90, 90, 90));
this.controlPanel.setLayout(new FlowLayout());
this.controlPanel.setMaximumSize(new Dimension(Integer.MAX_VALUE, controlPanel.getPreferredSize().height));
JButton viewFirstButton = new JButton("<<-");
JButton viewBackButton = new JButton("<-");
JButton viewForwardButton = new JButton("->");
JButton viewLastButton = new JButton("->>");
viewFirstButton.setEnabled(false);
viewBackButton.setEnabled(false);
viewForwardButton.setEnabled(false);
viewLastButton.setEnabled(false);
this.controlPanel.add(viewFirstButton);
this.controlPanel.add(viewBackButton);
this.controlPanel.add(viewForwardButton);
this.controlPanel.add(viewLastButton);
return controlPanel;
}
private JPanel getUiPlayerTwo() {
JPanel playerTwo = new JPanel();
@ -532,4 +563,20 @@ public class SpielFrame extends JFrame {
return clock;
}
private void enableControlPanelButtons() {
for (Component c : this.controlPanel.getComponents()) {
if (c instanceof JButton) {
c.setEnabled(!c.isEnabled());
}
}
}
public void setViewPointer(int i) {
this.viewPointer = i;
}
public int getViewPointer() {
return this.viewPointer;
}
}