use of javafx.beans.Observable in project org.csstudio.display.builder by kasemir.
the class WidgetTree method bindSelections.
/**
* Link selections in tree view and model
*/
private void bindSelections() {
// Update selected widgets in model from selection in tree_view
final ObservableList<TreeItem<WidgetOrTab>> tree_selection = tree_view.getSelectionModel().getSelectedItems();
InvalidationListener listener = (Observable observable) -> {
if (!active.compareAndSet(false, true))
return;
try {
final List<Widget> widgets = new ArrayList<>(tree_selection.size());
for (TreeItem<WidgetOrTab> item : tree_selection) {
final WidgetOrTab wot = item.getValue();
final Widget widget = wot.isWidget() ? wot.getWidget() : wot.getTab().getWidget();
if (!widgets.contains(widget))
widgets.add(widget);
}
;
logger.log(Level.FINE, "Selected in tree: {0}", widgets);
editor.getWidgetSelectionHandler().setSelection(widgets);
} finally {
active.set(false);
}
};
tree_selection.addListener(listener);
// Update selection in tree_view from selected widgets in model
editor.getWidgetSelectionHandler().addListener(this::setSelectedWidgets);
}
use of javafx.beans.Observable 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("C:\\Music\\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")));
else if (status == MediaStatus.REPEAT_MULTI)
repeat.setGraphic(new ImageView(new Image("com/negativevr/media_library/res/repeat_playlist.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_MULTI;
repeat.setGraphic(new ImageView(new Image("com/negativevr/media_library/res/repeat_playlist.png")));
} else if (status == MediaStatus.REPEAT_MULTI) {
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.beans.Observable in project Media-Library by The-Rain-Goddess.
the class ApplicationWindow method updatePlayer.
/**
* updates the media player object to account for new media being loaded
*/
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);
} else if (status == MediaStatus.REPEAT_MULTI) {
SortedList<MediaFile> list = getSortedData();
Media nextSong = null;
for (int i = 0; i < list.size(); i++) {
if (i != list.size() - 1 && player.getMedia().getSource().toString().contains(new File(list.get(i).getLibraryFilePath()).toURI().toString())) {
nextSong = new Media(new File(list.get(i + 1).getLibraryFilePath()).toURI().toString());
artistLabel.setText(list.get(i + 1).getArtistName() + " - " + list.get(i + 1).getAlbumName());
songLabel.setText(list.get(i + 1).getSongName());
} else if (i == list.size() - 1 && player.getMedia().getSource().toString().contains(new File(list.get(i).getLibraryFilePath()).toURI().toString())) {
nextSong = new Media(new File(list.get(0).getLibraryFilePath()).toURI().toString());
artistLabel.setText(list.get(0).getArtistName() + " - " + list.get(0).getAlbumName());
songLabel.setText(list.get(0).getSongName());
}
}
if (nextSong != null) {
player = new MediaPlayer(nextSong);
player.setAutoPlay(true);
updatePlayer();
player.play();
}
}
});
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);
}
use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.
the class ContainerEngineSettingsPanelSkin method updateEngineSettingsGrid.
/**
* Updates the engine settings in the given {@link GridPane engineSettingsGrid}
*
* @param engineSettingsGrid The GridPane containing the shown engine settings
*/
private void updateEngineSettingsGrid(final GridPane engineSettingsGrid) {
engineSettingsGrid.getChildren().clear();
final ContainerDTO container = getControl().getContainer();
for (EngineSetting engineSetting : getControl().getEngineSettings()) {
final int row = engineSettingsGrid.getRowCount();
final Text engineSettingDescription = new Text(engineSetting.getText());
engineSettingDescription.getStyleClass().add("captionTitle");
final ObservableList<String> items = FXCollections.observableArrayList(engineSetting.getOptions());
final ComboBox<String> engineSettingComboBox = new ComboBox<>(items);
engineSettingComboBox.getStyleClass().add("engine-setting-combo-box");
engineSettingComboBox.disableProperty().bind(getControl().lockEngineSettingsProperty());
// if the container is not specified set no default values
if (container != null) {
try {
engineSettingComboBox.setValue(engineSetting.getCurrentOption(container.getName()));
} catch (Exception e) {
engineSettingComboBox.getSelectionModel().select(0);
LOGGER.warn(String.format("Could not fetch current option for engine setting \"%s\", will use default.", engineSetting.getText()));
LOGGER.debug("Caused by: ", e);
}
engineSettingComboBox.valueProperty().addListener((Observable invalidation) -> Platform.runLater(() -> {
getControl().setLockEngineSettings(true);
engineSetting.setOption(container.getName(), items.indexOf(engineSettingComboBox.getValue()));
getControl().setLockEngineSettings(false);
}));
}
engineSettingsGrid.addRow(row, engineSettingDescription, engineSettingComboBox);
}
}
use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.
the class ContainerVerbsPanelSkin method initialise.
/**
* {@inheritDoc}
*/
@Override
public void initialise() {
final Text title = new Text(tr("Verbs"));
title.getStyleClass().add("title");
final GridPane verbs = new GridPane();
verbs.getStyleClass().add("verb-grid");
// ensure that the shown verbs are always up to date
getControl().getVerbScripts().addListener((Observable invalidation) -> updateVerbs(verbs));
// ensure that the shown verbs are correctly initialized
updateVerbs(verbs);
final ScrollPane verbScrollPanel = new ScrollPane(verbs);
verbScrollPanel.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER);
verbScrollPanel.setFitToWidth(true);
VBox.setVgrow(verbScrollPanel, Priority.ALWAYS);
final HBox verbManagementButtons = createVerbManagementButtons(verbs);
verbManagementButtons.getStyleClass().add("verb-management-button-container");
final VBox container = new VBox(title, verbScrollPanel, verbManagementButtons);
container.getStyleClass().addAll("container-details-panel", "container-verbs-panel");
getChildren().setAll(container);
}
Aggregations