Example usage for javafx.stage WindowEvent getEventType

List of usage examples for javafx.stage WindowEvent getEventType

Introduction

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

Prototype

@Override
    public EventType<WindowEvent> getEventType() 

Source Link

Usage

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

@Override
public void handle(WindowEvent event) {
    Sound dbSound = null;/*from w ww. j av  a 2 s.c  o  m*/
    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);
    }
}