-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloModel.java
More file actions
68 lines (52 loc) · 1.62 KB
/
Copy pathHelloModel.java
File metadata and controls
68 lines (52 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.example;
import javafx.application.Platform;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import java.io.File;
/**
* Model layer: encapsulates application data and business logic.
*/
public class HelloModel {
private final NtfyConnection connection;
private final ObservableList<NtfyMessageDto> messages = FXCollections.observableArrayList();
private final StringProperty messageToSend = new SimpleStringProperty();
public HelloModel(NtfyConnection connection) {
this.connection = connection;
receiveMessage();
}
public ObservableList<NtfyMessageDto> getMessages() {
return messages;
}
public String getMessageToSend() {
return messageToSend.get();
}
public StringProperty messageToSendProperty() {
return messageToSend;
}
public void setMessageToSend(String message) {
messageToSend.set(message);
}
/**
* Returns a greeting based on the current Java and JavaFX versions.
*/
public String getGreeting() {
return "Chat Client by Adam";
}
public void sendMessage() {
connection.send(messageToSend.get());
}
public void receiveMessage() {
connection.receive(m-> {
try {
Platform.runLater(()->messages.add(m));
} catch (IllegalStateException e) {
messages.add(m);
}
});
}
public void sendFile(File file) {
connection.sendFile(file);
}
}