error_popup: show an error message window when simulator crashes
git-svn-id: https://micropolis.googlecode.com/svn/trunk/micropolis-java@652 d9718cc8-9f43-0410-858b-315f434eb58c
This commit is contained in:
parent
4e27a04cc3
commit
6de75a7947
2 changed files with 49 additions and 0 deletions
|
@ -1123,12 +1123,58 @@ public class MainWindow extends JFrame
|
||||||
updateDateLabel();
|
updateDateLabel();
|
||||||
dirty2 = true;
|
dirty2 = true;
|
||||||
}};
|
}};
|
||||||
|
taskPerformer = wrapActionListener(taskPerformer);
|
||||||
|
|
||||||
assert simTimer == null;
|
assert simTimer == null;
|
||||||
simTimer = new Timer(engine.simSpeed.animationDelay, taskPerformer);
|
simTimer = new Timer(engine.simSpeed.animationDelay, taskPerformer);
|
||||||
simTimer.start();
|
simTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ActionListener wrapActionListener(final ActionListener l)
|
||||||
|
{
|
||||||
|
return new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent evt) {
|
||||||
|
try {
|
||||||
|
l.actionPerformed(evt);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
showErrorMessage(e);
|
||||||
|
}
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showErrorMessage(Throwable e)
|
||||||
|
{
|
||||||
|
StringWriter w = new StringWriter();
|
||||||
|
e.printStackTrace(new PrintWriter(w));
|
||||||
|
|
||||||
|
JTextPane stackTracePane = new JTextPane();
|
||||||
|
stackTracePane.setEditable(false);
|
||||||
|
stackTracePane.setText(w.toString());
|
||||||
|
|
||||||
|
final JScrollPane detailsPane = new JScrollPane(stackTracePane);
|
||||||
|
detailsPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
||||||
|
detailsPane.setPreferredSize(new Dimension(480,240));
|
||||||
|
detailsPane.setMinimumSize(new Dimension(0,0));
|
||||||
|
|
||||||
|
int rv = JOptionPane.showOptionDialog(this, e,
|
||||||
|
strings.getString("main.error_unexpected"),
|
||||||
|
JOptionPane.DEFAULT_OPTION,
|
||||||
|
JOptionPane.ERROR_MESSAGE,
|
||||||
|
null,
|
||||||
|
new String[] {
|
||||||
|
strings.getString("main.error_show_stacktrace"),
|
||||||
|
strings.getString("main.error_close")
|
||||||
|
},
|
||||||
|
1
|
||||||
|
);
|
||||||
|
if (rv == 0)
|
||||||
|
{
|
||||||
|
JOptionPane.showMessageDialog(this, detailsPane,
|
||||||
|
strings.getString("main.error_unexpected"),
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class EarthquakeStepper
|
class EarthquakeStepper
|
||||||
{
|
{
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
|
@ -15,6 +15,9 @@ main.date_label = Date:
|
||||||
main.funds_label = Funds:
|
main.funds_label = Funds:
|
||||||
main.population_label = Population:
|
main.population_label = Population:
|
||||||
main.error_caption = Error
|
main.error_caption = Error
|
||||||
|
main.error_unexpected = An unexpected error occurred
|
||||||
|
main.error_show_stacktrace = Show Details
|
||||||
|
main.error_close = Close
|
||||||
main.tools_caption = Tools
|
main.tools_caption = Tools
|
||||||
main.about_caption = About MicropolisJ
|
main.about_caption = About MicropolisJ
|
||||||
main.version_string = Version {0} (Java %java.version%, %java.vendor%)
|
main.version_string = Version {0} (Java %java.version%, %java.vendor%)
|
||||||
|
|
Reference in a new issue