import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DataFormat;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class BreakpointBugDemo extends Application{ 

	private static final DataFormat SERIALIZED_MIME_TYPE = new DataFormat( "application/x-java-serialized-object" ); 

	public static void main( String[] args ){ 
		System.out.println( System.getProperty( "java.vendor" ) ); 
		System.out.println( System.getProperty( "java.vm.version" ) ); 
		System.out.println( System.getProperty( "java.runtime.name" ) ); 
		System.out.println( System.getProperty( "java.vm.name" ) ); 
		launch( args ); 
	} 

	@Override 
	public void start( Stage pst ) throws Exception{ 
		HBox hbx = new HBox(); 

		Label lbl_from = new Label( "Banana Peel" ); 
		lbl_from.setStyle( "-fx-border-width: 2px; -fx-background-color: yellow;" ); 
		lbl_from.setOnDragDetected( drag_evt -> { 
			/* will hang on every breakpoint in here (no matter where to break): */ 
			System.out.println( "Pick" ); 
			Dragboard db = lbl_from.startDragAndDrop( TransferMode.MOVE ); 
			db.setDragView( lbl_from.snapshot( null, null ) ); 
			ClipboardContent cc = new ClipboardContent(); 
			cc.put( SERIALIZED_MIME_TYPE, "banana peel" ); 
			db.setContent( cc ); 
			drag_evt.consume(); 
		} ); 

		Label lbl_to = new Label( "Wastebin" ); 
		lbl_to.setStyle( "-fx-border-width: 2px; -fx-border-color: black; -fx-background-color: darkgrey;" ); 
		lbl_to.setOnDragOver( dragover_evt -> { 
			/* will hang on every breakpoint in here (no matter where to break), 
			 * but only if the dragged item is from inside this application, for other 
			 * items (e.g. files picked from the desktop and dragged over this label) 
			 * breakpoints work as expected, i.e. they interrupt execution without 
			 * causing inaccessibility: */ 
			Dragboard db = dragover_evt.getDragboard(); 
			if( db.hasContent( SERIALIZED_MIME_TYPE ) ){ 
				dragover_evt.acceptTransferModes( TransferMode.COPY_OR_MOVE ); 
				dragover_evt.consume(); 
			} 
		} ); 

		lbl_to.setOnDragDropped( drop_evt -> { 
			/* won't hang on any breakpoint in here (i.e. breakpoints work fine): */ 
			Dragboard db = drop_evt.getDragboard();	
			String content = (String) db.getContent( SERIALIZED_MIME_TYPE ); 
			if( "banana peel".equals( content ) ) { 
				drop_evt.setDropCompleted( true ); 
				drop_evt.consume(); 
				System.out.println( "Thanks for picking it up!" ); 
			} 
		} ); 

		hbx.getChildren().addAll( lbl_from, lbl_to ); 
		Scene scn = new Scene( hbx, 150, 25 ); 
		pst.setScene( scn ); 
		pst.show(); 
	} 
} 