Skip to content

Commit

Permalink
Fix empty window when "leela_gtp -g" is the default engine
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiraoka committed Nov 16, 2020
1 parent d790275 commit c500a89
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/main/java/featurecat/lizzie/Lizzie.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import featurecat.lizzie.gui.LizzieMain;
import featurecat.lizzie.gui.MainFrame;
import featurecat.lizzie.rules.Board;
import featurecat.lizzie.util.Utils;
import java.io.File;
import java.io.IOException;
import javax.swing.JOptionPane;
Expand Down Expand Up @@ -55,7 +56,7 @@ public static void initializeEngineManager() {
}
} catch (IOException e) {
frame.openConfigDialog();
JOptionPane.showMessageDialog(frame, "Please restart Lizzie to apply changes.");
Utils.showMessageDialog(frame, "Please restart Lizzie to apply changes.");
System.exit(1);
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/featurecat/lizzie/analysis/Leelaz.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public void startEngine() throws IOException {
// File lef = startfolder.toPath().resolve(new File(commands.get(0)).toPath()).toFile();
// System.out.println(lef.getPath());
// if (!lef.exists()) {
// JOptionPane.showMessageDialog(
// Utils.showMessageDialog(
// null,
// resourceBundle.getString("LizzieFrame.display.leelaz-missing"),
// "Lizzie - Error!",
Expand All @@ -175,7 +175,7 @@ public void startEngine() throws IOException {
// Check if network file is present
// File wf = startfolder.toPath().resolve(new File(currentWeightFile).toPath()).toFile();
// if (!wf.exists()) {
// JOptionPane.showMessageDialog(
// Utils.showMessageDialog(
// null, resourceBundle.getString("LizzieFrame.display.network-missing"));
// throw new IOException("network-file not present");
// }
Expand Down Expand Up @@ -240,7 +240,7 @@ private void alertEngineDown(String message) {
isDown = true;
Lizzie.frame.refresh();
String displayedMessage = String.format("%s\n\nEngine command: %s", message, engineCommand);
JOptionPane.showMessageDialog(
Utils.showMessageDialog(
Lizzie.frame, displayedMessage, "Lizzie - Error!", JOptionPane.ERROR_MESSAGE);
}

Expand All @@ -258,7 +258,7 @@ public void normalQuit() {
executor.shutdownNow();
}
if (!executor.awaitTermination(1, TimeUnit.SECONDS)) {
JOptionPane.showMessageDialog(
Utils.showMessageDialog(
Lizzie.frame,
"Engine does not close its pipe after GTP command 'quit'.",
"Lizzie - Error!",
Expand Down Expand Up @@ -453,7 +453,7 @@ private void parseLine(String line) {
int minor = Integer.parseInt(ver[1]);
// Gtp support added in version 15
if (minor < 15) {
JOptionPane.showMessageDialog(
Utils.showMessageDialog(
Lizzie.frame,
"Lizzie requires version 0.15 or later of Leela Zero for analysis (found "
+ params[1]
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/featurecat/lizzie/analysis/YaZenGtp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import featurecat.lizzie.Lizzie;
import featurecat.lizzie.gui.CountResults;
import featurecat.lizzie.rules.MoveList;
import featurecat.lizzie.util.Utils;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
Expand All @@ -11,7 +12,6 @@
import java.util.ResourceBundle;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import javax.swing.JOptionPane;

public class YaZenGtp {
private static final ResourceBundle resourceBundle =
Expand Down Expand Up @@ -53,7 +53,7 @@ public void startEngine(String engineCommand, int index) {
process = processBuilder.start();
} catch (IOException e) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(null, resourceBundle.getString("YaZenGtp.nofile"));
Utils.showMessageDialog(null, resourceBundle.getString("YaZenGtp.nofile"));
return;
}
initializeStreams();
Expand Down Expand Up @@ -99,7 +99,7 @@ private void parseLine(String line) {
}

if (line.startsWith("Throw")) {
JOptionPane.showMessageDialog(null, resourceBundle.getString("YaZenGtp.nofile"));
Utils.showMessageDialog(null, resourceBundle.getString("YaZenGtp.nofile"));
shutdown();
}
if (line.startsWith(" ")) {
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/featurecat/lizzie/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import featurecat.lizzie.rules.BoardData;
import featurecat.lizzie.rules.BoardHistoryNode;
import java.awt.Color;
import java.awt.Component;
import java.awt.FontMetrics;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
Expand All @@ -28,6 +29,7 @@
import javax.imageio.metadata.IIOMetadataNode;
import javax.imageio.stream.ImageOutputStream;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.TransferHandler;
Expand Down Expand Up @@ -298,6 +300,27 @@ public static void mustBeEventDispatchThread() {
}
}

public static void showMessageDialog(Component parentComponent, Object message) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
mustBeEventDispatchThread();
JOptionPane.showMessageDialog(parentComponent, message);
}
});
}

public static void showMessageDialog(
Component parentComponent, Object message, String title, int messageType) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
mustBeEventDispatchThread();
JOptionPane.showMessageDialog(parentComponent, message, title, messageType);
}
});
}

public static TransferHandler transFile =
new TransferHandler() {
@Override
Expand Down

0 comments on commit c500a89

Please sign in to comment.