|
|
@ -1,15 +1,11 @@
|
|
|
|
package me.goudham;
|
|
|
|
package me.goudham;
|
|
|
|
|
|
|
|
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Dimension;
|
|
|
|
import java.awt.Image;
|
|
|
|
|
|
|
|
import java.awt.datatransfer.Transferable;
|
|
|
|
import java.awt.datatransfer.Transferable;
|
|
|
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
|
|
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
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.listener.ClipboardEventListener;
|
|
|
|
|
|
|
|
import me.goudham.domain.MyClipboardContent;
|
|
|
|
import me.goudham.domain.MyClipboardContent;
|
|
|
|
|
|
|
|
|
|
|
|
import static me.goudham.domain.Contents.IMAGE;
|
|
|
|
import static me.goudham.domain.Contents.IMAGE;
|
|
|
@ -22,39 +18,31 @@ class MacClipboardListener extends ClipboardListener {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void execute() {
|
|
|
|
public void execute() {
|
|
|
|
Transferable oldClipboardContents = clipboard.getContents(null);
|
|
|
|
Transferable oldClipboardContents = clipboard.getContents(null);
|
|
|
|
final MyClipboardContent<?>[] myClipboardContents = new MyClipboardContent[]{ ClipboardUtils.getClipboardContents(oldClipboardContents, clipboard) };
|
|
|
|
final MyClipboardContent<?>[] myClipboardContents = new MyClipboardContent[] { ClipboardUtils.getClipboardContents(oldClipboardContents, clipboard) };
|
|
|
|
|
|
|
|
|
|
|
|
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
|
|
|
|
executor.scheduleAtFixedRate(() -> {
|
|
|
|
executor.scheduleAtFixedRate(() -> {
|
|
|
|
Transferable newClipboardContents = clipboard.getContents(null);
|
|
|
|
Transferable newClipboardContents = clipboard.getContents(null);
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (isTextMonitored()) {
|
|
|
|
if (isTextMonitored()) {
|
|
|
|
if (STRING.isAvailable(clipboard)) {
|
|
|
|
if (STRING.isAvailable(clipboard)) {
|
|
|
|
String newContent = (String) newClipboardContents.getTransferData(STRING.getDataFlavor());
|
|
|
|
String newStringContent = getStringContent(newClipboardContents);
|
|
|
|
if (!newContent.equals(myClipboardContents[0].getOldContent())) {
|
|
|
|
if (!newStringContent.equals(myClipboardContents[0].getOldContent())) {
|
|
|
|
for (ClipboardEventListener clipboardEventListener : eventsListener) {
|
|
|
|
notifyStringEvent(newStringContent);
|
|
|
|
clipboardEventListener.onCopyString(newContent);
|
|
|
|
myClipboardContents[0].setOldContent(newStringContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
myClipboardContents[0].setOldContent(newContent);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (isImagesMonitored()) {
|
|
|
|
if (isImagesMonitored()) {
|
|
|
|
if (IMAGE.isAvailable(clipboard)) {
|
|
|
|
if (IMAGE.isAvailable(clipboard)) {
|
|
|
|
BufferedImage bufferedImage = ClipboardUtils.convertToBufferedImage((Image) newClipboardContents.getTransferData(IMAGE.getDataFlavor()));
|
|
|
|
BufferedImage bufferedImageContent = getImageContent(newClipboardContents);
|
|
|
|
Dimension newContent = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight());
|
|
|
|
Dimension newDimensionContent = new Dimension(bufferedImageContent.getWidth(), bufferedImageContent.getHeight());
|
|
|
|
if (!newContent.equals(myClipboardContents[0].getOldContent())) {
|
|
|
|
if (!newDimensionContent.equals(myClipboardContents[0].getOldContent())) {
|
|
|
|
for (ClipboardEventListener clipboardEventListener : eventsListener) {
|
|
|
|
notifyImageEvent(bufferedImageContent);
|
|
|
|
clipboardEventListener.onCopyImage(bufferedImage);
|
|
|
|
myClipboardContents[0].setOldContent(newDimensionContent);
|
|
|
|
}
|
|
|
|
|
|
|
|
myClipboardContents[0].setOldContent(newContent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (UnsupportedFlavorException | IOException exp) {
|
|
|
|
|
|
|
|
exp.printStackTrace();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 0, 350, TimeUnit.MILLISECONDS);
|
|
|
|
}, 0, 350, TimeUnit.MILLISECONDS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|