Various fixes

This commit is contained in:
Christopher Schnick committed 2022-10-18 01:37:21 +02:00
1 parent 9e1363c5df
commit a2238be4cd
22 files changed
+323 -190

No files matched your search

@@ -19,7 +19,7 @@ public interface DataSourceProvider<T extends DataSource<?>> {
default Category getCategory() {
if (getFileProvider() != null) {
return Category.FILE;
return Category.STREAM;
}
throw new ExtensionException("Provider has no set general type");
@@ -43,7 +43,7 @@ public interface DataSourceProvider<T extends DataSource<?>> {
return getId() + "." + key;
}
default Region configGui(Property<T> source, Property<T> appliedSource, boolean all) {
default Region configGui(Property<T> source, boolean all) {
return null;
}
@@ -120,7 +120,7 @@ public interface DataSourceProvider<T extends DataSource<?>> {
List<String> getPossibleNames();
static enum Category {
FILE,
STREAM,
DATABASE;
}
@@ -46,6 +46,11 @@ public interface SupportedApplicationProvider {
PASSIVE
}
enum Direction {
RETRIEVE,
UPDATE
}
@Value
@AllArgsConstructor
public static class InstructionsDisplay {
@@ -26,18 +26,20 @@ public class CharsetChoiceComp extends SimpleComp {
},
new Label(I18n.get("extension.none")),
null);
builder.addFilter((charset, filter) -> {
return charset.getCharset().displayName().contains(filter);
});
builder.addHeader(I18n.get("extension.common"));
for (var e : StreamCharset.COMMON) {
builder.add(e);
}
builder.addHeader(I18n.get("extension.other"));
builder.addFilter((charset, filter) -> {
return charset.getCharset().displayName().contains(filter);
});
for (var e : StreamCharset.RARE) {
builder.add(e);
}
return builder.build();
var comboBox = builder.build();
comboBox.setVisibleRowCount(16);
return comboBox;
}
}
@@ -8,7 +8,6 @@ import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ScrollPane;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
@@ -19,7 +18,7 @@ import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
public class CodeSnippetComp extends Comp<CompStructure<StackPane>> {
public class CodeSnippetComp extends Comp<CompStructure<?>> {
private final ObservableValue<Boolean> showLineNumbers;
private final ObservableValue<CodeSnippet> value;
@@ -79,7 +78,7 @@ public class CodeSnippetComp extends Comp<CompStructure<StackPane>> {
}
@Override
public CompStructure<StackPane> createBase() {
public CompStructure<?> createBase() {
var s = new InlineCssTextArea();
s.setEditable(false);
s.setBackground(null);
@@ -88,6 +87,7 @@ public class CodeSnippetComp extends Comp<CompStructure<StackPane>> {
s.getParent().fireEvent(e);
e.consume();
});
s.prefHeightProperty().setValue(20* this.value.getValue().lines().stream().count());
var lineNumbers = new VBox();
lineNumbers.getStyleClass().add("line-numbers");
@@ -115,13 +115,10 @@ public class CodeSnippetComp extends Comp<CompStructure<StackPane>> {
}
});
HBox.setHgrow(s, Priority.ALWAYS);
var container = new ScrollPane(content);
container.setFitToWidth(true);
container.setFitToHeight(true);
var c = new StackPane(container);
container.prefHeightProperty().bind(c.heightProperty());
var c = new StackPane(content);
c.getStyleClass().add("code-snippet-container");
c.prefHeightProperty().bind(content.prefHeightProperty());
var copyButton = createCopyButton(c);
var pane = new AnchorPane(copyButton);
@@ -6,7 +6,6 @@ import io.xpipe.fxcomps.SimpleCompStructure;
import javafx.beans.Observable;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.control.Label;
@@ -34,7 +33,6 @@ public class DynamicOptionsComp extends Comp<CompStructure<FlowPane>> {
flow.setAlignment(Pos.CENTER);
flow.setHgap(7);
flow.setVgap(7);
flow.setPadding(new Insets(8, 0, 0, 0));
var nameRegions = new ArrayList<Region>();
var compRegions = new ArrayList<Region>();
@@ -0,0 +1,97 @@
package io.xpipe.extension.comp;
import io.xpipe.extension.util.XPipeDaemon;
import io.xpipe.fxcomps.SimpleComp;
import io.xpipe.fxcomps.util.PlatformThread;
import javafx.beans.binding.Bindings;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.value.ObservableValue;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.scene.web.WebView;
public class PrettyImageComp extends SimpleComp {
private final ObservableValue<String> value;
private final double width;
private final double height;
public PrettyImageComp(ObservableValue<String> value, double width, double height) {
this.value = value;
this.width = width;
this.height = height;
}
@Override
protected Region createSimple() {
var aspectRatioProperty = new SimpleDoubleProperty(1);
var widthProperty = Bindings.createDoubleBinding(
() -> {
boolean widthLimited = width / height < aspectRatioProperty.doubleValue();
if (widthLimited) {
return width;
} else {
return height * aspectRatioProperty.doubleValue();
}
},
aspectRatioProperty);
var heightProperty = Bindings.createDoubleBinding(
() -> {
boolean widthLimited = width / height < aspectRatioProperty.doubleValue();
if (widthLimited) {
return width / aspectRatioProperty.doubleValue();
} else {
return height;
}
},
aspectRatioProperty);
Node node;
if (value.getValue().endsWith(".svg")) {
var storeIcon =
SvgComp.create(Bindings.createStringBinding(() -> XPipeDaemon.getInstance().svgImage(value.getValue()), value));
aspectRatioProperty.bind(Bindings.createDoubleBinding(
() -> {
return storeIcon.getWidth().getValue().doubleValue()
/ storeIcon.getHeight().getValue().doubleValue();
},
storeIcon.getWidth(),
storeIcon.getHeight()));
node = storeIcon.createWebview();
((WebView) node).prefWidthProperty().bind(widthProperty);
((WebView) node).maxWidthProperty().bind(widthProperty);
((WebView) node).minWidthProperty().bind(widthProperty);
((WebView) node).prefHeightProperty().bind(heightProperty);
((WebView) node).maxHeightProperty().bind(heightProperty);
((WebView) node).minHeightProperty().bind(heightProperty);
} else {
var storeIcon = new ImageView();
storeIcon
.imageProperty()
.bind(Bindings.createObjectBinding(
() -> {
var image = XPipeDaemon.getInstance().image(value.getValue());
aspectRatioProperty.set(image.getWidth() / image.getHeight());
return image;
},
PlatformThread.sync(value)));
;
storeIcon.fitWidthProperty().bind(widthProperty);
storeIcon.fitHeightProperty().bind(heightProperty);
storeIcon.setSmooth(true);
node = storeIcon;
}
var stack = new StackPane(node);
stack.setPrefWidth(width);
stack.setMinWidth(width);
stack.setPrefHeight(height);
stack.setMinHeight(height);
stack.setAlignment(Pos.CENTER);
return stack;
}
}
@@ -100,6 +100,10 @@ public class SvgComp {
wv.maxWidthProperty().bind(wv.prefWidthProperty());
wv.maxHeightProperty().bind(wv.prefHeightProperty());
wv.minWidthProperty().bind(wv.prefWidthProperty());
wv.minHeightProperty().bind(wv.prefHeightProperty());
return wv;
}
@@ -5,27 +5,47 @@ import io.xpipe.fxcomps.CompStructure;
import io.xpipe.fxcomps.SimpleCompStructure;
import io.xpipe.fxcomps.util.PlatformThread;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleStringProperty;
import javafx.scene.control.TextArea;
public class TextAreaComp extends Comp<CompStructure<TextArea>> {
private final Property<String> value;
private final Property<String> lazyValue = new SimpleStringProperty();
private final boolean lazy;
public TextAreaComp(Property<String> value) {
this(value, false);
}
public TextAreaComp(Property<String> value, boolean lazy) {
this.value = value;
this.lazy = lazy;
if (!lazy) {
value.bind(lazyValue);
}
}
@Override
public CompStructure<TextArea> createBase() {
var text = new TextArea(value.getValue() != null ? value.getValue().toString() : null);
text.textProperty().addListener((c, o, n) -> {
value.setValue(n != null && n.length() > 0 ? n : null);
lazyValue.setValue(n != null && n.length() > 0 ? n : null);
});
value.addListener((c, o, n) -> {
lazyValue.setValue(n);
PlatformThread.runLaterIfNeeded(() -> {
text.setText(n);
});
});
text.focusedProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue) {
value.setValue(lazyValue.getValue());
}
});
return new SimpleCompStructure<>(text);
}
}
@@ -5,6 +5,7 @@ import io.xpipe.fxcomps.CompStructure;
import io.xpipe.fxcomps.SimpleCompStructure;
import io.xpipe.fxcomps.util.PlatformThread;
import javafx.beans.property.Property;
import javafx.beans.property.SimpleStringProperty;
import javafx.event.EventHandler;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode;
@@ -12,39 +13,57 @@ import javafx.scene.input.KeyEvent;
public class TextFieldComp extends Comp<CompStructure<TextField>> {
private final Property<String> value;
private final Property<String> lazyValue;
private final Property<String> lastAppliedValue;
private final Property<String> currentValue;
private final boolean lazy;
public TextFieldComp(Property<String> value) {
this.value = value;
this.lazyValue = value;
this(value, false);
}
public TextFieldComp(Property<String> value, Property<String> lazyValue) {
this.value = value;
this.lazyValue = lazyValue;
public TextFieldComp(Property<String> value, boolean lazy) {
this.lastAppliedValue = value;
this.currentValue = new SimpleStringProperty(value.getValue());
this.lazy = lazy;
if (!lazy) {
value.bind(currentValue);
}
}
@Override
public CompStructure<TextField> createBase() {
var text = new TextField(value.getValue() != null ? value.getValue().toString() : null);
var text = new TextField(
currentValue.getValue() != null ? currentValue.getValue().toString() : null);
text.textProperty().addListener((c, o, n) -> {
value.setValue(n != null && n.length() > 0 ? n : null);
currentValue.setValue(n != null && n.length() > 0 ? n : null);
});
value.addListener((c, o, n) -> {
lastAppliedValue.addListener((c, o, n) -> {
currentValue.setValue(n);
PlatformThread.runLaterIfNeeded(() -> {
text.setText(n);
});
});
text.setOnKeyPressed(new EventHandler<KeyEvent>() {
@Override
public void handle(KeyEvent ke) {
if (ke.getCode().equals(KeyCode.ENTER)) {
lazyValue.setValue(value.getValue());
text.getScene().getRoot().requestFocus();
}
if (lazy && ke.getCode().equals(KeyCode.ENTER)) {
lastAppliedValue.setValue(currentValue.getValue());
}
ke.consume();
}
});
text.focusedProperty().addListener((observable, oldValue, newValue) -> {
if (!newValue) {
lastAppliedValue.setValue(currentValue.getValue());
}
});
return new SimpleCompStructure<>(text);
}
}
@@ -23,8 +23,6 @@ public class DynamicOptionsBuilder {
private final List<DynamicOptionsComp.Entry> entries = new ArrayList<>();
private final List<Property<?>> props = new ArrayList<>();
private final List<Property<?>> lazyProperties = new ArrayList<>();
private final ObservableValue<String> title;
private final boolean wrap;
@@ -53,13 +51,6 @@ public class DynamicOptionsBuilder {
return this;
}
public DynamicOptionsBuilder makeLazy() {
var p = props.get(props.size() - 1);
props.remove(p);
lazyProperties.add(p);
return this;
}
public DynamicOptionsBuilder decorate(Check c) {
entries.get(entries.size() - 1).comp().apply(s -> c.decorates(s.get()));
@@ -133,8 +124,8 @@ public class DynamicOptionsBuilder {
return this;
}
public DynamicOptionsBuilder addStringArea(String nameKey, Property<String> prop) {
var comp = new TextAreaComp(prop);
public DynamicOptionsBuilder addStringArea(String nameKey, Property<String> prop, boolean lazy) {
var comp = new TextAreaComp(prop, lazy);
entries.add(new DynamicOptionsComp.Entry(I18n.observable(nameKey), comp));
props.add(prop);
return this;
@@ -147,11 +138,10 @@ public class DynamicOptionsBuilder {
return this;
}
public DynamicOptionsBuilder addLazyString(String nameKey, Property<String> prop, Property<String> lazy) {
public DynamicOptionsBuilder addString(String nameKey, Property<String> prop, boolean lazy) {
var comp = new TextFieldComp(prop, lazy);
entries.add(new DynamicOptionsComp.Entry(I18n.observable(nameKey), comp));
props.add(prop);
lazyProperties.add(lazy);
return this;
}
@@ -162,6 +152,13 @@ public class DynamicOptionsBuilder {
return this;
}
public DynamicOptionsBuilder addString(ObservableValue<String> name, Property<String> prop, boolean lazy) {
var comp = new TextFieldComp(prop, lazy);
entries.add(new DynamicOptionsComp.Entry(name, comp));
props.add(prop);
return this;
}
public DynamicOptionsBuilder addComp(Comp<?> comp) {
return addComp((ObservableValue<String>) null, comp, null);
}
@@ -220,17 +217,6 @@ public class DynamicOptionsBuilder {
return this;
}
public <T, V extends T> DynamicOptionsBuilder bindLazy(Supplier<V> creator, Property<T> toLazySet) {
lazyProperties.forEach(prop -> {
prop.addListener((c, o, n) -> {
toLazySet.setValue(creator.get());
});
});
toLazySet.setValue(creator.get());
return this;
}
public final <T, V extends T> DynamicOptionsBuilder bindChoice(
Supplier<Property<? extends V>> creator, Property<T> toSet) {
props.forEach(prop -> {
@@ -24,6 +24,11 @@ public class Validators {
throw new IllegalArgumentException(I18n.get("extension.null", name));
}
}
public static void notEmpty(String string, String name) {
if (string.trim().length() == 0) {
throw new IllegalArgumentException(I18n.get("extension.empty", name));
}
}
public static void namedStoreExists(DataStore store, String name) {
if (!XPipeDaemon.getInstance().getNamedStores().contains(store) && !(store instanceof LocalStore)) {
@@ -23,7 +23,9 @@ public interface XPipeDaemon {
List<DataStore> getNamedStores();
public Image image(String file);
Image image(String file);
String svgImage(String file);
<T extends Comp<?> & Validatable> T streamStoreChooser(
Property<DataStore> storeProperty,
@@ -36,7 +38,7 @@ public interface XPipeDaemon {
Property<? extends DataStore> selected,
DataStoreProvider.Category category);
Comp<?> namedSourceChooser(
<T extends Comp<?> & Validatable> T namedSourceChooser(
ObservableValue<Predicate<DataSource<?>>> filter,
Property<? extends DataSource<?>> selected,
DataSourceProvider.Category category);