use of pcgen.facade.core.CharacterFacade in project pcgen by PCGen.
the class ExportDialog method initComponents.
private void initComponents() {
characterBox.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
CharacterFacade character = (CharacterFacade) value;
return super.getListCellRendererComponent(list, character.getNameRef().get(), index, isSelected, cellHasFocus);
}
});
fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
fileList.addListSelectionListener(this);
exportButton.setDefaultCapable(true);
getRootPane().setDefaultButton(exportButton);
partyBox.setActionCommand(PARTY_COMMAND);
exportBox.setActionCommand(EXPORT_TO_COMMAND);
exportButton.setActionCommand(EXPORT_COMMAND);
closeButton.setActionCommand(CLOSE_COMMAND);
exportBox.addActionListener(this);
partyBox.addActionListener(this);
exportButton.addActionListener(this);
closeButton.addActionListener(this);
exportButton.setEnabled(false);
progressBar.setStringPainted(true);
progressBar.setString("Loading Templates");
progressBar.setIndeterminate(true);
setTitle("Export a PC or Party");
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
UIPropertyContext context = UIPropertyContext.createContext("ExportDialog");
String defaultOSType = context.getProperty(UIPropertyContext.DEFAULT_OS_TYPE);
if (defaultOSType != null) {
for (SheetFilter filter : SheetFilter.values()) {
if (defaultOSType.equals(filter.toString())) {
exportBox.setSelectedItem(filter);
}
}
}
}
use of pcgen.facade.core.CharacterFacade in project pcgen by PCGen.
the class ExportDialog method refreshFiles.
private void refreshFiles() {
if (allTemplates != null) {
String outputSheetsDir;
SheetFilter sheetFilter = (SheetFilter) exportBox.getSelectedItem();
IOFileFilter ioFilter = FileFilterUtils.asFileFilter(sheetFilter);
IOFileFilter prefixFilter;
String defaultSheet = null;
String outputSheetDirectory = SettingsHandler.getGame().getOutputSheetDirectory();
if (outputSheetDirectory == null) {
outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + sheetFilter.getPath();
} else {
outputSheetsDir = ConfigurationSettings.getOutputSheetsDir() + "/" + outputSheetDirectory + "/" + sheetFilter.getPath();
}
if (partyBox.isSelected()) {
prefixFilter = FileFilterUtils.prefixFileFilter(Constants.PARTY_TEMPLATE_PREFIX);
} else {
CharacterFacade character = (CharacterFacade) characterBox.getSelectedItem();
prefixFilter = FileFilterUtils.prefixFileFilter(Constants.CHARACTER_TEMPLATE_PREFIX);
defaultSheet = character.getDefaultOutputSheet(sheetFilter == SheetFilter.PDF);
if (StringUtils.isEmpty(defaultSheet)) {
defaultSheet = outputSheetsDir + "/" + SettingsHandler.getGame().getOutputSheetDefault(sheetFilter.getTag());
}
}
IOFileFilter filter = FileFilterUtils.and(prefixFilter, ioFilter);
List<File> files = FileFilterUtils.filterList(filter, allTemplates);
Collections.sort(files);
URI osPath = new File(outputSheetsDir).toURI();
Object[] uriList = new Object[files.size()];
for (int i = 0; i < uriList.length; i++) {
uriList[i] = osPath.relativize(files.get(i).toURI());
}
fileList.setListData(uriList);
if (StringUtils.isNotEmpty(defaultSheet)) {
URI defaultPath = new File(defaultSheet).toURI();
fileList.setSelectedValue(osPath.relativize(defaultPath), true);
}
}
}
use of pcgen.facade.core.CharacterFacade in project pcgen by PCGen.
the class FtlMigrationTest method runTest.
/**
* Run the test.
* @param character The PC
* @param mode The game mode
* @throws Exception
*/
public void runTest(String character, String mode) throws Exception {
System.out.println("RUNTEST with the character: " + character + " and the game mode: " + mode);
// Delete the old generated output for this test
File outputFolder = new File("code/testsuite/output");
outputFolder.mkdirs();
File originalSheet = new File(ORIG_SHEET);
File ftlSheet = new File(FTL_SHEET);
assertTrue("Ouptut sheet " + originalSheet + " should exist", originalSheet.exists());
assertTrue("Ouptut sheet " + ftlSheet + " should exist", ftlSheet.exists());
String outputFileName = character + ".html";
String outputFileNameFtl = character + "-new.html";
File outputFileFileOrig = new File(outputFolder, outputFileName);
File outputFileFileFtl = new File(outputFolder, outputFileNameFtl);
outputFileFileOrig.delete();
String configFolder = "testsuite";
String pccLoc = TestHelper.findDataFolder();
// The String holder for the XML of the expected result
String expected;
// The String holder for the XML of the actual result
String actual;
/*
* Override the pcc location, game mode and several other properties in
* the options.ini file
*/
try {
// TestHelper.createDummySettingsFile(TEST_CONFIG_FILE, configFolder,
// pccLoc);
// Fire off PCGen, which will produce an XML file
String characterFile = "code/testsuite/PCGfiles/" + character + Constants.EXTENSION_CHARACTER_FILE;
// Initialise PCGen
TestHelper.loadGameModes(TEST_CONFIG_FILE);
CharacterFacade pc = loadCharacter(characterFile);
Logging.log(Logging.INFO, "Output using template " + ftlSheet + " to " + outputFileFileFtl);
assertTrue("FTL export failed.", BatchExporter.exportCharacterToNonPDF(pc, outputFileFileFtl, ftlSheet));
Logging.log(Logging.INFO, "Output using template " + originalSheet + " to " + outputFileFileOrig);
assertTrue("Legacy export failed", BatchExporter.exportCharacterToNonPDF(pc, outputFileFileOrig, originalSheet));
// Read in the XML produced by the old sheet
expected = readFile(outputFileFileOrig);
// Read in the XML produced by the ftl sheet
actual = readFile(outputFileFileFtl);
} finally {
new File(TEST_CONFIG_FILE).delete();
}
// Do the XML comparison
XMLUnit.setIgnoreWhitespace(true);
//assertXMLEqual(expected, actual);
}
use of pcgen.facade.core.CharacterFacade in project pcgen by PCGen.
the class PCGenFrame method prepareForSave.
/**
* Prepare the character for a save. This is primarily concerned with
* ensuring all companions (or masters) have file names before the save is
* done.
* @param character The character being saved.
*/
private void prepareForSave(CharacterFacade character, boolean savingAll) {
List<CompanionFacade> tobeSaved = new ArrayList<>();
for (CompanionFacade comp : character.getCompanionSupport().getCompanions()) {
if (StringUtils.isEmpty(comp.getFileRef().get().getName()) && CharacterManager.getCharacterMatching(comp) != null) {
tobeSaved.add(comp);
}
}
if (!tobeSaved.isEmpty()) {
if (savingAll || showMessageConfirm(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("in_unsavedCompanions"))) {
for (CompanionFacade companionFacade : tobeSaved) {
CharacterFacade compChar = CharacterManager.getCharacterMatching(companionFacade);
showSaveCharacterChooser(compChar);
}
}
}
CharacterStubFacade master = character.getMaster();
if (master != null && (master.getFileRef().get() == null || StringUtils.isEmpty(master.getFileRef().get().getName()))) {
if (savingAll || showMessageConfirm(Constants.APPLICATION_NAME, //$NON-NLS-1$
LanguageBundle.getString("in_unsavedMaster"))) {
CharacterFacade masterChar = CharacterManager.getCharacterMatching(master);
showSaveCharacterChooser(masterChar);
}
}
}
use of pcgen.facade.core.CharacterFacade in project pcgen by PCGen.
the class PartyFacadeImpl method export.
@Override
public void export(ExportHandler theHandler, BufferedWriter buf) {
Collection<PlayerCharacter> characters = new ArrayList<>();
for (CharacterFacade character : this) {
if (character instanceof CharacterFacadeImpl) {
characters.add(((CharacterFacadeImpl) character).getTheCharacter());
}
}
theHandler.write(characters, buf);
}
Aggregations