22
33import java .io .IOException ;
44
5+ import org .fxmisc .richtext .StyleClassedTextArea ;
6+
57import de .jensd .fx .glyphs .fontawesome .FontAwesomeIconView ;
68import javafx .fxml .FXML ;
79import javafx .fxml .FXMLLoader ;
10+ import javafx .geometry .Insets ;
811import javafx .scene .control .Label ;
912import javafx .scene .control .ListCell ;
10- import javafx .scene .control . TextArea ;
13+ import javafx .scene .input . ScrollEvent ;
1114import javafx .scene .layout .AnchorPane ;
15+ import javafx .scene .layout .HBox ;
16+ import javafx .scene .layout .Priority ;
1217import javafx .scene .paint .Paint ;
1318import javafx .scene .text .Text ;
1419import lombok .extern .slf4j .Slf4j ;
@@ -28,9 +33,10 @@ public class AlertLogListViewCell extends ListCell<Log> {
2833 @ FXML
2934 FontAwesomeIconView logStatusIcon ;
3035 @ FXML
31- TextArea logContentTA ;
36+ HBox logContentHBox ;
3237
33- private Text textHolder = new Text ();
38+ public AlertLogListViewCell (String ... highlightKeywords ) {
39+ }
3440
3541 @ Override
3642 protected void updateItem (Log logObj , boolean empty ) {
@@ -50,9 +56,8 @@ protected void updateItem(Log logObj, boolean empty) {
5056 }
5157 }
5258
53-
5459 boolean isErrorLog = isErrorLog (logObj .getFullLogString ());
55-
60+
5661 // logTimeStamp
5762 logTimeLabel .setText (logObj .getLogTimeStamp ());
5863
@@ -63,25 +68,40 @@ protected void updateItem(Log logObj, boolean empty) {
6368 logStatusIcon .setFill (Paint .valueOf (isErrorLog ? "#d92a2a" : "#4d9c84" ));
6469
6570 // logContent
66- logContentTA .widthProperty ().addListener ((observable , oldValue , newValue ) -> {
67- Text text = new Text ();
68- text .setWrappingWidth (newValue .doubleValue ());
69- text .setText (logContentTA .getText ());
70- logContentTA .setPrefHeight (text .getLayoutBounds ().getHeight () * 1.35 );
71- });
72-
73- if (isErrorLog ) {
74- logContentTA .setStyle ("-fx-background-color: #ffbfbf" );
71+ StyleClassedTextArea codeArea = new StyleClassedTextArea ();
72+ codeArea .setPadding (new Insets (2 , 5 , 0 , 5 ));
73+ codeArea .setWrapText (false );
74+ codeArea .setEditable (false );
75+ codeArea .autosize ();
76+ codeArea .setFocusTraversable (true );
77+ HBox .setHgrow (codeArea , Priority .ALWAYS );
78+
79+ String baseDir = System .getProperty ("resourceBaseDir" );
80+ codeArea .getStylesheets ()
81+ .add (getClass ().getResource (baseDir + "/css/alertLogListViewCell.css" ).toExternalForm ());
82+ codeArea .getStyleClass ().add ("code-area" );
83+
84+ codeArea .replaceText (0 , 0 , logObj .getFullLogString ());
85+ if (isErrorLog ) {
86+ codeArea .getStyleClass ().add (".error" );
7587 }
76- logContentTA .setText (logObj .getFullLogString ());
77- logContentTA .setEditable (false );
78- logContentTA .setWrapText (true );
7988
80- textHolder .textProperty ().bind (logContentTA .textProperty ());
89+ // Set initial height
90+ Text text = new Text ();
91+ text .setWrappingWidth (logContentHBox .widthProperty ().doubleValue ());
92+ text .setText (codeArea .getText ());
93+ codeArea .setPrefHeight (text .getLayoutBounds ().getHeight ());
94+ logContentHBox .getChildren ().addAll (codeArea );
8195
8296 setText (null );
8397 setGraphic (rootAP );
8498 setStyle ("-fx-padding: 0" );
99+
100+ // Propagate scroll event to parent listview
101+ codeArea .addEventFilter (ScrollEvent .ANY , scroll -> {
102+ codeArea .getParent ().getParent ().getParent ().fireEvent (scroll );
103+ scroll .consume ();
104+ });
85105 }
86106 }
87107
0 commit comments