Merge remote-tracking branch 'origin/GP-1-dragonmacher-window-squash-fix'

This commit is contained in:
Ryan Kurtz 2023-10-30 08:45:20 -04:00
commit 481dc9adb1
5 changed files with 49 additions and 24 deletions

View file

@ -49,7 +49,7 @@ public class GhidraApplicationConfiguration extends HeadlessGhidraApplicationCon
if (showSplashScreen) { if (showSplashScreen) {
showUserAgreement(); showUserAgreement();
SplashScreen.showSplashScreen(); SplashScreen.showLater();
this.monitor = new StatusReportingTaskMonitor(); this.monitor = new StatusReportingTaskMonitor();
} }

View file

@ -320,10 +320,8 @@ public class DockingDialog extends JDialog implements HelpDescriptor {
return; return;
} }
Rectangle r = getBounds();
Point p = WindowUtilities.centerOnComponent(c, this); Point p = WindowUtilities.centerOnComponent(c, this);
r.setLocation(p); setLocation(p);
setBounds(r);
} }
@Override @Override

View file

@ -53,7 +53,7 @@ public class DockingApplicationConfiguration extends ApplicationConfiguration {
LookAndFeelUtils.performPlatformSpecificFixups(); LookAndFeelUtils.performPlatformSpecificFixups();
if (showSplashScreen) { if (showSplashScreen) {
SplashScreen.showSplashScreen(); SplashScreen.showLater();
} }
ApplicationKeyManagerFactory ApplicationKeyManagerFactory

View file

@ -32,6 +32,7 @@ import generic.theme.Gui;
import generic.util.WindowUtilities; import generic.util.WindowUtilities;
import ghidra.framework.Application; import ghidra.framework.Application;
import ghidra.util.Msg; import ghidra.util.Msg;
import ghidra.util.Swing;
import utility.application.ApplicationLayout; import utility.application.ApplicationLayout;
/** /**
@ -42,7 +43,6 @@ import utility.application.ApplicationLayout;
public class SplashScreen extends JWindow { public class SplashScreen extends JWindow {
private static final Color BG_COLOR = new GColor("color.bg.splashscreen"); private static final Color BG_COLOR = new GColor("color.bg.splashscreen");
private static final Color FG_COLOR = new GColor("color.fg.splashscreen");
private static final String FONT_ID = "font.splash.status"; private static final String FONT_ID = "font.splash.status";
@ -52,15 +52,42 @@ public class SplashScreen extends JWindow {
private static Timer hideSplashWindowTimer; private static Timer hideSplashWindowTimer;
/** /**
* Show the splash screen; displayed only when Ghidra is first coming up * Show the splash screen on the Swing thread later.
*/
public static void showLater() {
Swing.runIfSwingOrRunLater(() -> {
if (splashWindow != null) {
return; // already showing
}
JFrame parentFrame = getParentFrame();
splashWindow = new SplashScreen(parentFrame);
initializeSplashWindowAndParent(parentFrame);
createSplashScreenCloseListeners(parentFrame);
parentFrame.setVisible(true);
splashWindow.setVisible(true);
// this call is needed for the splash screen to initially paint correctly on the Mac
splashWindow.repaint();
});
}
/**
* Show the splash screen on the Swing thread now. This will block.
* @return the new splash screen * @return the new splash screen
*/ */
public static SplashScreen showSplashScreen() { public static SplashScreen showNow() {
return Swing.runNow(() -> {
if (splashWindow != null) { if (splashWindow != null) {
return splashWindow; // already showing return splashWindow; // already showing
} }
final JFrame parentFrame = getParentFrame(); JFrame parentFrame = getParentFrame();
splashWindow = new SplashScreen(parentFrame); splashWindow = new SplashScreen(parentFrame);
initializeSplashWindowAndParent(parentFrame); initializeSplashWindowAndParent(parentFrame);
@ -73,13 +100,13 @@ public class SplashScreen extends JWindow {
// this call is needed for the splash screen to initially paint correctly on the Mac // this call is needed for the splash screen to initially paint correctly on the Mac
splashWindow.repaint(); splashWindow.repaint();
return splashWindow; return splashWindow;
});
} }
private static void initializeSplashWindowAndParent(final JFrame parentFrame) { private static void initializeSplashWindowAndParent(final JFrame parentFrame) {
Dimension wd = splashWindow.getPreferredSize(); Dimension wd = splashWindow.getPreferredSize();
Point point = WindowUtilities.centerOnScreen(wd); Point point = WindowUtilities.centerOnScreen(wd);
splashWindow.setLocation(point); splashWindow.setLocation(point);
// move us when the parent frame moves // move us when the parent frame moves
@ -288,7 +315,7 @@ public class SplashScreen extends JWindow {
} }
private static void updateStatus(String status) { private static void updateStatus(String status) {
statusLabel.setText(status); Swing.runIfSwingOrRunLater(() -> statusLabel.setText(status));
} }
private JPanel createMainPanel() { private JPanel createMainPanel() {
@ -330,7 +357,7 @@ public class SplashScreen extends JWindow {
config.setShowSplashScreen(false); config.setShowSplashScreen(false);
Application.initializeApplication(layout, config); Application.initializeApplication(layout, config);
showSplashScreen(); showLater();
// tests that modal dialogs popup on top of the splash screen // tests that modal dialogs popup on top of the splash screen
// new Thread( new Runnable() { // new Thread( new Runnable() {

View file

@ -159,7 +159,7 @@ public class SplashScreenTest extends AbstractDockingTest {
private void showSplashScreen(final boolean makeVisible) { private void showSplashScreen(final boolean makeVisible) {
if (makeVisible) { if (makeVisible) {
SplashScreen splash = runSwing(() -> SplashScreen.showSplashScreen()); SplashScreen splash = SplashScreen.showNow();
assertNotNull("Failed showing splash screen", splash); assertNotNull("Failed showing splash screen", splash);
waitForSwing(); waitForSwing();
return; return;