|
2 | 2 |
|
3 | 3 | import java.io.IOException; |
4 | 4 |
|
5 | | -import com.jfoenix.controls.JFXTextArea; |
6 | | - |
7 | 5 | import javafx.fxml.FXML; |
8 | 6 | import javafx.fxml.FXMLLoader; |
9 | 7 | import javafx.scene.control.Label; |
10 | 8 | import javafx.scene.control.ListCell; |
| 9 | +import javafx.scene.control.TextArea; |
11 | 10 | import javafx.scene.layout.AnchorPane; |
| 11 | +import javafx.scene.text.Text; |
| 12 | +import lombok.extern.slf4j.Slf4j; |
12 | 13 | import root.core.domain.Log; |
13 | 14 | import root.javafx.DI.DependencyInjection; |
14 | 15 |
|
| 16 | +@Slf4j |
15 | 17 | public class AlertLogListViewCell extends ListCell<Log> { |
16 | 18 | 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 | + |
22 | 29 | @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"); |
32 | 39 | loader.setController(this); |
33 | | - try { |
| 40 | + try { |
34 | 41 | loader.load(); |
35 | 42 | } catch (IOException e) { |
36 | | - e.printStackTrace(); |
| 43 | + log.error(e.getMessage()); |
37 | 44 | } |
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); |
48 | 58 |
|
| 59 | + textHolder.textProperty().bind(logContentTA.textProperty()); |
| 60 | + |
| 61 | + setText(null); |
| 62 | + setGraphic(rootAP); |
| 63 | + } |
| 64 | + } |
49 | 65 | } |
0 commit comments