Skip to content

Commit

Permalink
Cleanup config component annotations, add binding bundle config compo…
Browse files Browse the repository at this point in the history
…nent factory allowing binds to be changed in the UI
  • Loading branch information
Col-E committed Apr 3, 2024
1 parent 96e7c04 commit e284559
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class BasicCollectionConfigValue<T, C extends Collection<T>> implements C
private final Class<C> collectionType;
private final Class<T> itemType;
private final ObservableCollection<T, C> observable;
private final boolean hidden;

/**
* @param key
Expand All @@ -29,15 +30,39 @@ public class BasicCollectionConfigValue<T, C extends Collection<T>> implements C
* @param observable
* Observable of value.
*/
public BasicCollectionConfigValue(@Nonnull String key,
@Nonnull Class<? extends Collection> type,
@Nonnull Class<T> itemType,
@Nonnull ObservableCollection<T, C> observable) {
this(key, type, itemType, observable, false);
}

/**
* @param key
* Value key.
* @param type
* Value type class.
* @param observable
* Observable of value.
* @param hidden
* Hidden flag.
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public BasicCollectionConfigValue(@Nonnull String key,
@Nonnull Class<? extends Collection> type,
@Nonnull Class<T> itemType,
@Nonnull ObservableCollection<T, C> observable) {
@Nonnull Class<? extends Collection> type,
@Nonnull Class<T> itemType,
@Nonnull ObservableCollection<T, C> observable,
boolean hidden) {
this.key = key;
this.collectionType = (Class<C>) type;
this.itemType = itemType;
this.observable = observable;
this.hidden = hidden;
}

@Override
public boolean isHidden() {
return hidden;
}

@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AssemblerPipelineGeneralConfig() {
super(ConfigGroups.SERVICE_ASSEMBLER, AssemblerPipelineManager.SERVICE_ID + ConfigGroups.PACKAGE_SPLIT + "general" + CONFIG_SUFFIX);

addValue(new BasicConfigValue<>("disassembly-indent", String.class, disassemblyIndent));
addValue(new BasicConfigValue<>("disassembly-ast-parse-delay", Integer.class, disassemblyAstParseDelay));
addValue(new BasicConfigValue<>("disassembly-ast-parse-delay", int.class, disassemblyAstParseDelay));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.coley.recaf.services.config;

import jakarta.annotation.Nonnull;
import javafx.scene.Node;
import software.coley.recaf.config.ConfigContainer;
import software.coley.recaf.config.ConfigValue;
Expand Down Expand Up @@ -45,5 +46,6 @@ public boolean isStandAlone() {
*
* @return Control to represent the value.
*/
public abstract Node create(ConfigContainer container, ConfigValue<T> value);
@Nonnull
public abstract Node create(@Nonnull ConfigContainer container, @Nonnull ConfigValue<T> value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
public class ConfigComponentManager implements Service {
public static final String ID = "config-components";
private final ConfigComponentFactory<Object> DEFAULT_FACTORY = new ConfigComponentFactory<>(false) {
@Nonnull
@Override
public Node create(ConfigContainer container, ConfigValue<Object> value) {
public Node create(@Nonnull ConfigContainer container, @Nonnull ConfigValue<Object> value) {
Label label = new Label("Unsupported: " + value.getType().getName());
label.getStyleClass().add(Styles.WARNING);
return label;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public abstract class TypedConfigComponentFactory<T> extends ConfigComponentFact
private final Class<T> type;

/**
* @param createLabel
* See {@link #isStandAlone()}. Determines if label is automatically added.
* @param isStandAlone
* See {@link #isStandAlone()}. Creates an adjacent label for the config value name if {@code true}.
* @param type
* The {@link ConfigValue#getType()} to support.
*/
protected TypedConfigComponentFactory(boolean createLabel, Class<T> type) {
super(createLabel);
protected TypedConfigComponentFactory(boolean isStandAlone, Class<T> type) {
super(isStandAlone);
this.type = type;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.coley.recaf.services.config.factories;

import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import javafx.scene.Node;
Expand Down Expand Up @@ -30,8 +31,9 @@ public AndroidDecompilerComponentFactory(DecompilerManager decompilerManager) {
.toList();
}

@Nonnull
@Override
public Node create(ConfigContainer container, ConfigValue<String> value) {
public Node create(@Nonnull ConfigContainer container, @Nonnull ConfigValue<String> value) {
return new ObservableComboBox<>(value.getObservable(), decompilers);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.coley.recaf.services.config.factories;

import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import javafx.scene.Node;
Expand All @@ -22,8 +23,9 @@ public BooleanComponentFactory() {
super(true, boolean.class);
}

@Nonnull
@Override
public Node create(ConfigContainer container, ConfigValue<Boolean> value) {
public Node create(@Nonnull ConfigContainer container, @Nonnull ConfigValue<Boolean> value) {
Observable<Boolean> observable = value.getObservable();
String translationKey = container.getScopedId(value);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.coley.recaf.services.config.factories;

import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import javafx.scene.Node;
Expand All @@ -23,8 +24,9 @@ public EnumComponentFactory() {
super(false, Enum.class);
}

@Nonnull
@Override
public Node create(ConfigContainer container, ConfigValue<Enum> value) {
public Node create(@Nonnull ConfigContainer container, @Nonnull ConfigValue<Enum> value) {
Enum[] enumConstants = value.getType().getEnumConstants();
return new ObservableComboBox<>(value.getObservable(), Arrays.asList(enumConstants));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.coley.recaf.services.config.factories;

import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import javafx.beans.value.ChangeListener;
Expand Down Expand Up @@ -27,8 +28,9 @@ protected IntegerComponentFactory() {
super(false, int.class);
}

@Nonnull
@Override
public Node create(ConfigContainer container, ConfigValue<Integer> value) {
public Node create(@Nonnull ConfigContainer container, @Nonnull ConfigValue<Integer> value) {
Observable<Integer> observable = value.getObservable();
TextField textField = new TextField();
textField.setText(Integer.toString(observable.getValue()));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.coley.recaf.services.config.factories;

import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import javafx.scene.Node;
Expand Down Expand Up @@ -30,8 +31,9 @@ public JvmDecompilerComponentFactory(DecompilerManager decompilerManager) {
.toList();
}

@Nonnull
@Override
public Node create(ConfigContainer container, ConfigValue<String> value) {
public Node create(@Nonnull ConfigContainer container, @Nonnull ConfigValue<String> value) {
return new ObservableComboBox<>(value.getObservable(), decompilers);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package software.coley.recaf.services.config.factories;

import jakarta.annotation.Nonnull;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import javafx.scene.Node;
Expand All @@ -21,8 +22,9 @@ protected StringComponentFactory() {
super(false, String.class);
}

@Nonnull
@Override
public Node create(ConfigContainer container, ConfigValue<String> value) {
public Node create(@Nonnull ConfigContainer container, @Nonnull ConfigValue<String> value) {
Observable<String> observable = value.getObservable();
TextField textField = new TextField();
textField.setText(observable.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public String getId() {
*
* @return Binding from keys + mask.
*/
@Nonnull
public static Binding newBind(@Nonnull String id, @Nonnull String codesString, @Nullable KeyCode mask) {
String[] codes = codesString.split("\\+");
Stream<String> stream = Arrays.stream(codes);
Expand All @@ -59,6 +60,7 @@ public static Binding newBind(@Nonnull String id, @Nonnull String codesString, @
*
* @return Binding from keys of the event.
*/
@Nonnull
public static Binding newBind(@Nonnull String id, @Nonnull KeyEvent event) {
return newBind(id, namesOf(event));
}
Expand All @@ -72,12 +74,29 @@ public static Binding newBind(@Nonnull String id, @Nonnull KeyEvent event) {
*
* @return Binding from keys.
*/
@Nonnull
public static Binding newBind(@Nonnull String id, @Nonnull KeyCode... codes) {
return Arrays.stream(codes).map(KeyCode::getName)
.map(String::toLowerCase)
.collect(Collectors.toCollection(() -> new Binding(id)));
}

/**
* @param id
* Unique identifier of the binding.
* @param codes
* Series of keys for a keybind, in string representation.
*
* @return Binding from keys.
*/
@Nonnull
public static Binding from(@Nonnull String id, @Nonnull Collection<String> codes) {
return codes.stream()
.map(String::toLowerCase)
.sorted((a, b) -> (a.length() > b.length()) ? -1 : a.compareTo(b))
.collect(Collectors.toCollection(() -> new Binding(id)));
}

/**
* @param id
* Unique identifier of the binding.
Expand All @@ -86,6 +105,7 @@ public static Binding newBind(@Nonnull String id, @Nonnull KeyCode... codes) {
*
* @return Binding from keys.
*/
@Nonnull
public static Binding newBind(@Nonnull String id, @Nonnull Collection<String> codes) {
return codes.stream()
.map(String::toLowerCase)
Expand All @@ -95,7 +115,7 @@ public static Binding newBind(@Nonnull String id, @Nonnull Collection<String> co

@Override
public String toString() {
return String.join("+", this);
return String.join(" + ", this);
}

/**
Expand Down
Loading

0 comments on commit e284559

Please sign in to comment.