Java Reference
In-Depth Information
To allow this feature, we have to make some code changes to our application.
First, we have to add a javafx.stage.AppletStageExtension object to the
stage for the viewer. The most important variable in AppletStageExtension to
enable dragging the applet off the browser is to define a function for should-
DragStart . When this function is invoked, it returns true if an undocking drag is
allowed. In our case, we first check to see if the "isBrowser" script variable is
true. "isBrowser" is set if the Applet Parameter "isApplet" is set in the HTML
JavaFX launcher function. From JavaFX, you set this using the javafx.lang.FX
getArgument function.
var isBrowser:Boolean =
(FX.getArgument("isApplet") as String).equals("true");
Next, you check to see if the primary mouse button is down. Lastly, because the
user can use the mouse in the application to select images to view, you restrict
this drag operation to the “bar” area at the top of the display. You could have
done this differently by just changing the logic defined in the shouldDragStart
function. For example, you could have used the secondary mouse button and
changed the area to the entire application. This is demonstrated in Listing 9.5.
Listing 9.5
Draggable Applet - JavaFX Code
var stage:Stage = Stage {
title: "NASA Image Viewer"
width: 1000
height: 1000
extensions: [
AppletStageExtension {
shouldDragStart : function(e): Boolean {
return isBrowser and e.primaryButtonDown
and dragArea.hover;
}
onDragStarted : function() {
isBrowser = false;
}
onAppletRestored : function() {
isBrowser = true;
}
useDefaultClose : false
}
]
...
...
 
Search WWH ::




Custom Search