Lab3 #2
@@ -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());
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user