From ee4e63166ba1f0652843c2fb972f45da4dd1cc39 Mon Sep 17 00:00:00 2001 From: Hammy Date: Wed, 28 Jul 2021 01:16:41 +0100 Subject: [PATCH] Refactor STRING -> TEXT for increased readability --- src/main/java/me/goudham/ClipboardUtils.java | 10 +++++----- src/main/java/me/goudham/EventManager.java | 4 ++-- src/main/java/me/goudham/MacClipboardListener.java | 6 +++--- src/main/java/me/goudham/domain/Contents.java | 2 +- src/main/java/me/goudham/event/ClipboardEvent.java | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/me/goudham/ClipboardUtils.java b/src/main/java/me/goudham/ClipboardUtils.java index 728e23f..d6835b3 100644 --- a/src/main/java/me/goudham/ClipboardUtils.java +++ b/src/main/java/me/goudham/ClipboardUtils.java @@ -12,7 +12,7 @@ import me.goudham.domain.MyClipboardContent; import me.goudham.domain.OldClipboardContent; import static me.goudham.domain.Contents.IMAGE; -import static me.goudham.domain.Contents.STRING; +import static me.goudham.domain.Contents.TEXT; class ClipboardUtils { @@ -20,8 +20,8 @@ class ClipboardUtils { MyClipboardContent myClipboardContent = new MyClipboardContent<>(); try { - if (STRING.isAvailable(clipboard)) { - myClipboardContent.setOldContent(contents.getTransferData(STRING.getDataFlavor())); + if (TEXT.isAvailable(clipboard)) { + myClipboardContent.setOldContent(contents.getTransferData(TEXT.getDataFlavor())); } else if (IMAGE.isAvailable(clipboard)) { BufferedImage bufferedImage = convertToBufferedImage((Image) contents.getTransferData(IMAGE.getDataFlavor())); myClipboardContent.setOldContent(new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight())); @@ -37,8 +37,8 @@ class ClipboardUtils { OldClipboardContent oldClipboardContent = null; try { - if (oldContents.isDataFlavorSupported(STRING.getDataFlavor())) { - oldClipboardContent = new OldClipboardContent((String) oldContents.getTransferData(STRING.getDataFlavor())); + if (oldContents.isDataFlavorSupported(TEXT.getDataFlavor())) { + oldClipboardContent = new OldClipboardContent((String) oldContents.getTransferData(TEXT.getDataFlavor())); } else if (oldContents.isDataFlavorSupported(IMAGE.getDataFlavor())) { oldClipboardContent = new OldClipboardContent(convertToBufferedImage((Image) oldContents.getTransferData(IMAGE.getDataFlavor()))); } diff --git a/src/main/java/me/goudham/EventManager.java b/src/main/java/me/goudham/EventManager.java index 54eb27d..4ce2890 100644 --- a/src/main/java/me/goudham/EventManager.java +++ b/src/main/java/me/goudham/EventManager.java @@ -35,9 +35,9 @@ class EventManager { * * @param stringContent {@link String} to be consumed */ - void notifyStringEvent(OldClipboardContent oldClipboardContent, String stringContent) { + void notifyTextEvent(OldClipboardContent oldClipboardContent, String stringContent) { for (ClipboardEvent clipboardEvent : eventListeners) { - clipboardEvent.onCopyString(oldClipboardContent, stringContent); + clipboardEvent.onCopyText(oldClipboardContent, stringContent); } } diff --git a/src/main/java/me/goudham/MacClipboardListener.java b/src/main/java/me/goudham/MacClipboardListener.java index 9428fdd..9cd8bf2 100644 --- a/src/main/java/me/goudham/MacClipboardListener.java +++ b/src/main/java/me/goudham/MacClipboardListener.java @@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit; import me.goudham.domain.MyClipboardContent; import static me.goudham.domain.Contents.IMAGE; -import static me.goudham.domain.Contents.STRING; +import static me.goudham.domain.Contents.TEXT; class MacClipboardListener extends ClipboardListener { @@ -23,7 +23,7 @@ class MacClipboardListener extends ClipboardListener { */ void checkText(Transferable newClipboardContents, MyClipboardContent[] myClipboardContents) { if (isTextMonitored()) { - if (STRING.isAvailable(clipboard)) { + if (TEXT.isAvailable(clipboard)) { String newStringContent = getStringContent(newClipboardContents); String oldStringContent = (String) myClipboardContents[0].getOldContent(); if (!newStringContent.equals(oldStringContent)) { @@ -41,7 +41,7 @@ class MacClipboardListener extends ClipboardListener { * @param myClipboardContents {@link MyClipboardContent[]} of Unknown {@link Class} containing previous contents */ void checkImages(Transferable newClipboardContents, MyClipboardContent[] myClipboardContents) { - if (isImagesMonitored()) { + if (isImageMonitored()) { if (IMAGE.isAvailable(clipboard)) { BufferedImage bufferedImageContent = getImageContent(newClipboardContents); Dimension newDimensionContent = new Dimension(bufferedImageContent.getWidth(), bufferedImageContent.getHeight()); diff --git a/src/main/java/me/goudham/domain/Contents.java b/src/main/java/me/goudham/domain/Contents.java index 556a0ff..d12cf73 100644 --- a/src/main/java/me/goudham/domain/Contents.java +++ b/src/main/java/me/goudham/domain/Contents.java @@ -4,7 +4,7 @@ import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; public enum Contents { - STRING(DataFlavor.stringFlavor) { + TEXT(DataFlavor.stringFlavor) { @Override public boolean isAvailable(Clipboard clipboard) { return clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor); diff --git a/src/main/java/me/goudham/event/ClipboardEvent.java b/src/main/java/me/goudham/event/ClipboardEvent.java index cdfef20..2b1486a 100644 --- a/src/main/java/me/goudham/event/ClipboardEvent.java +++ b/src/main/java/me/goudham/event/ClipboardEvent.java @@ -6,7 +6,7 @@ import java.util.List; import me.goudham.domain.OldClipboardContent; public interface ClipboardEvent { - void onCopyString(OldClipboardContent oldContent, String newContent); + void onCopyText(OldClipboardContent oldContent, String newContent); void onCopyImage(OldClipboardContent oldContent, BufferedImage newContent); void onCopyFiles(OldClipboardContent oldContent, List newContent); }