Lexxicon

FXCanvas example

Sep 3rd, 2014
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.88 KB | None | 0 0
  1. package swt;
  2.  
  3. import java.io.BufferedOutputStream;
  4.  
  5. import javafx.embed.swt.FXCanvas;
  6. import javafx.event.EventHandler;
  7. import javafx.scene.Scene;
  8. import javafx.scene.control.TextField;
  9. import javafx.scene.input.ClipboardContent;
  10. import javafx.scene.input.DataFormat;
  11. import javafx.scene.input.DragEvent;
  12. import javafx.scene.input.Dragboard;
  13. import javafx.scene.input.MouseEvent;
  14. import javafx.scene.input.TransferMode;
  15. import javafx.scene.layout.Pane;
  16.  
  17. import org.eclipse.swt.SWT;
  18. import org.eclipse.swt.layout.RowLayout;
  19. import org.eclipse.swt.widgets.Display;
  20. import org.eclipse.swt.widgets.Shell;
  21.  
  22. public class SWTApp {
  23.     static DataFormat refTrans = new DataFormat("MyDraggable");
  24.     public static void main (String [] args) {
  25.         Display display = new Display ();
  26.         Shell shell = new Shell(display);
  27.             final RowLayout layout = new RowLayout();
  28.             shell.setLayout(layout);
  29.         FXCanvas canvas = new FXCanvas(shell, SWT.FILL);
  30.         final Pane pane = new Pane();
  31.         pane.setOnDragDetected(new EventHandler<MouseEvent>() {
  32.  
  33.             @Override
  34.             public void handle(MouseEvent event) {
  35.                 Dragboard db = pane.startDragAndDrop(TransferMode.COPY_OR_MOVE);
  36.                     ClipboardContent content = new ClipboardContent();
  37.                     BufferedOutputStream o = null;
  38.                     content.put(refTrans, "SomeText");
  39.                     db.setContent(content);
  40.                 event.consume();
  41.             }
  42.         });
  43.         pane.setOnDragEntered(new EventHandler<DragEvent>() {
  44.  
  45.             @Override
  46.             public void handle(DragEvent event) {
  47.                 System.out.println("DragEnter");
  48.                 for(DataFormat df : event.getDragboard().getContentTypes()){
  49.                     System.out.println(df.equals(refTrans));
  50.                 }
  51.                
  52.             }
  53.         });
  54.         Scene scene = new Scene(pane, 800, 600);
  55.         canvas.setScene(scene);
  56.         shell.open ();
  57.         while (!shell.isDisposed ()) {
  58.             if (!display.readAndDispatch ()) display.sleep ();
  59.         }
  60.         display.dispose ();
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment