Search in sources :

Example 1 with Chart

use of javafx.scene.chart.Chart in project jgnash by ccavanaugh.

the class ChartUtilities method takeSnapshot.

private static WritableImage takeSnapshot(final Pane pane) {
    Map<Chart, Boolean> animationMap = new HashMap<>();
    // Need to disable chart animations for printing
    pane.getChildren().stream().filter(node -> node instanceof Chart).forEach(node -> {
        animationMap.put((Chart) node, ((Chart) node).getAnimated());
        ((Chart) node).setAnimated(false);
    });
    final SnapshotParameters snapshotParameters = new SnapshotParameters();
    snapshotParameters.setTransform(new Scale(SNAPSHOT_SCALE_FACTOR, SNAPSHOT_SCALE_FACTOR));
    final WritableImage image = pane.snapshot(snapshotParameters, null);
    // Restore animation
    for (Map.Entry<Chart, Boolean> entry : animationMap.entrySet()) {
        entry.getKey().setAnimated(entry.getValue());
    }
    return image;
}
Also used : StaticUIMethods(jgnash.uifx.StaticUIMethods) MainView(jgnash.uifx.views.main.MainView) ResourceUtils(jgnash.util.ResourceUtils) WritableImage(javafx.scene.image.WritableImage) IOException(java.io.IOException) HashMap(java.util.HashMap) SnapshotParameters(javafx.scene.SnapshotParameters) Chart(javafx.scene.chart.Chart) File(java.io.File) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) FileChooser(javafx.stage.FileChooser) Clipboard(javafx.scene.input.Clipboard) Locale(java.util.Locale) ImageView(javafx.scene.image.ImageView) FileUtils(jgnash.util.FileUtils) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) SwingFXUtils(javafx.embed.swing.SwingFXUtils) Scale(javafx.scene.transform.Scale) ClipboardContent(javafx.scene.input.ClipboardContent) Pane(javafx.scene.layout.Pane) WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) HashMap(java.util.HashMap) Scale(javafx.scene.transform.Scale) HashMap(java.util.HashMap) Map(java.util.Map) Chart(javafx.scene.chart.Chart)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 SwingFXUtils (javafx.embed.swing.SwingFXUtils)1 SnapshotParameters (javafx.scene.SnapshotParameters)1 Chart (javafx.scene.chart.Chart)1 ImageView (javafx.scene.image.ImageView)1 WritableImage (javafx.scene.image.WritableImage)1 Clipboard (javafx.scene.input.Clipboard)1 ClipboardContent (javafx.scene.input.ClipboardContent)1 Pane (javafx.scene.layout.Pane)1 Scale (javafx.scene.transform.Scale)1 FileChooser (javafx.stage.FileChooser)1 ImageIO (javax.imageio.ImageIO)1 StaticUIMethods (jgnash.uifx.StaticUIMethods)1 JavaFXUtils (jgnash.uifx.util.JavaFXUtils)1 MainView (jgnash.uifx.views.main.MainView)1 FileUtils (jgnash.util.FileUtils)1