Skip to content

Commit 7bc9024

Browse files
authored
Merge pull request #490 from DropSnorz/feat/plugin-filter
Implement plugin filters
2 parents 84a0217 + 27cae7e commit 7bc9024

21 files changed

Lines changed: 732 additions & 75 deletions

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ Philip Emery
66
Christian Derr
77
Antti Aro
88
Kim T
9+
Ramiro Montes De Oca

owlplug-client/src/main/java/com/owlplug/core/components/ApplicationDefaults.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
import com.owlplug.core.model.OperatingSystem;
2222
import com.owlplug.core.model.RuntimePlatform;
23-
import com.owlplug.explore.model.RemotePackage;
2423
import com.owlplug.plugin.model.PluginFormat;
2524
import com.owlplug.plugin.model.PluginType;
2625
import com.owlplug.project.model.DawApplication;
@@ -32,7 +31,6 @@
3231
import java.util.List;
3332
import java.util.stream.Collectors;
3433
import javafx.scene.image.Image;
35-
import org.kordamp.ikonli.javafx.FontIcon;
3634
import org.slf4j.Logger;
3735
import org.slf4j.LoggerFactory;
3836
import org.springframework.beans.factory.annotation.Autowired;
@@ -64,7 +62,7 @@ public class ApplicationDefaults {
6462
public final Image vst3Image = new Image(getClass().getResourceAsStream("/icons/vst3-green-16.png"));
6563
public final Image auImage = new Image(getClass().getResourceAsStream("/icons/au-purple-16.png"));
6664
public final Image lv2Image = new Image(getClass().getResourceAsStream("/icons/lv2-orange-16.png"));
67-
public final Image pluginComponentImage = new Image(getClass().getResourceAsStream("/icons/cube-white-16.png"));
65+
public final Image defaultFormat = new Image(getClass().getResourceAsStream("/icons/format-white-16.png"));
6866
public final Image verifiedSourceImage = new Image(getClass().getResourceAsStream("/icons/doublecheck-grey-16.png"));
6967
public final Image suggestedSourceImage = new Image(
7068
ApplicationDefaults.class.getResourceAsStream("/icons/check-grey-16.png"));
@@ -160,14 +158,14 @@ public RuntimePlatform getRuntimePlatform() {
160158
*/
161159
public Image getPluginFormatIcon(PluginFormat format) {
162160
if (format == null) {
163-
return pluginComponentImage;
161+
return defaultFormat;
164162
}
165163
return switch (format) {
166164
case VST2 -> vst2Image;
167165
case VST3 -> vst3Image;
168166
case AU -> auImage;
169167
case LV2 -> lv2Image;
170-
default -> pluginComponentImage;
168+
default -> defaultFormat;
171169
};
172170
}
173171

owlplug-client/src/main/java/com/owlplug/core/utils/StringUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ public static String ellipsis(String input, int maxLength, int clearEndLength) {
4343
}
4444
}
4545

46+
public static String capitalize(String str) {
47+
if (str == null || str.isEmpty()) {
48+
return str;
49+
}
50+
return Character.toUpperCase(str.charAt(0)) + str.substring(1);
51+
}
52+
4653
public static String getStackTraceAsString(Throwable throwable) {
4754
if (throwable == null) {
4855
return "null throwable";
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/* OwlPlug
2+
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
3+
*
4+
* This file is part of OwlPlug.
5+
*
6+
* OwlPlug is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 3
8+
* as published by the Free Software Foundation.
9+
*
10+
* OwlPlug is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.owlplug.plugin.components;
20+
21+
import com.owlplug.plugin.model.IPlugin;
22+
import com.owlplug.plugin.model.Plugin;
23+
import com.owlplug.plugin.model.PluginComponent;
24+
import com.owlplug.plugin.model.PluginFormat;
25+
import com.owlplug.plugin.model.PluginType;
26+
import java.util.function.Predicate;
27+
import javafx.beans.binding.Bindings;
28+
import javafx.beans.property.ObjectProperty;
29+
import javafx.beans.property.SimpleObjectProperty;
30+
import javafx.collections.FXCollections;
31+
import javafx.collections.ObservableSet;
32+
import org.springframework.stereotype.Component;
33+
34+
@Component
35+
public class PluginFilterState {
36+
37+
private final ObservableSet<PluginFormat> selectedFormats = FXCollections.observableSet();
38+
private final ObservableSet<PluginType> selectedTypes = FXCollections.observableSet();
39+
private final ObservableSet<String> selectedManufacturers = FXCollections.observableSet();
40+
private final ObservableSet<String> selectedCategories = FXCollections.observableSet();
41+
private final ObjectProperty<Predicate<IPlugin>> predicate = new SimpleObjectProperty<>();
42+
43+
public PluginFilterState() {
44+
predicate.bind(Bindings.createObjectBinding(this::buildPredicate,
45+
selectedFormats, selectedTypes, selectedManufacturers, selectedCategories));
46+
}
47+
48+
private Predicate<IPlugin> buildPredicate() {
49+
if (selectedFormats.isEmpty() && selectedTypes.isEmpty()
50+
&& selectedManufacturers.isEmpty() && selectedCategories.isEmpty()) {
51+
return null;
52+
}
53+
return plugin -> {
54+
if (plugin instanceof PluginComponent component) {
55+
return matchesFormat(component.asPlugin().getFormat())
56+
&& matchesType(component.getType())
57+
&& matchesManufacturer(component.getManufacturerName())
58+
&& matchesCategory(component.getCategory());
59+
} else {
60+
Plugin p = (Plugin) plugin;
61+
return matchesFormat(p.getFormat())
62+
&& (matchesType(p.getType())
63+
|| p.getComponents().stream().anyMatch(c -> matchesType(c.getType())))
64+
&& (matchesManufacturer(p.getManufacturerName())
65+
|| p.getComponents().stream().anyMatch(c -> matchesManufacturer(c.getManufacturerName())))
66+
&& (matchesCategory(p.getCategory())
67+
|| p.getComponents().stream().anyMatch(c -> matchesCategory(c.getCategory())));
68+
}
69+
};
70+
}
71+
72+
private boolean matchesFormat(PluginFormat format) {
73+
return selectedFormats.isEmpty() || selectedFormats.contains(format);
74+
}
75+
76+
private boolean matchesType(PluginType type) {
77+
return selectedTypes.isEmpty() || selectedTypes.contains(type);
78+
}
79+
80+
private boolean matchesManufacturer(String manufacturer) {
81+
return selectedManufacturers.isEmpty() || selectedManufacturers.contains(manufacturer);
82+
}
83+
84+
private boolean matchesCategory(String category) {
85+
return selectedCategories.isEmpty() || selectedCategories.contains(category);
86+
}
87+
88+
public ObservableSet<PluginFormat> getSelectedFormats() {
89+
return selectedFormats;
90+
}
91+
92+
public ObservableSet<PluginType> getSelectedTypes() {
93+
return selectedTypes;
94+
}
95+
96+
public ObservableSet<String> getSelectedManufacturers() {
97+
return selectedManufacturers;
98+
}
99+
100+
public ObservableSet<String> getSelectedCategories() {
101+
return selectedCategories;
102+
}
103+
104+
public ObjectProperty<Predicate<IPlugin>> predicateProperty() {
105+
return predicate;
106+
}
107+
108+
public void clearAll() {
109+
selectedFormats.clear();
110+
selectedTypes.clear();
111+
selectedManufacturers.clear();
112+
selectedCategories.clear();
113+
}
114+
}

owlplug-client/src/main/java/com/owlplug/plugin/controllers/ComponentInfoController.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.owlplug.plugin.model.PluginComponent;
2525
import com.owlplug.plugin.services.PluginService;
2626
import com.owlplug.plugin.ui.PluginFormatBadgeView;
27+
import com.owlplug.plugin.ui.PluginKindBadgeView;
2728
import com.owlplug.plugin.ui.PluginStateView;
2829
import java.util.ArrayList;
2930
import java.util.Optional;
@@ -82,13 +83,15 @@ public class ComponentInfoController extends BaseController {
8283
public void initialize() {
8384
componentProperty.addListener(e -> refresh());
8485
pluginScreenshotPane.setEffect(new ColorAdjust(0, 0, -0.6, 0));
86+
pluginFormatBadgeContainer.setSpacing(5);
8587

8688
}
8789

8890
public void refresh() {
8991
PluginComponent component = componentProperty.get();
9092
pluginFormatBadgeContainer.getChildren().setAll(
91-
new PluginFormatBadgeView(component.getPlugin().getFormat(), this.getApplicationDefaults()));
93+
new PluginKindBadgeView(component, this.getApplicationDefaults()),
94+
new Label(component.asPlugin().getFormat().getName() + " Component"));
9295
pluginTitleLabel.setText(component.getName());
9396
pluginNameLabel.setText(Optional.ofNullable(component.getDescriptiveName()).orElse(component.getName()));
9497
pluginVersionLabel.setText(Optional.ofNullable(component.getVersion()).orElse("Unknown"));

0 commit comments

Comments
 (0)