Search in sources :

Example 1 with Slider

use of javafx.scene.control.Slider in project JFoenix by jfoenixadmin.

the class JFXSliderSkinOLD method positionThumb.

private void positionThumb(final boolean animate) {
    Slider s = getSkinnable();
    if (s.getValue() > s.getMax()) {
        // this can happen if we are bound to something 
        return;
    }
    final double endX = (isHorizontal) ? trackStart + (((trackLength * ((s.getValue() - s.getMin()) / (s.getMax() - s.getMin()))))) - snappedLeftInset() : thumbLeft;
    final double endY = (isHorizontal) ? thumbTop : snappedTopInset() + thumbRadius + trackLength - (trackLength * ((s.getValue() - s.getMin()) / (s.getMax() - s.getMin())));
    if (animate) {
        // lets animate the thumb transition
        final double startX = thumb.getLayoutX();
        final double startY = thumb.getLayoutY();
        Transition transition = new Transition() {

            {
                setCycleDuration(Duration.millis(20));
            }

            @Override
            protected void interpolate(double frac) {
                if (!Double.isNaN(startX)) {
                    thumb.setLayoutX(startX + frac * (endX - startX));
                }
                if (!Double.isNaN(startY)) {
                    thumb.setLayoutY(startY + frac * (endY - startY));
                }
            }
        };
        transition.play();
    } else {
        thumb.setLayoutX(endX);
        thumb.setLayoutY(endY);
    }
}
Also used : JFXSlider(com.jfoenix.controls.JFXSlider) Slider(javafx.scene.control.Slider)

Example 2 with Slider

use of javafx.scene.control.Slider in project fxexperience2 by EricCanull.

the class ColorPickerControl method initialize.

/**
     * Private
     */
