Comments and UI Logik added
This commit is contained in:
parent
e4276d6cca
commit
1eb9ee4624
@ -89,7 +89,7 @@ public class MqttJavaClient implements MqttCallback {
|
|||||||
System.out.println(" Inhalt: " + new String(message.getPayload()));
|
System.out.println(" Inhalt: " + new String(message.getPayload()));
|
||||||
System.out.println(" QoS: " + message.getQos());
|
System.out.println(" QoS: " + message.getQos());
|
||||||
|
|
||||||
Consumer<String> listener = topicListeners.get(topic);
|
Consumer<String> listener = topicListeners.get(topic); // Consumer<String> aus HashMap holen
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.accept(payload);
|
listener.accept(payload);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,24 +16,27 @@ import javafx.beans.property.StringProperty;
|
|||||||
* @author naumueller
|
* @author naumueller
|
||||||
*/
|
*/
|
||||||
public class FxViewModel {
|
public class FxViewModel {
|
||||||
|
|
||||||
private final FxModel model;
|
private final FxModel model;
|
||||||
private Map<String, StringProperty> topicMessages = new HashMap<>();
|
private Map<String, StringProperty> topicMessages = new HashMap<>();
|
||||||
private final StringProperty incomingMessage = new SimpleStringProperty("");
|
private final StringProperty incomingMessage = new SimpleStringProperty("");
|
||||||
private final StringProperty outgoingMessage = new SimpleStringProperty("");
|
private final StringProperty outgoingMessage = new SimpleStringProperty("");
|
||||||
|
|
||||||
private final StringProperty messageToSend = new SimpleStringProperty("");
|
private final StringProperty messageToSend = new SimpleStringProperty("");
|
||||||
|
|
||||||
public FxViewModel(FxModel model) {
|
public FxViewModel(FxModel model) {
|
||||||
this.model = model;
|
this.model = model;
|
||||||
|
|
||||||
subscribeTopic("Text");
|
subscribeTopic("Text");
|
||||||
subscribeTopic("Temperatur");
|
subscribeTopic("Temperatur");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void subscribeTopic(String topic) {
|
public void subscribeTopic(String topic) {
|
||||||
model.getMqttClient().addTopicListeners(topic, msg -> {
|
model.getMqttClient().addTopicListeners(topic, msg -> { // Consumer<String> mit Lambda-Funktion (wird ausgeführt, wenn message für topic ankommt)
|
||||||
Platform.runLater(() -> getTopicProperty(topic).set(msg));
|
Platform.runLater(() -> {
|
||||||
|
getTopicProperty(topic).set(msg); // Richtige Property für topic aus HashMap holen und Message anzeigen.
|
||||||
|
incomingMessage.set(msg);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user