fixed UI updates so that they are guaranteed to run in EDT

This commit is contained in:
BetaSteward 2011-06-11 23:13:15 -04:00
parent b7e754d8d9
commit d46a421bfa

View file

@ -536,7 +536,7 @@ public class MageFrame extends javax.swing.JFrame implements Client {
if (MageFrame.connect(connection)) { if (MageFrame.connect(connection)) {
return true; return true;
} else { } else {
JOptionPane.showMessageDialog(rootPane, "Unable to connect to server"); showMessage("Unable to connect to server");
} }
} finally { } finally {
setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
@ -834,14 +834,6 @@ public class MageFrame extends javax.swing.JFrame implements Client {
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String args[]) { public static void main(String args[]) {
final SplashScreen splash = SplashScreen.getSplashScreen();
if (splash != null) {
Graphics2D g = splash.createGraphics();
if (g != null) {
renderSplashFrame(g);
}
splash.update();
}
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) { public void uncaughtException(Thread t, Throwable e) {
@ -850,6 +842,14 @@ public class MageFrame extends javax.swing.JFrame implements Client {
}); });
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
public void run() { public void run() {
final SplashScreen splash = SplashScreen.getSplashScreen();
if (splash != null) {
Graphics2D g = splash.createGraphics();
if (g != null) {
renderSplashFrame(g);
}
splash.update();
}
new MageFrame().setVisible(true); new MageFrame().setVisible(true);
} }
}); });
@ -923,27 +923,71 @@ public class MageFrame extends javax.swing.JFrame implements Client {
} }
@Override @Override
public void connected(String message) { public void connected(final String message) {
setStatusText(message); if (SwingUtilities.isEventDispatchThread()) {
enableButtons(); setStatusText(message);
enableButtons();
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setStatusText(message);
enableButtons();
}
});
}
} }
@Override @Override
public void disconnected() { public void disconnected() {
setStatusText("Not connected"); if (SwingUtilities.isEventDispatchThread()) {
disableButtons(); setStatusText("Not connected");
hideGames(); disableButtons();
hideTables(); hideGames();
hideTables();
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
setStatusText("Not connected");
disableButtons();
hideGames();
hideTables();
}
});
}
} }
@Override @Override
public void showMessage(String message) { public void showMessage(final String message) {
JOptionPane.showMessageDialog(this, message); if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(desktopPane, message);
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(desktopPane, message);
}
});
}
} }
@Override @Override
public void showError(String message) { public void showError(final String message) {
JOptionPane.showMessageDialog(this, message, "Error", JOptionPane.ERROR_MESSAGE); if (SwingUtilities.isEventDispatchThread()) {
JOptionPane.showMessageDialog(desktopPane, message, "Error", JOptionPane.ERROR_MESSAGE);
}
else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JOptionPane.showMessageDialog(desktopPane, message, "Error", JOptionPane.ERROR_MESSAGE);
}
});
}
} }
@Override @Override