diff --git a/src/zutil/log/net/NetLogGuiClientInstance.java b/src/zutil/log/net/NetLogGuiClientInstance.java index 1961ce4..a0230e7 100644 --- a/src/zutil/log/net/NetLogGuiClientInstance.java +++ b/src/zutil/log/net/NetLogGuiClientInstance.java @@ -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,12 +38,14 @@ 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 { private static final Logger logger = LogUtil.getLogger(); private static enum Status{RUNNING, PAUSED, DISCONNECTED} @@ -52,29 +55,29 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener { private Status status; private final ObservableList 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.(FileInputStream.java) \n at java.io.FileInputStream.(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.(FileInputStream.java) \n at java.io.FileInputStream.(FileInputStream.java) \n at ExTest.readMyFile(ExTest.java:19) \n at ExTest.main(ExTest.java:7)") + ); + // UI elements @FXML private ToggleButton pauseButton; @FXML private Label logCountLabel; @FXML private ProgressBar progressBar; @FXML private Label errorLabel; - - @FXML private TableView logTable; - @FXML private TableColumn logTimestampColumn; - @FXML private TableColumn logLevelColumn; - @FXML private TableColumn logColumn; - + + @FXML private TableView logTable; + @FXML private TableColumn logTimestampColumn; + @FXML private TableColumn logLevelColumn; + @FXML private TableColumn logColumn; + @FXML private TableView exceptionTable; - @FXML private TableColumn exCountColumn; - @FXML private TableColumn exNameColumn; - @FXML private TableColumn exMessageColumn; - @FXML private TableColumn exStackTraceColumn; - + @FXML private TableColumn exCountColumn; + @FXML private TableColumn exNameColumn; + @FXML private TableColumn exMessageColumn; + @FXML private TableColumn exStackTraceColumn; + public void initialize(URL arg0, ResourceBundle arg1) { // Connect to Server @@ -88,21 +91,26 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener { errorLabel.setText(e.getMessage()); } updateStatus(); - + // Setup Gui logTimestampColumn.setCellValueFactory(new PropertyValueFactory("timestamp")); logLevelColumn.setCellValueFactory(new PropertyValueFactory("level")); + logLevelColumn.setCellFactory(new RowCssCellFactory(){ + public String getStyleName(String item){ + return item; + } + }); logColumn.setCellValueFactory(new PropertyValueFactory("log")); - + exCountColumn.setCellValueFactory(new PropertyValueFactory("count")); exNameColumn.setCellValueFactory(new PropertyValueFactory("name")); exMessageColumn.setCellValueFactory(new PropertyValueFactory("message")); exStackTraceColumn.setCellValueFactory(new PropertyValueFactory("stackTrace")); - + //logTable.setItems(logData); exceptionTable.setItems(exceptionData); } - + /************* NETWORK *****************/ public void handleLogMessage(NetLogMessage log) { logTable.getItems().add( log ); @@ -114,11 +122,11 @@ public class NetLogGuiClientInstance implements Initializable, NetLogListener { public void handleStatusMessage(NetLogStatusMessage status) { // TODO Auto-generated method stub - + } - + /*************** 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,23 +145,23 @@ 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){ return; } - + if(status == Status.RUNNING){ progressBar.setProgress(-1.0); 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 implements Callback, TableCell> { + + public TableCell call(TableColumn p) { + TableCell cell = new TableCell() { + @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); + } } \ No newline at end of file