changeset 6406:4742b5a6eb9b 8u20-b04

RT-35197: Use Lambda in FX runtime and samples [swt] Summary: This component was lambdified (unlambdified file names recorded in the JIRA)
author snorthov
date Mon, 03 Mar 2014 15:38:59 -0500
parents a46da8e2262b
children 3f993a203fe0 81208afdb29a e164a77392b6
files modules/swt/src/main/java/javafx/embed/swt/FXCanvas.java modules/swt/src/main/java/javafx/embed/swt/SWTFXUtils.java
diffstat 2 files changed, 57 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/modules/swt/src/main/java/javafx/embed/swt/FXCanvas.java	Mon Mar 03 13:26:38 2014 -0500
+++ b/modules/swt/src/main/java/javafx/embed/swt/FXCanvas.java	Mon Mar 03 15:38:59 2014 -0500
@@ -158,18 +158,16 @@
     private IntBuffer pixelsBuf = null;
     
     // This filter runs when any widget is moved
-    Listener moveFilter = new Listener() {
-        public void handleEvent(Event event) {
-            // If a parent has moved, send a move event to FX
-            Control control = FXCanvas.this;
-            while (control != null) {
-                if (control == event.widget) {
-                    sendMoveEventToFX();
-                    break;
-                }
-                control = control.getParent();
-            };
-        }
+    Listener moveFilter = event -> {
+        // If a parent has moved, send a move event to FX
+        Control control = FXCanvas.this;
+        while (control != null) {
+            if (control == event.widget) {
+                sendMoveEventToFX();
+                break;
+            }
+            control = control.getParent();
+        };
     };
     
     private double scaleFactor = 1.0;
@@ -248,11 +246,9 @@
     }
 
     private static void initFx() {
-        AccessController.doPrivileged(new PrivilegedAction<Void>() {
-            public Void run() {
-                System.setProperty("javafx.embed.isEventThread", "true");
-                return null;
-            }
+        AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
+            System.setProperty("javafx.embed.isEventThread", "true");
+            return null;
         });
         Map map = Application.getDeviceDetails();
         if (map == null) {
@@ -276,11 +272,8 @@
             map.put("javafx.embed.eventProc", eventProc);
         }
         // Note that calling PlatformImpl.startup more than once is OK
-        PlatformImpl.startup(new Runnable() {
-            @Override
-            public void run() {
-                Application.GetApplication().setName(Display.getAppName());
-            }
+        PlatformImpl.startup(() -> {
+            Application.GetApplication().setName(Display.getAppName());
         });
     }
     
@@ -378,11 +371,8 @@
             }
         });
 
