Skip to content

Commit

Permalink
fix channel grid previews sometimes flickering/briefly showing wrong …
Browse files Browse the repository at this point in the history
…image
  • Loading branch information
s1mpl3x committed May 21, 2016
1 parent a18fe54 commit c46be99
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/java/eu/over9000/skadi/ui/cells/ChannelGridCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javafx.beans.value.WeakChangeListener;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.layout.VBox;
Expand All @@ -50,6 +51,9 @@ public class ChannelGridCell extends GridCell<Channel> {
private final VBox vBox;

private final ChannelGrid grid;
private Channel lastItem;
private WeakChangeListener<Image> weakPreviewListener;


public ChannelGridCell(final ChannelGrid grid, final MainWindow mainWindow) {
this.grid = grid;
Expand Down Expand Up @@ -105,6 +109,11 @@ private void doSelectionUpdate(final ChannelGrid grid, final MainWindow mainWind
protected void updateItem(final Channel item, final boolean empty) {
super.updateItem(item, empty);

if (lastItem != null && !lastItem.equals(item)) {
lastItem.previewProperty().removeListener(weakPreviewListener);
}
lastItem = item;

if (empty || item == null) {
imageView.setImage(null);
setGraphic(null);
Expand All @@ -130,7 +139,8 @@ protected void updateItem(final Channel item, final boolean empty) {
game.textProperty().bind(item.gameProperty());
game.setGraphic(GlyphsDude.createIcon(FontAwesomeIcon.GAMEPAD));

item.previewProperty().addListener(new WeakChangeListener<>((observable, oldValue, newValue) -> imageView.setImage(newValue)));
weakPreviewListener = new WeakChangeListener<>((observable, oldValue, newValue) -> imageView.setImage(newValue));
item.previewProperty().addListener(weakPreviewListener);

imageView.setImage(item.getPreview());

Expand Down

0 comments on commit c46be99

Please sign in to comment.