1 package net.sf.openrocket.gui.dialogs;
3 import java.awt.SplashScreen;
4 import java.awt.Window;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
8 import javax.swing.JDialog;
9 import javax.swing.JLabel;
10 import javax.swing.JPanel;
11 import javax.swing.JProgressBar;
12 import javax.swing.Timer;
14 import net.miginfocom.swing.MigLayout;
15 import net.sf.openrocket.database.ThrustCurveMotorSetDatabase;
16 import net.sf.openrocket.gui.util.GUIUtil;
17 import net.sf.openrocket.l10n.Translator;
18 import net.sf.openrocket.logging.LogHelper;
19 import net.sf.openrocket.startup.Application;
22 * A progress dialog displayed while loading motors.
24 * @author Sampo Niskanen <sampo.niskanen@iki.fi>
26 public class MotorDatabaseLoadingDialog extends JDialog {
27 private static final LogHelper log = Application.getLogger();
28 private static final Translator trans = Application.getTranslator();
31 private MotorDatabaseLoadingDialog(Window parent) {
33 super(parent, trans.get("MotorDbLoadDlg.title"), ModalityType.APPLICATION_MODAL);
35 JPanel panel = new JPanel(new MigLayout("fill"));
36 //// Loading motors...
37 panel.add(new JLabel(trans.get("MotorDbLoadDlg.Loadingmotors")), "wrap para");
39 JProgressBar progress = new JProgressBar();
40 progress.setIndeterminate(true);
41 panel.add(progress, "growx");
45 this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
46 this.setLocationByPlatform(true);
47 GUIUtil.setWindowIcons(this);
52 * Check whether the motor database is loaded and block until it is.
53 * An uncloseable modal dialog window is opened while loading unless the splash screen
54 * is still being displayed.
56 * @param parent the parent window for the dialog, or <code>null</code>
58 public static void check(Window parent) {
59 // TODO - ugly blind cast
60 final ThrustCurveMotorSetDatabase db = (ThrustCurveMotorSetDatabase) Application.getMotorSetDatabase();
64 if (SplashScreen.getSplashScreen() == null) {
66 log.info(1, "Motor database not loaded yet, displaying dialog");
68 final MotorDatabaseLoadingDialog dialog = new MotorDatabaseLoadingDialog(parent);
70 final Timer timer = new Timer(100, new ActionListener() {
71 private int count = 0;
74 public void actionPerformed(ActionEvent e) {
77 log.debug("Database loaded, closing dialog");
78 dialog.setVisible(false);
79 } else if (count % 10 == 0) {
80 log.debug("Database not loaded, count=" + count);
87 dialog.setVisible(true);
92 log.info(1, "Motor database not loaded yet, splash screen still present, delaying until loaded");
96 while (!db.isLoaded()) {
99 } catch (InterruptedException e) {
104 if (count % 10 == 0) {
105 log.debug("Database not loaded, count=" + count);
111 log.info("Motor database now loaded");