use of javafx.scene.control.TreeItem in project tokentool by RPTools.
the class AppPreferences method savePreferences.
public static void savePreferences(TokenTool_Controller tokentool_Controller) {
log.info("Saving preferences to " + prefs.toString());
// Save Overlay details
prefs.putBoolean(OVERLAY_ASPECT, tokentool_Controller.getOverlayAspect());
prefs.putInt(OVERLAY_WIDTH, tokentool_Controller.getOverlayWidth());
prefs.putInt(OVERLAY_HEIGHT, tokentool_Controller.getOverlayHeight());
prefs.putBoolean(OVERLAY_USE_BASE, tokentool_Controller.getOverlayUseAsBase());
prefs.putBoolean(OVERLAY_CLIP_PORTRAIT, tokentool_Controller.getClipPortraitCheckbox());
// Save naming details
prefs.putBoolean(USE_FILE_NUMBERING, tokentool_Controller.getUseFileNumberingCheckbox());
prefs.put(FILE_NAME_TEXT_FIELD, tokentool_Controller.getFileNameTextField());
prefs.put(FILE_NAME_SUFFIX_TEXT_FIELD, tokentool_Controller.getFileNameSuffixTextField());
prefs.put(PORTRAIT_NAME_TEXT_FIELD, tokentool_Controller.getPortraitNameTextField());
prefs.putBoolean(USE_TOKEN_NAME, tokentool_Controller.getUseTokenNameCheckbox());
prefs.put(PORTRAIT_NAME_SUFFIX_TEXT_FIELD, tokentool_Controller.getPortraitNameSuffixTextField());
prefs.putBoolean(SAVE_PORTRAIT_ON_DRAG, tokentool_Controller.getSavePortraitOnDragCheckbox());
prefs.putBoolean(USE_BACKGROUND_ON_DRAG, tokentool_Controller.getUseBackgroundOnDragCheckbox());
// Save recent overlays used
log.debug("...saving recent overlay count");
Map<Path, TreeItem<Path>> recentOverlays = tokentool_Controller.getRecentOverlayTreeItems();
prefs.putInt(RECENT_OVERLAY_COUNT, recentOverlays.size());
log.debug("...saving recent overlays");
int i = 1;
for (Path path : recentOverlays.keySet()) prefs.put(RECENT_OVERLAY + i++, path.toString());
// Save location of save
log.debug("...saving last file save location");
try {
if (FileSaveUtil.getLastFile() != null)
if (FileSaveUtil.getLastFile().getParentFile().exists())
prefs.put(LAST_TOKEN_SAVE_LOCATION, FileSaveUtil.getLastFile().getCanonicalPath());
} catch (NullPointerException e) {
log.warn("No last save location to save...");
} catch (IOException e) {
log.error("Error saving last file preference.", e);
}
// Save last portrait used
try {
File lastPortrait = new File(AppConstants.CACHE_DIR, "last_portrait.png");
ImageIO.write(SwingFXUtils.fromFXImage(tokentool_Controller.getPortraitImage(), null), "png", lastPortrait);
prefs.put(PORTRAIT_IMAGEVIEW_PREFERENCES, tokentool_Controller.getPortrait_Preferences(lastPortrait.getCanonicalPath()));
} catch (NullPointerException e) {
log.warn("No portrait to save...");
} catch (IOException e) {
log.error("Error saving last portrait preference.", e);
}
// Save last background used
try {
Image backgroundImage = tokentool_Controller.getBackgroundImage();
if (backgroundImage != null) {
File lastBackground = new File(AppConstants.CACHE_DIR, "last_background.png");
ImageIO.write(SwingFXUtils.fromFXImage(tokentool_Controller.getBackgroundImage(), null), "png", lastBackground);
prefs.put(BACKGROUND_IMAGEVIEW_PREFERENCES, tokentool_Controller.getBackground_Preferences(lastBackground.getCanonicalPath()));
} else {
prefs.put(BACKGROUND_IMAGEVIEW_PREFERENCES, tokentool_Controller.getBackground_Preferences(null));
}
} catch (IOException e) {
log.error("Error saving last background preference.", e);
}
// Save window size/position
prefs.put(WINDOW_MAIN_PREFERENCES, new Window_Preferences(TokenTool.getInstance().getStage()).toJson());
}
Aggregations