Lab3 #2

Merged
bytegrip merged 6 commits from lab3 into master 2023-10-17 21:36:00 +00:00
2 changed files with 37 additions and 4 deletions
Showing only changes of commit 655813fc07 - Show all commits

View File

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

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();
}
}
}