changeset 6435:29346901e6f1

RT-35197: Use Lambda in FX runtime and samples [media] Summary: This component was lambdified (unlambdified file names recorded in the JIRA)
author snorthov
date Thu, 06 Mar 2014 16:20:43 -0500
parents dfd9bd2f536d
children efb0a3d40c1f
files modules/media/src/main/java/com/sun/javafx/media/PrismMediaFrameHandler.java modules/media/src/main/java/com/sun/media/jfxmediaimpl/HostUtils.java modules/media/src/main/java/com/sun/media/jfxmediaimpl/MediaDisposer.java modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaAudioClipPlayer.java modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaManager.java modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/PlatformManager.java modules/media/src/main/java/javafx/scene/media/Media.java modules/media/src/main/java/javafx/scene/media/MediaPlayer.java modules/media/src/main/java/javafx/scene/media/MediaView.java
diffstat 9 files changed, 113 insertions(+), 204 deletions(-) [+]
line wrap: on
line diff
--- a/modules/media/src/main/java/com/sun/javafx/media/PrismMediaFrameHandler.java	Thu Mar 06 13:54:35 2014 -0500
+++ b/modules/media/src/main/java/com/sun/javafx/media/PrismMediaFrameHandler.java	Thu Mar 06 16:20:43 2014 -0500
@@ -157,11 +157,9 @@
         textures.clear();
     }
     
