Notifications hehehehehehehehehehe

This commit is contained in:
2023-10-18 00:25:17 +03:00
parent 0ab6addf63
commit 655813fc07
2 changed files with 37 additions and 4 deletions

View File

@@ -6,6 +6,7 @@ import org.lumijiez.enums.DiffType;
import org.lumijiez.util.FileDiffer; import org.lumijiez.util.FileDiffer;
import org.lumijiez.enums.StateType; import org.lumijiez.enums.StateType;
import org.lumijiez.util.FileFactory; import org.lumijiez.util.FileFactory;
import org.lumijiez.util.NotificationHandler;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
@@ -52,10 +53,7 @@ public class TrackerThread extends Thread {
fileList.addListSelectionListener(e -> { fileList.addListSelectionListener(e -> {
if (!e.getValueIsAdjusting()) { if (!e.getValueIsAdjusting()) {
Document selectedDocument = fileList.getSelectedValue(); refreshFileInfo();
if (selectedDocument != null) {
fileInfoTextPane.setText(selectedDocument.getInfo());
}
} }
}); });
} }
@@ -64,6 +62,16 @@ public class TrackerThread extends Thread {
fileStates.clear(); fileStates.clear();
} }
public void refreshFileInfo() {
Document selectedDocument = fileList.getSelectedValue();
if (selectedDocument != null) {
fileInfoTextPane.setText(selectedDocument.getInfo());
} else {
fileInfoTextPane.setText("");
}
}
public void checkDirectory() { public void checkDirectory() {
Map<DiffType, ArrayList<Document>> result = FileDiffer.diff(fileContents, FileDiffer.crawlDirectory(MainFrame.FOLDER_PATH)); Map<DiffType, ArrayList<Document>> result = FileDiffer.diff(fileContents, FileDiffer.crawlDirectory(MainFrame.FOLDER_PATH));
@@ -81,6 +89,7 @@ public class TrackerThread extends Thread {
if (somethingNew) { if (somethingNew) {
init(); init();
refreshFileInfo();
for (File file : fileStates.keySet()) { for (File file : fileStates.keySet()) {
if (fileStates.get(file) != StateType.NONE) { if (fileStates.get(file) != StateType.NONE) {
if (fileStates.get(file) == StateType.NEW) { if (fileStates.get(file) == StateType.NEW) {
@@ -93,6 +102,7 @@ public class TrackerThread extends Thread {
toShow.append("<span color=\"orange\">"); toShow.append("<span color=\"orange\">");
} }
toShow.append(file.getName()).append(" has been ").append(fileStates.get(file).getAction()).append("</span><br>"); toShow.append(file.getName()).append(" has been ").append(fileStates.get(file).getAction()).append("</span><br>");
NotificationHandler.showNotification(file.getName(), fileStates.get(file));
} }
} }
textPane.setText(toShow.toString()); textPane.setText(toShow.toString());

View File

@@ -0,0 +1,23 @@
package org.lumijiez.util;
import org.lumijiez.enums.StateType;
import java.awt.*;
import java.awt.TrayIcon.MessageType;
public class NotificationHandler {
public static void showNotification(String filename, StateType stateType) {
try {
SystemTray tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().createImage("some-icon.png");
TrayIcon trayIcon = new TrayIcon(image, "Java AWT Tray Demo");
trayIcon.setImageAutoSize(true);
trayIcon.setToolTip("File Tracker");
tray.add(trayIcon);
trayIcon.displayMessage("File Tracker", filename + " has been " + stateType.getAction(), MessageType.INFO);
} catch (Exception e) {
e.printStackTrace();
}
}
}