Search in sources :

Example 6 with ActionEvent

use of javafx.event.ActionEvent in project Media-Library by The-Rain-Goddess.

the class ApplicationWindow method getMenuItem.

private MenuItem getMenuItem(String name, MenuAction action) {
    MenuItem item = new MenuItem(name, new ImageView(new Image("com/negativevr/media_library/res/" + name.toLowerCase() + ".png")));
    item.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            action.execute();
        }
    });
    return item;
}
Also used : ActionEvent(javafx.event.ActionEvent) MenuItem(javafx.scene.control.MenuItem) ImageView(javafx.scene.image.ImageView) Image(javafx.scene.image.Image)

Example 7 with ActionEvent

use of javafx.event.ActionEvent in project Media-Library by The-Rain-Goddess.

the class ApplicationWindow method updatePlayer.

private void updatePlayer() {
    timeSlider.valueProperty().addListener(new InvalidationListener() {

        @Override
        public void invalidated(Observable ov) {
            if (timeSlider.isValueChanging()) {
                //Duration duration = player.getCurrentTime();
                Duration duration = player.getMedia().getDuration();
                if (duration != null) {
                    player.seek(duration.multiply(timeSlider.getValue() / 100.0));
                }
                updateValues();
            }
        }
    });
    player.setOnReady(() -> {
        duration = player.getMedia().getDuration();
        updateValues();
    });
    player.currentTimeProperty().addListener(new ChangeListener<Duration>() {

        @Override
        public void changed(ObservableValue<? extends Duration> arg0, Duration arg1, Duration arg2) {
            updateValues();
        }
    });
    player.volumeProperty().bindBidirectional(volumeSlider.valueProperty());
    Image PlayButtonImage = new Image("com/negativevr/media_library/res/play.png");
    Image PauseButtonImage = new Image("com/negativevr/media_library/res/pause.png");
    ImageView imageViewPlay = new ImageView(PlayButtonImage);
    ImageView imageViewPause = new ImageView(PauseButtonImage);
    play.setGraphic(imageViewPause);
    play.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            updateValues();
            Status status = player.getStatus();
            if (status == Status.PAUSED || status == Status.READY || status == Status.UNKNOWN || status == Status.STOPPED) {
                player.play();
                play.setGraphic(imageViewPause);
            } else {
                player.pause();
                play.setGraphic(imageViewPlay);
            }
        }
    });
    player.setOnEndOfMedia(() -> {
        play.setGraphic(imageViewPlay);
        if (status == MediaStatus.REPEAT_NONE) {
            player.seek(new Duration(0));
            player.pause();
            play.setGraphic(imageViewPlay);
        } else if (status == MediaStatus.REPEAT_SINGLE) {
            player.seek(new Duration(0));
            player.play();
            play.setGraphic(imageViewPause);
        }
    });
    reload.setOnAction((ActionEvent e) -> {
        player.seek(player.getStartTime());
    });
    skip.setOnAction((ActionEvent e) -> {
        player.seek(player.getStopTime());
    });
    //fade in time line
    final Timeline fadeInTimeline = new Timeline(new KeyFrame(FADE_DURATION, new KeyValue(player.volumeProperty(), 1.0)));
    //fade out timeline
    final Timeline fadeOutTimeline = new Timeline(new KeyFrame(FADE_DURATION, new KeyValue(player.volumeProperty(), 0.0)));
    //fade in button
    fadeIn = new Button("Fade In");
    fadeIn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            fadeInTimeline.play();
        }
    });
    fadeIn.setMaxWidth(Double.MAX_VALUE);
    //fade out button
    fadeOut = new Button("Fade Out");
    fadeOut.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            fadeOutTimeline.play();
        }
    });
    fadeOut.setMaxWidth(Double.MAX_VALUE);
}
Also used : Status(javafx.scene.media.MediaPlayer.Status) KeyValue(javafx.animation.KeyValue) ActionEvent(javafx.event.ActionEvent) Duration(javafx.util.Duration) Image(javafx.scene.image.Image) Observable(javafx.beans.Observable) Timeline(javafx.animation.Timeline) Button(javafx.scene.control.Button) MouseButton(javafx.scene.input.MouseButton) InvalidationListener(javafx.beans.InvalidationListener) KeyFrame(javafx.animation.KeyFrame) ImageView(javafx.scene.image.ImageView)

Example 8 with ActionEvent

use of javafx.event.ActionEvent in project Media-Library by The-Rain-Goddess.

the class ApplicationWindow method setDataTableClickEvents.

