forked from lfkdsk/PracticeCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
82 lines (59 loc) · 2.28 KB
/
Copy pathMain.java
File metadata and controls
82 lines (59 loc) · 2.28 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package sample;
import javafx.application.Application;
import javafx.collections.ListChangeListener;
import javafx.scene.Scene;
import javafx.scene.control.TextArea;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;
import java.util.ArrayList;
public class Main extends Application {
public static String getCurrentString(DfaState currentState) {
String tempString = "";
DfaState tempState = currentState;
while (tempState.getParentState() != null) {
tempString = (char) tempState.getParentInput() + tempString;
tempState = tempState.getParentState();
}
return tempString;
}
@Override
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("Fuck Writing!!!");
BorderPane borderPane = new BorderPane();
HBox box = new HBox();
DfaBuilder builder = new DfaBuilder();
builder.setDfaCallBack((current, states) -> {
System.out.println("current list " + getCurrentString(current));
System.out.println("预测文本 =》");
ArrayList<DfaState> list = new ArrayList<>();
for (Integer key : states.keySet()) {
states.get(key).returnEndList(list);
}
for (DfaState state : list) {
System.out.println("prediction list " + getCurrentString(state));
}
});
TextArea field = new TextArea();
field.setPrefSize(500, 500);
field.getParagraphs().addListener((ListChangeListener<CharSequence>) c -> {
while (c.next()) {
int size = c.getAddedSubList().get(0).length();
// System.out.println(size);
// System.out.println(c);
if (size >= 1) {
System.out.println(c.getAddedSubList().get(0).charAt(size - 1));
builder.input(c.getAddedSubList().get(0).charAt(size - 1));
}
}
});
box.getChildren().addAll(field);
borderPane.setCenter(box);
Scene scene = new Scene(borderPane);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}