use of pcgen.system.PCGenSettings in project pcgen by PCGen.
the class CampaignPanel method saveSourceSelection.
private void saveSourceSelection(CDOMObject pc) {
List<Campaign> selCampaigns = pc.getSafeListFor(ListKey.CAMPAIGN);
PCGenSettings context = PCGenSettings.getInstance();
context.setProperty(PCGenSettings.CONVERT_SOURCES, StringUtils.join(selCampaigns, "|"));
}
use of pcgen.system.PCGenSettings in project pcgen by PCGen.
the class PCGenFrame method showOpenPartyChooser.
void showOpenPartyChooser() {
PCGenSettings context = PCGenSettings.getInstance();
chooser.setCurrentDirectory(new File(context.getProperty(PCGenSettings.PCP_SAVE_PATH)));
chooser.resetChoosableFileFilters();
chooser.setFileFilter(new FileNameExtensionFilter("Pcp files only", "pcp"));
int returnVal = chooser.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
loadPartyFromFile(file);
}
}
use of pcgen.system.PCGenSettings in project pcgen by PCGen.
the class PCGenFrame method showSaveCharacterChooser.
/**
* This brings up a file chooser allows the user to select
* the location that a character should be saved to.
* @param character the character to be saved
*/
boolean showSaveCharacterChooser(CharacterFacade character) {
PCGenSettings context = PCGenSettings.getInstance();
String parentPath = lastCharacterPath;
if (parentPath == null) {
parentPath = context.getProperty(PCGenSettings.PCG_SAVE_PATH);
}
chooser.setCurrentDirectory(new File(parentPath));
File file = character.getFileRef().get();
File prevFile = file;
if (file == null || StringUtils.isEmpty(file.getName())) {
file = new File(parentPath, character.getNameRef().get() + Constants.EXTENSION_CHARACTER_FILE);
}
chooser.setSelectedFile(file);
chooser.resetChoosableFileFilters();
FileFilter filter = new FileNameExtensionFilter("Pcg files only", "pcg");
chooser.addChoosableFileFilter(filter);
chooser.setFileFilter(filter);
int ret = chooser.showSaveDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
file = chooser.getSelectedFile();
if (!file.getName().endsWith(Constants.EXTENSION_CHARACTER_FILE)) {
file = new File(file.getParent(), file.getName() + Constants.EXTENSION_CHARACTER_FILE);
}
UIDelegate delegate = character.getUIDelegate();
if (file.isDirectory()) {
delegate.showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("in_savePcDirOverwrite"));
return showSaveCharacterChooser(character);
}
if (file.exists() && (prevFile == null || !file.getName().equals(prevFile.getName()))) {
boolean overwrite = delegate.showWarningConfirm(LanguageBundle.getFormattedString(//$NON-NLS-1$
"in_savePcConfirmOverTitle", file.getName()), LanguageBundle.getFormattedString(//$NON-NLS-1$
"in_savePcConfirmOverMsg", file.getName()));
if (!overwrite) {
return showSaveCharacterChooser(character);
}
}
try {
character.setFile(file);
prepareForSave(character, false);
if (!reallySaveCharacter(character)) {
return showSaveCharacterChooser(character);
}
lastCharacterPath = chooser.getCurrentDirectory().toString();
return true;
} catch (Exception e) {
//$NON-NLS-1$
Logging.errorPrint("Error saving character to new file " + file, e);
delegate.showErrorMessage(Constants.APPLICATION_NAME, LanguageBundle.getFormattedString("in_saveFailMsg", //$NON-NLS-1$
file.getName()));
}
}
return false;
}
use of pcgen.system.PCGenSettings in project pcgen by PCGen.
the class PCGenFrame method showOpenCharacterChooser.
void showOpenCharacterChooser() {
PCGenSettings context = PCGenSettings.getInstance();
String path = lastCharacterPath;
if (path == null) {
path = context.getProperty(PCGenSettings.PCG_SAVE_PATH);
}
chooser.setCurrentDirectory(new File(path));
//$NON-NLS-1$
chooser.setSelectedFile(new File(""));
chooser.resetChoosableFileFilters();
FileFilter filter = new FileNameExtensionFilter("Pcg files only", "pcg");
chooser.addChoosableFileFilter(filter);
chooser.setFileFilter(filter);
int ret = chooser.showOpenDialog(this);
if (ret == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
loadCharacterFromFile(file);
lastCharacterPath = chooser.getCurrentDirectory().toString();
}
}
use of pcgen.system.PCGenSettings in project pcgen by PCGen.
the class WriteDirectoryPanel method setupDisplay.
@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
panel.setLayout(layout);
Component label = new JLabel("Please select the Directory where Converted files should be written: ");
AbstractButton button = new JButton("Browse...");
button.setMnemonic('r');
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
chooser.setCurrentDirectory(path.getParentFile());
chooser.setSelectedFile(path);
while (true) {
int open = chooser.showOpenDialog(null);
if (open == JFileChooser.APPROVE_OPTION) {
File fileToOpen = chooser.getSelectedFile();
if (fileToOpen.isDirectory() && fileToOpen.canRead() && fileToOpen.canWrite()) {
path = fileToOpen;
pc.put(ObjectKey.WRITE_DIRECTORY, path);
fileLabel.setText(path.getAbsolutePath());
PCGenSettings context = PCGenSettings.getInstance();
context.setProperty(PCGenSettings.CONVERT_OUTPUT_SAVE_PATH, path.getAbsolutePath());
showWarning();
break;
}
JOptionPane.showMessageDialog(null, "Selection must be a valid " + "(readable & writeable) Directory");
chooser.setCurrentDirectory(path.getParentFile());
} else if (open == JFileChooser.CANCEL_OPTION) {
break;
}
}
}
});
panel.add(label);
panel.add(fileLabel);
panel.add(button);
panel.add(warningLabel);
showWarning();
layout.putConstraint(SpringLayout.NORTH, label, 50, SpringLayout.NORTH, panel);
layout.putConstraint(SpringLayout.NORTH, fileLabel, 75 + label.getPreferredSize().height, SpringLayout.NORTH, panel);
layout.putConstraint(SpringLayout.NORTH, button, 75 + label.getPreferredSize().height, SpringLayout.NORTH, panel);
layout.putConstraint(SpringLayout.WEST, label, 25, SpringLayout.WEST, panel);
layout.putConstraint(SpringLayout.WEST, fileLabel, 25, SpringLayout.WEST, panel);
layout.putConstraint(SpringLayout.EAST, button, -50, SpringLayout.EAST, panel);
layout.putConstraint(SpringLayout.NORTH, warningLabel, 20, SpringLayout.SOUTH, fileLabel);
layout.putConstraint(SpringLayout.WEST, warningLabel, 25, SpringLayout.WEST, panel);
fileLabel.setText(path.getAbsolutePath());
}
Aggregations