-    private RenderJob releaseRenderJob = new RenderJob(new Runnable() {
-            public void run() {
-                releaseData();
-            }
-        });
+    private RenderJob releaseRenderJob = new RenderJob(() -> {
+        releaseData();
+    });
 
     /**
      * Call this when you no longer need to render movie frames, for example
--- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/HostUtils.java	Thu Mar 06 13:54:35 2014 -0500
+++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/HostUtils.java	Thu Mar 06 16:20:43 2014 -0500
@@ -38,17 +38,15 @@
     private static boolean is64bit = false;
 
     static {
-        embedded = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
-            @Override public Boolean run() {
-                osName = System.getProperty("os.name").toLowerCase();
-                osArch = System.getProperty("os.arch").toLowerCase();
+        embedded = AccessController.doPrivileged((PrivilegedAction<Boolean>) () -> {
+            osName = System.getProperty("os.name").toLowerCase();
+            osArch = System.getProperty("os.arch").toLowerCase();
 
-                is64bit =  osArch.equals("x64")
-                        || osArch.equals("x86_64")
-                        || osArch.equals("ia64");
+            is64bit =  osArch.equals("x64")
+                    || osArch.equals("x86_64")
+                    || osArch.equals("ia64");
 
-                return Boolean.getBoolean("com.sun.javafx.isEmbedded");
-            }
+            return Boolean.getBoolean("com.sun.javafx.isEmbedded");
         });
     }
 
--- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/MediaDisposer.java	Thu Mar 06 13:54:35 2014 -0500
+++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/MediaDisposer.java	Thu Mar 06 16:20:43 2014 -0500
@@ -105,10 +105,8 @@
 
             // start a background thread that blocks on purgatory and runs indefinitely
             Thread disposerThread = new Thread(
-                    new Runnable() {
-                        public void run() {
-                            theDisposinator.disposerLoop();
-                        }
+                    () -> {
+                        theDisposinator.disposerLoop();
                     },
                     "Media Resource Disposer");
             disposerThread.setDaemon(true);
--- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaAudioClipPlayer.java	Thu Mar 06 13:54:35 2014 -0500
+++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaAudioClipPlayer.java	Thu Mar 06 16:20:43 2014 -0500
@@ -81,10 +81,8 @@
         private static final Thread schedulerThread;
 
         static {
-            schedulerThread = new Thread(new Runnable() {
-                public void run() {
-                    clipScheduler();
-                }
+            schedulerThread = new Thread(() -> {
+                clipScheduler();
             });
             schedulerThread.setDaemon(true);
             schedulerThread.start();
--- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaManager.java	Thu Mar 06 13:54:35 2014 -0500
+++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/NativeMediaManager.java	Thu Mar 06 16:20:43 2014 -0500
@@ -103,19 +103,17 @@
 
             // Load native libraries.
             try {
-                AccessController.doPrivileged(new PrivilegedExceptionAction() {
-                    public Object run() throws Exception {
-                        if (HostUtils.isWindows() || HostUtils.isMacOSX()) {
-                            NativeLibLoader.loadLibrary("glib-lite");
-                        }
+                AccessController.doPrivileged((PrivilegedExceptionAction) () -> {
+                    if (HostUtils.isWindows() || HostUtils.isMacOSX()) {
+                        NativeLibLoader.loadLibrary("glib-lite");
+                    }
 
-                        if (!HostUtils.isLinux() && !HostUtils.isIOS()) {
-                            NativeLibLoader.loadLibrary("gstreamer-lite");
-                        }
+                    if (!HostUtils.isLinux() && !HostUtils.isIOS()) {
+                        NativeLibLoader.loadLibrary("gstreamer-lite");
+                    }
 
-                        NativeLibLoader.loadLibrary("jfxmedia");
-                        return null;
-                    }
+                    NativeLibLoader.loadLibrary("jfxmedia");
+                    return null;
                 });
             } catch (Exception e) {
                 MediaUtils.error(null, MediaError.ERROR_MANAGER_ENGINEINIT_FAIL.code(),
--- a/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/PlatformManager.java	Thu Mar 06 13:54:35 2014 -0500
+++ b/modules/media/src/main/java/com/sun/media/jfxmediaimpl/platform/PlatformManager.java	Thu Mar 06 16:20:43 2014 -0500
@@ -47,11 +47,9 @@
 public final class PlatformManager {
     private static String enabledPlatforms;
     static {
-        AccessController.doPrivileged(new PrivilegedAction() {
-            public Object run() {
-                getPlatformSettings();
-                return null;
-            }
+        AccessController.doPrivileged((PrivilegedAction) () -> {
+            getPlatformSettings();
+            return null;
         });
     }
 
--- a/modules/media/src/main/java/javafx/scene/media/Media.java	Thu Mar 06 13:54:35 2014 -0500
+++ b/modules/media/src/main/java/javafx/scene/media/Media.java	Thu Mar 06 16:20:43 2014 -0500
@@ -538,14 +538,11 @@
         @Override
         public void onMetadata(final Map<String, Object> metadata) {
             // Clean up metadata
-            Platform.runLater(new Runnable() {
-                @Override
-                public void run() {
-                    updateMetadata(metadata);
-                    jfxParser.removeListener(metadataListener);
-                    jfxParser.stopParser();
-                    jfxParser = null;
-                }
+            Platform.runLater(() -> {
+                updateMetadata(metadata);
+                jfxParser.removeListener(metadataListener);
+                jfxParser.stopParser();
+                jfxParser = null;
             });
         }
     }
--- a/modules/media/src/main/java/javafx/scene/media/MediaPlayer.java	Thu Mar 06 13:54:35 2014 -0500
+++ b/modules/media/src/main/java/javafx/scene/media/MediaPlayer.java	Thu Mar 06 16:20:43 2014 -0500
@@ -512,11 +512,8 @@
         }
 
         // Register for the Player's event
-        Platform.runLater(new Runnable() {
-            @Override
-            public void run() {
-                registerListeners();
-            }
+        Platform.runLater(() -> {
+            registerListeners();
         });
     }
 
@@ -1039,12 +1036,8 @@
         if (isStartValueSet) {
             jfxPlayer.setStartTime(startStop[0]);
             if (getStatus() == Status.READY || getStatus() == Status.PAUSED) {
-                Platform.runLater(new Runnable() {
-
-                    @Override
-                    public void run() {
-                        setCurrentTime(getStartTime());
-                    }
+                Platform.runLater(() -> {
+                    setCurrentTime(getStartTime());
                 });
             }
         }
@@ -1727,17 +1720,15 @@
 
     // This function sets the player's error property on the UI thread.
     void handleError(final MediaException error) {
-        Platform.runLater(new Runnable() {
-            @Override public void run () {
-                setError(error);
+        Platform.runLater(() -> {
+            setError(error);
 
-                // Propogate errors that related to media to media object
-                if (error.getType() == MediaException.Type.MEDIA_CORRUPTED
-                        || error.getType() == MediaException.Type.MEDIA_UNSUPPORTED
-                        || error.getType() == MediaException.Type.MEDIA_INACCESSIBLE
-                        || error.getType() == MediaException.Type.MEDIA_UNAVAILABLE) {
-                    media._setError(error.getType(), error.getMessage());
-                }
+            // Propogate errors that related to media to media object
+            if (error.getType() == MediaException.Type.MEDIA_CORRUPTED
+                    || error.getType() == MediaException.Type.MEDIA_UNSUPPORTED
+                    || error.getType() == MediaException.Type.MEDIA_INACCESSIBLE
+                    || error.getType() == MediaException.Type.MEDIA_UNAVAILABLE) {
+                media._setError(error.getType(), error.getMessage());
             }
         });
     }
@@ -2431,14 +2422,10 @@
 
         @Override
         public void onMarker(final MarkerEvent evt) {
-            Platform.runLater(new Runnable() {
-
-                @Override
-                public void run() {
-                    Duration markerTime = Duration.millis(evt.getPresentationTime() * 1000.0);
-                    if (getOnMarker() != null) {
-                        getOnMarker().handle(new MediaMarkerEvent(new Pair<String, Duration>(evt.getMarkerName(), markerTime)));
-                    }
+            Platform.runLater(() -> {
+                Duration markerTime = Duration.millis(evt.getPresentationTime() * 1000.0);
+                if (getOnMarker() != null) {
+                    getOnMarker().handle(new MediaMarkerEvent(new Pair<String, Duration>(evt.getMarkerName(), markerTime)));
                 }
             });
         }
@@ -2448,16 +2435,13 @@
         @Override
         public void onReady(PlayerStateEvent evt) {
             //System.out.println("** MediaPlayerFX received onReady!");
-            Platform.runLater(new Runnable() {
-                @Override
-                public void run() {
-                    synchronized (disposeLock) {
-                        if (getStatus() == Status.DISPOSED) {
-                            return;
-                        }
-                        
-                        preReady();
+            Platform.runLater(() -> {
+                synchronized (disposeLock) {
+                    if (getStatus() == Status.DISPOSED) {
+                        return;
                     }
+
+                    preReady();
                 }
             });
         }
@@ -2467,11 +2451,9 @@
             //System.err.println("** MediaPlayerFX received onPlaying!");
             startTimeAtStop = null;
             
-            Platform.runLater(new Runnable() {
-                @Override public void run() {                    
-                    createMediaTimer();
-                    setStatus(Status.PLAYING);
-                }
+            Platform.runLater(() -> {
+                createMediaTimer();
+                setStatus(Status.PLAYING);
             });
         }
 
@@ -2479,25 +2461,17 @@
         public void onPause(PlayerStateEvent evt) {
             //System.err.println("** MediaPlayerFX received onPause!");
             
-            Platform.runLater(new Runnable() {
+            Platform.runLater(() -> {
+                // Disable updating currentTime.
+                isUpdateTimeEnabled = false;
 
-                @Override
-                public void run() {
-                    // Disable updating currentTime.
-                    isUpdateTimeEnabled = false;
-
-                    setStatus(Status.PAUSED);
-                }
+                setStatus(Status.PAUSED);
             });
             
             if (startTimeAtStop != null && startTimeAtStop != getStartTime()) {
                 startTimeAtStop = null;
-                Platform.runLater(new Runnable() {
-
-                    @Override
-                    public void run() {
-                        setCurrentTime(getStartTime());
-                    }
+                Platform.runLater(() -> {
+                    setCurrentTime(getStartTime());
                 });
             }
         }
@@ -2505,31 +2479,23 @@
         @Override
         public void onStop(PlayerStateEvent evt) {
             //System.err.println("** MediaPlayerFX received onStop!");
-            Platform.runLater(new Runnable() {
-
-                @Override
-                public void run() {
-                    // Destroy media time and update current time
-                    destroyMediaTimer();
-                    startTimeAtStop = getStartTime();
-                    setCurrentTime(getStartTime());
-                    setStatus(Status.STOPPED);
-                }
+            Platform.runLater(() -> {
+                // Destroy media time and update current time
+                destroyMediaTimer();
+                startTimeAtStop = getStartTime();
+                setCurrentTime(getStartTime());
+                setStatus(Status.STOPPED);
             });
         }
 
         @Override
         public void onStall(PlayerStateEvent evt) {
             //System.err.println("** MediaPlayerFX received onStall!");
-            Platform.runLater(new Runnable() {
+            Platform.runLater(() -> {
+                // Disable updating currentTime.
+                isUpdateTimeEnabled = false;
 
-                @Override
-                public void run() {
-                    // Disable updating currentTime.
-                    isUpdateTimeEnabled = false;
-
-                    setStatus(Status.STALLED);
-                }
+                setStatus(Status.STALLED);
             });
         }
 
@@ -2574,27 +2540,19 @@
             //System.err.println("** MediaPlayerFX received onFinish!");
             startTimeAtStop = null;
             
-            Platform.runLater(new Runnable() {
-
-                @Override
-                public void run() {
-                    handleFinish();
-                }
+            Platform.runLater(() -> {
+                handleFinish();
             });
         }
 
         @Override
         public void onHalt(final PlayerStateEvent evt) {
-            Platform.runLater(new Runnable() {
+            Platform.runLater(() -> {
+                setStatus(Status.HALTED);
+                handleError(MediaException.haltException(evt.getMessage()));
 
-                @Override
-                public void run() {
-                    setStatus(Status.HALTED);
-                    handleError(MediaException.haltException(evt.getMessage()));
-
-                    // Disable updating currentTime.
-                    isUpdateTimeEnabled = false;
-                }
+                // Disable updating currentTime.
+                isUpdateTimeEnabled = false;
             });
         }
     }
@@ -2609,13 +2567,9 @@
         @Override
         public void onDurationChanged(final double duration) {
             //System.err.println("** MediaPlayerFX received onDurationChanged!");
-            Platform.runLater(new Runnable() {
-
-                @Override
-                public void run() {
-                    theDuration = duration;
-                    handleDurationChanged();
-                }
+            Platform.runLater(() -> {
+                theDuration = duration;
+                handleDurationChanged();
             });
         }
     }
@@ -2626,15 +2580,11 @@
 
         @Override
         public void onSizeChanged(final int width, final int height) {
-            Platform.runLater(new Runnable() {
-
-                @Override
-                public void run() {
-                    if (media != null) {
-                        trackWidth = width;
-                        trackHeight = height;
-                        setSize();
-                    }
+            Platform.runLater(() -> {
+                if (media != null) {
+                    trackWidth = width;
+                    trackHeight = height;
+                    setSize();
                 }
             });
         }
@@ -2675,10 +2625,8 @@
                     bufferedTime = position/stop * evt.getDuration()*1000.0;
                     lastBufferEvent = null;
 
-                    Platform.runLater(new Runnable() {
-                       @Override public void run() {
-                            setBufferProgressTime(Duration.millis(bufferedTime));
-                       }
+                    Platform.runLater(() -> {
+                         setBufferProgressTime(Duration.millis(bufferedTime));
                     });
                 } else {
                     lastBufferEvent = evt;
@@ -2692,15 +2640,13 @@
         private float[] phases;
 
         @Override public void onAudioSpectrumEvent(final AudioSpectrumEvent evt) {
-            Platform.runLater(new Runnable() {
-                @Override public void run () {
-                    AudioSpectrumListener listener = getAudioSpectrumListener();
-                    if (listener != null) {
-                        listener.spectrumDataUpdate(evt.getTimestamp(),
-                                evt.getDuration(),
-                                magnitudes = evt.getSource().getMagnitudes(magnitudes),
-                                phases = evt.getSource().getPhases(phases));
-                    }
+            Platform.runLater(() -> {
+                AudioSpectrumListener listener = getAudioSpectrumListener();
+                if (listener != null) {
+                    listener.spectrumDataUpdate(evt.getTimestamp(),
+                            evt.getDuration(),
+                            magnitudes = evt.getSource().getMagnitudes(magnitudes),
+                            phases = evt.getSource().getPhases(phases));
                 }
             });
         }
@@ -2893,12 +2839,9 @@
             final MediaPlayer player = playerRef.get();
             if (player != null) {
 
-                Platform.runLater(new Runnable() {
-                    @Override
-                    public void run() {
-                        synchronized (timerLock) {
-                            player.updateTime();
-                        }
+                Platform.runLater(() -> {
+                    synchronized (timerLock) {
+                        player.updateTime();
                     }
                 });
             } else {
--- a/modules/media/src/main/java/javafx/scene/media/MediaView.java	Thu Mar 06 13:54:35 2014 -0500
+++ b/modules/media/src/main/java/javafx/scene/media/MediaView.java	Thu Mar 06 16:20:43 2014 -0500
@@ -113,11 +113,9 @@
     private InvalidationListener errorListener = new MediaErrorInvalidationListener();
 
     /** Listener which causes the geometry to be updated when the media dimension changes. */
