package spike.com.msiops; import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.TextArea; import javafx.scene.input.DragEvent; import javafx.scene.input.TransferMode; import javafx.scene.layout.AnchorPane; import javafx.stage.Stage; import com.sun.glass.ui.Screen; public class OutlookDragTarget extends Application { public static void main( final String[] args ) { launch( args ); } private TextArea logArea; @Override public void start( final Stage primaryStage ) { initControls( ); final Scene scene = assembleScene( ); primaryStage.setScene( scene ); initStage( primaryStage ); primaryStage.show( ); scene.getRoot( ).addEventHandler( DragEvent.DRAG_OVER, new OverHandler( ) ); scene.getRoot( ).addEventHandler( DragEvent.DRAG_DROPPED, new DropHandler( ) ); } private Scene assembleScene() { AnchorPane.setTopAnchor( logArea, 0D ); AnchorPane.setRightAnchor( logArea, 0D ); AnchorPane.setBottomAnchor( logArea, 0D ); AnchorPane.setLeftAnchor( logArea, 0D ); final AnchorPane root = new AnchorPane( ); root.getChildren( ).setAll( logArea ); return new Scene( root ); } private void initControls() { logArea = new TextArea( ); logArea.setWrapText( true ); logArea.setEditable( false ); } private void initStage( final Stage stage ) { stage.setX( Screen.getMainScreen( ).getVisibleX( ) + 50D ); stage.setY( Screen.getMainScreen( ).getVisibleY( ) + 50D ); stage.setWidth( 400D ); stage.setHeight( 500D ); } private final class DropHandler implements EventHandler { @Override public void handle( final DragEvent evt ) { if ( evt.getDragboard( ).hasString( ) ) { logArea.setText( new StringBuilder( logArea.getText( ) ) .append( "====== DROPPED ================" ) .append( "\n" ) .append( evt.getDragboard( ).getString( ) ) .append( "\n" ) .toString( ) ); evt.setDropCompleted( true ); evt.consume( ); } } } private final class OverHandler implements EventHandler { @Override public void handle( final DragEvent evt ) { if ( evt.getDragboard( ).hasString( ) ) { evt.acceptTransferModes( TransferMode.COPY ); evt.consume( ); } } } }