|
|
|
@ -1,15 +1,11 @@
|
|
|
|
|
package me.goudham;
|
|
|
|
|
|
|
|
|
|
import java.awt.Dimension;
|
|
|
|
|
import java.awt.Image;
|
|
|
|
|
import java.awt.datatransfer.Transferable;
|
|
|
|
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.concurrent.Executors;
|
|
|
|
|
import java.util.concurrent.ScheduledExecutorService;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
import me.goudham.listener.ClipboardEventListener;
|
|
|
|
|
import me.goudham.domain.MyClipboardContent;
|
|
|
|
|
|
|
|
|
|
import static me.goudham.domain.Contents.IMAGE;
|
|
|
|
@ -28,33 +24,25 @@ class MacClipboardListener extends ClipboardListener {
|
|
|
|
|
executor.scheduleAtFixedRate(() -> {
|
|
|
|
|
Transferable newClipboardContents = clipboard.getContents(null);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (isTextMonitored()) {
|
|
|
|
|
if (STRING.isAvailable(clipboard)) {
|
|
|
|
|
String newContent = (String) newClipboardContents.getTransferData(STRING.getDataFlavor());
|
|
|
|
|
if (!newContent.equals(myClipboardContents[0].getOldContent())) {
|
|
|
|
|
for (ClipboardEventListener clipboardEventListener : eventsListener) {
|
|
|
|
|
clipboardEventListener.onCopyString(newContent);
|
|
|
|
|
}
|
|
|
|
|
myClipboardContents[0].setOldContent(newContent);
|
|
|
|
|
String newStringContent = getStringContent(newClipboardContents);
|
|
|
|
|
if (!newStringContent.equals(myClipboardContents[0].getOldContent())) {
|
|
|
|
|
notifyStringEvent(newStringContent);
|
|
|
|
|
myClipboardContents[0].setOldContent(newStringContent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isImagesMonitored()) {
|
|
|
|
|
if (IMAGE.isAvailable(clipboard)) {
|
|
|
|
|
BufferedImage bufferedImage = ClipboardUtils.convertToBufferedImage((Image) newClipboardContents.getTransferData(IMAGE.getDataFlavor()));
|
|
|
|
|
Dimension newContent = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight());
|
|
|
|
|
if (!newContent.equals(myClipboardContents[0].getOldContent())) {
|
|
|
|
|
for (ClipboardEventListener clipboardEventListener : eventsListener) {
|
|
|
|
|
clipboardEventListener.onCopyImage(bufferedImage);
|
|
|
|
|
}
|
|
|
|
|
myClipboardContents[0].setOldContent(newContent);
|
|
|
|
|
}
|
|
|
|
|
BufferedImage bufferedImageContent = getImageContent(newClipboardContents);
|
|
|
|
|
Dimension newDimensionContent = new Dimension(bufferedImageContent.getWidth(), bufferedImageContent.getHeight());
|
|
|
|
|
if (!newDimensionContent.equals(myClipboardContents[0].getOldContent())) {
|
|
|
|
|
notifyImageEvent(bufferedImageContent);
|
|
|
|
|
myClipboardContents[0].setOldContent(newDimensionContent);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (UnsupportedFlavorException | IOException exp) {
|
|
|
|
|
exp.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}, 0, 350, TimeUnit.MILLISECONDS);
|
|
|
|
|
}
|
|
|
|
|