From 6b6bda32ee35a8ae3f0b0af494e6042e25519f0b Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Tue, 30 Jul 2019 06:18:24 +0200 Subject: [PATCH] Simplified EngineUtil and MenuBar --- src/dev/kske/chess/ui/EngineUtil.java | 3 +-- src/dev/kske/chess/ui/MenuBar.java | 29 +++++---------------------- 2 files changed, 6 insertions(+), 26 deletions(-) diff --git a/src/dev/kske/chess/ui/EngineUtil.java b/src/dev/kske/chess/ui/EngineUtil.java index 3a97228..b56c416 100644 --- a/src/dev/kske/chess/ui/EngineUtil.java +++ b/src/dev/kske/chess/ui/EngineUtil.java @@ -30,7 +30,7 @@ public class EngineUtil { private EngineUtil() {} - public static void addEngine(String enginePath, Runnable followup) { + public static void addEngine(String enginePath) { try { EngineInfo info = new EngineInfo(enginePath); UCIHandle handle = new UCIHandle(enginePath); @@ -51,7 +51,6 @@ public class EngineUtil { engineInfos.add(info); handle.quit(); saveEngineInfos(); - followup.run(); } }); handle.start(); diff --git a/src/dev/kske/chess/ui/MenuBar.java b/src/dev/kske/chess/ui/MenuBar.java index 16f7a6d..e564be6 100644 --- a/src/dev/kske/chess/ui/MenuBar.java +++ b/src/dev/kske/chess/ui/MenuBar.java @@ -9,7 +9,6 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; import dev.kske.chess.game.Game; -import dev.kske.chess.ui.EngineUtil.EngineInfo; /** * Project: Chess
@@ -52,37 +51,19 @@ public class MenuBar extends JMenuBar { private void initEngineMenu() { JMenu engineMenu = new JMenu("Engine"); - // TODO: Adjust menu - JMenuItem addEngineMenuItem = new JMenuItem("Add engine"); addEngineMenuItem.addActionListener((evt) -> { String enginePath = JOptionPane.showInputDialog(getParent(), "Enter the path to a UCI-compatible chess engine:", "Engine selection", JOptionPane.QUESTION_MESSAGE); - if (enginePath != null) { - EngineUtil.addEngine(enginePath, () -> { - EngineInfo info = EngineUtil.getEngineInfos() - .get(EngineUtil.getEngineInfos().size() - 1); - /* - * JMenuItem engineMenuItem = new JMenuItem(info.name); - * engineMenuItem.addActionListener((evt2) -> - * startGame(Game.createUCI(boardPane, info.path))); - * engineMenu.add(engineMenuItem); - */ - }); - } + if (enginePath != null) EngineUtil.addEngine(enginePath); }); - engineMenu.add(addEngineMenuItem); - /* - * for (EngineInfo info : EngineUtil.getEngineInfos()) { - * JMenuItem engineMenuItem = new JMenuItem(info.name); - * engineMenuItem.addActionListener((evt) -> startGame(Game.createUCI(boardPane, - * info.path))); - * engineMenu.add(engineMenuItem); - * } - */ + JMenuItem showInfoMenuItem = new JMenuItem("Show engine info"); + + engineMenu.add(addEngineMenuItem); + engineMenu.add(showInfoMenuItem); add(engineMenu); }