mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-11-25 00:50:31 +00:00
Rework serial
This commit is contained in:
parent
58fef0c182
commit
06415a7971
3 changed files with 76 additions and 3 deletions
|
@ -0,0 +1,75 @@
|
|||
package io.xpipe.app.fxcomps.impl;
|
||||
|
||||
import io.xpipe.app.fxcomps.Comp;
|
||||
import io.xpipe.app.fxcomps.CompStructure;
|
||||
import io.xpipe.app.fxcomps.SimpleCompStructure;
|
||||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.scene.control.ComboBox;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
|
||||
public class IntComboFieldComp extends Comp<CompStructure<ComboBox<String>>> {
|
||||
|
||||
Property<Integer> value;
|
||||
List<Integer> predefined;
|
||||
boolean allowNegative;
|
||||
|
||||
public IntComboFieldComp(Property<Integer> value, List<Integer> predefined, boolean allowNegative) {
|
||||
this.value = value;
|
||||
this.predefined = predefined;
|
||||
this.allowNegative = allowNegative;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompStructure<ComboBox<String>> createBase() {
|
||||
var text = new ComboBox<String>();
|
||||
text.setEditable(true);
|
||||
text.setValue(value.getValue() != null ? value.getValue().toString() : null);
|
||||
text.setItems(FXCollections.observableList(predefined.stream().map(integer -> "" + integer).toList()));
|
||||
text.setMaxWidth(2000);
|
||||
|
||||
value.addListener((ChangeListener<Number>) (observableValue, oldValue, newValue) -> {
|
||||
PlatformThread.runLaterIfNeeded(() -> {
|
||||
if (newValue == null) {
|
||||
text.setValue("");
|
||||
} else {
|
||||
text.setValue(newValue.toString());
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
text.addEventFilter(KeyEvent.KEY_TYPED, keyEvent -> {
|
||||
if (allowNegative) {
|
||||
if (!"-0123456789".contains(keyEvent.getCharacter())) {
|
||||
keyEvent.consume();
|
||||
}
|
||||
} else {
|
||||
if (!"0123456789".contains(keyEvent.getCharacter())) {
|
||||
keyEvent.consume();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
text.valueProperty().addListener((observableValue, oldValue, newValue) -> {
|
||||
if (newValue == null
|
||||
|| newValue.isEmpty()
|
||||
|| (allowNegative && "-".equals(newValue))
|
||||
|| !newValue.matches("-?\\d+")) {
|
||||
value.setValue(null);
|
||||
return;
|
||||
}
|
||||
|
||||
int intValue = Integer.parseInt(newValue);
|
||||
value.setValue(intValue);
|
||||
});
|
||||
|
||||
return new SimpleCompStructure<>(text);
|
||||
}
|
||||
}
|
|
@ -4,12 +4,10 @@ import io.xpipe.app.fxcomps.Comp;
|
|||
import io.xpipe.app.fxcomps.CompStructure;
|
||||
import io.xpipe.app.fxcomps.SimpleCompStructure;
|
||||
import io.xpipe.app.fxcomps.util.PlatformThread;
|
||||
|
||||
import javafx.beans.property.Property;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.scene.control.TextField;
|
||||
import javafx.scene.input.KeyEvent;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.experimental.FieldDefaults;
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ rtsCts=RTS/CTS
|
|||
dsrDtr=DSR/DTR
|
||||
putty=PuTTY
|
||||
screen=Screen
|
||||
wslMinicom=WSL1 Minicom
|
||||
minicom=Minicom
|
||||
odd=Odd
|
||||
even=Even
|
||||
mark=Mark
|
||||
|
|
Loading…
Reference in a new issue