예제 #1
0
  public void exit(boolean kill) {
    log.debug("Exiting application");
    PreferencesStore.savePreferences();

    FileOutputStream out = null;
    File a = getApplicationPreferencesDirectory();

    if (a != null) {
      try {
        File f = new File(getApplicationPreferencesDirectory(), getApplicationName() + ".mru");
        ;

        if (log.isDebugEnabled()) {
          log.debug("Saving MRU to " + f.getAbsolutePath());
        }

        out = new FileOutputStream(f);

        PrintWriter w = new PrintWriter(out, true);
        w.println(mruModel.getMRUList().toString());
      } catch (IOException ioe) {
        log.error("Could not save MRU. ", ioe);
      } finally {
        IOUtil.closeStream(out);
      }
    } else {
      log.debug("Not saving preferences because no preferences directory is available.");
    }
    if (kill) {
      com.sshtools.common.util.ShutdownHooks.exit(kill);
    }
  }
예제 #2
0
  /**
   * Creates a new SshToolsApplication object.
   *
   * @param panelClass
   * @param defaultContainerClass
   */
  public SshToolsApplication(Class panelClass, Class defaultContainerClass) {
    this.panelClass = panelClass;
    this.defaultContainerClass = defaultContainerClass;
    additionalOptionsTabs = new java.util.ArrayList();

    try {
      if (System.getSecurityManager() != null) {
        AccessController.checkPermission(new FilePermission("<<ALL FILES>>", "write"));
      }

      File a = getApplicationPreferencesDirectory();

      if (a == null) {
        throw new AccessControlException("Application preferences directory not specified.");
      }

      InputStream in = null;
      MRUList mru = new MRUList();

      try {
        File f = new File(a, getApplicationName() + ".mru");

        if (f.exists()) {
          if (log.isDebugEnabled()) {
            log.debug("Loading MRU from " + f.getAbsolutePath());
          }

          in = new FileInputStream(f);
          mru.reload(in);
        } else {
          if (log.isDebugEnabled()) {
            log.debug("MRU file " + f.getAbsolutePath() + " doesn't exist, creating empty list");
          }
        }
      } catch (Exception e) {
        log.error("Could not load MRU list.", e);
      } finally {
        IOUtil.closeStream(in);
      }

      mruModel = new MRUListModel();
      mruModel.setMRUList(mru);
    } catch (AccessControlException ace) {
      log.error("Could not load MRU.", ace);
    }
  }