Add javadoc & send Old Clipboard Content to consumers

MYC-Refactor
Hammy 3 years ago
parent f742b03fb9
commit 6699906053

@ -4,8 +4,10 @@ import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.ClipboardOwner; import java.awt.datatransfer.ClipboardOwner;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.Arrays;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import me.goudham.domain.OldClipboardContent;
import static java.lang.Thread.currentThread; import static java.lang.Thread.currentThread;
import static java.lang.Thread.sleep; import static java.lang.Thread.sleep;
@ -24,22 +26,31 @@ class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnab
} }
Transferable newClipboardContents = oldClipboard.getContents(currentThread()); Transferable newClipboardContents = oldClipboard.getContents(currentThread());
processContents(oldClipboard, newClipboardContents); processContents(oldClipboard, oldClipboardContents, newClipboardContents);
regainOwnership(oldClipboard, newClipboardContents); regainOwnership(oldClipboard, newClipboardContents);
} }
public void processContents(Clipboard oldClipboard, Transferable newClipboardContents) { /**
*
*
* @param oldClipboard The clipboard that is no longer owned
* @param oldClipboardContents The old contents of the clipboard
* @param newClipboardContents The new contents of the clipboard
*/
public void processContents(Clipboard oldClipboard, Transferable oldClipboardContents, Transferable newClipboardContents) {
OldClipboardContent oldClipboardContent = ClipboardUtils.getOldClipboardContent(oldClipboardContents);
if (isTextMonitored()) { if (isTextMonitored()) {
if (STRING.isAvailable(oldClipboard)) { if (STRING.isAvailable(oldClipboard)) {
String stringContent = getStringContent(newClipboardContents); String stringContent = getStringContent(newClipboardContents);
getEventManager().notifyStringEvent(stringContent); getEventManager().notifyStringEvent(oldClipboardContent, stringContent);
} }
} }
if (isImagesMonitored()) { if (isImagesMonitored()) {
if (IMAGE.isAvailable(oldClipboard)) { if (IMAGE.isAvailable(oldClipboard)) {
BufferedImage bufferedImage = getImageContent(newClipboardContents); BufferedImage bufferedImage = getImageContent(newClipboardContents);
getEventManager().notifyImageEvent(bufferedImage); getEventManager().notifyImageEvent(oldClipboardContent, bufferedImage);
} }
} }
} }
@ -60,12 +71,13 @@ class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnab
@Override @Override
public void run() { public void run() {
Transferable currentClipboardContents = clipboard.getContents(null); Transferable currentClipboardContents = clipboard.getContents(null);
processContents(clipboard, currentClipboardContents); processContents(clipboard, currentClipboardContents, currentClipboardContents);
regainOwnership(clipboard, currentClipboardContents); regainOwnership(clipboard, currentClipboardContents);
} }
/** /**
* * Entry point for {@link WindowsOrUnixClipboardListener}
* <p>Retrieves a thread from {@link Executors#newCachedThreadPool()} and executes code in the background</p>
*/ */
@Override @Override
public void execute() { public void execute() {

Loading…
Cancel
Save