Added Colored rows to log

This commit is contained in:
Ziver Koc 2013-05-08 14:36:11 +00:00
parent 4360a11357
commit 6dd346eee7

View file

@ -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 {
@ -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"));
@ -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);
}
}