Skip to content

Commit 0fce75f

Browse files
committed
Move Splash initialization to EDT and make it no longer modal
- about 100ms faster startup (main method duration measured) and technically more correct anyway - use JFrame to get double buffering (no progress bar flicker during repaint) and we can use the opportunity to initialize swing asynchronously while NB is busy bootstrapping. - other change: splash window is no longer modal - code renovations most changes come from the fact that the model needed to be extracted from UI code so that it can be updated from any thread while the UI paints on EDT.
1 parent 462e4e1 commit 0fce75f

File tree

3 files changed

+296
-331
lines changed

3 files changed

+296
-331
lines changed

platform/core.startup/src/org/netbeans/core/startup/Main.java

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
package org.netbeans.core.startup;
2121

22-
import java.beans.Introspector;
2322
import java.io.File;
2423
import java.io.IOException;
2524
import java.lang.reflect.InvocationTargetException;
@@ -89,7 +88,7 @@ public static void initUICustomizations() {
8988
return;
9089
}
9190

92-
Class uiClass = CLIOptions.uiClass;
91+
Class<?> uiClass = CLIOptions.uiClass;
9392
// try again loading L&F class, this time with full module system.
9493
if (CLIOptions.uiClassName != null && CLIOptions.uiClass == null) {
9594
// try again
@@ -163,7 +162,7 @@ public static ModuleSystem getModuleSystem(boolean init) {
163162
SystemFileSystem.registerMutex(moduleSystem.getManager().mutex());
164163
} catch (IOException ioe) {
165164
// System will be screwed up.
166-
throw (IllegalStateException) new IllegalStateException("Module system cannot be created").initCause(ioe); // NOI18N
165+
throw new IllegalStateException("Module system cannot be created", ioe); // NOI18N
167166
}
168167
StartLog.logProgress ("ModuleSystem created"); // NOI18N
169168
}
@@ -316,7 +315,6 @@ static void start (String[] args) throws SecurityException {
316315
level.run();
317316
}
318317

319-
Splash.getInstance().setRunning(false);
320318
Splash.getInstance().dispose();
321319
StartLog.logProgress ("Splash hidden"); // NOI18N
322320
StartLog.logEnd ("Preparation"); // NOI18N
@@ -347,7 +345,7 @@ private static void rm(File f) {
347345
}
348346

349347
/** Loads a class from available class loaders. */
350-
private static final Class getKlass(String cls) {
348+
private static Class<?> getKlass(String cls) {
351349
try {
352350
ClassLoader loader;
353351
ModuleSystem ms = moduleSystem;
@@ -380,7 +378,7 @@ public boolean shouldDoAnImport () {
380378
return classname != null && !installed.exists ();
381379
}
382380

383-
381+
@Override
384382
public void run() {
385383
// This module is included in our distro somewhere... may or may not be turned on.
386384
// Whatever - try running some classes from it anyway.
@@ -400,16 +398,12 @@ public void run() {
400398
} else {
401399
LOG.log(Level.WARNING, null, ex);
402400
}
403-
} catch (Exception e) {
401+
} catch (Exception | LinkageError e) {
404402
// If exceptions are thrown, notify them - something is broken.
405403
LOG.log(Level.WARNING, null, e);
406-
} catch (LinkageError e) {
407-
// These too...
408-
LOG.log(Level.WARNING, null, e);
409404
}
410405
}
411406

412-
413407
public boolean canContinue () {
414408
if (shouldDoAnImport ()) {
415409
try {
@@ -440,7 +434,6 @@ public boolean canContinue () {
440434
}
441435
}
442436

443-
444437
ImportHandler handler = new ImportHandler ();
445438

446439
return handler.canContinue ();
@@ -493,12 +486,9 @@ public void run() {
493486
} else {
494487
LOG.log(Level.WARNING, null, ex);
495488
}
496-
} catch (Exception ex) {
489+
} catch (Exception | LinkageError ex) {
497490
// If exceptions are thrown, notify them - something is broken.
498491
LOG.log(Level.WARNING, null, ex);
499-
} catch (LinkageError ex) {
500-
// These too...
501-
LOG.log(Level.WARNING, null, ex);
502492
}
503493
}
504494

platform/core.startup/src/org/netbeans/core/startup/NbEvents.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
package org.netbeans.core.startup;
2121

22-
import java.awt.Component;
2322
import java.awt.Desktop;
2423
import java.awt.Dimension;
2524
import java.awt.EventQueue;
2625
import java.awt.GraphicsEnvironment;
2726
import java.awt.event.ActionEvent;
2827
import java.awt.event.ActionListener;
2928
import java.io.File;
29+
import java.lang.reflect.InvocationTargetException;
3030
import java.util.ArrayList;
3131
import java.util.Collection;
3232
import java.util.List;
@@ -51,7 +51,6 @@
5151
import org.openide.modules.SpecificationVersion;
5252
import org.openide.util.NbBundle.Messages;
5353
import org.openide.util.NbCollections;
54-
import org.openide.util.RequestProcessor;
5554

5655
/** Report events to the performance logger, status text/splash screen,
5756
* console, and so on.
@@ -333,9 +332,8 @@ private void notify(String text, boolean warn) {
333332
private static final class Notifier implements Runnable {
334333
private static boolean showDialog = true;
335334

336-
private boolean warn;
335+
private final boolean warn;
337336
private String text;
338-
private static RequestProcessor RP = new RequestProcessor("Notify About Module System"); // NOI18N
339337

340338
public Notifier(String text, boolean type) {
341339
this.warn = type;
@@ -347,7 +345,11 @@ void show() {
347345
if (EventQueue.isDispatchThread()) {
348346
run();
349347
} else {
350-
RP.post(this, 0, Thread.MIN_PRIORITY).waitFinished ();
348+
try {
349+
EventQueue.invokeAndWait(this);
350+
} catch (InterruptedException | InvocationTargetException ex) {
351+
logger.log(Level.SEVERE, "Notifier failed", ex); // NOI18N
352+
}
351353
}
352354
}
353355
}
@@ -362,17 +364,9 @@ void show() {
362364
int type = warn ? JOptionPane.WARNING_MESSAGE : JOptionPane.INFORMATION_MESSAGE;
363365
String msg = warn ? MSG_warning() : MSG_info();
364366

365-
Splash out = Splash.getInstance();
366-
final Component c = out.getComponent() == null ? null : out.getComponent();
367367
try {
368368
UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ());
369-
} catch (ClassNotFoundException ex) {
370-
logger.log(Level.INFO, null, ex);
371-
} catch (InstantiationException ex) {
372-
logger.log(Level.INFO, null, ex);
373-
} catch (IllegalAccessException ex) {
374-
logger.log(Level.INFO, null, ex);
375-
} catch (UnsupportedLookAndFeelException ex) {
369+
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
376370
logger.log(Level.INFO, null, ex);
377371
}
378372
JTextPane tp = new JTextPane ();
@@ -423,7 +417,7 @@ void show() {
423417
Object [] options = new JButton [] {continueButton, exitButton};
424418
op.setOptions (options);
425419
op.setInitialValue (options [1]);
426-
JDialog d = op.createDialog (c, msg);
420+
JDialog d = op.createDialog(Splash.getInstance().getComponent(), msg);
427421
d.setResizable (true);
428422
d.pack();
429423
d.setVisible (true);

0 commit comments

Comments
 (0)