Ensure that files are checked when polling

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

@ -3,12 +3,15 @@ package me.goudham;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import me.goudham.domain.MyClipboardContent; import me.goudham.domain.MyClipboardContent;
import me.goudham.domain.OldClipboardContent; 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.IMAGE;
import static me.goudham.domain.Contents.TEXT; import static me.goudham.domain.Contents.TEXT;
@ -50,14 +53,39 @@ class MacClipboardListener extends ClipboardListener {
if (bufferedImageContent == null) return; if (bufferedImageContent == null) return;
Dimension newDimensionContent = new Dimension(bufferedImageContent.getWidth(), bufferedImageContent.getHeight()); Dimension newDimensionContent = new Dimension(bufferedImageContent.getWidth(), bufferedImageContent.getHeight());
if (!newDimensionContent.equals(myClipboardContents[0].getOldContent())) { if (!newDimensionContent.equals(myClipboardContents[0].getOldDimensionContent())) {
// getEventManager().notifyImageEvent(bufferedImageContent); OldClipboardContent oldClipboardContent = ClipboardUtils.getOldClipboardContent(myClipboardContents[0].getOldContent());
myClipboardContents[0].setOldContent(newDimensionContent); 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} * Main entry point for {@link MacClipboardListener}
* <p>Retrieves thread from {@link Executors#newSingleThreadScheduledExecutor()} and executes code on a fixed delay</p> * <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); Transferable newClipboardContents = clipboard.getContents(null);
checkText(newClipboardContents, myClipboardContents); checkText(newClipboardContents, myClipboardContents);
checkImages(newClipboardContents, myClipboardContents); checkImages(newClipboardContents, myClipboardContents);
checkFiles(newClipboardContents, myClipboardContents);
}, 0, 350, TimeUnit.MILLISECONDS); }, 0, 350, TimeUnit.MILLISECONDS);
} }
} }

Loading…
Cancel
Save