private void setDataTableClickEvents() {
    dataTable.setRowFactory(tv -> {
        TableRow<MediaFile> row = new TableRow<>();
        row.setOnMouseClicked(event -> {
            try {
                if (event.getButton() == MouseButton.SECONDARY) {
                    ContextMenu cMenu = new ContextMenu();
                    MenuItem remove = new MenuItem("Remove");
                    remove.setOnAction((ActionEvent ev) -> {
                        Main.getMasterData().remove(row.getItem().getUUID());
                        updateDataTable();
                        updateFileSystem();
                    });
                    cMenu.getItems().add(remove);
                    row.setOnContextMenuRequested(e -> cMenu.show(row, event.getScreenX(), event.getScreenY()));
                } else {
                    if (event.getClickCount() == 1) {
                        System.out.println("Clicked");
                        System.out.println(row.getItem());
                    } else if (event.getClickCount() == 2) {
                        System.out.println("Playing: \n" + row.getItem());
                        File mediaFile = new File(row.getItem().getLibraryFilePath());
                        Media mediaToPlay = new Media(mediaFile.toURI().toString());
                        artistLabel.setText(row.getItem().getArtistName() + " - " + row.getItem().getAlbumName());
                        songLabel.setText(row.getItem().getSongName());
                        player.stop();
                        player = new MediaPlayer(mediaToPlay);
                        player.setAutoPlay(true);
                        updatePlayer();
                    }
                }
            } catch (MediaException e) {
                Stage errorWindow = new Stage();
                VBox componentLayout = new VBox();
                Label errorLabel = new Label(e.getMessage());
                VBox.setMargin(errorLabel, new Insets(10, 10, 10, 10));
                componentLayout.getChildren().addAll(errorLabel);
                Scene scene = new Scene(componentLayout);
                errorWindow.setScene(scene);
                errorWindow.show();
            }
        });
        return row;
    });
}
Also used : MediaFile(com.negativevr.media_library.files.MediaFile) Insets(javafx.geometry.Insets) MediaException(javafx.scene.media.MediaException) ActionEvent(javafx.event.ActionEvent) Media(javafx.scene.media.Media) Label(javafx.scene.control.Label) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) Scene(javafx.scene.Scene) TableRow(javafx.scene.control.TableRow) Stage(javafx.stage.Stage) MediaFile(com.negativevr.media_library.files.MediaFile) File(java.io.File) VBox(javafx.scene.layout.VBox) MediaPlayer(javafx.scene.media.MediaPlayer)

Example 9 with ActionEvent

use of javafx.event.ActionEvent in project Media-Library by The-Rain-Goddess.

the class ApplicationWindow method setupMediaPlayer.

