예제 #1
0
  @Override
  public void previewSpells() {
    boolean aBool = SettingsHandler.getPrintSpellsWithPC();
    SettingsHandler.setPrintSpellsWithPC(true);

    String templateFileName =
        PCGenSettings.getInstance().getProperty(PCGenSettings.SELECTED_SPELL_SHEET_PATH);
    if (StringUtils.isEmpty(templateFileName)) {
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME, LanguageBundle.getString("in_spellNoSheet")); // $NON-NLS-1$
      return;
    }
    File templateFile = new File(templateFileName);

    File outputFile = BatchExporter.getTempOutputFilename(templateFile);

    boolean success;
    if (ExportUtilities.isPdfTemplate(templateFile)) {
      success = BatchExporter.exportCharacterToPDF(pcFacade, outputFile, templateFile);
    } else {
      success = BatchExporter.exportCharacterToNonPDF(pcFacade, outputFile, templateFile);
    }
    if (success) {
      try {
        Utility.viewInBrowser(outputFile);
      } catch (IOException e) {
        Logging.errorPrint("SpellSupportFacadeImpl.previewSpells failed", e);
        delegate.showErrorMessage(
            Constants.APPLICATION_NAME,
            LanguageBundle.getString("in_spellPreviewFail")); // $NON-NLS-1$
      }
    }
    SettingsHandler.setPrintSpellsWithPC(aBool);
  }
예제 #2
0
 @Override
 public boolean performAnalysis(CDOMObject pc) {
   TaskStrategyMessage.sendStatus(this, "Finding Data Directories");
   campaignList = pc.getListFor(ListKey.CAMPAIGN);
   path = pc.get(ObjectKey.WRITE_DIRECTORY);
   if (path != null) {
     fileLabel.setText(path.getAbsolutePath());
   } else {
     PCGenSettings context = PCGenSettings.getInstance();
     String outputPathName =
         context.initProperty(PCGenSettings.CONVERT_OUTPUT_SAVE_PATH, SystemUtils.USER_DIR);
     path = new File(outputPathName);
   }
   pc.put(ObjectKey.WRITE_DIRECTORY, path);
   fireProgressEvent(ProgressEvent.ALLOWED);
   return true;
 }
예제 #3
0
  @Override
  public void exportSpells() {
    final String template =
        PCGenSettings.getInstance().getProperty(PCGenSettings.SELECTED_SPELL_SHEET_PATH);
    if (StringUtils.isEmpty(template)) {
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME, LanguageBundle.getString("in_spellNoSheet")); // $NON-NLS-1$
      return;
    }
    String ext = template.substring(template.lastIndexOf('.'));

    // Get the name of the file to output to.
    JFileChooser fcExport = new JFileChooser();
    fcExport.setCurrentDirectory(new File(PCGenSettings.getPcgDir()));
    fcExport.setDialogTitle(
        LanguageBundle.getString("InfoSpells.export.spells.for")
            + charDisplay.getDisplayName()); // $NON-NLS-1$

    if (fcExport.showSaveDialog(null) != JFileChooser.APPROVE_OPTION) {
      return;
    }
    final String aFileName = fcExport.getSelectedFile().getAbsolutePath();
    if (aFileName.length() < 1) {
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME,
          LanguageBundle.getString("InfoSpells.must.set.filename")); // $NON-NLS-1$
      return;
    }

    try {
      final File outFile = new File(aFileName);

      if (outFile.isDirectory()) {
        delegate.showErrorMessage(
            Constants.APPLICATION_NAME,
            LanguageBundle.getString("InfoSpells.can.not.overwrite.directory")); // $NON-NLS-1$
        return;
      }

      if (outFile.exists()) {
        int reallyClose =
            JOptionPane.showConfirmDialog(
                null,
                LanguageBundle.getFormattedString(
                    "InfoSpells.confirm.overwrite", outFile.getName()), // $NON-NLS-1$
                LanguageBundle.getFormattedString("InfoSpells.overwriting", outFile.getName()),
                JOptionPane.YES_NO_OPTION); // $NON-NLS-1$

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

      // Output the file
      File templateFile = new File(template);
      boolean success;
      if (ExportUtilities.isPdfTemplate(templateFile)) {
        success = BatchExporter.exportCharacterToPDF(pcFacade, outFile, templateFile);
      } else {
        success = BatchExporter.exportCharacterToNonPDF(pcFacade, outFile, templateFile);
      }

      if (!success) {
        delegate.showErrorMessage(
            Constants.APPLICATION_NAME,
            LanguageBundle.getFormattedString(
                "InfoSpells.export.failed", charDisplay.getDisplayName())); // $NON-NLS-1$
      }
    } catch (Exception ex) {
      Logging.errorPrint(
          LanguageBundle.getFormattedString(
              "InfoSpells.export.failed", charDisplay.getDisplayName()),
          ex); //$NON-NLS-1$
      delegate.showErrorMessage(
          Constants.APPLICATION_NAME,
          LanguageBundle.getFormattedString(
              "InfoSpells.export.failed.retry", charDisplay.getDisplayName())); // $NON-NLS-1$
    }
  }