/* * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package test; import javafx.application.Application; import javafx.event.EventHandler; import javafx.geometry.Rectangle2D; import javafx.scene.Group; import javafx.scene.PerspectiveCamera; import javafx.scene.PointLight; import javafx.scene.Scene; import javafx.scene.SnapshotParameters; import javafx.scene.image.ImageView; import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.scene.paint.PhongMaterial; import javafx.scene.shape.Box; import javafx.scene.shape.Rectangle; import javafx.stage.Stage; public class Snapshot extends Application { @Override public void start(Stage stage) { stage.setTitle("Snapshot"); final Group root = new Group(); final Scene scene = new Scene(root, 600, 450); scene.setFill(Color.LIGHTGREEN); scene.setCamera(new PerspectiveCamera()); final ImageView iw = new ImageView(); iw.setTranslateY(150); final Group rnb = new Group(); final Rectangle rect = new Rectangle(); rect.setX(125); rect.setY(40); rect.setWidth(100); rect.setHeight(50); rect.setFill(Color.RED); rect.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent e) { SnapshotParameters sp = new SnapshotParameters(); iw.setImage(rect.snapshot(sp, null)); sp.setCamera(new PerspectiveCamera()); e.consume(); } }); final Box box = new Box(50, 50, 1); box.setTranslateX(50); box.setTranslateY(50); PhongMaterial pm = new PhongMaterial(Color.RED); pm.setSpecularColor(Color.ORANGE); box.setMaterial(pm); box.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent e) { SnapshotParameters sp = new SnapshotParameters(); sp.setCamera(new PerspectiveCamera()); iw.setImage(box.snapshot(sp, null)); e.consume(); } }); scene.setOnMousePressed(new EventHandler() { @Override public void handle(MouseEvent e) { SnapshotParameters sp = new SnapshotParameters(); sp.setCamera(new PerspectiveCamera()); sp.setViewport(new Rectangle2D(0, 0 , 600, 450)); iw.setImage(rnb.snapshot(sp, null)); e.consume(); } }); PointLight pl = new PointLight(); pl.setTranslateZ(-500); rnb.getChildren().add(pl); rnb.getChildren().add(rect); rnb.getChildren().add(box); root.getChildren().add(rnb); root.getChildren().add(iw); stage.setScene(scene); stage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(args); } }