#800 Resolves issue with rendering of icons in playlist alias editor and slow loading of icons in dropdown combobox. Adds error checking to the icon manager to notify user when there is an issue with loading a custom icon in the ADD method. (#803)

Co-authored-by: Denny <denny@denny-desktop>
This commit is contained in:
Denny Sheirer
2020-05-07 09:51:21 +00:00
committed by GitHub
parent 91cae70fa1
commit 316cdb4068
4 changed files with 83 additions and 54 deletions

View File

@@ -38,7 +38,6 @@ import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
@@ -358,7 +357,20 @@ public class IconManager extends Editor<Icon>
Icon icon = new Icon();
icon.setName(name);
icon.setPath(path);
mIconModel.addIcon(icon);
if(icon.getFxImage() != null && icon.getFxImage().getException() != null)
{
Alert alert = new Alert(Alert.AlertType.ERROR, "Unable to load icon image from selected " +
"file. Please select a valid image file for the icon", ButtonType.OK);
alert.setHeaderText("Invalid image file");
alert.setTitle("Save Icon");
alert.showAndWait();
return;
}
else
{
mIconModel.addIcon(icon);
}
}
showEditor(false);
@@ -538,30 +550,15 @@ public class IconManager extends Editor<Icon>
{
Icon icon = getTableRow().getItem();
if(icon != null)
if(icon != null && icon.getFxImage() != null)
{
try
{
if(icon.getPath().startsWith("images"))
{
Image image = new Image(icon.getPath(), 0, 16, true, true);
setGraphic(new ImageView(image));
}
else
{
Path path = Path.of(icon.getPath());
Image image = new Image(path.toUri().toString(), 0, 16, true, true);
setGraphic(new ImageView(image));
}
}
catch(Exception e)
{
mLog.error("Error loading image: " + (icon != null ? icon.getPath() : "null"), e);
}
setGraphic(new ImageView(icon.getFxImage()));
setText(null);
}
else
{
setGraphic(null);
setText("Can't load image");
}
}
}

View File

@@ -56,7 +56,6 @@ import javafx.scene.control.TextField;
import javafx.scene.control.TextFormatter;
import javafx.scene.control.TextInputDialog;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
@@ -779,14 +778,13 @@ public class AliasConfigurationEditor extends SplitPane
{
Icon icon = mPlaylistManager.getIconModel().getIcon(alias.getIconName());
try
if(icon != null && icon.getFxImage() != null)
{
Image image = new Image(icon.getPath(), 0, 16, true, true);
setGraphic(new ImageView(image));
setGraphic(new ImageView(icon.getFxImage()));
}
catch(Exception e)
else
{
setGraphic(null);
}
}
}

View File

@@ -22,6 +22,7 @@
package io.github.dsheirer.gui.playlist.alias;
import com.google.common.collect.Ordering;
import com.google.common.eventbus.Subscribe;
import impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding;
import impl.org.controlsfx.autocompletion.SuggestionProvider;
@@ -67,6 +68,7 @@ import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ListChangeListener;
import javafx.collections.transformation.SortedList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
@@ -88,8 +90,8 @@ import javafx.scene.control.ScrollPane;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
@@ -103,7 +105,6 @@ import org.controlsfx.control.ToggleSwitch;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -1041,7 +1042,7 @@ public class AliasItemEditor extends Editor<Alias>
mIconNodeComboBox = new ComboBox<>();
mIconNodeComboBox.setMaxWidth(Double.MAX_VALUE);
mIconNodeComboBox.setDisable(true);
mIconNodeComboBox.setItems(mPlaylistManager.getIconModel().iconsProperty());
mIconNodeComboBox.setItems(new SortedList(mPlaylistManager.getIconModel().iconsProperty(), Ordering.natural()));
mIconNodeComboBox.setCellFactory(new IconCellFactory());
mIconNodeComboBox.getSelectionModel().selectedItemProperty()
.addListener((observable, oldValue, newValue) -> modifiedProperty().set(true));
@@ -1556,6 +1557,15 @@ public class AliasItemEditor extends Editor<Alias>
@Override
public ListCell<Icon> call(ListView<Icon> param)
{
Label iconLabel = new Label();
Label textLabel = new Label();
GridPane gridPane = new GridPane();
gridPane.setHgap(5);
GridPane.setHalignment(iconLabel, HPos.RIGHT);
gridPane.getColumnConstraints().add(new ColumnConstraints(50));
gridPane.add(iconLabel, 0, 0);
gridPane.add(textLabel,1,0);
ListCell<Icon> cell = new ListCell<>()
{
@Override
@@ -1570,29 +1580,9 @@ public class AliasItemEditor extends Editor<Alias>
}
else
{
setText(item.getName());
String path = item.getPath();
try
{
if(path.startsWith("images"))
{
Image image = new Image(path, 0, 20, true, true);
setGraphic(new ImageView(image));
}
else
{
Path filePath = Path.of(path);
Image image = new Image(filePath.toUri().toString(), 0, 16, true, true);
setGraphic(new ImageView(image));
}
}
catch(Exception e)
{
mLog.error("Error loading icon for [" + item.getName() + "] path [" + item.getPath() + "]");
}
textLabel.setText(item.getName());
iconLabel.setGraphic(new ImageView(item.getFxImage()));
setGraphic(gridPane);
}
}
};