-        addPaintListener(new PaintListener() {
-            @Override
-            public void paintControl(PaintEvent pe) {
-                FXCanvas.this.paintControl(pe);
-            }
+        addPaintListener(pe -> {
+            FXCanvas.this.paintControl(pe);
         });
 
         addMouseListener(new MouseListener() {
@@ -400,22 +390,16 @@
             }
         });
 
-        addMouseMoveListener(new MouseMoveListener() {
-            @Override
-            public void mouseMove(MouseEvent me) {
-                if ((me.stateMask & SWT.BUTTON_MASK) != 0) {
-                    FXCanvas.this.sendMouseEventToFX(me, AbstractEvents.MOUSEEVENT_DRAGGED);
-                } else {
-                    FXCanvas.this.sendMouseEventToFX(me, AbstractEvents.MOUSEEVENT_MOVED);
-                }
+        addMouseMoveListener(me -> {
+            if ((me.stateMask & SWT.BUTTON_MASK) != 0) {
+                FXCanvas.this.sendMouseEventToFX(me, AbstractEvents.MOUSEEVENT_DRAGGED);
+            } else {
+                FXCanvas.this.sendMouseEventToFX(me, AbstractEvents.MOUSEEVENT_MOVED);
             }
         });
 
-        addMouseWheelListener(new MouseWheelListener() {
-            @Override
-            public void mouseScrolled(MouseEvent me) {
-                FXCanvas.this.sendMouseEventToFX(me, AbstractEvents.MOUSEEVENT_WHEEL);
-            }
+        addMouseWheelListener(me -> {
+            FXCanvas.this.sendMouseEventToFX(me, AbstractEvents.MOUSEEVENT_WHEEL);
         });
 
         addMouseTrackListener(new MouseTrackListener() {
@@ -467,11 +451,8 @@
             }
         });
         
-        addMenuDetectListener(new MenuDetectListener() {
-            @Override
-            public void menuDetected(MenuDetectEvent e) {
-                FXCanvas.this.sendMenuEventToFX(e);
-            }
+        addMenuDetectListener(e -> {
+            FXCanvas.this.sendMenuEventToFX(e);
         });
     }
 
@@ -891,11 +872,9 @@
                     data = null;
                     //transferData = null;
                     currentTransferData = null;
-                    getDisplay().asyncExec(new Runnable () {
-                        public void run () {
-                            if (ignoreLeave) return;
-                            fxDropTarget.handleDragLeave();
-                        }
+                    getDisplay().asyncExec(() -> {
+                        if (ignoreLeave) return;
+                        fxDropTarget.handleDragLeave();
                     });
                 }
                 public void dragOperationChanged(DropTargetEvent event) {
@@ -950,21 +929,16 @@
             if (pWidth > 0 && pHeight > 0) {
                 scenePeer.setSize(pWidth, pHeight);
             }
-            scenePeer.setDragStartListener(new HostDragStartListener() {
-                @Override
-                public void dragStarted(final EmbeddedSceneDSInterface fxDragSource, final TransferMode dragAction) {
-                    Platform.runLater(new Runnable ()  {
-                        public void run () {
-                            DragSource dragSource = createDragSource(fxDragSource, dragAction);
-                            if (dragSource == null) {
-                                fxDragSource.dragDropEnd(null);
-                            } else {
-                                updateDropTarget();
-                                FXCanvas.this.notifyListeners(SWT.DragDetect, null);
-                            }
-                        }
-                    });
-                }
+            scenePeer.setDragStartListener((fxDragSource, dragAction) -> {
+                Platform.runLater(() -> {
+                    DragSource dragSource = createDragSource(fxDragSource, dragAction);
+                    if (dragSource == null) {
+                        fxDragSource.dragDropEnd(null);
+                    } else {
+                        updateDropTarget();
+                        FXCanvas.this.notifyListeners(SWT.DragDetect, null);
+                    }
+                });
             });
             //Force the old drop target to be disposed before creating a new one
             setDropTarget(null);
@@ -973,12 +947,9 @@
 
         @Override
         public boolean requestFocus() {
-            Display.getDefault().asyncExec(new Runnable() {
-                @Override
-                public void run() {
-                    if (isDisposed()) return;
-                    FXCanvas.this.forceFocus();
-                }
+            Display.getDefault().asyncExec(() -> {
+                if (isDisposed()) return;
+                FXCanvas.this.forceFocus();
             });
             return true;
         }
@@ -995,16 +966,13 @@
             synchronized (lock) {
                 if (queued) return;
                 queued = true;
-                Display.getDefault().asyncExec(new Runnable() {
-                    @Override
-                    public void run() {
-                        try {
-                            if (isDisposed()) return;
-                            FXCanvas.this.redraw();
-                        } finally {
-                            synchronized (lock) {
-                                queued = false;
-                            }
+                Display.getDefault().asyncExec(() -> {
+                    try {
+                        if (isDisposed()) return;
+                        FXCanvas.this.redraw();
+                    } finally {
+                        synchronized (lock) {
+                            queued = false;
                         }
                     }
                 });
--- a/modules/swt/src/main/java/javafx/embed/swt/SWTFXUtils.java	Mon Mar 03 13:26:38 2014 -0500
+++ b/modules/swt/src/main/java/javafx/embed/swt/SWTFXUtils.java	Mon Mar 03 15:38:59 2014 -0500
@@ -194,13 +194,11 @@
     private static int readValue(final String name) throws Exception {
         final Class<?> clazz = ImageData.class;
         return AccessController.doPrivileged(
-            new PrivilegedExceptionAction<Integer>() {
-                public Integer run() throws Exception {
+                (PrivilegedExceptionAction<Integer>) () -> {
                     Field field = clazz.getDeclaredField(name);
                     field.setAccessible(true);
                     return field.getInt(clazz);
-                }
-            });
+                });
     }
 
     private static Method blitDirect;
@@ -226,14 +224,12 @@
                     I, I, I, I,
                     I, I, I, B, B};
             blitDirect = AccessController.doPrivileged(
-                new PrivilegedExceptionAction<Method>() {
-                    public Method run() throws Exception {
+                    (PrivilegedExceptionAction<Method>) () -> {
                         Method method = clazz.
                             getDeclaredMethod("blit", argClasses);
                         method.setAccessible(true);
                         return method;
-                    }
-                });
+                    });
         }
         if (blitDirect != null) {
             blitDirect.invoke(clazz, op,
@@ -271,14 +267,12 @@
                     I, I, I, I,
                     I, I, I, B, B};
             blitPalette = AccessController.doPrivileged(
-                new PrivilegedExceptionAction<Method>() {
-                    public Method run() throws Exception {
+                    (PrivilegedExceptionAction<Method>) () -> {
                         Method method = clazz.
                             getDeclaredMethod("blit", argClasses);
                         method.setAccessible(true);
                         return method;
-                    }
-                });
+                    });
         }
         if (blitPalette != null) {
             blitPalette.invoke(clazz, op,
@@ -298,13 +292,11 @@
         final Class<?> clazz = ImageData.class;
         if (getByteOrderMethod != null) {
             getByteOrderMethod = AccessController.doPrivileged(
-                new PrivilegedExceptionAction<Method>() {
-                    public Method run() throws Exception {
+                    (PrivilegedExceptionAction<Method>) () -> {
                         Method method = clazz.getDeclaredMethod("getByteOrder");
                         method.setAccessible(true);
                         return method;
-                    }
-                });
+                    });
         }
         if (getByteOrderMethod != null) {
             return (Integer)getByteOrderMethod.invoke(image);