MCPcopy Create free account
hub / github.com/PCGen/pcgen / loadCharacterFromFile

Method loadCharacterFromFile

code/src/java/pcgen/gui2/PCGenFrame.java:1006–1095  ·  view source on GitHub ↗

Loads a character from a file. Any sources that are required for this character are loaded first, then the character is loaded from the file and a tab is opened for it. @param pcgFile a file specifying the character to be loaded

(final File pcgFile)

Source from the content-addressed store, hash-verified

1004 * @param pcgFile a file specifying the character to be loaded
1005 */
1006 public void loadCharacterFromFile(final File pcgFile)
1007 {
1008 if (!PCGFile.isPCGenCharacterFile(pcgFile))
1009 {
1010 this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcInvalid", pcgFile),
1011 LanguageBundle.getFormattedString("in_loadPcInvalid", pcgFile) );
1012 return;
1013 }
1014 if (!pcgFile.canRead())
1015 {
1016 this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcFailTtile"),
1017 LanguageBundle.getFormattedString("in_loadPcNoRead", pcgFile) );
1018 return;
1019 }
1020
1021 SourceSelectionFacade sources = CharacterManager.getRequiredSourcesForCharacter(pcgFile, this);
1022 if (sources == null)
1023 {
1024 this.showErrorMessage(LanguageBundle.getFormattedString("in_loadPcNoSources", pcgFile),
1025 LanguageBundle.getString("in_loadPcFailTtile"));
1026 }
1027 else if (!sources.getCampaigns().isEmpty())
1028 {
1029 // Check if the user has asked that sources not be loaded with the character
1030 boolean dontLoadSources = currentSourceSelection.get() != null
1031 && !PCGenSettings.OPTIONS_CONTEXT.initBoolean(PCGenSettings.OPTION_AUTOLOAD_SOURCES_WITH_PC, true);
1032 boolean sourcesSame = checkSourceEquality(sources, currentSourceSelection.get());
1033 boolean gameModesSame = checkGameModeEquality(sources, currentSourceSelection.get());
1034 if (!dontLoadSources && !sourcesSame && gameModesSame)
1035 {
1036 Object[] btnNames = {LanguageBundle.getString("in_loadPcDiffSourcesLoaded"),
1037 LanguageBundle.getString("in_loadPcDiffSourcesCharacter"), LanguageBundle.getString("in_cancel")};
1038 int choice = JOptionPane.showOptionDialog(this,
1039 LanguageBundle.getFormattedString("in_loadPcDiffSources",
1040 getFormattedCampaigns(currentSourceSelection.get()), getFormattedCampaigns(sources)),
1041 LanguageBundle.getString("in_loadPcSourcesLoadTitle"), JOptionPane.YES_NO_CANCEL_OPTION,
1042 JOptionPane.QUESTION_MESSAGE, null, btnNames, null);
1043 if (choice == JOptionPane.CANCEL_OPTION)
1044 {
1045 return;
1046 }
1047 if (choice == JOptionPane.YES_OPTION)
1048 {
1049 openCharacter(pcgFile, currentDataSetRef.get());
1050 return;
1051 }
1052 }
1053
1054 if (dontLoadSources)
1055 {
1056 if (!checkSourceEquality(sources, currentSourceSelection.get()))
1057 {
1058 Logging.log(Logging.WARNING, "Loading character with different sources. Character: " + sources
1059 + " current: " + currentSourceSelection.get());
1060 }
1061 openCharacter(pcgFile, currentDataSetRef.get());
1062 }
1063 else if (loadSourceSelection(sources))

Callers 4

actionPerformedMethod · 0.80
showCompanionMethod · 0.80

Calls 15

isPCGenCharacterFileMethod · 0.95
showErrorMessageMethod · 0.95
getFormattedStringMethod · 0.95
getStringMethod · 0.95
getCampaignsMethod · 0.95
checkSourceEqualityMethod · 0.95
checkGameModeEqualityMethod · 0.95
getFormattedCampaignsMethod · 0.95
openCharacterMethod · 0.95
logMethod · 0.95
loadSourceSelectionMethod · 0.95

Tested by

no test coverage detected