Example usage for javafx.stage WindowEvent WINDOW_SHOWN

List of usage examples for javafx.stage WindowEvent WINDOW_SHOWN

Introduction

In this page you can find the example usage for javafx.stage WindowEvent WINDOW_SHOWN.

Prototype

EventType WINDOW_SHOWN

To view the source code for javafx.stage WindowEvent WINDOW_SHOWN.

Click Source Link

Document

This event occurs on window just after it is shown.

Usage

From source file:benedict.zhang.addon.soundmanager.controller.SoundManagerConfigureController.java

@Override
public void handle(WindowEvent event) {
    Sound dbSound = null;//from  w w  w.  ja va  2 s  . com
    if (WindowEvent.WINDOW_SHOWN.equals(event.getEventType())) {
        try {
            dbSound = SoundDataProxy.getInstance().getDataSound(ApplicationUIConstants.SOUND_INFO,
                    Boolean.TRUE);
            BeanUtils.copyProperties(sound, dbSound);
            Media media = new Media(new File(sound.getSoundPath()).toURI().toURL().toString());
            if (media != null) {
                mediaPlayer = new MediaPlayer(media);
                mediaPlayer.setOnPlaying(() -> {
                    btnSoundPlayPause.setText("Pause");
                    this.sound.setTotalDuration(mediaPlayer.getTotalDuration());
                });
                mediaPlayer.setOnPaused(() -> {
                    btnSoundPlayPause.setText("Play");
                });
                mediaPlayer.setOnStopped(() -> {
                    btnSoundPlayPause.setText("Play");
                });
                mediaPlayer.setOnEndOfMedia(() -> {
                    btnSoundPlayPause.setText("Play");
                    mediaPlayer.stop();
                });
                configMediaView.setMediaPlayer(mediaPlayer);
                String mediaInfo = sound.getSoundPath();
                soundFileName.setText(mediaInfo);
                mediaPlayer.play();
            }
        } catch (MalformedURLException ex) {
            this.dialog.hide();
        } catch (IllegalAccessException ex) {
            this.dialog.hide();
        } catch (InvocationTargetException ex) {
            this.dialog.hide();
        } catch (MediaException me) {
            if (dbSound != null) {
                PersistenceManager.getInstance().removeSound(dbSound);
            }
            this.dialog.hide();

        }
    }

    if (WindowEvent.WINDOW_HIDING.equals(event.getEventType())) {
        if (this.mediaPlayer != null) {
            this.mediaPlayer.stop();
        }
        SoundDataProxy.getInstance().storeSound(ApplicationUIConstants.SOUND_INFO, oriSound);
    }
}