Refactor code

MYC-Refactor
Hammy 3 years ago
parent 061e2502c3
commit 50f521fd1a

@ -15,25 +15,20 @@ class MacClipboardListener extends ClipboardListener {
MacClipboardListener() { }
@Override
public void execute() {
Transferable oldClipboardContents = clipboard.getContents(null);
final MyClipboardContent<?>[] myClipboardContents = new MyClipboardContent[] { ClipboardUtils.getClipboardContents(oldClipboardContents, clipboard) };
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(() -> {
Transferable newClipboardContents = clipboard.getContents(null);
void checkText(Transferable newClipboardContents, MyClipboardContent<?>[] myClipboardContents) {
if (isTextMonitored()) {
if (STRING.isAvailable(clipboard)) {
String newStringContent = getStringContent(newClipboardContents);
if (!newStringContent.equals(myClipboardContents[0].getOldContent())) {
String oldStringContent = (String) myClipboardContents[0].getOldContent();
if (!newStringContent.equals(oldStringContent)) {
getEventManager().notifyStringEvent(newStringContent);
myClipboardContents[0].setOldContent(newStringContent);
}
}
}
}
void checkImages(Transferable newClipboardContents, MyClipboardContent<?>[] myClipboardContents) {
if (isImagesMonitored()) {
if (IMAGE.isAvailable(clipboard)) {
BufferedImage bufferedImageContent = getImageContent(newClipboardContents);
@ -44,6 +39,19 @@ class MacClipboardListener extends ClipboardListener {
}
}
}
}
@Override
void execute() {
Transferable oldClipboardContents = clipboard.getContents(null);
final MyClipboardContent<?>[] myClipboardContents = new MyClipboardContent[] { ClipboardUtils.getClipboardContents(oldClipboardContents, clipboard) };
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.scheduleAtFixedRate(() -> {
Transferable newClipboardContents = clipboard.getContents(null);
checkText(newClipboardContents, myClipboardContents);
checkImages(newClipboardContents, myClipboardContents);
}, 0, 350, TimeUnit.MILLISECONDS);
}
}

Loading…
Cancel
Save