Search in sources :

Example 11 with CharacterFacade

use of pcgen.facade.core.CharacterFacade in project pcgen by PCGen.

the class SpellsKnownTab method initComponents.

private void initComponents() {
    availableTable.setTreeCellRenderer(spellRenderer);
    selectedTable.setTreeCellRenderer(spellRenderer);
    selectedTable.setRowSorter(new SortableTableRowSorter() {

        @Override
        public SortableTableModel getModel() {
            return (SortableTableModel) selectedTable.getModel();
        }
    });
    selectedTable.getRowSorter().toggleSortOrder(0);
    FilterBar<CharacterFacade, SuperNode> filterBar = new FilterBar<>();
    filterBar.addDisplayableFilter(new SearchFilterPanel());
    //$NON-NLS-1$
    qFilterButton.setText(LanguageBundle.getString("in_igQualFilter"));
    filterBar.addDisplayableFilter(qFilterButton);
    FlippingSplitPane upperPane = new FlippingSplitPane("SpellsKnownTop");
    JPanel availPanel = FilterUtilities.configureFilteredTreeViewPane(availableTable, filterBar);
    Box box = Box.createVerticalBox();
    box.add(Box.createVerticalStrut(2));
    {
        Box hbox = Box.createHorizontalBox();
        hbox.add(Box.createHorizontalStrut(5));
        hbox.add(autoKnownBox);
        hbox.add(Box.createHorizontalGlue());
        box.add(hbox);
    }
    //box.add(Box.createVerticalStrut(2));
    {
        Box hbox = Box.createHorizontalBox();
        hbox.add(Box.createHorizontalStrut(5));
        hbox.add(slotsBox);
        hbox.add(Box.createHorizontalGlue());
        hbox.add(Box.createHorizontalStrut(10));
        hbox.add(addButton);
        hbox.add(Box.createHorizontalStrut(5));
        box.add(hbox);
    }
    box.add(Box.createVerticalStrut(5));
    availPanel.add(box, BorderLayout.SOUTH);
    upperPane.setLeftComponent(availPanel);
    box = Box.createVerticalBox();
    box.add(new JScrollPane(selectedTable));
    box.add(Box.createVerticalStrut(4));
    {
        Box hbox = Box.createHorizontalBox();
        hbox.add(Box.createHorizontalStrut(5));
        hbox.add(removeButton);
        hbox.add(Box.createHorizontalStrut(10));
        JButton spellSheetButton = new JButton(LanguageBundle.getString("InfoSpells.select.spellsheet"));
        spellSheetButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                selectSpellSheetButton();
            }
        });
        hbox.add(spellSheetButton);
        hbox.add(Box.createHorizontalStrut(3));
        String text = PCGenSettings.getSelectedSpellSheet();
        if (text != null) {
            text = new File(text).getName();
        }
        spellSheetField.setEditable(false);
        spellSheetField.setText(text);
        spellSheetField.setToolTipText(text);
        hbox.add(spellSheetField);
        hbox.add(Box.createHorizontalStrut(3));
        previewSpellsButton = new JButton(Icons.PrintPreview16.getImageIcon());
        hbox.add(previewSpellsButton);
        hbox.add(Box.createHorizontalStrut(3));
        exportSpellsButton = new JButton(Icons.Print16.getImageIcon());
        hbox.add(exportSpellsButton);
        hbox.add(Box.createHorizontalStrut(5));
        box.add(hbox);
    }
    box.add(Box.createVerticalStrut(5));
    upperPane.setRightComponent(box);
    upperPane.setResizeWeight(0);
    setTopComponent(upperPane);
    FlippingSplitPane bottomPane = new FlippingSplitPane("SpellsKnownBottom");
    bottomPane.setLeftComponent(spellsPane);
    bottomPane.setRightComponent(classPane);
    setBottomComponent(bottomPane);
    setOrientation(VERTICAL_SPLIT);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) SuperNode(pcgen.facade.core.SpellSupportFacade.SuperNode) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) SortableTableRowSorter(pcgen.gui2.util.table.SortableTableRowSorter) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) SortableTableModel(pcgen.gui2.util.table.SortableTableModel) CharacterFacade(pcgen.facade.core.CharacterFacade) FlippingSplitPane(pcgen.gui2.tools.FlippingSplitPane) FilterBar(pcgen.gui2.filter.FilterBar) ActionListener(java.awt.event.ActionListener) SearchFilterPanel(pcgen.gui2.filter.SearchFilterPanel) File(java.io.File)

