Skip to content

Commit

Permalink
Added period and timestamp display to messages, flush log file period…
Browse files Browse the repository at this point in the history
…ically
  • Loading branch information
VyaasBaskar committed Dec 23, 2024
1 parent 9d85e9d commit 7504776
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 27 deletions.
24 changes: 21 additions & 3 deletions src/main/java/com/funkylogclient/FunkyLogSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.LinkedList;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javafx.animation.PauseTransition;
import javafx.scene.control.Alert;
Expand All @@ -31,6 +34,20 @@ public class FunkyLogSorter {
public static String log_file_directory = System.getProperty("user.dir") + "/logs846";
public static FileWriter log_file;

private static final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

static {
scheduler.scheduleAtFixedRate(() -> {
if (log_file != null) {
try {
log_file.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}, 3000, 1000, TimeUnit.MILLISECONDS);
}

public static void clear() {
messages.clear();
filtered.clear();
Expand Down Expand Up @@ -75,8 +92,6 @@ public static void trimMessages() {
}

public static void addMessage(Message m) {
System.out.println(m);

messages.add(m);

if (log_file != null) {
Expand All @@ -85,6 +100,8 @@ public static void addMessage(Message m) {
} catch (IOException exc) {
exc.printStackTrace();
}
} else {
System.out.println("Log file not open");
}

if (m.isError()) {
Expand Down Expand Up @@ -172,6 +189,8 @@ public static void makeNewLogFile() {
if (log_file != null)
log_file.close();
log_file = new FileWriter(log_file_directory + "/" + makeLogFileName());
System.out.print("Log file created: ");
System.out.println(log_file_directory + "/" + makeLogFileName());
} catch (IOException exc) {
exc.printStackTrace();
}
Expand Down Expand Up @@ -225,5 +244,4 @@ public static void createTestError(Stage pstage) {
addMessage(new Message("2;TestSender;This is an Error;0.0;0;0.0"));
logAllMessages();
}

}
2 changes: 1 addition & 1 deletion src/main/java/com/funkylogclient/FunkyLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class FunkyLogs extends Application {
@Override
public void start(Stage primaryStage) {
FunkyLogSorter.makeNewLogFile();
primaryStage.setTitle("FunkyLogs v1.1.0");
primaryStage.setTitle("FunkyLogs v1.1.2");

root = new BorderPane();
root.getStyleClass().add("root");
Expand Down
39 changes: 37 additions & 2 deletions src/main/java/com/funkylogclient/Message.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package com.funkylogclient;

import java.math.BigDecimal;
import java.math.RoundingMode;

import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.text.TextAlignment;

public class Message {
private int type;
Expand All @@ -26,6 +31,9 @@ public Message(String unparsed) {
sender = split[1];
content = split[2];

period = Integer.parseInt(split[4]);
period_timestamp = Double.parseDouble(split[5]);

isValid = true;
} catch (Exception exc) {
System.out.println("Error in parsing message: " + unparsed);
Expand All @@ -34,6 +42,9 @@ public Message(String unparsed) {
sender = new String("Unknown");
time = 0.0;

period = 0;
period_timestamp = 0.0;

isValid = false;
}
}
Expand Down Expand Up @@ -71,6 +82,17 @@ public int getPeriod() {
return period;
}

public String getPeriodName() {
switch (getPeriod()) {
case 1:
return "TELE-OP";
case 2:
return "AUTON";
default:
return "DISABLED";
}
}

public boolean isLog() {
return type == 0;
}
Expand Down Expand Up @@ -112,9 +134,22 @@ public Node getComponent() {

box.setPadding(new Insets(5, 5, 5, 5));

Text top = new Text(time + " [" + sender + "]");
HBox topBox = new HBox();
topBox.setPadding(new Insets(0, 0, 5, 0));
topBox.setSpacing(400);

Text top = new Text(
new BigDecimal(this.time).setScale(1, RoundingMode.HALF_UP).toString() + " [" + sender + "]");
top.setStyle(Styles.TEXT_STYLE + Styles.TEXT_SMALL);

Text topRight = new Text(getPeriodName() + " " + new BigDecimal(this.period_timestamp)
.setScale(0, RoundingMode.HALF_UP).toString());
topRight.setStyle(Styles.TEXT_STYLE + Styles.TEXT_SMALLER);
HBox.setHgrow(topRight, Priority.ALWAYS);
topRight.setTextAlignment(TextAlignment.RIGHT);

topBox.getChildren().addAll(top, topRight);

HBox body = new HBox();
body.setPadding(new Insets(5, 5, 5, 30));

Expand All @@ -124,7 +159,7 @@ public Node getComponent() {

body.getChildren().add(contentText);

box.getChildren().addAll(top, body);
box.getChildren().addAll(topBox, body);

return box;
}
Expand Down
36 changes: 18 additions & 18 deletions src/main/java/com/funkylogclient/SidebarOtherSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ public static VBox getSidebarOtherSettings(ChangeListener<Boolean> autoScrollCha
});
otherSettingsBox.getChildren().add(fileSelectionDialog);

// Region testLogButtonspacing = new Region();
// testLogButtonspacing.setMinHeight(20);
// otherSettingsBox.getChildren().add(testLogButtonspacing);
Region testLogButtonspacing = new Region();
testLogButtonspacing.setMinHeight(20);
otherSettingsBox.getChildren().add(testLogButtonspacing);

// Button testLogButton = new Button("Test Log");
// testLogButton.setOnAction((ev) -> {
// FunkyLogSorter.createTestLog(primaryStage);
// });
// otherSettingsBox.getChildren().add(testLogButton);
Button testLogButton = new Button("Test Log");
testLogButton.setOnAction((ev) -> {
FunkyLogSorter.createTestLog(primaryStage);
});
otherSettingsBox.getChildren().add(testLogButton);

// Button testWarningButton = new Button("Test Warning");
// testWarningButton.setOnAction((ev) -> {
// FunkyLogSorter.createTestWarning(primaryStage);
// });
// otherSettingsBox.getChildren().add(testWarningButton);
Button testWarningButton = new Button("Test Warning");
testWarningButton.setOnAction((ev) -> {
FunkyLogSorter.createTestWarning(primaryStage);
});
otherSettingsBox.getChildren().add(testWarningButton);

// Button testErrorButton = new Button("Test Error");
// testErrorButton.setOnAction((ev) -> {
// FunkyLogSorter.createTestError(primaryStage);
// });
// otherSettingsBox.getChildren().add(testErrorButton);
Button testErrorButton = new Button("Test Error");
testErrorButton.setOnAction((ev) -> {
FunkyLogSorter.createTestError(primaryStage);
});
otherSettingsBox.getChildren().add(testErrorButton);

return otherSettingsBox;
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/funkylogclient/Styles.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ public class Styles {
public static final String TEXT_MED = "-fx-font-size: 14px; -fx-fill: #aaa; -fx-font-family: Poppins;";
public static final String TEXT_GMED = "-fx-font-size: 16px; -fx-fill: #aaa; -fx-font-family: Poppins;";
public static final String TEXT_SMALL = "-fx-font-size: 14px;";
public static final String TEXT_SMALLER = "-fx-font-size: 11px;";
public static final String BOLD_TEXT = " -fx-font-weight: bold;";

public static final String DEFAULT_MSG = "-fx-border-width: 3px;";

public static final String SCROLL_PANE_STYLE = "-fx-background-color: #1E1E1E;";

public static final String RIGHT_SIDEBAR_STYLE =
"-fx-background-radius:10; -fx-background-color: #1E1E1E;"
+ "-fx-border-color: transparent transparent transparent #fff; -fx-border-width: 0.2px;";
public static final String RIGHT_SIDEBAR_STYLE = "-fx-background-radius:10; -fx-background-color: #1E1E1E;"
+ "-fx-border-color: transparent transparent transparent #fff; -fx-border-width: 0.2px;";

}
Binary file modified target/classes/com/funkylogclient/FunkyLogSorter.class
Binary file not shown.
Binary file modified target/classes/com/funkylogclient/FunkyLogs.class
Binary file not shown.
Binary file modified target/classes/com/funkylogclient/Message.class
Binary file not shown.
Binary file modified target/classes/com/funkylogclient/SidebarOtherSettings.class
Binary file not shown.
Binary file modified target/classes/com/funkylogclient/Styles.class
Binary file not shown.

0 comments on commit 7504776

Please sign in to comment.