From 616843b547305fd0ec27a3110129157e8b0f7c9b Mon Sep 17 00:00:00 2001 From: kske Date: Sat, 16 May 2020 22:43:17 +0200 Subject: [PATCH] Remove AIConfigDialog, simplify some lambdas --- src/dev/kske/chess/ui/AIConfigDialog.java | 81 ----------------------- src/dev/kske/chess/ui/GamePane.java | 2 +- src/dev/kske/chess/ui/MainWindow.java | 4 +- 3 files changed, 3 insertions(+), 84 deletions(-) delete mode 100644 src/dev/kske/chess/ui/AIConfigDialog.java diff --git a/src/dev/kske/chess/ui/AIConfigDialog.java b/src/dev/kske/chess/ui/AIConfigDialog.java deleted file mode 100644 index 54ef3d3..0000000 --- a/src/dev/kske/chess/ui/AIConfigDialog.java +++ /dev/null @@ -1,81 +0,0 @@ -package dev.kske.chess.ui; - -import java.awt.Dimension; - -import javax.swing.*; - -/** - * Project: Chess
- * File: AIConfigDialog.java
- * Created: 16.07.2019
- * - * @since Chess v0.1-alpha - * @author Kai S. K. Engelbart - */ -@Deprecated -@SuppressWarnings("javadoc") -public class AIConfigDialog extends JDialog { - - private static final long serialVersionUID = -8047984368152479992L; - - private int maxDepth; - private int alphaBetaThreshold; - private boolean startGame = false; - - public AIConfigDialog() { - setSize(new Dimension(337, 212)); - setModal(true); - setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); - setTitle("AI Configuration"); - getContentPane().setLayout(null); - - JSpinner spAlphaBetaThreshold = new JSpinner(); - spAlphaBetaThreshold.setBounds(222, 68, 95, 28); - getContentPane().add(spAlphaBetaThreshold); - spAlphaBetaThreshold.setModel(new SpinnerNumberModel(-10, -100, 100, 5)); - - JSpinner spMaxDepth = new JSpinner(); - spMaxDepth.setBounds(222, 6, 95, 28); - getContentPane().add(spMaxDepth); - spMaxDepth.setModel(new SpinnerNumberModel(4, 1, 10, 1)); - - JLabel lblAlphabetaThreshold = new JLabel("Alpha-Beta Threshold:"); - lblAlphabetaThreshold.setBounds(16, 68, 194, 28); - getContentPane().add(lblAlphabetaThreshold); - - JButton btnOk = new JButton("OK"); - btnOk.setBounds(16, 137, 84, 28); - getContentPane().add(btnOk); - btnOk.addActionListener((evt) -> { - maxDepth = ((Integer) spMaxDepth.getValue()); - alphaBetaThreshold = ((Integer) spAlphaBetaThreshold.getValue()); - startGame = true; - dispose(); - }); - btnOk.setToolTipText("Start the game"); - - JButton btnCancel = new JButton("Cancel"); - btnCancel.setBounds(222, 137, 95, 28); - getContentPane().add(btnCancel); - btnCancel.addActionListener((evt) -> dispose()); - btnCancel.setToolTipText("Cancel the game start"); - - JLabel lblMaximalRecursionDepth = new JLabel("Maximal Recursion Depth:"); - lblMaximalRecursionDepth.setBounds(16, 12, 194, 16); - getContentPane().add(lblMaximalRecursionDepth); - - setLocationRelativeTo(null); - } - - public int getMaxDepth() { return maxDepth; } - - public void setMaxDepth(int maxDepth) { this.maxDepth = maxDepth; } - - public int getAlphaBetaThreshold() { return alphaBetaThreshold; } - - public void setAlphaBetaThreshold(int alphaBetaThreshold) { this.alphaBetaThreshold = alphaBetaThreshold; } - - public boolean isStartGame() { return startGame; } - - public void setStartGame(boolean startGame) { this.startGame = startGame; } -} diff --git a/src/dev/kske/chess/ui/GamePane.java b/src/dev/kske/chess/ui/GamePane.java index ef88934..4df7095 100644 --- a/src/dev/kske/chess/ui/GamePane.java +++ b/src/dev/kske/chess/ui/GamePane.java @@ -177,7 +177,7 @@ public class GamePane extends JComponent { if (game.getBoard().getLog() == null) return; DefaultListModel model = new DefaultListModel<>(); - game.getBoard().getLog().forEach(node -> model.addElement(node)); + game.getBoard().getLog().forEach(model::addElement); pgnList.setModel(model); } diff --git a/src/dev/kske/chess/ui/MainWindow.java b/src/dev/kske/chess/ui/MainWindow.java index 86ae49f..351a67d 100644 --- a/src/dev/kske/chess/ui/MainWindow.java +++ b/src/dev/kske/chess/ui/MainWindow.java @@ -37,7 +37,7 @@ public class MainWindow extends JFrame { * * @param args command line arguments are ignored */ - public static void main(String[] args) { SwingUtilities.invokeLater(() -> new MainWindow()); } + public static void main(String[] args) { SwingUtilities.invokeLater(MainWindow::new); } /** * Create the application. @@ -185,7 +185,7 @@ public class MainWindow extends JFrame { } catch (IOException e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, - "Failed to save the file " + file.getName() + ": " + e.toString(), + "Failed to save the file " + file.getName() + ": " + e, "File saving error", JOptionPane.ERROR_MESSAGE); }