Пример #1
0
  /**
   * Main UI initialization.
   *
   * @param trayname - name for the tray icon
   */
  public static void startUI(String trayname) {

    Errmsg.setErrorHandler(new UIErrorHandler());

    // check database timestamp
    try {
      JdbcDB.checkTimestamp();
    } catch (Warning e1) {
      Errmsg.getErrorHandler().notice(e1.getMessage());
    } catch (Exception e) {
      Errmsg.getErrorHandler().errmsg(e);
    }

    // default font
    String deffont = Prefs.getPref(PrefName.DEFFONT);
    if (!deffont.equals("")) {
      Font f = Font.decode(deffont);
      NwFontChooserS.setDefaultFont(f);
    }

    // set the look and feel
    String lnf = Prefs.getPref(PrefName.LNF);
    try {

      // set default jgoodies theme
      if (lnf.contains("jgoodies")) {
        String theme = System.getProperty("Plastic.defaultTheme");
        if (theme == null) {
          System.setProperty("Plastic.defaultTheme", Prefs.getPref(PrefName.GOODIESTHEME));
        }
      }

      UIManager.setLookAndFeel(lnf);
      UIManager.getLookAndFeelDefaults().put("ClassLoader", UIControl.class.getClassLoader());
    } catch (Exception e) {
      log.severe(e.toString());
    }

    // pop up the splash if the option is set
    if (Prefs.getBoolPref(PrefName.SPLASH)) {
      splashScreen = new SplashScreen();
      splashScreen.setText(Resource.getResourceString("Initializing"));
      splashScreen.setVisible(true);
      final String tn = trayname;

      /*
       * in order for the splash to be seen, we will complete
       * initialization later (in the swing thread).
       */
      Timer t =
          new Timer(
              3000,
              new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent arg0) {
                  completeUIInitialization(tn);
                }
              });
      t.setRepeats(false);
      t.start();
    } else completeUIInitialization(trayname);
  }
Пример #2
0
  /** shuts down the UI, including db backup */
  public static void shutDownUI() {

    // prompt for shutdown and backup options
    boolean do_backup = false;
    boolean backup_email = false;
    final String backupdir = Prefs.getPref(PrefName.BACKUPDIR);

    if (backupdir != null && !backupdir.equals("")) {

      String shutdown_action = Prefs.getPref(PrefName.SHUTDOWN_ACTION);
      if (shutdown_action.isEmpty() || SHUTDOWN_ACTION.PROMPT.toString().equals(shutdown_action)) {
        JRadioButton b1 =
            new JRadioButton(Resource.getResourceString("backup_notice") + " " + backupdir);
        JRadioButton b2 = new JRadioButton(Resource.getResourceString("exit_no_backup"));
        JRadioButton b3 = new JRadioButton(Resource.getResourceString("dont_exit"));
        JRadioButton b4 = new JRadioButton(Resource.getResourceString("backup_with_email"));

        b1.setSelected(true);

        ButtonGroup group = new ButtonGroup();
        group.add(b1);
        group.add(b2);
        group.add(b3);
        group.add(b4);

        Object[] array = {
          b1, b4, b2, b3,
        };

        int res =
            JOptionPane.showConfirmDialog(
                null,
                array,
                Resource.getResourceString("shutdown_options"),
                JOptionPane.OK_CANCEL_OPTION);

        if (res != JOptionPane.YES_OPTION) {
          return;
        }

        if (b3.isSelected()) return;
        if (b1.isSelected() || b4.isSelected()) do_backup = true;
        if (b4.isSelected()) backup_email = true;
      } else if (SHUTDOWN_ACTION.BACKUP.toString().equals(shutdown_action)) {
        do_backup = true;
      } else if (SHUTDOWN_ACTION.EMAIL.toString().equals(shutdown_action)) {
        do_backup = true;
        backup_email = true;
      }
    }

    // stop popup timer and destroy popups
    ReminderManager rm = ReminderManager.getReminderManager();
    if (rm != null) rm.remove();

    // show a splash screen for shutdown
    try {
      SplashScreen ban = new SplashScreen();
      ban.setText(Resource.getResourceString("shutdown"));
      ban.setVisible(true);

    } catch (Exception e) {
      e.printStackTrace();
    }

    // backup data
    if (do_backup == true) {
      try {
        ExportImport.exportToZip(backupdir, backup_email);
      } catch (Exception e) {
        Errmsg.getErrorHandler().errmsg(e);
        return;
      }
    }

    // non-UI shutdown
    if (shutdownListener != null) shutdownListener.update(null, null);
  }