Simplified EngineUtil and MenuBar

This commit is contained in:
Kai S. K. Engelbart 2019-07-30 06:18:24 +02:00
parent 8077aaafdb
commit d173fb7851
Signed by: kske
GPG Key ID: 8BEB13EC5DF7EF13
2 changed files with 6 additions and 26 deletions

View File

@ -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();

View File

@ -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: <strong>Chess</strong><br>
@ -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);
}