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)
| 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)) |
no test coverage detected