private void initialize() {
    final FXMLLoader loader = new FXMLLoader();
    //NOI18N
    loader.setLocation(ColorPickerControl.class.getResource("/fxml/FXMLColorPicker.fxml"));
    loader.setController(this);
    loader.setRoot(this);
    try {
        loader.load();
    } catch (IOException ex) {
        Logger.getLogger(ColorPickerControl.class.getName()).log(Level.SEVERE, null, ex);
    }
    assert hue_slider != null;
    assert picker_region != null;
    assert hue_textfield != null;
    assert saturation_textfield != null;
    assert brightness_textfield != null;
    assert alpha_textfield != null;
    assert red_textfield != null;
    assert green_textfield != null;
    assert blue_textfield != null;
    assert alpha_slider != null;
    // Make the grad for hue slider
    hue_slider.setStyle(makeHueSliderCSS());
    // Investigate why height + width listeners do not work
    // Indeed, the picker_handle_stackpane bounds may still be null at this point
    // UPDATE BELOW TO BE CALLED ONCE ONLY AT DISPLAY TIME
    picker_region.boundsInParentProperty().addListener((ov, oldb, newb) -> {
        picker_scrollpane.setHvalue(0.5);
        picker_scrollpane.setVvalue(0.5);
        // Init time only
        final Paint paint = paintPickerController.getPaintProperty();
        if (paint instanceof Color) {
            updateUI((Color) paint);
        } else if (paint instanceof LinearGradient || paint instanceof RadialGradient) {
            final GradientPicker gradientPicker = paintPickerController.getGradientPicker();
            final GradientPickerStop gradientPickerStop = gradientPicker.getSelectedStop();
            // Update the color preview with the color of the selected stop
            if (gradientPickerStop != null) {
                updateUI(gradientPickerStop.getColor());
            }
        }
    });
    final ChangeListener<Boolean> onHSBFocusedChange = (ov, oldValue, newValue) -> {
        if (newValue == false) {
            // Update UI
            final Color color = updateUI_OnHSBChange();
            // Update model
            setPaintProperty(color);
        }
    };
    final ChangeListener<Boolean> onRGBFocusedChange = (ov, oldValue, newValue) -> {
        if (newValue == false) {
            // Update UI
            final Color color = updateUI_OnRGBChange();
            // Update model
            setPaintProperty(color);
        }
    };
    final ChangeListener<Boolean> onHexaFocusedChange = (ov, oldValue, newValue) -> {
        if (newValue == false) {
            try {
                // Update UI
                final Color color = updateUI_OnHexaChange();
                // Update model
                setPaintProperty(color);
            } catch (IllegalArgumentException iae) {
                handleHexaException();
            }
        }
    };
    // TextField ON FOCUS LOST event handler
    hue_textfield.focusedProperty().addListener(onHSBFocusedChange);
    saturation_textfield.focusedProperty().addListener(onHSBFocusedChange);
    brightness_textfield.focusedProperty().addListener(onHSBFocusedChange);
    alpha_textfield.focusedProperty().addListener(onHSBFocusedChange);
    red_textfield.focusedProperty().addListener(onRGBFocusedChange);
    green_textfield.focusedProperty().addListener(onRGBFocusedChange);
    blue_textfield.focusedProperty().addListener(onRGBFocusedChange);
    hexa_textfield.focusedProperty().addListener(onHexaFocusedChange);
    // Slider ON VALUE CHANGE event handler
    hue_slider.valueProperty().addListener((ov, oldValue, newValue) -> {
        if (updating == true) {
            return;
        }
        double hue = newValue.doubleValue();
        // retrieve HSB TextFields values
        double saturation = Double.valueOf(saturation_textfield.getText()) / 100.0;
        double brightness = Double.valueOf(brightness_textfield.getText()) / 100.0;
        double alpha = Double.valueOf(alpha_textfield.getText());
        // Update UI
        final Color color = updateUI(hue, saturation, brightness, alpha);
        // Update model
        setPaintProperty(color);
    });
    alpha_slider.valueProperty().addListener((ov, oldValue, newValue) -> {
        if (updating == true) {
            return;
        }
        double alpha = newValue.doubleValue();
        // retrieve HSB TextFields values
        double hue = Double.valueOf(hue_textfield.getText());
        double saturation = Double.valueOf(saturation_textfield.getText()) / 100.0;
        double brightness = Double.valueOf(brightness_textfield.getText()) / 100.0;
        // Update UI
        final Color color = updateUI(hue, saturation, brightness, alpha);
        // Update model
        setPaintProperty(color);
    });
    final ChangeListener<Boolean> liveUpdateListener = (ov, oldValue, newValue) -> paintPickerController.setLiveUpdate(newValue);
    picker_region.pressedProperty().addListener(liveUpdateListener);
    hue_slider.pressedProperty().addListener(liveUpdateListener);
    alpha_slider.pressedProperty().addListener(liveUpdateListener);
}
Also used : Color(javafx.scene.paint.Color) TextField(javafx.scene.control.TextField) Mode(com.fxexperience.javafx.scene.control.paintpicker.PaintPicker.Mode) MouseEvent(javafx.scene.input.MouseEvent) IOException(java.io.IOException) StackPane(javafx.scene.layout.StackPane) LinearGradient(javafx.scene.paint.LinearGradient) GradientPickerStop(com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop) Logger(java.util.logging.Logger) VBox(javafx.scene.layout.VBox) Level(java.util.logging.Level) FXML(javafx.fxml.FXML) PaintPickerController(com.fxexperience.javafx.scene.control.paintpicker.PaintPickerController) ActionEvent(javafx.event.ActionEvent) ScrollPane(javafx.scene.control.ScrollPane) Slider(javafx.scene.control.Slider) Region(javafx.scene.layout.Region) Paint(javafx.scene.paint.Paint) FXMLLoader(javafx.fxml.FXMLLoader) RadialGradient(javafx.scene.paint.RadialGradient) GradientPicker(com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker) ChangeListener(javafx.beans.value.ChangeListener) Circle(javafx.scene.shape.Circle) Bounds(javafx.geometry.Bounds) Color(javafx.scene.paint.Color) RadialGradient(javafx.scene.paint.RadialGradient) IOException(java.io.IOException) Paint(javafx.scene.paint.Paint) FXMLLoader(javafx.fxml.FXMLLoader) GradientPickerStop(com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop) GradientPicker(com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker) LinearGradient(javafx.scene.paint.LinearGradient)

