Search in sources :

Example 76 with TreeItem

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());
}
Also used : Path(java.nio.file.Path) TreeItem(javafx.scene.control.TreeItem) IOException(java.io.IOException) Image(javafx.scene.image.Image) File(java.io.File) Window_Preferences(net.rptools.tokentool.model.Window_Preferences)

Aggregations

TreeItem (javafx.scene.control.TreeItem)76 File (java.io.File)15 TreeView (javafx.scene.control.TreeView)11 ArrayList (java.util.ArrayList)10 List (java.util.List)10 ObjectProperty (javafx.beans.property.ObjectProperty)9 MenuItem (javafx.scene.control.MenuItem)9 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 IOException (java.io.IOException)7 Optional (java.util.Optional)7 FXCollections (javafx.collections.FXCollections)7 ListChangeListener (javafx.collections.ListChangeListener)7 ObservableList (javafx.collections.ObservableList)7 ActionEvent (javafx.event.ActionEvent)7 ContextMenu (javafx.scene.control.ContextMenu)7 Stage (javafx.stage.Stage)7 FXML (javafx.fxml.FXML)6 Button (javafx.scene.control.Button)6