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);
}
}
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);
}
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;
}
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));
}
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();
}
Aggregations