Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make askYesNo async to avoid deadlock.
- Loading branch information
rsmudge
committed
Mar 9, 2014
1 parent
107585f
commit dd2168e
Showing
6 changed files
with
46 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package ui; | ||
|
||
import java.awt.*; | ||
import java.awt.event.*; | ||
|
||
import javax.swing.*; | ||
import java.util.*; | ||
|
||
/* Spawn common dialogs in their own thread (so they don't block Sleep interpreter) | ||
and report their results to a callback function */ | ||
public class SafeDialogs { | ||
/* our callback interface... will always return a string I guess */ | ||
public interface SafeDialogCallback { | ||
public void result(String r); | ||
} | ||
|
||
/* prompts the user with a yes/no question. Does not call callback unless the user presses | ||
yes. askYesNo is always a confirm action anyways */ | ||
public static void askYesNo(final String text, final String title, final SafeDialogCallback callback) { | ||
new Thread(new Runnable() { | ||
public void run() { | ||
int result = JOptionPane.showConfirmDialog(null, text, title, JOptionPane.YES_NO_OPTION); | ||
if (result == JOptionPane.YES_OPTION || result == JOptionPane.OK_OPTION) { | ||
callback.result("yes"); | ||
} | ||
} | ||
}).start(); | ||
} | ||
} |