Example 3 with Slider

use of javafx.scene.control.Slider 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 4 with Slider

use of javafx.scene.control.Slider in project trex-stateless-gui by cisco-system-traffic-generator.

the class MultiplierView method buildUI.

/**
     * Build UI
     */
private void buildUI() {
    // add slider area
    addLabel("Bandwidth", 7, 336);
    addLabel("0", 22, 287);
    addLabel("100", 22, 454);
    slider = new Slider(0, 100, 1);
    slider.setDisable(true);
    getChildren().add(slider);
    MultiplierView.setTopAnchor(slider, 22d);
    MultiplierView.setLeftAnchor(slider, 304d);
    slider.valueProperty().addListener(new ChangeListener<Number>() {

        @Override
        public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
            // check min value for slider
            if ((double) newValue < MultiplierType.percentage.getMinRate(rate)) {
                slider.setValue(MultiplierType.percentage.getMinRate(rate));
            }
            updateOptionsValues(slider.getValue(), updateAll);
            if (fireUpdateCommand) {
                optionValueChangeHandler.optionValueChanged();
            }
        }
    });
    // add separator
    Separator separator = new Separator(Orientation.HORIZONTAL);
    separator.setPrefHeight(1);
    getChildren().add(separator);
    MultiplierView.setTopAnchor(separator, 50d);
    MultiplierView.setLeftAnchor(separator, 15d);
    MultiplierView.setRightAnchor(separator, 15d);
    group = new ToggleGroup();
    int index = 0;
    double prevComponentWidth = 0;
    AnchorPane optionContainer = new AnchorPane();
    getChildren().add(optionContainer);
    MultiplierView.setTopAnchor(optionContainer, 51d);
    MultiplierView.setLeftAnchor(optionContainer, 15d);
    MultiplierView.setRightAnchor(optionContainer, 150d);
    for (MultiplierType type : MultiplierType.values()) {
        MultiplierOption option = new MultiplierOption(type.getTitle(), group, type, this);
        option.setMultiplierSelectionEvent(this);
        optionContainer.getChildren().add(option);
        double leftSpace = prevComponentWidth + (index * 15);
        MultiplierView.setLeftAnchor(option, leftSpace);
        MultiplierView.setTopAnchor(option, 0d);
        MultiplierView.setBottomAnchor(option, 0d);
        multiplierOptionMap.put(type, option);
        index++;
        prevComponentWidth += option.getComponentWidth();
    }
    multiplierOptionMap.get(MultiplierType.pps).setSelected();
    // add suration
    Separator vSeparator = new Separator(Orientation.VERTICAL);
    vSeparator.setPrefWidth(1);
    getChildren().add(vSeparator);
    MultiplierView.setTopAnchor(vSeparator, 93d);
    MultiplierView.setLeftAnchor(vSeparator, 560d);
    MultiplierView.setBottomAnchor(vSeparator, 15d);
    addLabel("Duration", 70, 606);
    durationCB = new CheckBox();
    getChildren().add(durationCB);
    MultiplierView.setTopAnchor(durationCB, 94d);
    MultiplierView.setLeftAnchor(durationCB, 581d);
    MultiplierView.setBottomAnchor(durationCB, 20d);
    durationTF = new TextField("0");
    durationTF.setPrefSize(70, 22);
    durationTF.setDisable(true);
    getChildren().add(durationTF);
    MultiplierView.setTopAnchor(durationTF, 93d);
    MultiplierView.setLeftAnchor(durationTF, 606d);
    MultiplierView.setBottomAnchor(durationTF, 15d);
    durationTF.disableProperty().bind(durationCB.selectedProperty().not());
    durationTF.setTextFormatter(Util.getNumberFilter(4));
}
Also used : Slider(javafx.scene.control.Slider) MultiplierOption(com.exalttech.trex.ui.components.MultiplierOption) MultiplierType(com.exalttech.trex.ui.MultiplierType) CheckBox(javafx.scene.control.CheckBox) ToggleGroup(javafx.scene.control.ToggleGroup) TextField(javafx.scene.control.TextField) AnchorPane(javafx.scene.layout.AnchorPane) Separator(javafx.scene.control.Separator)

