Search in sources :

Example 1 with UIPropertyContext

use of pcgen.gui2.UIPropertyContext in project pcgen by PCGen.

the class ExportDialog method maybeOpenFile.

private void maybeOpenFile(File file) {
    UIPropertyContext context = UIPropertyContext.getInstance();
    String value = context.getProperty(UIPropertyContext.ALWAYS_OPEN_EXPORT_FILE);
    Boolean openFile = StringUtils.isEmpty(value) ? null : Boolean.valueOf(value);
    if (openFile == null) {
        JCheckBox checkbox = new JCheckBox();
        checkbox.setText("Always perform this action");
        JPanel message = PCGenFrame.buildMessageLabelPanel("Do you want to open " + file.getName() + "?", checkbox);
        int ret = JOptionPane.showConfirmDialog(this, message, "Select an Option", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
        if (ret == JOptionPane.CLOSED_OPTION) {
            return;
        }
        openFile = BooleanUtils.toBoolean(ret, JOptionPane.YES_OPTION, JOptionPane.NO_OPTION);
        if (checkbox.isSelected()) {
            context.setBoolean(UIPropertyContext.ALWAYS_OPEN_EXPORT_FILE, openFile);
        }
    }
    if (!openFile) {
        return;
    }
    if (!Desktop.isDesktopSupported() || !Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
        pcgenFrame.showErrorMessage("Cannot Open " + file.getName(), "Operating System does not support this operation");
        return;
    }
    try {
        Desktop.getDesktop().open(file);
    } catch (IOException ex) {
        String message = "Failed to open " + file.getName();
        pcgenFrame.showErrorMessage(Constants.APPLICATION_NAME, message);
        Logging.errorPrint(message, ex);
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) IOException(java.io.IOException) UIPropertyContext(pcgen.gui2.UIPropertyContext)

Example 2 with UIPropertyContext

use of pcgen.gui2.UIPropertyContext in project pcgen by PCGen.

the class ExportDialog method export.

private void export(boolean pdf) {
    UIPropertyContext context = UIPropertyContext.createContext("ExportDialog");
    final JFileChooser fcExport = new JFileChooser();
    fcExport.setFileSelectionMode(JFileChooser.FILES_ONLY);
    File baseDir = null;
    {
        String path;
        if (pdf) {
            path = context.getProperty(PDF_EXPORT_DIR_PROP);
        } else {
            path = context.getProperty(HTML_EXPORT_DIR_PROP);
        }
        if (path != null) {
            baseDir = new File(path);
        }
    }
    if (baseDir == null || !baseDir.isDirectory()) {
        baseDir = SystemUtils.getUserHome();
    }
    fcExport.setCurrentDirectory(baseDir);
    URI uri = (URI) fileList.getSelectedValue();
    String extension = ExportUtilities.getOutputExtension(uri.toString(), pdf);
    if (pdf) {
        FileFilter fileFilter = new FileNameExtensionFilter("PDF Documents (*.pdf)", "pdf");
        fcExport.addChoosableFileFilter(fileFilter);
        fcExport.setFileFilter(fileFilter);
    } else if ("htm".equalsIgnoreCase(extension) || "html".equalsIgnoreCase(extension)) {
        FileFilter fileFilter = new FileNameExtensionFilter("HTML Documents (*.htm, *.html)", "htm", "html");
        fcExport.addChoosableFileFilter(fileFilter);
        fcExport.setFileFilter(fileFilter);
    } else if ("xml".equalsIgnoreCase(extension)) {
        FileFilter fileFilter = new FileNameExtensionFilter("XML Documents (*.xml)", "xml");
        fcExport.addChoosableFileFilter(fileFilter);
        fcExport.setFileFilter(fileFilter);
    } else {
        String desc = extension + " Files (*." + extension + ")";
        fcExport.addChoosableFileFilter(new FileNameExtensionFilter(desc, extension));
    }
    String name;
    File path;
    if (!partyBox.isSelected()) {
        CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem();
        path = character.getFileRef().get();
        if (path != null) {
            path = path.getParentFile();
        } else {
            path = new File(PCGenSettings.getPcgDir());
        }
        name = character.getTabNameRef().get();
        if (StringUtils.isEmpty(name)) {
            name = character.getNameRef().get();
        }
    } else {
        path = new File(PCGenSettings.getPcgDir());
        name = "Entire Party";
    }
    if (pdf) {
        fcExport.setSelectedFile(new File(path, name + ".pdf"));
    } else {
        fcExport.setSelectedFile(new File(path, name + "." + extension));
    }
    fcExport.setDialogTitle("Export " + name);
    if (fcExport.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
        return;
    }
    final File outFile = fcExport.getSelectedFile();
    if (pdf) {
        context.setProperty(PDF_EXPORT_DIR_PROP, outFile.getParent());
    } else {
        context.setProperty(HTML_EXPORT_DIR_PROP, outFile.getParent());
    }
    if (StringUtils.isEmpty(outFile.getName())) {
        pcgenFrame.showErrorMessage("PCGen", "You must set a filename.");
        return;
    }
    if (outFile.isDirectory()) {
        pcgenFrame.showErrorMessage("PCGen", "You cannot overwrite a directory with a file.");
        return;
    }
    if (outFile.exists() && SettingsHandler.getAlwaysOverwrite() == false) {
        int reallyClose = JOptionPane.showConfirmDialog(this, "The file " + outFile.getName() + " already exists, are you sure you want to overwrite it?", "Confirm overwriting " + outFile.getName(), JOptionPane.YES_NO_OPTION);
        if (reallyClose != JOptionPane.YES_OPTION) {
            return;
        }
    }
    try {
        if (pdf) {
            new PDFExporter(outFile, extension, name).execute();
        } else {
            if (!printToFile(outFile)) {
                String message = "The character export failed. Please see the log for details.";
                pcgenFrame.showErrorMessage(Constants.APPLICATION_NAME, message);
                return;
            }
            maybeOpenFile(outFile);
            Globals.executePostExportCommandStandard(outFile.getAbsolutePath());
        }
    } catch (IOException ex) {
        pcgenFrame.showErrorMessage("PCGen", "Could not export " + name + ". Try another filename.");
        Logging.errorPrint("Could not export " + name, ex);
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) IOException(java.io.IOException) IOFileFilter(org.apache.commons.io.filefilter.IOFileFilter) TrueFileFilter(org.apache.commons.io.filefilter.TrueFileFilter) SuffixFileFilter(org.apache.commons.io.filefilter.SuffixFileFilter) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) UIPropertyContext(pcgen.gui2.UIPropertyContext) File(java.io.File) URI(java.net.URI) CharacterFacade(pcgen.facade.core.CharacterFacade)

Example 3 with UIPropertyContext

use of pcgen.gui2.UIPropertyContext in project pcgen by PCGen.

the class CharacterFacadeImpl method setDefaultOutputSheet.

@Override
public void setDefaultOutputSheet(boolean pdf, File outputSheet) {
    UIPropertyContext context = UIPropertyContext.getInstance();
    String outputSheetPath = outputSheet.getAbsolutePath();
    if (pdf) {
        context.setProperty(UIPropertyContext.DEFAULT_PDF_OUTPUT_SHEET, outputSheetPath);
    } else {
        context.setProperty(UIPropertyContext.DEFAULT_HTML_OUTPUT_SHEET, outputSheetPath);
    }
    if (context.getBoolean(UIPropertyContext.SAVE_OUTPUT_SHEET_WITH_PC)) {
        if (pdf) {
            theCharacter.setSelectedCharacterPDFOutputSheet(outputSheetPath);
        } else {
            theCharacter.setSelectedCharacterHTMLOutputSheet(outputSheetPath);
        }
    }
}
Also used : UIPropertyContext(pcgen.gui2.UIPropertyContext)

Example 4 with UIPropertyContext

use of pcgen.gui2.UIPropertyContext in project pcgen by PCGen.

the class OutputPanel method applyOptionValuesToControls.

/**
	 * @see pcgen.gui2.prefs.PreferencesPanel#initPreferences()
	 */
@Override
public void applyOptionValuesToControls() {
    UIPropertyContext context = UIPropertyContext.getInstance();
    paperType.setSelectedIndex(Globals.getSelectedPaper());
    weaponProfPrintout.setSelected(SettingsHandler.getWeaponProfPrintout());
    outputSheetHTMLDefault.setText(context.getProperty(UIPropertyContext.DEFAULT_HTML_OUTPUT_SHEET));
    outputSheetPDFDefault.setText(context.getProperty(UIPropertyContext.DEFAULT_PDF_OUTPUT_SHEET));
    saveOutputSheetWithPC.setSelected(context.getBoolean(UIPropertyContext.SAVE_OUTPUT_SHEET_WITH_PC));
    removeTempFiles.setSelected(context.initBoolean(UIPropertyContext.CLEANUP_TEMP_FILES, true));
    printSpellsWithPC.setSelected(SettingsHandler.getPrintSpellsWithPC());
    skillFilter.setSelectedItem(SkillFilter.getByValue(PCGenSettings.OPTIONS_CONTEXT.initInt(PCGenSettings.OPTION_SKILL_FILTER, SkillFilter.Usable.getValue())));
    String value = context.getProperty(UIPropertyContext.ALWAYS_OPEN_EXPORT_FILE);
    exportChoice.setSelectedItem(ExportChoices.getChoice(value));
    generateTempFileWithPdf.setSelected(PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_GENERATE_TEMP_FILE_WITH_PDF, false));
}
Also used : UIPropertyContext(pcgen.gui2.UIPropertyContext)

Example 5 with UIPropertyContext

use of pcgen.gui2.UIPropertyContext in project pcgen by PCGen.

the class OutputPanel method setOptionsBasedOnControls.

/**
	 * @see pcgen.gui2.prefs.PreferencesPanel#applyPreferences()
	 */
@Override
public void setOptionsBasedOnControls() {
    UIPropertyContext context = UIPropertyContext.getInstance();
    Globals.selectPaper((String) paperType.getSelectedItem());
    context.setBoolean(UIPropertyContext.CLEANUP_TEMP_FILES, removeTempFiles.isSelected());
    if (SettingsHandler.getWeaponProfPrintout() != weaponProfPrintout.isSelected()) {
        SettingsHandler.setWeaponProfPrintout(weaponProfPrintout.isSelected());
    }
    if (SettingsHandler.getAlwaysOverwrite() || alwaysOverwrite.isSelected()) {
        SettingsHandler.setAlwaysOverwrite(alwaysOverwrite.isSelected());
    }
    if (SettingsHandler.getShowSingleBoxPerBundle() || showSingleBoxPerBundle.isSelected()) {
        SettingsHandler.setShowSingleBoxPerBundle(showSingleBoxPerBundle.isSelected());
    }
    context.setProperty(UIPropertyContext.DEFAULT_HTML_OUTPUT_SHEET, outputSheetHTMLDefault.getText());
    context.setProperty(UIPropertyContext.DEFAULT_PDF_OUTPUT_SHEET, outputSheetPDFDefault.getText());
    SettingsHandler.setSelectedEqSetTemplate(outputSheetEqSet.getText());
    context.setBoolean(UIPropertyContext.SAVE_OUTPUT_SHEET_WITH_PC, saveOutputSheetWithPC.isSelected());
    SettingsHandler.setSelectedSpellSheet(outputSheetSpellsDefault.getText());
    SettingsHandler.setPrintSpellsWithPC(printSpellsWithPC.isSelected());
    SettingsHandler.setPostExportCommandStandard(postExportCommandStandard.getText());
    SettingsHandler.setPostExportCommandPDF(postExportCommandPDF.getText());
    SettingsHandler.setInvalidToHitText(invalidToHitText.getText());
    SettingsHandler.setInvalidDmgText(invalidDmgText.getText());
    PCGenSettings.OPTIONS_CONTEXT.setInt(PCGenSettings.OPTION_SKILL_FILTER, ((SkillFilter) skillFilter.getSelectedItem()).getValue());
    ExportChoices choice = (ExportChoices) exportChoice.getSelectedItem();
    context.setProperty(UIPropertyContext.ALWAYS_OPEN_EXPORT_FILE, choice.getValue());
    PCGenSettings.OPTIONS_CONTEXT.setBoolean(PCGenSettings.OPTION_GENERATE_TEMP_FILE_WITH_PDF, generateTempFileWithPdf.isSelected());
}
Also used : UIPropertyContext(pcgen.gui2.UIPropertyContext)

Aggregations

UIPropertyContext (pcgen.gui2.UIPropertyContext)7 IOException (java.io.IOException)2 CharacterFacade (pcgen.facade.core.CharacterFacade)2 Component (java.awt.Component)1 File (java.io.File)1 URI (java.net.URI)1 DefaultListCellRenderer (javax.swing.DefaultListCellRenderer)1 JCheckBox (javax.swing.JCheckBox)1 JFileChooser (javax.swing.JFileChooser)1 JList (javax.swing.JList)1 JPanel (javax.swing.JPanel)1 FileFilter (javax.swing.filechooser.FileFilter)1 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)1 IOFileFilter (org.apache.commons.io.filefilter.IOFileFilter)1 SuffixFileFilter (org.apache.commons.io.filefilter.SuffixFileFilter)1 TrueFileFilter (org.apache.commons.io.filefilter.TrueFileFilter)1 PropertyContext (pcgen.system.PropertyContext)1