Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hopefully fix hang-up that was reported in #777 and #780 #782

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/java/featurecat/lizzie/Lizzie.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
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;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

Expand All @@ -29,6 +31,15 @@ public static void main(String[] args) throws IOException {
setLookAndFeel();
mainArgs = args;
config = new Config();
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
mainInEDT();
}
});
}

private static void mainInEDT() {
frame = config.panelUI ? new LizzieMain() : new LizzieFrame();
gtpConsole = new GtpConsolePane(frame);
gtpConsole.setVisible(config.leelazConfig.optBoolean("print-comms", false));
Expand All @@ -45,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
3 changes: 3 additions & 0 deletions src/main/java/featurecat/lizzie/gui/BoardPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ public void mouseDragged(MouseEvent e) {}

/** Clears related status from empty board. */
public void clear() {
Utils.mustBeEventDispatchThread();
if (LizzieMain.winratePane != null) {
LizzieMain.winratePane.clear();
}
Expand All @@ -162,6 +163,7 @@ public void clear() {
*/
@Override
protected void paintComponent(Graphics g0) {
Utils.mustBeEventDispatchThread();
super.paintComponent(g0);
autosaveMaybe();

Expand Down Expand Up @@ -219,6 +221,7 @@ protected void paintComponent(Graphics g0) {

/** Display the controls */
void drawControls() {
Utils.mustBeEventDispatchThread();
userAlreadyKnowsAboutCommandString = true;

cachedImage = new BufferedImage(getWidth(), getHeight(), TYPE_INT_ARGB);
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/featurecat/lizzie/gui/GtpConsolePane.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package featurecat.lizzie.gui;

import featurecat.lizzie.Lizzie;
import featurecat.lizzie.util.Utils;
import featurecat.lizzie.util.WindowPosition;
import java.awt.BorderLayout;
import java.awt.Color;
Expand All @@ -18,6 +19,7 @@
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.text.BadLocationException;
import javax.swing.text.Element;
import javax.swing.text.ElementIterator;
Expand Down Expand Up @@ -46,6 +48,7 @@ public class GtpConsolePane extends JDialog {
/** Creates a Gtp Console Window */
public GtpConsolePane(Window owner) {
super(owner);
Utils.mustBeEventDispatchThread();
setTitle("Gtp Console");

JSONArray pos = WindowPosition.gtpWindowPos();
Expand Down Expand Up @@ -91,6 +94,20 @@ public GtpConsolePane(Window owner) {
txtCommand.addActionListener(e -> postCommand(e));
}

public void setVisible(boolean b) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
setVisibleInEDT(b);
}
});
}

private void setVisibleInEDT(boolean b) {
Utils.mustBeEventDispatchThread();
super.setVisible(b);
}

public void addCommand(String command, int commandNumber) {
if (command == null || command.trim().length() == 0) {
return;
Expand Down Expand Up @@ -126,6 +143,16 @@ public void addZenCommand(String command, int commandNumber) {
}

private void addText(String text) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
addTextInEDT(text);
}
});
}

private void addTextInEDT(String text) {
Utils.mustBeEventDispatchThread();
try {
htmlKit.insertHTML(htmlDoc, htmlDoc.getLength(), text, 0, 0, null);
removeOldText();
Expand All @@ -136,6 +163,7 @@ private void addText(String text) {
}

private void removeOldText() {
Utils.mustBeEventDispatchThread();
Element body =
htmlDoc.getElement(
htmlDoc.getDefaultRootElement(), StyleConstants.NameAttribute, HTML.Tag.BODY);
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public LizzieFrame() {
new JPanel(true) {
@Override
protected void paintComponent(Graphics g) {
Utils.mustBeEventDispatchThread();
super.paintComponent(g);

paintMainPanel(g);
Expand Down Expand Up @@ -1430,14 +1431,16 @@ public void run() {
thread.start();
}

public void removeEstimateRect() {
protected void removeEstimateRectInEDT() {
Utils.mustBeEventDispatchThread();
boardRenderer.removeEstimateRect();
if (Lizzie.config.showSubBoard) {
subBoardRenderer.removeEstimateRect();
}
}

public void drawEstimateRectKata(ArrayList<Double> estimateArray) {
protected void drawEstimateRectKataInEDT(ArrayList<Double> estimateArray) {
Utils.mustBeEventDispatchThread();
if (!Lizzie.config.showKataGoEstimate) {
return;
}
Expand Down Expand Up @@ -1498,11 +1501,13 @@ public void noEstimateByZen(boolean byToolBar) {
if (byToolBar) countResults.setVisible(false);
}

public void updateEngineMenu(List<Leelaz> engineList) {
protected void updateEngineMenuInEDT(List<Leelaz> engineList) {
Utils.mustBeEventDispatchThread();
menu.updateEngineMenu(engineList);
}

public void updateEngineIcon(List<Leelaz> engineList, int currentEngineNo) {
protected void updateEngineIconInEDT(List<Leelaz> engineList, int currentEngineNo) {
Utils.mustBeEventDispatchThread();
menu.updateEngineIcon(engineList, currentEngineNo);
}

Expand Down
53 changes: 47 additions & 6 deletions src/main/java/featurecat/lizzie/gui/LizzieMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.json.JSONArray;

public class LizzieMain extends MainFrame {
Expand Down Expand Up @@ -109,6 +110,7 @@ public LizzieMain() {
new JPanel() {
@Override
protected void paintComponent(Graphics g) {
Utils.mustBeEventDispatchThread();
if (g instanceof Graphics2D) {
int width = getWidth();
int height = getHeight();
Expand Down Expand Up @@ -478,21 +480,42 @@ public void toggleDesignMode() {

@Override
public void updateBasicInfo(String bTime, String wTime) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
updateBasicInfoInEDT(bTime, wTime);
}
});
}

@Override
public void updateBasicInfo() {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
updateBasicInfoInEDT();
}
});
}

private void updateBasicInfoInEDT(String bTime, String wTime) {
Utils.mustBeEventDispatchThread();
if (basicInfoPane != null) {
basicInfoPane.bTime = bTime;
basicInfoPane.wTime = wTime;
basicInfoPane.repaint();
}
}

@Override
public void updateBasicInfo() {
private void updateBasicInfoInEDT() {
Utils.mustBeEventDispatchThread();
if (basicInfoPane != null) {
basicInfoPane.repaint();
}
}

public void invalidLayout() {
Utils.mustBeEventDispatchThread();
// TODO
layout.layoutContainer(getContentPane());
layout.invalidateLayout(getContentPane());
Expand All @@ -506,6 +529,16 @@ public void refresh() {

@Override
public void refresh(int type) {
SwingUtilities.invokeLater(
new Runnable() {
public void run() {
refreshInEDT(type);
}
});
}

private void refreshInEDT(int type) {
Utils.mustBeEventDispatchThread();
if (type == 2) {
invalidLayout();
} else {
Expand All @@ -517,6 +550,7 @@ public void refresh(int type) {
}

public void repaintSub() {
Utils.mustBeEventDispatchThread();
if (Lizzie.leelaz != null && Lizzie.leelaz.isLoaded()) {
if (Lizzie.config.showSubBoard && !subBoardPane.isVisible()) {
subBoardPane.setVisible(true);
Expand All @@ -530,6 +564,7 @@ public void repaintSub() {
}

public void updateStatus() {
Utils.mustBeEventDispatchThread();
// basicInfoPane.revalidate();
basicInfoPane.repaint();
if (Lizzie.leelaz != null && Lizzie.leelaz.isLoaded()) {
Expand All @@ -547,6 +582,7 @@ public void updateStatus() {

@Override
public void drawControls() {
Utils.mustBeEventDispatchThread();
boardPane.drawControls();
}

Expand Down Expand Up @@ -634,14 +670,16 @@ public void clear() {
boardPane.clear();
}

public void removeEstimateRect() {
protected void removeEstimateRectInEDT() {
Utils.mustBeEventDispatchThread();
boardPane.removeEstimateRect();
if (Lizzie.config.showSubBoard) {
subBoardPane.removeEstimateRect();
}
}

public void drawEstimateRectKata(ArrayList<Double> estimateArray) {
protected void drawEstimateRectKataInEDT(ArrayList<Double> estimateArray) {
Utils.mustBeEventDispatchThread();
if (!Lizzie.config.showKataGoEstimate) {
return;
}
Expand Down Expand Up @@ -714,11 +752,14 @@ public void saveImage() {
boardPane.saveImage();
};

public void updateEngineMenu(List<Leelaz> engineList) {
protected void updateEngineMenuInEDT(List<Leelaz> engineList) {
Utils.mustBeEventDispatchThread();
menu.updateEngineMenu(engineList);
refresh(); // update "Engine is loading..."
}

public void updateEngineIcon(List<Leelaz> engineList, int currentEngineNo) {
protected void updateEngineIconInEDT(List<Leelaz> engineList, int currentEngineNo) {
Utils.mustBeEventDispatchThread();
menu.updateEngineIcon(engineList, currentEngineNo);
}

Expand Down
Loading