Search in sources :

Example 1 with PCGenSettings

use of pcgen.system.PCGenSettings in project pcgen by PCGen.

the class SourceSelectionPanel method setupDisplay.

@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
    panel.setLayout(new GridBagLayout());
    JLabel label = new JLabel("Please select the Source Directory to Convert: ");
    GridBagConstraints gbc = new GridBagConstraints();
    Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
    gbc.insets = new Insets(50, 25, 10, 25);
    panel.add(label, gbc);
    JButton button = new JButton("Browse...");
    button.setMnemonic('r');
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JFileChooser chooser = new JFileChooser(SourceFolder.OTHER.getFile());
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            chooser.setDialogType(JFileChooser.OPEN_DIALOG);
            chooser.setSelectedFile(path);
            while (true) {
                int open = chooser.showOpenDialog(null);
                if (open == JFileChooser.APPROVE_OPTION) {
                    File fileToOpen = chooser.getSelectedFile();
                    if (fileToOpen.isDirectory()) {
                        path = fileToOpen;
                        SourceFolder.OTHER.setFile(fileToOpen);
                        pc.put(ObjectKey.DIRECTORY, path);
                        PCGenSettings context = PCGenSettings.getInstance();
                        context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, path.getAbsolutePath());
                        JRadioButton button = radioButtons[SourceFolder.OTHER.ordinal()];
                        button.setSelected(true);
                        button.setText(buildFolderText(SourceFolder.OTHER, fileToOpen.getAbsolutePath()));
                        break;
                    }
                    JOptionPane.showMessageDialog(null, "Selection must be a valid Directory");
                    chooser.setSelectedFile(path);
                } else if (open == JFileChooser.CANCEL_OPTION) {
                    break;
                }
            }
        }
    });
    radioButtons = new JRadioButton[SourceFolder.values().length];
    String selectedPath = null;
    File selectedFile = pc.get(ObjectKey.DIRECTORY);
    if (selectedFile != null) {
        selectedPath = selectedFile.getAbsolutePath();
    } else {
        PCGenSettings context = PCGenSettings.getInstance();
        selectedPath = context.getProperty(PCGenSettings.CONVERT_INPUT_PATH, null);
    }
    ButtonGroup group = new ButtonGroup();
    boolean haveSelected = false;
    Font font = panel.getFont();
    font = FontManipulation.plain(font);
    for (SourceFolder folder : SourceFolder.values()) {
        JRadioButton pathButton = new JRadioButton();
        final SourceFolder buttonFolder = folder;
        pathButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                PCGenSettings context = PCGenSettings.getInstance();
                context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, buttonFolder.getFile().getAbsolutePath());
                pc.put(ObjectKey.DIRECTORY, buttonFolder.getFile());
            }
        });
        String path;
        if (folder.getFile() == null) {
            path = "Undefined";
            pathButton.setEnabled(false);
        } else {
            path = folder.getFile().getAbsolutePath();
            if (path.equals(selectedPath)) {
                pathButton.setSelected(true);
                haveSelected = true;
                PCGenSettings context = PCGenSettings.getInstance();
                context.setProperty(PCGenSettings.CONVERT_INPUT_PATH, path);
                selectedFile = folder.getFile();
            }
        }
        pathButton.setText(buildFolderText(folder, path));
        pathButton.setFont(font);
        radioButtons[folder.ordinal()] = pathButton;
        group.add(pathButton);
        if (folder == SourceFolder.OTHER) {
            Utility.buildRelativeConstraints(gbc, 1, GridBagConstraints.REMAINDER, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
        } else {
            Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTHWEST);
        }
        gbc.insets = new Insets(10, 25, 10, 25);
        panel.add(pathButton, gbc);
        if (folder == SourceFolder.OTHER) {
            Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHEAST);
            gbc.insets = new Insets(10, 25, 10, 25);
            panel.add(button, gbc);
        }
    }
    Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER, 1.0, 1.0, GridBagConstraints.BOTH, GridBagConstraints.NORTHWEST);
    panel.add(new JLabel(" "), gbc);
    if (!haveSelected) {
        if (selectedPath != null) {
            JRadioButton btn = radioButtons[SourceFolder.OTHER.ordinal()];
            btn.setSelected(true);
            selectedFile = new File(selectedPath);
            SourceFolder.OTHER.setFile(selectedFile);
            path = selectedFile;
            btn.setText(buildFolderText(SourceFolder.OTHER, selectedFile.getAbsolutePath()));
        } else if (radioButtons[SourceFolder.VENDORDATA.ordinal()].isEnabled()) {
            JRadioButton btn = radioButtons[SourceFolder.VENDORDATA.ordinal()];
            btn.setSelected(true);
            selectedFile = SourceFolder.VENDORDATA.getFile();
        } else if (radioButtons[SourceFolder.HOMEBREWDATA.ordinal()].isEnabled()) {
            JRadioButton btn = radioButtons[SourceFolder.HOMEBREWDATA.ordinal()];
            btn.setSelected(true);
            selectedFile = SourceFolder.HOMEBREWDATA.getFile();
        } else {
            JRadioButton btn = radioButtons[SourceFolder.DATA.ordinal()];
            btn.setSelected(true);
            selectedFile = SourceFolder.DATA.getFile();
        }
    }
    pc.put(ObjectKey.DIRECTORY, selectedFile);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) JRadioButton(javax.swing.JRadioButton) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Font(java.awt.Font) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) ButtonGroup(javax.swing.ButtonGroup) PCGenSettings(pcgen.system.PCGenSettings) File(java.io.File)

Example 2 with PCGenSettings

use of pcgen.system.PCGenSettings in project pcgen by PCGen.

the class CampaignPanel method initSourceSelection.

/**
	 * 
	 */
private void initSourceSelection(CampaignTableModel model, JTable table) {
    // Select any previous selections
    PCGenSettings context = PCGenSettings.getInstance();
    String sourceString = context.initProperty(PCGenSettings.CONVERT_SOURCES, "");
    String[] sources = sourceString.split("\\|");
    for (String srcName : sources) {
        for (Campaign camp : gameModeCampaigns) {
            if (camp.toString().equals(srcName)) {
                for (int i = 0; i < model.getRowCount(); i++) {
                    if (camp.equals(model.getValueAt(i, 0))) {
                        table.getSelectionModel().addSelectionInterval(i, i);
                        break;
                    }
                }
                break;
            }
        }
    }
}
Also used : Campaign(pcgen.core.Campaign) PCGenSettings(pcgen.system.PCGenSettings)

Example 3 with PCGenSettings

use of pcgen.system.PCGenSettings in project pcgen by PCGen.

the class GameModePanel method setupDisplay.

@Override
public void setupDisplay(JPanel panel, final CDOMObject pc) {
    panel.setLayout(layout);
    JLabel introLabel = new JLabel("Please select the Game Mode to Convert:");
    panel.add(introLabel);
    layout.putConstraint(SpringLayout.NORTH, introLabel, 50, SpringLayout.NORTH, panel);
    layout.putConstraint(SpringLayout.WEST, introLabel, 25, SpringLayout.WEST, panel);
    List<GameMode> games = SystemCollections.getUnmodifiableGameModeList();
    gameModeCombo = new JComboBoxEx(games.toArray());
    gameModeCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            getSelection(pc);
            saveGameMode(pc);
        }
    });
    PCGenSettings context = PCGenSettings.getInstance();
    SettingsHandler.setGame(context.initProperty(PCGenSettings.CONVERT_GAMEMODE, SettingsHandler.getGame().getName()));
    GameMode currGame = SettingsHandler.getGame();
    if (pc.get(ObjectKey.GAME_MODE) != null) {
        currGame = pc.get(ObjectKey.GAME_MODE);
    }
    gameModeCombo.setSelectedItem(currGame);
    getSelection(pc);
    saveGameMode(pc);
    panel.add(gameModeCombo);
    layout.putConstraint(SpringLayout.NORTH, gameModeCombo, 20, SpringLayout.SOUTH, introLabel);
    layout.putConstraint(SpringLayout.WEST, gameModeCombo, 25, SpringLayout.WEST, panel);
}
Also used : GameMode(pcgen.core.GameMode) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JComboBoxEx(pcgen.gui2.util.JComboBoxEx) PCGenSettings(pcgen.system.PCGenSettings)

Example 4 with PCGenSettings

use of pcgen.system.PCGenSettings in project pcgen by PCGen.

the class GameModePanel method getSelection.

private void getSelection(CDOMObject pc) {
    GameMode gameMode = (GameMode) gameModeCombo.getSelectedItem();
    pc.put(ObjectKey.GAME_MODE, gameMode);
    PCGenSettings context = PCGenSettings.getInstance();
    context.setProperty(PCGenSettings.CONVERT_GAMEMODE, gameMode.getName());
}
Also used : GameMode(pcgen.core.GameMode) PCGenSettings(pcgen.system.PCGenSettings)

Example 5 with PCGenSettings

use of pcgen.system.PCGenSettings in project pcgen by PCGen.

the class PCGenFrame method showSavePartyChooser.

boolean showSavePartyChooser() {
    PartyFacade party = CharacterManager.getCharacters();
    PCGenSettings context = PCGenSettings.getInstance();
    String parentPath = context.getProperty(PCGenSettings.PCP_SAVE_PATH);
    chooser.setCurrentDirectory(new File(parentPath));
    File file = party.getFileRef().get();
    chooser.setSelectedFile(file);
    chooser.resetChoosableFileFilters();
    FileFilter filter = new FileNameExtensionFilter("Pcp files only", "pcp");
    chooser.addChoosableFileFilter(filter);
    chooser.setFileFilter(filter);
    int ret = chooser.showSaveDialog(this);
    if (ret != JFileChooser.APPROVE_OPTION) {
        return false;
    }
    file = chooser.getSelectedFile();
    if (!file.getName().endsWith(Constants.EXTENSION_PARTY_FILE)) {
        file = new File(file.getParent(), file.getName() + Constants.EXTENSION_PARTY_FILE);
    }
    if (file.isDirectory()) {
        showErrorMessage(Constants.APPLICATION_NAME, //$NON-NLS-1$
        LanguageBundle.getString("in_savePcDirOverwrite"));
        return showSavePartyChooser();
    }
    if (file.exists()) {
        boolean overwrite = showWarningConfirm(LanguageBundle.getFormattedString("in_savePcConfirmOverTitle", //$NON-NLS-1$
        file.getName()), LanguageBundle.getFormattedString("in_savePcConfirmOverMsg", //$NON-NLS-1$
        file.getName()));
        if (!overwrite) {
            return showSavePartyChooser();
        }
    }
    party.setFile(file);
    context.setProperty(PCGenSettings.PCP_SAVE_PATH, file.getParent());
    if (!saveAllCharacters()) {
        showErrorMessage(//$NON-NLS-1$
        LanguageBundle.getString("in_savePartyFailTitle"), //$NON-NLS-1$
        LanguageBundle.getString("in_savePartyFailMsg"));
        return false;
    }
    if (!CharacterManager.saveCurrentParty()) {
        return showSavePartyChooser();
    }
    return true;
}
Also used : PartyFacade(pcgen.facade.core.PartyFacade) PCGenSettings(pcgen.system.PCGenSettings) FileFilter(javax.swing.filechooser.FileFilter) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) PCGFile(pcgen.io.PCGFile) 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