//private Media Player accessors / mutators
private HBox setupMediaPlayer() {
    HBox mediaSlot = new HBox();
    VBox timeControls = new VBox();
    VBox timeBox = new VBox();
    HBox mediaControlBox = new HBox();
    HBox searchBox = new HBox();
    HBox fadeBox = new HBox(5);
    VBox volumeControls = new VBox(10);
    if (Main.getMasterDataAsList().size() != 0) {
        Path path = Paths.get(Main.getMasterDataAsList().get(0).getLibraryFilePath());
        Media media = new Media(path.toFile().toURI().toString());
        player = new MediaPlayer(media);
    } else {
    //player = new MediaPlayer(new Media(Paths.get("src/com/negativevr/media_library/res/init.mp3").toFile().toURI().toString()));
    }
    //player.setAutoPlay(true);
    MediaView mediaView = new MediaView();
    mediaView.setMediaPlayer(player);
    Image PlayButtonImage = new Image("com/negativevr/media_library/res/play.png");
    Image PauseButtonImage = new Image("com/negativevr/media_library/res/pause.png");
    ImageView imageViewPlay = new ImageView(PlayButtonImage);
    ImageView imageViewPause = new ImageView(PauseButtonImage);
    play = new Button();
    play.setGraphic(imageViewPlay);
    play.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            updateValues();
            Status status = player.getStatus();
            if (status == Status.PAUSED || status == Status.READY || status == Status.UNKNOWN || status == Status.STOPPED) {
                player.play();
                play.setGraphic(imageViewPause);
            } else {
                player.pause();
                play.setGraphic(imageViewPlay);
            }
        }
    });
    reload = new Button();
    reload.setGraphic(new ImageView(new Image("com/negativevr/media_library/res/reload.png")));
    reload.setOnAction((ActionEvent e) -> {
        player.seek(player.getStartTime());
    });
    skip = new Button();
    skip.setGraphic((new ImageView(new Image("com/negativevr/media_library/res/skip.png"))));
    skip.setOnAction((ActionEvent e) -> {
        player.seek(player.getStopTime());
    });
    previous = new Button();
    previous.setGraphic(new ImageView(new Image("com/negativevr/media_library/res/previous.png")));
    next = new Button();
    next.setGraphic(new ImageView(new Image("com/negativevr/media_library/res/next.png")));
    Button repeat = new Button();
    if (status == MediaStatus.REPEAT_NONE)
        repeat.setGraphic(new ImageView(new Image("com/negativevr/media_library/res/repeat_none.png")));
    else if (status == MediaStatus.REPEAT_SINGLE)
        repeat.setGraphic(new ImageView(new Image("com/negativevr/media_library/res/repeat_single.png")));
    repeat.setOnAction((ActionEvent e) -> {
        if (status == MediaStatus.REPEAT_SINGLE) {
            status = MediaStatus.REPEAT_NONE;
            repeat.setGraphic(new ImageView(new Image("com/negativevr/media_library/res/repeat_none.png")));
        } else if (status == MediaStatus.REPEAT_NONE) {
            status = MediaStatus.REPEAT_SINGLE;
            repeat.setGraphic(new ImageView(new Image("com/negativevr/media_library/res/repeat_single.png")));
        }
    });
    timeSlider = new Slider();
    HBox.setHgrow(timeSlider, Priority.ALWAYS);
    timeSlider.setMinSize(100, 50);
    timeSlider.valueProperty().addListener(new InvalidationListener() {

        @Override
        public void invalidated(Observable ov) {
            if (timeSlider.isValueChanging()) {
                Duration duration = player.getMedia().getDuration();
                if (duration != null) {
                    player.seek(duration.multiply(timeSlider.getValue() / 100.0));
                }
                updateValues();
            }
        }
    });
    List<MediaFile> data = Main.getMasterDataAsList();
    if (data.size() != 0) {
        artistLabel = new Label(data.get(0).getArtistName() + " - " + data.get(0).getAlbumName());
        songLabel = new Label(data.get(0).getSongName());
    } else {
        artistLabel = new Label();
        songLabel = new Label();
    }
    player.currentTimeProperty().addListener(new InvalidationListener() {

        @Override
        public void invalidated(Observable ov) {
            updateValues();
        }
    });
    player.currentTimeProperty().addListener(new ChangeListener<Duration>() {

        @Override
        public void changed(ObservableValue<? extends Duration> arg0, Duration arg1, Duration arg2) {
            updateValues();
        }
    });
    time = new Label();
    time.setTextFill(Color.BLACK);
    player.setOnReady(() -> {
        duration = player.getMedia().getDuration();
        updateValues();
    });
    //volume control slider
    volumeSlider = new Slider(0, 1, 0);
    player.volumeProperty().bindBidirectional(volumeSlider.valueProperty());
    player.setVolume(0.5);
    //fade in time line
    final Timeline fadeInTimeline = new Timeline(new KeyFrame(FADE_DURATION, new KeyValue(player.volumeProperty(), 1.0)));
    //fade out timeline
    final Timeline fadeOutTimeline = new Timeline(new KeyFrame(FADE_DURATION, new KeyValue(player.volumeProperty(), 0.0)));
    //fade in button
    fadeIn = new Button("Fade In");
    fadeIn.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            fadeInTimeline.play();
        }
    });
    fadeIn.setMaxWidth(Double.MAX_VALUE);
    //fade out button
    fadeOut = new Button("Fade Out");
    fadeOut.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            fadeOutTimeline.play();
        }
    });
    fadeOut.setMaxWidth(Double.MAX_VALUE);
    player.setOnEndOfMedia(() -> {
        play.setGraphic(imageViewPlay);
        if (status == MediaStatus.REPEAT_NONE) {
            player.seek(new Duration(0));
            player.pause();
            play.setGraphic(imageViewPlay);
        } else if (status == MediaStatus.REPEAT_SINGLE) {
            player.seek(new Duration(0));
            player.play();
            play.setGraphic(imageViewPause);
        }
    });
    //volume cotrol box
    fadeBox.getChildren().addAll(fadeOut, fadeIn);
    fadeBox.setAlignment(Pos.CENTER);
    volumeControls.getChildren().setAll(new Label("Volume"), volumeSlider, fadeBox);
    volumeControls.setAlignment(Pos.CENTER);
    volumeControls.disableProperty().bind(Bindings.or(Bindings.equal(Timeline.Status.RUNNING, fadeInTimeline.statusProperty()), Bindings.equal(Timeline.Status.RUNNING, fadeOutTimeline.statusProperty())));
    timeControls.getChildren().addAll(songLabel, artistLabel, timeSlider);
    timeControls.setAlignment(Pos.CENTER);
    timeControls.setFillWidth(true);
    timeControls.setMinWidth(300);
    timeBox.getChildren().addAll(repeat, time);
    timeBox.setAlignment(Pos.CENTER);
    mediaControlBox.getChildren().addAll(previous, reload, play, skip, next);
    mediaControlBox.setAlignment(Pos.CENTER);
    searchBox.getChildren().addAll(new Label("Search"), search);
    searchBox.setAlignment(Pos.CENTER_RIGHT);
    mediaSlot.getChildren().addAll(mediaControlBox, timeBox, timeControls, volumeControls, mediaView, searchBox);
    mediaSlot.setSpacing(10);
    HBox.setHgrow(timeControls, Priority.ALWAYS);
    return mediaSlot;
}
Also used : HBox(javafx.scene.layout.HBox) KeyValue(javafx.animation.KeyValue) Slider(javafx.scene.control.Slider) ActionEvent(javafx.event.ActionEvent) Label(javafx.scene.control.Label) Image(javafx.scene.image.Image) MediaView(javafx.scene.media.MediaView) Button(javafx.scene.control.Button) MouseButton(javafx.scene.input.MouseButton) ImageView(javafx.scene.image.ImageView) Path(java.nio.file.Path) Status(javafx.scene.media.MediaPlayer.Status) MediaFile(com.negativevr.media_library.files.MediaFile) Media(javafx.scene.media.Media) Duration(javafx.util.Duration) Observable(javafx.beans.Observable) Timeline(javafx.animation.Timeline) InvalidationListener(javafx.beans.InvalidationListener) KeyFrame(javafx.animation.KeyFrame) VBox(javafx.scene.layout.VBox) MediaPlayer(javafx.scene.media.MediaPlayer)

