From a4665bf9a8525e2cd9e4a947c34613ba3196ae11 Mon Sep 17 00:00:00 2001 From: Hammy Date: Wed, 28 Jul 2021 01:23:27 +0100 Subject: [PATCH] Notify consumers about file changes --- .../WindowsOrUnixClipboardListener.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/goudham/WindowsOrUnixClipboardListener.java b/src/main/java/me/goudham/WindowsOrUnixClipboardListener.java index 2a00fa4..2562dbb 100644 --- a/src/main/java/me/goudham/WindowsOrUnixClipboardListener.java +++ b/src/main/java/me/goudham/WindowsOrUnixClipboardListener.java @@ -4,15 +4,17 @@ import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.ClipboardOwner; import java.awt.datatransfer.Transferable; import java.awt.image.BufferedImage; -import java.util.Arrays; +import java.io.File; +import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import me.goudham.domain.OldClipboardContent; import static java.lang.Thread.currentThread; import static java.lang.Thread.sleep; +import static me.goudham.domain.Contents.FILELIST; import static me.goudham.domain.Contents.IMAGE; -import static me.goudham.domain.Contents.STRING; +import static me.goudham.domain.Contents.TEXT; class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnable, ClipboardOwner { @@ -41,18 +43,25 @@ class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnab OldClipboardContent oldClipboardContent = ClipboardUtils.getOldClipboardContent(oldClipboardContents); if (isTextMonitored()) { - if (STRING.isAvailable(oldClipboard)) { + if (TEXT.isAvailable(oldClipboard)) { String stringContent = getStringContent(newClipboardContents); - getEventManager().notifyStringEvent(oldClipboardContent, stringContent); + getEventManager().notifyTextEvent(oldClipboardContent, stringContent); } } - if (isImagesMonitored()) { + if (isImageMonitored()) { if (IMAGE.isAvailable(oldClipboard)) { BufferedImage bufferedImage = getImageContent(newClipboardContents); getEventManager().notifyImageEvent(oldClipboardContent, bufferedImage); } } + + if (isFileListMonitored()) { + if (FILELIST.isAvailable(oldClipboard)) { + List fileList = getFileContent(newClipboardContents); + getEventManager().notifyFilesEvent(oldClipboardContent, fileList); + } + } } public void regainOwnership(Clipboard clipboard, Transferable newClipboardContents) {