Search in sources :

Example 1 with Window_Preferences

use of net.rptools.tokentool.model.Window_Preferences in project tokentool by RPTools.

the class TokenTool_Controller method setWindoFrom_Preferences.

// For user preferences...
public void setWindoFrom_Preferences(String preferencesJson) {
    if (preferencesJson != null) {
        Window_Preferences window_Preferences = new Gson().fromJson(preferencesJson, new TypeToken<Window_Preferences>() {
        }.getType());
        window_Preferences.setWindow(TokenTool.getInstance().getStage());
    }
}
Also used : TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) Window_Preferences(net.rptools.tokentool.model.Window_Preferences)

Example 2 with Window_Preferences

use of net.rptools.tokentool.model.Window_Preferences in project tokentool by RPTools.

the class RegionSelector_Controller method captureButton_onAction.

@FXML
void captureButton_onAction(ActionEvent event) {
    Stage stage = (Stage) captureButton.getScene().getWindow();
    Scene scene = stage.getScene();
    int x = (int) stage.getX();
    int y = (int) stage.getY();
    int sceneWidth = (int) scene.getWidth();
    int sceneHeight = (int) scene.getHeight();
    stage.hide();
    log.debug("Rect: " + new Rectangle(x, y, sceneWidth, sceneHeight));
    // Test to see if this works better on Linux. Linux would still capture this stage in the
    // image...
    Platform.runLater(() -> {
        try {
            // Robot robot = new
            // Robot(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice());
            BufferedImage bi = new Robot().createScreenCapture(new Rectangle(x, y, sceneWidth, sceneHeight));
            tokenTool_Controller.updateImage(SwingFXUtils.toFXImage(bi, null));
            AppPreferences.setPreference(AppPreferences.WINDOW_REGION_SELECTOR_PREFERENCES, new Window_Preferences(stage).toJson());
            stage.close();
        } catch (AWTException e) {
            log.error("Error capturing screen shot!", e);
        }
    });
}
Also used : Rectangle(java.awt.Rectangle) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene) Robot(java.awt.Robot) BufferedImage(java.awt.image.BufferedImage) Window_Preferences(net.rptools.tokentool.model.Window_Preferences) AWTException(java.awt.AWTException) FXML(javafx.fxml.FXML)

Example 3 with Window_Preferences

use of net.rptools.tokentool.model.Window_Preferences 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

Window_Preferences (net.rptools.tokentool.model.Window_Preferences)3 Gson (com.google.gson.Gson)1 TypeToken (com.google.gson.reflect.TypeToken)1 AWTException (java.awt.AWTException)1 Rectangle (java.awt.Rectangle)1 Robot (java.awt.Robot)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 FXML (javafx.fxml.FXML)1 Scene (javafx.scene.Scene)1 TreeItem (javafx.scene.control.TreeItem)1 Image (javafx.scene.image.Image)1 Stage (javafx.stage.Stage)1