-    private InvalidationListener mediaDimensionListener = new InvalidationListener() {
-        @Override public void invalidated(Observable value) {
-            impl_markDirty(DirtyBits.NODE_VIEWPORT);
-            impl_geomChanged();
-        }
+    private InvalidationListener mediaDimensionListener = value -> {
+        impl_markDirty(DirtyBits.NODE_VIEWPORT);
+        impl_geomChanged();
     };
 
     /** Listener for decoded frame rate. */
@@ -138,19 +136,11 @@
         if (listenerProp == null || !Boolean.getBoolean(VIDEO_FRAME_RATE_PROPERTY_NAME)) {
             return null;
         } else {
-            return new com.sun.media.jfxmedia.events.VideoFrameRateListener() {
-
-                @Override
-                public void onFrameRateChanged(final double videoFrameRate) {
-                    Platform.runLater(new Runnable() {
-
-                        @Override
-                        public void run() {
-                            ObservableMap props = getProperties();
-                            props.put(VIDEO_FRAME_RATE_PROPERTY_NAME, videoFrameRate);
-                        }
-                    });
-                }
+            return videoFrameRate -> {
+                Platform.runLater(() -> {
+                    ObservableMap props = getProperties();
+                    props.put(VIDEO_FRAME_RATE_PROPERTY_NAME, videoFrameRate);
+                });
             };
         }
     }
@@ -164,25 +154,16 @@
     private ChangeListener<Number> opacityListener;
     
     private void createListeners() {
-        parentListener = new ChangeListener<Parent>() {
-            @Override
-            public void changed(ObservableValue<? extends Parent> ov, Parent oldParent, Parent newParent) {
-                updateOverlayVisibility();
-            }
+        parentListener = (ov2, oldParent, newParent) -> {
+            updateOverlayVisibility();
         };
         
-        treeVisibleListener = new ChangeListener<Boolean>() {
-            @Override
-            public void changed(ObservableValue<? extends Boolean> ov, Boolean oldVisible, Boolean newVisible) {
-                updateOverlayVisibility();
-            }
+        treeVisibleListener = (ov1, oldVisible, newVisible) -> {
+            updateOverlayVisibility();
         };
         
-        opacityListener = new ChangeListener<Number>() {
-            @Override
-            public void changed(ObservableValue<? extends Number> ov, Number oldOpacity, Number newOpacity) {
-                updateOverlayOpacity();
-            }
+        opacityListener = (ov, oldOpacity, newOpacity) -> {
+            updateOverlayOpacity();
         };
     }