コード例 #1
0
ファイル: Launcher.java プロジェクト: XPSCAVENGER/icepdf
  /**
   * Starts the viewe application.
   *
   * @param contentFile URI of a file which will be loaded at runtime, can be null.
   * @param contentURL URL of a file which will be loaded at runtime, can be null.
   * @param contentProperties URI of a properties file which will be used in place of the default
   *     path
   * @param messageBundle messageBundle to pull strings from
   */
  private static void run(
      String contentFile,
      String contentURL,
      String contentProperties,
      ResourceBundle messageBundle) {

    // initiate the properties manager.
    Properties sysProps = System.getProperties();
    propertiesManager = new PropertiesManager(sysProps, contentProperties, messageBundle);

    // initiate font Cache manager, reads system font data and stores summary
    // information in a properties file.  If new font are added to the OS
    // then the properties file can be deleted to initiate a re-read of the
    // font data.
    new FontPropertiesManager(propertiesManager, sysProps, messageBundle);

    // input new System properties
    System.setProperties(sysProps);

    // set look & feel
    setupLookAndFeel(messageBundle);

    ViewModel.setDefaultFilePath(propertiesManager.getDefaultFilePath());
    ViewModel.setDefaultURL(propertiesManager.getDefaultURL());

    // application instance
    windowManager = new WindowManager(propertiesManager, messageBundle);
    if (contentFile != null && contentFile.length() > 0) {
      windowManager.newWindow(contentFile);
      ViewModel.setDefaultFilePath(contentFile);
    }

    // load a url if specified
    if (contentURL != null && contentURL.length() > 0) {
      URLAccess urlAccess = URLAccess.doURLAccess(contentURL);
      urlAccess.closeConnection();
      if (urlAccess.errorMessage != null) {

        // setup a patterned message
        Object[] messageArguments = {urlAccess.errorMessage, urlAccess.urlLocation};
        MessageFormat formatter =
            new MessageFormat(messageBundle.getString("viewer.launcher.URLError.dialog.message"));

        JOptionPane.showMessageDialog(
            null,
            formatter.format(messageArguments),
            messageBundle.getString("viewer.launcher.URLError.dialog.title"),
            JOptionPane.INFORMATION_MESSAGE);
      } else {
        windowManager.newWindow(urlAccess.url);
      }
      ViewModel.setDefaultURL(urlAccess.urlLocation);
      urlAccess.dispose();
    }

    // Start an empy viewer if there was no command line parameters
    if (((contentFile == null || contentFile.length() == 0)
            && (contentURL == null || contentURL.length() == 0))
        || (windowManager.getNumberOfWindows() == 0)) {
      windowManager.newWindow("");
    }
  }