Ensure that files are checked when polling

MYC-Refactor
Hammy 3 years ago
parent 42416a694f
commit ed97a46735

@ -3,18 +3,21 @@ package me.goudham;
import java.awt.Dimension;
import java.awt.datatransfer.Transferable;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import me.goudham.domain.MyClipboardContent;
import me.goudham.domain.OldClipboardContent;
import static me.goudham.domain.Contents.FILELIST;
import static me.goudham.domain.Contents.IMAGE;
import static me.goudham.domain.Contents.TEXT;
class MacClipboardListener extends ClipboardListener {
MacClipboardListener() { }
MacClipboardListener() {}
/**
* Checks if {@link String} is within the clipboard and changed
@ -50,14 +53,39 @@ class MacClipboardListener extends ClipboardListener {
if (bufferedImageContent == null) return;
Dimension newDimensionContent = new Dimension(bufferedImageContent.getWidth(), bufferedImageContent.getHeight());
if (!newDimensionContent.equals(myClipboardContents[0].getOldContent())) {
// getEventManager().notifyImageEvent(bufferedImageContent);
myClipboardContents[0].setOldContent(newDimensionContent);
if (!newDimensionContent.equals(myClipboardContents[0].getOldDimensionContent())) {
OldClipboardContent oldClipboardContent = ClipboardUtils.getOldClipboardContent(myClipboardContents[0].getOldContent());
getEventManager().notifyImageEvent(oldClipboardContent, bufferedImageContent);
myClipboardContents[0].setOldContent(bufferedImageContent);
myClipboardContents[0].setOldDimensionContent(newDimensionContent);
}
}
}
}
/**
* Checks if {@link java.util.List} of {@link java.io.File} is within the clipboard and changed
*
* @param newClipboardContents {@link Transferable} containing new clipboard contents
* @param myClipboardContents {@link MyClipboardContent[]} of Unknown {@link Class} containing previous contents
*/
void checkFiles(Transferable newClipboardContents, MyClipboardContent<?>[] myClipboardContents) {
if (isFileListMonitored()) {
if (FILELIST.isAvailable(clipboard)) {
List<File> fileListContent = getFileContent(newClipboardContents);
if (fileListContent == null) return;
if (!fileListContent.equals(myClipboardContents[0].getOldContent())) {
OldClipboardContent oldClipboardContent = ClipboardUtils.getOldClipboardContent(myClipboardContents[0].getOldContent());
getEventManager().notifyFilesEvent(oldClipboardContent, fileListContent);
myClipboardContents[0].setOldContent(fileListContent);
}
}
}
}
/**
* Main entry point for {@link MacClipboardListener}
* <p>Retrieves thread from {@link Executors#newSingleThreadScheduledExecutor()} and executes code on a fixed delay</p>
@ -72,6 +100,7 @@ class MacClipboardListener extends ClipboardListener {
Transferable newClipboardContents = clipboard.getContents(null);
checkText(newClipboardContents, myClipboardContents);
checkImages(newClipboardContents, myClipboardContents);
checkFiles(newClipboardContents, myClipboardContents);
}, 0, 350, TimeUnit.MILLISECONDS);
}
}

Loading…
Cancel
Save