Refactor code

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

@ -15,25 +15,20 @@ class MacClipboardListener extends ClipboardListener {
MacClipboardListener() { } MacClipboardListener() { }
@Override void checkText(Transferable newClipboardContents, MyClipboardContent<?>[] myClipboardContents) {
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);
if (isTextMonitored()) { if (isTextMonitored()) {
if (STRING.isAvailable(clipboard)) { if (STRING.isAvailable(clipboard)) {
String newStringContent = getStringContent(newClipboardContents); String newStringContent = getStringContent(newClipboardContents);
if (!newStringContent.equals(myClipboardContents[0].getOldContent())) { String oldStringContent = (String) myClipboardContents[0].getOldContent();
if (!newStringContent.equals(oldStringContent)) {
getEventManager().notifyStringEvent(newStringContent); getEventManager().notifyStringEvent(newStringContent);
myClipboardContents[0].setOldContent(newStringContent); myClipboardContents[0].setOldContent(newStringContent);
} }
} }
} }
}
void checkImages(Transferable newClipboardContents, MyClipboardContent<?>[] myClipboardContents) {
if (isImagesMonitored()) { if (isImagesMonitored()) {
if (IMAGE.isAvailable(clipboard)) { if (IMAGE.isAvailable(clipboard)) {
BufferedImage bufferedImageContent = getImageContent(newClipboardContents); 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); }, 0, 350, TimeUnit.MILLISECONDS);
} }
} }

Loading…
Cancel
Save