Added Colored rows to log
This commit is contained in:
parent
4360a11357
commit
6dd346eee7
1 changed files with 75 additions and 32 deletions
|
|
@ -30,6 +30,7 @@ import zutil.log.LogUtil;
|
|||
|
||||
import javafx.collections.FXCollections;
|
||||
import javafx.collections.ObservableList;
|
||||
import javafx.concurrent.Task;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.event.Event;
|
||||
import javafx.fxml.FXML;
|
||||
|
|
@ -37,10 +38,12 @@ import javafx.fxml.Initializable;
|
|||
import javafx.scene.control.ProgressBar;
|
||||
import javafx.scene.control.TableCell;
|
||||
import javafx.scene.control.TableColumn;
|
||||
import javafx.scene.control.TableRow;
|
||||
import javafx.scene.control.ToggleButton;
|
||||
import javafx.scene.control.TableView;
|
||||
import javafx.scene.control.Label;
|
||||
import javafx.scene.control.cell.PropertyValueFactory;
|
||||
import javafx.scene.layout.Priority;
|
||||
import javafx.util.Callback;
|
||||
|
||||
public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||
|
|
@ -52,11 +55,11 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
|||
private Status status;
|
||||
|
||||
private final ObservableList<NetLogExceptionMessage> exceptionData =
|
||||
FXCollections.observableArrayList(
|
||||
new NetLogExceptionMessage("java.lang.NullPointerException", "", " at com.example.myproject.Book.getTitle(Book.java:16) \n at com.example.myproject.Author.getBookTitles(Author.java:25) \n at com.example.myproject.Bootstrap.main(Bootstrap.java:14)"),
|
||||
new NetLogExceptionMessage("java.lang.NullPointerException", "", " at com.example.myproject.Book.getTitle(Book.java:16) \n at com.example.myproject.Author.getBookTitles(Author.java:25) \n at com.example.myproject.Bootstrap.main(Bootstrap.java:14)"),
|
||||
new NetLogExceptionMessage("java.io.FileNotFoundException", "fred.txt", " at java.io.FileInputStream.<init>(FileInputStream.java) \n at java.io.FileInputStream.<init>(FileInputStream.java) \n at ExTest.readMyFile(ExTest.java:19) \n at ExTest.main(ExTest.java:7)")
|
||||
);
|
||||
FXCollections.observableArrayList(
|
||||
new NetLogExceptionMessage("java.lang.NullPointerException", "", " at com.example.myproject.Book.getTitle(Book.java:16) \n at com.example.myproject.Author.getBookTitles(Author.java:25) \n at com.example.myproject.Bootstrap.main(Bootstrap.java:14)"),
|
||||
new NetLogExceptionMessage("java.lang.NullPointerException", "", " at com.example.myproject.Book.getTitle(Book.java:16) \n at com.example.myproject.Author.getBookTitles(Author.java:25) \n at com.example.myproject.Bootstrap.main(Bootstrap.java:14)"),
|
||||
new NetLogExceptionMessage("java.io.FileNotFoundException", "fred.txt", " at java.io.FileInputStream.<init>(FileInputStream.java) \n at java.io.FileInputStream.<init>(FileInputStream.java) \n at ExTest.readMyFile(ExTest.java:19) \n at ExTest.main(ExTest.java:7)")
|
||||
);
|
||||
|
||||
// UI elements
|
||||
@FXML private ToggleButton pauseButton;
|
||||
|
|
@ -64,16 +67,16 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
|||
@FXML private ProgressBar progressBar;
|
||||
@FXML private Label errorLabel;
|
||||
|
||||
@FXML private TableView<NetLogMessage> logTable;
|
||||
@FXML private TableColumn<NetLogMessage, Long> logTimestampColumn;
|
||||
@FXML private TableColumn<NetLogMessage, String> logLevelColumn;
|
||||
@FXML private TableColumn<NetLogMessage, String> logColumn;
|
||||
@FXML private TableView<NetLogMessage> logTable;
|
||||
@FXML private TableColumn<NetLogMessage, Long> logTimestampColumn;
|
||||
@FXML private TableColumn<NetLogMessage, String> logLevelColumn;
|
||||
@FXML private TableColumn<NetLogMessage, String> logColumn;
|
||||
|
||||
@FXML private TableView<NetLogExceptionMessage> exceptionTable;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, Long> exCountColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, String> exNameColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, String> exMessageColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, String> exStackTraceColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, Long> exCountColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, String> exNameColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, String> exMessageColumn;
|
||||
@FXML private TableColumn<NetLogExceptionMessage, String> exStackTraceColumn;
|
||||
|
||||
|
||||
public void initialize(URL arg0, ResourceBundle arg1) {
|
||||
|
|
@ -92,6 +95,11 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
|||
// Setup Gui
|
||||
logTimestampColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, Long>("timestamp"));
|
||||
logLevelColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, String>("level"));
|
||||
logLevelColumn.setCellFactory(new RowCssCellFactory<NetLogMessage,String>(){
|
||||
public String getStyleName(String item){
|
||||
return item;
|
||||
}
|
||||
});
|
||||
logColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, String>("log"));
|
||||
|
||||
exCountColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, Long>("count"));
|
||||
|
|
@ -118,7 +126,7 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
|||
}
|
||||
|
||||
/*************** GUI *******************/
|
||||
@FXML
|
||||
@FXML
|
||||
protected void handlePauseAction(ActionEvent event) {
|
||||
if(status == Status.RUNNING){
|
||||
status = Status.PAUSED;
|
||||
|
|
@ -129,7 +137,7 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
|||
logger.info("Logging Unpaused");
|
||||
}
|
||||
updateStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleDisconnectAction(Event event) {
|
||||
|
|
@ -137,17 +145,17 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
|||
net.close();
|
||||
status = Status.DISCONNECTED;
|
||||
updateStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleLevelChanged(ActionEvent event) {
|
||||
logger.info("Updating Log Level");
|
||||
}
|
||||
}
|
||||
|
||||
@FXML
|
||||
protected void handleIntervalChanged(ActionEvent event) {
|
||||
logger.info("Updating Log Interval");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStatus(){
|
||||
if(progressBar == null || pauseButton == null){
|
||||
|
|
@ -168,4 +176,39 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* http://stackoverflow.com/questions/13697115/javafx-tableview-colors
|
||||
*/
|
||||
public abstract class RowCssCellFactory<S,T> implements Callback<TableColumn<S,T>, TableCell<S,T>> {
|
||||
|
||||
public TableCell<S,T> call(TableColumn<S,T> p) {
|
||||
TableCell<S, T> cell = new TableCell<S, T>() {
|
||||
@Override
|
||||
public void updateItem(T item, boolean empty) {
|
||||
super.updateItem(item, empty);
|
||||
setText(empty ? null : getString());
|
||||
setGraphic(null);
|
||||
|
||||
String style = getStyleName(item);
|
||||
if(style != null){
|
||||
TableRow<?> row = getTableRow();
|
||||
row.getStyleClass().add(style);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSelected(boolean upd){
|
||||
super.updateSelected(upd);
|
||||
}
|
||||
|
||||
|
||||
private String getString() {
|
||||
return getItem() == null ? "NULL" : getItem().toString();
|
||||
}
|
||||
};
|
||||
return cell;
|
||||
}
|
||||
|
||||
public abstract String getStyleName(T item);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue