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.FXCollections;
|
||||||
import javafx.collections.ObservableList;
|
import javafx.collections.ObservableList;
|
||||||
|
import javafx.concurrent.Task;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.Event;
|
import javafx.event.Event;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
|
|
@ -37,12 +38,14 @@ import javafx.fxml.Initializable;
|
||||||
import javafx.scene.control.ProgressBar;
|
import javafx.scene.control.ProgressBar;
|
||||||
import javafx.scene.control.TableCell;
|
import javafx.scene.control.TableCell;
|
||||||
import javafx.scene.control.TableColumn;
|
import javafx.scene.control.TableColumn;
|
||||||
|
import javafx.scene.control.TableRow;
|
||||||
import javafx.scene.control.ToggleButton;
|
import javafx.scene.control.ToggleButton;
|
||||||
import javafx.scene.control.TableView;
|
import javafx.scene.control.TableView;
|
||||||
import javafx.scene.control.Label;
|
import javafx.scene.control.Label;
|
||||||
import javafx.scene.control.cell.PropertyValueFactory;
|
import javafx.scene.control.cell.PropertyValueFactory;
|
||||||
|
import javafx.scene.layout.Priority;
|
||||||
import javafx.util.Callback;
|
import javafx.util.Callback;
|
||||||
|
|
||||||
public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||||
private static final Logger logger = LogUtil.getLogger();
|
private static final Logger logger = LogUtil.getLogger();
|
||||||
private static enum Status{RUNNING, PAUSED, DISCONNECTED}
|
private static enum Status{RUNNING, PAUSED, DISCONNECTED}
|
||||||
|
|
@ -52,29 +55,29 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||||
private Status status;
|
private Status status;
|
||||||
|
|
||||||
private final ObservableList<NetLogExceptionMessage> exceptionData =
|
private final ObservableList<NetLogExceptionMessage> exceptionData =
|
||||||
FXCollections.observableArrayList(
|
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.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)")
|
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
|
// UI elements
|
||||||
@FXML private ToggleButton pauseButton;
|
@FXML private ToggleButton pauseButton;
|
||||||
@FXML private Label logCountLabel;
|
@FXML private Label logCountLabel;
|
||||||
@FXML private ProgressBar progressBar;
|
@FXML private ProgressBar progressBar;
|
||||||
@FXML private Label errorLabel;
|
@FXML private Label errorLabel;
|
||||||
|
|
||||||
@FXML private TableView<NetLogMessage> logTable;
|
@FXML private TableView<NetLogMessage> logTable;
|
||||||
@FXML private TableColumn<NetLogMessage, Long> logTimestampColumn;
|
@FXML private TableColumn<NetLogMessage, Long> logTimestampColumn;
|
||||||
@FXML private TableColumn<NetLogMessage, String> logLevelColumn;
|
@FXML private TableColumn<NetLogMessage, String> logLevelColumn;
|
||||||
@FXML private TableColumn<NetLogMessage, String> logColumn;
|
@FXML private TableColumn<NetLogMessage, String> logColumn;
|
||||||
|
|
||||||
@FXML private TableView<NetLogExceptionMessage> exceptionTable;
|
@FXML private TableView<NetLogExceptionMessage> exceptionTable;
|
||||||
@FXML private TableColumn<NetLogExceptionMessage, Long> exCountColumn;
|
@FXML private TableColumn<NetLogExceptionMessage, Long> exCountColumn;
|
||||||
@FXML private TableColumn<NetLogExceptionMessage, String> exNameColumn;
|
@FXML private TableColumn<NetLogExceptionMessage, String> exNameColumn;
|
||||||
@FXML private TableColumn<NetLogExceptionMessage, String> exMessageColumn;
|
@FXML private TableColumn<NetLogExceptionMessage, String> exMessageColumn;
|
||||||
@FXML private TableColumn<NetLogExceptionMessage, String> exStackTraceColumn;
|
@FXML private TableColumn<NetLogExceptionMessage, String> exStackTraceColumn;
|
||||||
|
|
||||||
|
|
||||||
public void initialize(URL arg0, ResourceBundle arg1) {
|
public void initialize(URL arg0, ResourceBundle arg1) {
|
||||||
// Connect to Server
|
// Connect to Server
|
||||||
|
|
@ -88,21 +91,26 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||||
errorLabel.setText(e.getMessage());
|
errorLabel.setText(e.getMessage());
|
||||||
}
|
}
|
||||||
updateStatus();
|
updateStatus();
|
||||||
|
|
||||||
// Setup Gui
|
// Setup Gui
|
||||||
logTimestampColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, Long>("timestamp"));
|
logTimestampColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, Long>("timestamp"));
|
||||||
logLevelColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, String>("level"));
|
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"));
|
logColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, String>("log"));
|
||||||
|
|
||||||
exCountColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, Long>("count"));
|
exCountColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, Long>("count"));
|
||||||
exNameColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, String>("name"));
|
exNameColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, String>("name"));
|
||||||
exMessageColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, String>("message"));
|
exMessageColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, String>("message"));
|
||||||
exStackTraceColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, String>("stackTrace"));
|
exStackTraceColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, String>("stackTrace"));
|
||||||
|
|
||||||
//logTable.setItems(logData);
|
//logTable.setItems(logData);
|
||||||
exceptionTable.setItems(exceptionData);
|
exceptionTable.setItems(exceptionData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/************* NETWORK *****************/
|
/************* NETWORK *****************/
|
||||||
public void handleLogMessage(NetLogMessage log) {
|
public void handleLogMessage(NetLogMessage log) {
|
||||||
logTable.getItems().add( log );
|
logTable.getItems().add( log );
|
||||||
|
|
@ -114,11 +122,11 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||||
|
|
||||||
public void handleStatusMessage(NetLogStatusMessage status) {
|
public void handleStatusMessage(NetLogStatusMessage status) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************** GUI *******************/
|
/*************** GUI *******************/
|
||||||
@FXML
|
@FXML
|
||||||
protected void handlePauseAction(ActionEvent event) {
|
protected void handlePauseAction(ActionEvent event) {
|
||||||
if(status == Status.RUNNING){
|
if(status == Status.RUNNING){
|
||||||
status = Status.PAUSED;
|
status = Status.PAUSED;
|
||||||
|
|
@ -129,7 +137,7 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||||
logger.info("Logging Unpaused");
|
logger.info("Logging Unpaused");
|
||||||
}
|
}
|
||||||
updateStatus();
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleDisconnectAction(Event event) {
|
protected void handleDisconnectAction(Event event) {
|
||||||
|
|
@ -137,23 +145,23 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener {
|
||||||
net.close();
|
net.close();
|
||||||
status = Status.DISCONNECTED;
|
status = Status.DISCONNECTED;
|
||||||
updateStatus();
|
updateStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleLevelChanged(ActionEvent event) {
|
protected void handleLevelChanged(ActionEvent event) {
|
||||||
logger.info("Updating Log Level");
|
logger.info("Updating Log Level");
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
protected void handleIntervalChanged(ActionEvent event) {
|
protected void handleIntervalChanged(ActionEvent event) {
|
||||||
logger.info("Updating Log Interval");
|
logger.info("Updating Log Interval");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateStatus(){
|
private void updateStatus(){
|
||||||
if(progressBar == null || pauseButton == null){
|
if(progressBar == null || pauseButton == null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(status == Status.RUNNING){
|
if(status == Status.RUNNING){
|
||||||
progressBar.setProgress(-1.0);
|
progressBar.setProgress(-1.0);
|
||||||
pauseButton.setText("Pause");
|
pauseButton.setText("Pause");
|
||||||
|
|
@ -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