Example 12 with CharacterFacade

use of pcgen.facade.core.CharacterFacade in project pcgen by PCGen.

the class SpellsPreparedTab method initComponents.

private void initComponents() {
    availableTable.setTreeCellRenderer(spellRenderer);
    selectedTable.setTreeCellRenderer(spellRenderer);
    selectedTable.setRowSorter(new SortableTableRowSorter() {

        @Override
        public SortableTableModel getModel() {
            return (SortableTableModel) selectedTable.getModel();
        }
    });
    selectedTable.getRowSorter().toggleSortOrder(0);
    FilterBar<CharacterFacade, SuperNode> filterBar = new FilterBar<>();
    filterBar.addDisplayableFilter(new SearchFilterPanel());
    //$NON-NLS-1$
    qFilterButton.setText(LanguageBundle.getString("in_igQualFilter"));
    filterBar.addDisplayableFilter(qFilterButton);
    FlippingSplitPane upperPane = new FlippingSplitPane("SpellsPreparedTop");
    JPanel availPanel = FilterUtilities.configureFilteredTreeViewPane(availableTable, filterBar);
    Box box = Box.createVerticalBox();
    box.add(Box.createVerticalStrut(5));
    {
        Box hbox = Box.createHorizontalBox();
        addMMSpellButton.setHorizontalTextPosition(SwingConstants.LEADING);
        hbox.add(addMMSpellButton);
        box.add(hbox);
    }
    box.add(Box.createVerticalStrut(2));
    {
        Box hbox = Box.createHorizontalBox();
        hbox.add(Box.createHorizontalStrut(5));
        hbox.add(slotsBox);
        hbox.add(Box.createHorizontalGlue());
        hbox.add(Box.createHorizontalStrut(10));
        hbox.add(addSpellButton);
        hbox.add(Box.createHorizontalStrut(5));
        box.add(hbox);
    }
    box.add(Box.createVerticalStrut(5));
    availPanel.add(box, BorderLayout.SOUTH);
    upperPane.setLeftComponent(availPanel);
    box = Box.createVerticalBox();
    box.add(new JScrollPane(selectedTable));
    box.add(Box.createVerticalStrut(4));
    {
        Box hbox = Box.createHorizontalBox();
        hbox.add(Box.createHorizontalStrut(5));
        hbox.add(removeSpellButton);
        hbox.add(Box.createHorizontalStrut(10));
        hbox.add(new JLabel(LanguageBundle.getString("InfoPreparedSpells.preparedList")));
        hbox.add(Box.createHorizontalStrut(3));
        hbox.add(spellListField);
        hbox.add(Box.createHorizontalStrut(3));
        hbox.add(addSpellListButton);
        hbox.add(Box.createHorizontalStrut(3));
        hbox.add(removeSpellListButton);
        hbox.add(Box.createHorizontalStrut(5));
        box.add(hbox);
    }
    box.add(Box.createVerticalStrut(5));
    upperPane.setRightComponent(box);
    upperPane.setResizeWeight(0);
    setTopComponent(upperPane);
    FlippingSplitPane bottomPane = new FlippingSplitPane("SpellsPreparedBottom");
    bottomPane.setLeftComponent(spellsPane);
    bottomPane.setRightComponent(classPane);
    setBottomComponent(bottomPane);
    setOrientation(VERTICAL_SPLIT);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) SuperNode(pcgen.facade.core.SpellSupportFacade.SuperNode) JLabel(javax.swing.JLabel) SortableTableRowSorter(pcgen.gui2.util.table.SortableTableRowSorter) Box(javax.swing.Box) JCheckBox(javax.swing.JCheckBox) SortableTableModel(pcgen.gui2.util.table.SortableTableModel) CharacterFacade(pcgen.facade.core.CharacterFacade) FlippingSplitPane(pcgen.gui2.tools.FlippingSplitPane) FilterBar(pcgen.gui2.filter.FilterBar) SearchFilterPanel(pcgen.gui2.filter.SearchFilterPanel)

Example 13 with CharacterFacade

use of pcgen.facade.core.CharacterFacade in project pcgen by PCGen.

the class BatchExporter method exportCharacter.

/**
	 * Export a character sheet for the character to the output file using the 
	 * pre-registered template. If the output file is null then a default file 
	 * will be used based on the character file name and the type of export 
	 * template in use. If the output file exists it will be overwritten.
	 * <p>
	 * This method will load the required data for the character, load the 
	 * character and then export the character sheet.
	 * 
	 * @param characterFilename The path to the character PCG file.
	 * @param outputFile The path to the output file to be created. May be null.
	 * @return true if the export was successful, false if it failed in some way.
	 */
boolean exportCharacter(String characterFilename, String outputFile) {
    File file = new File(characterFilename);
    if (!PCGFile.isPCGenCharacterFile(file)) {
        Logging.errorPrint("Invalid character file specified: " + file.getAbsolutePath());
        return false;
    }
    String outFilename = outputFile;
    if (outFilename == null) {
        outFilename = generateOutputFilename(characterFilename);
    }
    Logging.log(Logging.INFO, "Started export of " + file.getAbsolutePath() + " using " + exportTemplateFilename + " to " + outFilename);
    // Load data
    SourceSelectionFacade sourcesForCharacter = CharacterManager.getRequiredSourcesForCharacter(file, uiDelegate);
    Logging.log(Logging.INFO, "Loading sources " + sourcesForCharacter.getCampaigns() + " using game mode " + sourcesForCharacter.getGameMode());
    SourceFileLoader loader = new SourceFileLoader(sourcesForCharacter, uiDelegate);
    loader.execute();
    // Load character
    CharacterFacade character = CharacterManager.openCharacter(file, uiDelegate, loader.getDataSetFacade());
    if (character == null) {
        return false;
    }
    // Export character
    File templateFile = new File(exportTemplateFilename);
    File outFile = new File(outFilename);
    if (isPdf) {
        return exportCharacterToPDF(character, outFile, templateFile);
    } else {
        return exportCharacterToNonPDF(character, outFile, templateFile);
    }
}
Also used : SourceSelectionFacade(pcgen.facade.core.SourceSelectionFacade) SourceFileLoader(pcgen.persistence.SourceFileLoader) PCGFile(pcgen.io.PCGFile) File(java.io.File) CharacterFacade(pcgen.facade.core.CharacterFacade)

Example 14 with CharacterFacade

use of pcgen.facade.core.CharacterFacade 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 15 with CharacterFacade

use of pcgen.facade.core.CharacterFacade in project pcgen by PCGen.

the class ExportDialog method printToFile.

private boolean printToFile(File outFile) throws IOException {
    File template = getSelectedTemplate();
    if (partyBox.isSelected()) {
        SettingsHandler.setSelectedPartyHTMLOutputSheet(template.getAbsolutePath());
        PartyFacade party = CharacterManager.getCharacters();
        return BatchExporter.exportPartyToNonPDF(party, outFile, template);
    } else {
        CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem();
        return BatchExporter.exportCharacterToNonPDF(character, outFile, template);
    }
}
Also used : PartyFacade(pcgen.facade.core.PartyFacade) File(java.io.File) CharacterFacade(pcgen.facade.core.CharacterFacade)

Aggregations

CharacterFacade (pcgen.facade.core.CharacterFacade)31 File (java.io.File)11 JPanel (javax.swing.JPanel)9 JScrollPane (javax.swing.JScrollPane)9 FilterBar (pcgen.gui2.filter.FilterBar)9 SearchFilterPanel (pcgen.gui2.filter.SearchFilterPanel)9 FlippingSplitPane (pcgen.gui2.tools.FlippingSplitPane)9 Box (javax.swing.Box)8 BorderLayout (java.awt.BorderLayout)6 ArrayList (java.util.ArrayList)5 PCGFile (pcgen.io.PCGFile)5 EmptyBorder (javax.swing.border.EmptyBorder)4 JCheckBox (javax.swing.JCheckBox)3 JLabel (javax.swing.JLabel)3 PlayerCharacter (pcgen.core.PlayerCharacter)3 SuperNode (pcgen.facade.core.SpellSupportFacade.SuperNode)3 SortableTableModel (pcgen.gui2.util.table.SortableTableModel)3 SortableTableRowSorter (pcgen.gui2.util.table.SortableTableRowSorter)3 IOException (java.io.IOException)2 URI (java.net.URI)2