Example 10 with ActionEvent

use of javafx.event.ActionEvent in project bitsquare by bitsquare.

the class Transitions method blur.

public void blur(Node node, int duration, double brightness, boolean removeNode, double blurRadius) {
    if (removeEffectTimeLine != null)
        removeEffectTimeLine.stop();
    node.setMouseTransparent(true);
    GaussianBlur blur = new GaussianBlur(0.0);
    Timeline timeline = new Timeline();
    KeyValue kv1 = new KeyValue(blur.radiusProperty(), blurRadius);
    KeyFrame kf1 = new KeyFrame(Duration.millis(getDuration(duration)), kv1);
    ColorAdjust darken = new ColorAdjust();
    darken.setBrightness(0.0);
    blur.setInput(darken);
    KeyValue kv2 = new KeyValue(darken.brightnessProperty(), brightness);
    KeyFrame kf2 = new KeyFrame(Duration.millis(getDuration(duration)), kv2);
    timeline.getKeyFrames().addAll(kf1, kf2);
    node.setEffect(blur);
    if (removeNode)
        timeline.setOnFinished(actionEvent -> UserThread.execute(() -> ((Pane) (node.getParent())).getChildren().remove(node)));
    timeline.play();
}
Also used : EventHandler(javafx.event.EventHandler) Inject(javax.inject.Inject) Preferences(io.bitsquare.user.Preferences) ActionEvent(javafx.event.ActionEvent) Duration(javafx.util.Duration) UserThread(io.bitsquare.common.UserThread) Node(javafx.scene.Node) javafx.animation(javafx.animation) ColorAdjust(javafx.scene.effect.ColorAdjust) GaussianBlur(javafx.scene.effect.GaussianBlur) Pane(javafx.scene.layout.Pane) GaussianBlur(javafx.scene.effect.GaussianBlur) ColorAdjust(javafx.scene.effect.ColorAdjust) Pane(javafx.scene.layout.Pane)

Aggregations

ActionEvent (javafx.event.ActionEvent)37 List (java.util.List)11 Label (javafx.scene.control.Label)11 ObservableList (javafx.collections.ObservableList)10 FxUtil (com.kyj.fx.voeditor.visual.util.FxUtil)9 ArrayList (java.util.ArrayList)9 Optional (java.util.Optional)9 Button (javafx.scene.control.Button)9 MenuItem (javafx.scene.control.MenuItem)9 Stage (javafx.stage.Stage)9 ResourceLoader (com.kyj.fx.voeditor.visual.momory.ResourceLoader)8 DialogUtil (com.kyj.fx.voeditor.visual.util.DialogUtil)8 ValueUtil (com.kyj.fx.voeditor.visual.util.ValueUtil)8 File (java.io.File)8 MouseEvent (javafx.scene.input.MouseEvent)8 Pair (javafx.util.Pair)8 Logger (org.slf4j.Logger)8 ConfigResourceLoader (com.kyj.fx.voeditor.visual.momory.ConfigResourceLoader)7 Iterator (java.util.Iterator)7 FXCollections (javafx.collections.FXCollections)7