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);
}
}
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);
}
}
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);
}
}
}
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));
}
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());
}
Aggregations