Ejemplo n.º 1
0
  public static final void main(String[] args) {
    ResourceLoader.scalingHint = Image.SCALE_SMOOTH;
    setupUI(args);

    DrawDialog splash = new DrawDialog(null, APP_NAME + " Splash", true);
    splash.setModal(false);
    ImageIcon icon = ResourceLoader.getImage("jdomain/jdraw/images/logo.png");
    splash.getContentPane().add(new JLabel(icon));
    splash.open();

    preload();
    Picture picture = null;
    final int len = args.length;
    if (len > 0) {
      for (int i = 0; i < len; i++) {
        if (args[i] != null) {
          picture = LoadAction.readImage(args[i]);
          break;
        }
      }
    }
    if (picture == null) {
      picture = Picture.createDefaultPicture();
    }
    setPicture(picture);
    ResourceLoader.getImage("jdomain/jdraw/images/background.gif");

    Util.delay(SPLASH_DELAY);
    splash.close();
    ((DrawMenu) MainFrame.INSTANCE.getJMenuBar()).buildLastFilesMenu();
    DrawBrowser.INSTANCE.setOpenDir(Settings.INSTANCE.getOpenDir());
    DrawBrowser.INSTANCE.setSaveDir(Settings.INSTANCE.getSaveDir());
    ToolPanel.INSTANCE.getCurrentTool().activate();
    MainFrame.INSTANCE.setVisible(true);

    Log.info("Happy drawing!");
  }
 /**
  * Setup missing application files into the "home directory".
  *
  * @param targetDir
  * @throws IOException
  * @return true on success
  */
 private boolean restoreMissingFiles(final File targetDir) throws IOException {
   Debug.enter();
   boolean success = false;
   final SharedPreferences prefs = Settings.INSTANCE.getSharedPreferences();
   final String oldTarball = prefs.getString(SettingsStorage.FIELD_TARBALL, null);
   final String newTarball = getString(R.string.build_tarball);
   final boolean keepOldFiles = newTarball.equals(oldTarball);
   try {
     // extract the tar-ball to recover any missing file, if any
     final TarArchive tarball = new TarArchive(new GZIPInputStream(tarballFile()));
     tarball.keepOldFiles = keepOldFiles;
     tarball.extract(targetDir);
     tarball.close();
     // once the restore is completed successfully,
     // we need to update the shared preference, if necessary
     if (!keepOldFiles) {
       final SharedPreferences.Editor edit = prefs.edit();
       edit.putString(SettingsStorage.FIELD_TARBALL, newTarball);
       success = edit.commit();
     } else {
       success = true;
     }
   } catch (final Resources.NotFoundException ex) {
     // this exception usually would happen from the unit-tests
     Debug.error(ex, "tarball resources not found", keepOldFiles);
     // not really a fatal error if keepOldFiles is true
     if (!keepOldFiles) {
       Debug.leave();
       throw new IOException("Tarball resources missing");
     }
   } catch (final TarArchive.TarHeaderException ex) {
     Debug.error(ex, "invalid tarball header", keepOldFiles);
     Debug.leave();
     throw new IOException("Invalid tarball format");
   } catch (final IOException ex) {
     Debug.error(ex, "unable to install tarball", keepOldFiles);
     // not really a fatal error if keepOldFiles is true
     if (!keepOldFiles) {
       Debug.leave();
       throw ex;
     }
   }
   Debug.leave(success);
   return success;
 }