Example 5 with Slider

use of javafx.scene.control.Slider in project DistributedFractalNetwork by Budder21.

the class OpacityBox method display.

public static double display(ArrowButton button) {
    //TODO this isn't working correctly
    Slider opacityLevel = new Slider(0, 1, (Double) button.getData());
    Label opacityCaption = new Label("Opacity Level:");
    Label opacityValue = new Label(Double.toString(opacityLevel.getValue()));
    Stage window = new Stage();
    window.setTitle("Opacity Picker");
    window.setMinWidth(450);
    window.setMinHeight(100);
    window.initModality(Modality.APPLICATION_MODAL);
    Group root = new Group();
    Scene scene = new Scene(root);
    GridPane grid = new GridPane();
    grid.setPadding(new Insets(10, 10, 10, 10));
    grid.setVgap(10);
    grid.setHgap(70);
    scene.setRoot(grid);
    GridPane.setConstraints(opacityCaption, 0, 1);
    grid.getChildren().add(opacityCaption);
    opacityLevel.valueProperty().addListener(new ChangeListener<Number>() {

        public void changed(ObservableValue<? extends Number> ov, Number old_val, Number new_val) {
            System.out.println(new_val.doubleValue());
            opacityValue.setText(String.format("%.2f", new_val));
        }
    });
    GridPane.setConstraints(opacityLevel, 1, 1);
    grid.getChildren().add(opacityLevel);
    GridPane.setConstraints(opacityValue, 2, 1);
    grid.getChildren().add(opacityValue);
    Button b = new Button("Submit");
    b.setOnAction(e -> {
        window.close();
    });
    GridPane.setConstraints(b, 2, 2);
    grid.getChildren().add(b);
    window.setOnCloseRequest(e -> {
    });
    window.setScene(scene);
    window.show();
    return opacityLevel.getValue();
}
Also used : Group(javafx.scene.Group) GridPane(javafx.scene.layout.GridPane) Insets(javafx.geometry.Insets) Slider(javafx.scene.control.Slider) Button(javafx.scene.control.Button) Label(javafx.scene.control.Label) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene)

Aggregations

Slider (javafx.scene.control.Slider)8 Label (javafx.scene.control.Label)4 VBox (javafx.scene.layout.VBox)3 Stage (javafx.stage.Stage)3 ActionEvent (javafx.event.ActionEvent)2 Button (javafx.scene.control.Button)2 CheckBox (javafx.scene.control.CheckBox)2 TextField (javafx.scene.control.TextField)2 GridPane (javafx.scene.layout.GridPane)2 Text (javafx.scene.text.Text)2 TextFlow (javafx.scene.text.TextFlow)2 Test (org.junit.Test)2 MultiplierType (com.exalttech.trex.ui.MultiplierType)1 MultiplierOption (com.exalttech.trex.ui.components.MultiplierOption)1 GradientPicker (com.fxexperience.javafx.scene.control.gradientpicker.GradientPicker)1 GradientPickerStop (com.fxexperience.javafx.scene.control.gradientpicker.GradientPickerStop)1 Mode (com.fxexperience.javafx.scene.control.paintpicker.PaintPicker.Mode)1 PaintPickerController (com.fxexperience.javafx.scene.control.paintpicker.PaintPickerController)1 JFXSlider (com.jfoenix.controls.JFXSlider)1 MediaFile (com.negativevr.media_library.files.MediaFile)1