package santahat; import javafx.ext.swing.SwingTextField; import javafx.scene.CustomNode; import javafx.scene.input.MouseEvent; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.VBox; import javafx.scene.layout.HBox; import javafx.scene.Node; import javafx.scene.Scene; import javafx.stage.Stage; import javafx.ext.swing.SwingButton; var imgview = ImageView { image: Image { url: "{__DIR__}help.png" } } var txtfield:SwingTextField = SwingTextField { columns: 45 text: "your image url" editable: true action: function(){ println(txtfield.text); imgview.image = Image { url: txtfield.text; } } }; var santahat:ImageView = ImageView { x: 240 y: -5 var startX = 0.0 var startY = 0.0 var zoom = 1.0 var angle = 0.0 scaleX: bind zoom scaleY: bind zoom rotate: bind angle onMousePressed: function( e: MouseEvent ):Void { startX = e.sceneX - santahat.translateX; startY = e.sceneY - santahat.translateY; } onMouseDragged: function( e: MouseEvent ):Void { santahat.translateX = e.sceneX - startX; santahat.translateY = e.sceneY - startY; } onMouseWheelMoved: function( e: MouseEvent ):Void { if(e.controlDown) { angle += e.wheelRotation * 10; } else { zoom += e.wheelRotation / 20; } } image: Image { url: "{__DIR__}santahat.png" } } // Based on the Jean's ScreenshotMaker // http://javafx.com/samples/ScreenshotMaker/index.html var stage:Stage = Stage { title: "Santa Hat" width: 510 height: 480 scene: Scene { content: [ VBox { content: [ txtfield, imgview, SwingButton { text: "Save" action: function() { var x = stage.x + stage.scene.x; var y = stage.y + stage.scene.y + txtfield.height; var w = imgview.image.width; var h = imgview.image.height; var screenRect:java.awt.Rectangle = new java.awt.Rectangle(x,y,w,h); var tmpfile = ScreenCapturer.capture(screenRect); var fchooser = javax.swing.JFileChooser{}; var target = new java.io.File(fchooser.getCurrentDirectory(),"santa.jpg"); fchooser.setSelectedFile(target); var filefilter = Util.JPGFileFilter{}; fchooser.setFileFilter(filefilter); if (fchooser.showSaveDialog(null) == javax.swing.JFileChooser.APPROVE_OPTION) { try { fchooser.getSelectedFile().createNewFile(); Util.copyFile(tmpfile, fchooser.getSelectedFile()); } catch (e:java.lang.Exception){ e.printStackTrace(); print("Exception {e}"); } } } }] }, santahat] } }