From 684419e1a9f27702ccf2b9ebbee6e6b920695573 Mon Sep 17 00:00:00 2001 From: Arthur Poiret Date: Mon, 5 Aug 2024 23:09:59 +0200 Subject: [PATCH] feat: display bunde formats icon in explore view --- .../com/owlplug/core/model/PluginFormat.java | 21 +++++++++++++++++ .../controllers/PackageInfoController.java | 2 +- .../model/json/RegistryModelAdapter.java | 2 +- .../explore/services/ExploreService.java | 10 ++++---- .../explore/ui/ProductBundlesView.java | 23 +++++++++++++++++-- 5 files changed, 49 insertions(+), 9 deletions(-) diff --git a/owlplug-client/src/main/java/com/owlplug/core/model/PluginFormat.java b/owlplug-client/src/main/java/com/owlplug/core/model/PluginFormat.java index 74d1bd20..d35635cb 100644 --- a/owlplug-client/src/main/java/com/owlplug/core/model/PluginFormat.java +++ b/owlplug-client/src/main/java/com/owlplug/core/model/PluginFormat.java @@ -18,6 +18,8 @@ package com.owlplug.core.model; +import java.util.Arrays; + public enum PluginFormat { VST2("VST2"), VST3("VST3"), AU("AU"), LV2("LV2"); @@ -31,4 +33,23 @@ public String getText() { return text; } + /** + * Retrieves an enum instance matching a text string. Returns null if the given + * string doesn't match any defined enum instance. + * + * @param text enum unique text + * @return + */ + public static PluginFormat fromBundleString(String text) { + if (text.equalsIgnoreCase("vst")) { + return PluginFormat.VST2; + } + for (PluginFormat f : PluginFormat.values()) { + if (f.text.equalsIgnoreCase(text)) { + return f; + } + } + return null; + } + } diff --git a/owlplug-client/src/main/java/com/owlplug/explore/controllers/PackageInfoController.java b/owlplug-client/src/main/java/com/owlplug/explore/controllers/PackageInfoController.java index 9cb45886..d666d909 100644 --- a/owlplug-client/src/main/java/com/owlplug/explore/controllers/PackageInfoController.java +++ b/owlplug-client/src/main/java/com/owlplug/explore/controllers/PackageInfoController.java @@ -113,7 +113,7 @@ public void initialize() { sidebar.collapse(); }); - bundlesView = new ProductBundlesView(); + bundlesView = new ProductBundlesView(this.getApplicationDefaults()); bundlesContainer.getChildren().add(bundlesView); } diff --git a/owlplug-client/src/main/java/com/owlplug/explore/model/json/RegistryModelAdapter.java b/owlplug-client/src/main/java/com/owlplug/explore/model/json/RegistryModelAdapter.java index a04c1141..51a9c8b0 100644 --- a/owlplug-client/src/main/java/com/owlplug/explore/model/json/RegistryModelAdapter.java +++ b/owlplug-client/src/main/java/com/owlplug/explore/model/json/RegistryModelAdapter.java @@ -113,7 +113,7 @@ public static PackageBundle jsonMapperToEntity(BundleJsonMapper bundleMapper) { } else if (bundleMapper.getFormat() != null) { List formats = new ArrayList<>(); formats.add(bundleMapper.getFormat()); - packageBundle.setFormats(new ArrayList<>()); + packageBundle.setFormats(formats); } else { packageBundle.setFormats(new ArrayList<>(List.of("vst"))); } diff --git a/owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java b/owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java index 594f0ba7..91efa322 100644 --- a/owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java +++ b/owlplug-client/src/main/java/com/owlplug/explore/services/ExploreService.java @@ -257,15 +257,15 @@ public void delete(RemoteSource remoteSource) { public String getBundleInstallFolder(PackageBundle bundle) { String formatValue = bundle.getFormats().getFirst(); - PluginFormat format = PluginFormat.valueOf(formatValue.toLowerCase()); + PluginFormat format = PluginFormat.fromBundleString(formatValue); - if (format.equals(PluginFormat.VST2)) { + if (PluginFormat.VST2.equals(format)) { return this.getPreferences().get(ApplicationDefaults.VST_DIRECTORY_KEY, ""); - } else if (format.equals(PluginFormat.VST3)) { + } else if (PluginFormat.VST3.equals(format)) { return this.getPreferences().get(ApplicationDefaults.VST3_DIRECTORY_KEY, ""); - } else if (format.equals(PluginFormat.AU)) { + } else if (PluginFormat.AU.equals(format)) { return this.getPreferences().get(ApplicationDefaults.AU_DIRECTORY_KEY, ""); - } else if (format.equals(PluginFormat.LV2)) { + } else if (PluginFormat.LV2.equals(format)) { return this.getPreferences().get(ApplicationDefaults.LV2_DIRECTORY_KEY, ""); } diff --git a/owlplug-client/src/main/java/com/owlplug/explore/ui/ProductBundlesView.java b/owlplug-client/src/main/java/com/owlplug/explore/ui/ProductBundlesView.java index f239bace..9ab59c48 100644 --- a/owlplug-client/src/main/java/com/owlplug/explore/ui/ProductBundlesView.java +++ b/owlplug-client/src/main/java/com/owlplug/explore/ui/ProductBundlesView.java @@ -18,6 +18,8 @@ package com.owlplug.explore.ui; +import com.owlplug.core.components.ApplicationDefaults; +import com.owlplug.core.model.PluginFormat; import com.owlplug.core.utils.FileUtils; import com.owlplug.explore.model.PackageBundle; import javafx.event.ActionEvent; @@ -26,6 +28,8 @@ import javafx.geometry.Pos; import javafx.scene.control.Button; import javafx.scene.control.Label; +import javafx.scene.control.Tooltip; +import javafx.scene.image.ImageView; import javafx.scene.layout.Background; import javafx.scene.layout.BackgroundFill; import javafx.scene.layout.CornerRadii; @@ -41,6 +45,8 @@ public class ProductBundlesView extends VBox { + private ApplicationDefaults applicationDefaults; + private static final Paint FILL = new LinearGradient(0, 0, 6, 0, false, CycleMethod.REPEAT, new Stop(0, Color.GRAY), new Stop(0.5, Color.GRAY), new Stop(0.5, Color.TRANSPARENT)); @@ -48,9 +54,9 @@ public class ProductBundlesView extends VBox { private static final Background DOT_BACKGROUND = new Background( new BackgroundFill(FILL, CornerRadii.EMPTY, Insets.EMPTY)); - public ProductBundlesView() { + public ProductBundlesView(ApplicationDefaults applicationDefaults) { super(); - + this.applicationDefaults = applicationDefaults; this.setSpacing(5); } @@ -65,6 +71,19 @@ public void addProductBundle(PackageBundle bundle, EventHandler ins hbox.setAlignment(Pos.CENTER_LEFT); hbox.setFillHeight(false); + HBox formatsContainer = new HBox(2); + for (String formatValue : bundle.getFormats()) { + PluginFormat format = PluginFormat.fromBundleString(formatValue); + if (format != null) { + ImageView iv = new ImageView(this.applicationDefaults.getPluginFormatIcon(format)); + Label labelIv = new Label(); + labelIv.setGraphic(iv); + labelIv.setTooltip(new Tooltip(format.toString())); + formatsContainer.getChildren().add(labelIv); + } + } + hbox.getChildren().add(formatsContainer); + Label bundleName = new Label(bundle.getName()); hbox.getChildren().add(bundleName); Region filler = new Region();