Refactor code

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

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

Loading…
Cancel
Save