Skip to content

Commit

Permalink
Fixed error popups
Browse files Browse the repository at this point in the history
  • Loading branch information
VyaasBaskar committed Dec 24, 2024
1 parent 7504776 commit 8b5ca8a
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 51 deletions.
30 changes: 3 additions & 27 deletions src/main/java/com/funkylogclient/FunkyLogSorter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javafx.animation.PauseTransition;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.stage.FileChooser;
import javafx.stage.Stage;
import javafx.util.Duration;

public class FunkyLogSorter {
private static int MAX_LEN = 1200;
Expand All @@ -24,13 +20,13 @@ public class FunkyLogSorter {
private static boolean allowWarnings = true;
private static boolean allowLogs = true;

public static LinkedList<Message> errors = new LinkedList<>();

private static String searchTerm = "";

public static LinkedList<Message> messages = new LinkedList<>();
public static LinkedList<Message> filtered = new LinkedList<>();

public static int num_open_alerts = 0;

public static String log_file_directory = System.getProperty("user.dir") + "/logs846";
public static FileWriter log_file;

Expand Down Expand Up @@ -105,27 +101,7 @@ public static void addMessage(Message m) {
}

if (m.isError()) {
if (num_open_alerts < 5) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("FunkyLogs Error Notification");
alert.setHeaderText(m.getSender());
alert.setContentText(m.getContent());

alert.setX(alert.getX() + (num_open_alerts * 70));
alert.setY(alert.getY() + (num_open_alerts * 70));

alert.show();

PauseTransition delay = new PauseTransition(Duration.seconds(5));

delay.setOnFinished(event -> {
alert.close();
FunkyLogSorter.num_open_alerts--;
});

delay.play();

}
errors.add(m);
}

if (!checkMessageBySearch(m)) {
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/funkylogclient/FunkyLogs.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.funkylogclient;

import java.util.Iterator;
import java.util.LinkedList;

import javafx.animation.PauseTransition;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.concurrent.Task;
import javafx.geometry.*;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.ScrollPane;
import javafx.scene.control.TextField;
import javafx.scene.layout.BorderPane;
Expand All @@ -15,6 +19,7 @@
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.util.Duration;
import javafx.scene.Cursor;
import javafx.scene.text.*;

Expand All @@ -34,6 +39,8 @@ public class FunkyLogs extends Application {
private static String serverIP = UDPClient.serverIP;
private static int port = UDPClient.port;

private static int num_open_alerts = 0;

@Override
public void start(Stage primaryStage) {
FunkyLogSorter.makeNewLogFile();
Expand Down Expand Up @@ -118,6 +125,37 @@ protected Void call() throws Exception {
Thread.sleep(200);
try {
FunkyLogs.updateMessageZone(primaryStage);

Platform.runLater(() -> {
Iterator<Message> iterator = FunkyLogSorter.errors.iterator();
while (iterator.hasNext()) {
Message x = iterator.next();
if (num_open_alerts < 5) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle("FunkyLogs Error Notification");
alert.setHeaderText(x.getSender());
alert.setContentText(x.getContent());

alert.setX(alert.getX() + (num_open_alerts * 70));
alert.setY(alert.getY() + (num_open_alerts * 70));

alert.show();

num_open_alerts += 1;

PauseTransition delay = new PauseTransition(Duration.seconds(5));

delay.setOnFinished(event -> {
num_open_alerts--;
alert.close();
});

delay.play();

iterator.remove();
}
}
});
} catch (Exception exc) {
System.out.println(exc);
}
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/funkylogclient/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,22 @@ public Node getComponent() {

HBox topBox = new HBox();
topBox.setPadding(new Insets(0, 0, 5, 0));
topBox.setSpacing(400);
topBox.setSpacing(20);

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

Text topRight = new Text(getPeriodName() + " " + new BigDecimal(this.period_timestamp)
Text topMid = new Text(getPeriodName() + " " + new BigDecimal(this.period_timestamp)
.setScale(0, RoundingMode.HALF_UP).toString());
topRight.setStyle(Styles.TEXT_STYLE + Styles.TEXT_SMALLER);
topMid.setStyle(Styles.TEXT_STYLE + Styles.TEXT_SMALLER);

Text topRight = new Text(sender);
topRight.setStyle(Styles.TEXT_STYLE + Styles.TEXT_SMALL);
HBox.setHgrow(topRight, Priority.ALWAYS);
topRight.setTextAlignment(TextAlignment.RIGHT);

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

HBox body = new HBox();
body.setPadding(new Insets(5, 5, 5, 30));
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
Binary file modified target/classes/com/funkylogclient/FunkyLogSorter.class
Binary file not shown.
Binary file modified target/classes/com/funkylogclient/FunkyLogs$1.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.

0 comments on commit 8b5ca8a

Please sign in to comment.