Skip to content

Commit 9d339bf

Browse files
committed
Wrapping text that alertLog content in textarea component
1 parent 2433140 commit 9d339bf

File tree

2 files changed

+49
-30
lines changed

2 files changed

+49
-30
lines changed

src/main/java/root/core/domain/Log.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ public int getTotalLineCount() {
2020

2121
public String getFullLogString() {
2222
StringBuffer result = new StringBuffer();
23-
for(String s : logContents) {
24-
result.append(s);
23+
for (int i = 0; i < logContents.size(); i++) {
24+
result.append(logContents.get(i));
25+
if (i != logContents.size()) {
26+
result.append(System.lineSeparator());
27+
}
2528
}
2629
return result.toString();
2730
}

src/main/java/root/javafx/CustomView/AlertLogListViewCell.java

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,64 @@
22

33
import java.io.IOException;
44

5-
import com.jfoenix.controls.JFXTextArea;
6-
75
import javafx.fxml.FXML;
86
import javafx.fxml.FXMLLoader;
97
import javafx.scene.control.Label;
108
import javafx.scene.control.ListCell;
9+
import javafx.scene.control.TextArea;
1110
import javafx.scene.layout.AnchorPane;
11+
import javafx.scene.text.Text;
12+
import lombok.extern.slf4j.Slf4j;
1213
import root.core.domain.Log;
1314
import root.javafx.DI.DependencyInjection;
1415

16+
@Slf4j
1517
public class AlertLogListViewCell extends ListCell<Log> {
1618
private FXMLLoader loader;
17-
18-
@FXML AnchorPane rootAP;
19-
@FXML Label logTimeLabel;
20-
@FXML JFXTextArea logContentTA;
21-
19+
20+
@FXML
21+
AnchorPane rootAP;
22+
@FXML
23+
Label logTimeLabel;
24+
@FXML
25+
TextArea logContentTA;
26+
27+
private Text textHolder = new Text();
28+
2229
@Override
23-
protected void updateItem(Log log, boolean empty) {
24-
super.updateItem(log, empty);
25-
26-
if(empty || log == null) {
27-
setText(null);
28-
setGraphic(null);
29-
} else {
30-
if (loader == null) {
31-
FXMLLoader loader = DependencyInjection.getLoader("/fxml/AlertLogListViewCell.fxml");
30+
protected void updateItem(Log logObj, boolean empty) {
31+
super.updateItem(logObj, empty);
32+
33+
if (empty || logObj == null) {
34+
setText(null);
35+
setGraphic(null);
36+
} else {
37+
if (loader == null) {
38+
FXMLLoader loader = DependencyInjection.getLoader("/fxml/AlertLogListViewCell.fxml");
3239
loader.setController(this);
33-
try {
40+
try {
3441
loader.load();
3542
} catch (IOException e) {
36-
e.printStackTrace();
43+
log.error(e.getMessage());
3744
}
38-
}
39-
40-
logTimeLabel.setText(log.getLogTimeStamp());
41-
logContentTA.setPrefRowCount(log.getTotalLineCount());
42-
logContentTA.setText(log.getFullLogString());
43-
44-
setText(null);
45-
setGraphic(rootAP);
46-
}
47-
}
45+
}
46+
47+
logContentTA.widthProperty().addListener((observable, oldValue, newValue) -> {
48+
Text text = new Text();
49+
text.setWrappingWidth(newValue.doubleValue());
50+
text.setText(logContentTA.getText());
51+
logContentTA.setPrefHeight(text.getLayoutBounds().getHeight() * 1.35);
52+
});
53+
54+
logTimeLabel.setText(logObj.getLogTimeStamp());
55+
logContentTA.setText(logObj.getFullLogString());
56+
logContentTA.setEditable(false);
57+
logContentTA.setWrapText(true);
4858

59+
textHolder.textProperty().bind(logContentTA.textProperty());
60+
61+
setText(null);
62+
setGraphic(rootAP);
63+
}
64+
}
4965
}

0 commit comments

Comments
 (0)