Skip to content

Commit

Permalink
feat: display bunde formats icon in explore view
Browse files Browse the repository at this point in the history
  • Loading branch information
DropSnorz committed Aug 5, 2024
1 parent bb03a0d commit 684419e
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package com.owlplug.core.model;

import java.util.Arrays;

public enum PluginFormat {
VST2("VST2"), VST3("VST3"), AU("AU"), LV2("LV2");

Expand All @@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public void initialize() {
sidebar.collapse();
});

bundlesView = new ProductBundlesView();
bundlesView = new ProductBundlesView(this.getApplicationDefaults());
bundlesContainer.getChildren().add(bundlesView);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static PackageBundle jsonMapperToEntity(BundleJsonMapper bundleMapper) {
} else if (bundleMapper.getFormat() != null) {
List<String> formats = new ArrayList<>();
formats.add(bundleMapper.getFormat());
packageBundle.setFormats(new ArrayList<>());
packageBundle.setFormats(formats);
} else {
packageBundle.setFormats(new ArrayList<>(List.of("vst")));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -41,16 +45,18 @@

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));

// create background for regions
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);

}
Expand All @@ -65,6 +71,19 @@ public void addProductBundle(PackageBundle bundle, EventHandler<ActionEvent> 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();
Expand Down

0 comments on commit 684419e

Please sign in to comment.