Search in sources :

Example 6 with PCGenSettings

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, "|"));
}
Also used : Campaign(pcgen.core.Campaign) PCGenSettings(pcgen.system.PCGenSettings)

Example 7 with PCGenSettings

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);
    }
}
Also used : PCGenSettings(pcgen.system.PCGenSettings) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Example 8 with PCGenSettings

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;
}
Also used : PCGenSettings(pcgen.system.PCGenSettings) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) PCGFile(pcgen.io.PCGFile) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) UIDelegate(pcgen.facade.core.UIDelegate)

Example 9 with PCGenSettings

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();
    }
}
Also used : PCGenSettings(pcgen.system.PCGenSettings) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) PCGFile(pcgen.io.PCGFile) File(java.io.File)

Example 10 with PCGenSettings

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());
}
Also used : AbstractButton(javax.swing.AbstractButton) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Component(java.awt.Component) PCGenSettings(pcgen.system.PCGenSettings) File(java.io.File)

Aggregations

PCGenSettings (pcgen.system.PCGenSettings)11 File (java.io.File)7 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)4 PCGFile (pcgen.io.PCGFile)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JLabel (javax.swing.JLabel)3 FileFilter (javax.swing.filechooser.FileFilter)3 JButton (javax.swing.JButton)2 JFileChooser (javax.swing.JFileChooser)2 Campaign (pcgen.core.Campaign)2 GameMode (pcgen.core.GameMode)2 Component (java.awt.Component)1 Font (java.awt.Font)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 AbstractButton (javax.swing.AbstractButton)1