Refactor STRING -> TEXT for increased readability

MYC-Refactor
Hammy 4 years ago
parent 96dac0ad5f
commit ee4e63166b

@ -12,7 +12,7 @@ import me.goudham.domain.MyClipboardContent;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.OldClipboardContent;
import static me.goudham.domain.Contents.IMAGE; import static me.goudham.domain.Contents.IMAGE;
import static me.goudham.domain.Contents.STRING; import static me.goudham.domain.Contents.TEXT;
class ClipboardUtils { class ClipboardUtils {
@ -20,8 +20,8 @@ class ClipboardUtils {
MyClipboardContent<?> myClipboardContent = new MyClipboardContent<>(); MyClipboardContent<?> myClipboardContent = new MyClipboardContent<>();
try { try {
if (STRING.isAvailable(clipboard)) { if (TEXT.isAvailable(clipboard)) {
myClipboardContent.setOldContent(contents.getTransferData(STRING.getDataFlavor())); myClipboardContent.setOldContent(contents.getTransferData(TEXT.getDataFlavor()));
} else if (IMAGE.isAvailable(clipboard)) { } else if (IMAGE.isAvailable(clipboard)) {
BufferedImage bufferedImage = convertToBufferedImage((Image) contents.getTransferData(IMAGE.getDataFlavor())); BufferedImage bufferedImage = convertToBufferedImage((Image) contents.getTransferData(IMAGE.getDataFlavor()));
myClipboardContent.setOldContent(new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight())); myClipboardContent.setOldContent(new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight()));
@ -37,8 +37,8 @@ class ClipboardUtils {
OldClipboardContent oldClipboardContent = null; OldClipboardContent oldClipboardContent = null;
try { try {
if (oldContents.isDataFlavorSupported(STRING.getDataFlavor())) { if (oldContents.isDataFlavorSupported(TEXT.getDataFlavor())) {
oldClipboardContent = new OldClipboardContent((String) oldContents.getTransferData(STRING.getDataFlavor())); oldClipboardContent = new OldClipboardContent((String) oldContents.getTransferData(TEXT.getDataFlavor()));
} else if (oldContents.isDataFlavorSupported(IMAGE.getDataFlavor())) { } else if (oldContents.isDataFlavorSupported(IMAGE.getDataFlavor())) {
oldClipboardContent = new OldClipboardContent(convertToBufferedImage((Image) oldContents.getTransferData(IMAGE.getDataFlavor()))); oldClipboardContent = new OldClipboardContent(convertToBufferedImage((Image) oldContents.getTransferData(IMAGE.getDataFlavor())));
} }

@ -35,9 +35,9 @@ class EventManager {
* *
* @param stringContent {@link String} to be consumed * @param stringContent {@link String} to be consumed
*/ */
void notifyStringEvent(OldClipboardContent oldClipboardContent, String stringContent) { void notifyTextEvent(OldClipboardContent oldClipboardContent, String stringContent) {
for (ClipboardEvent clipboardEvent : eventListeners) { for (ClipboardEvent clipboardEvent : eventListeners) {
clipboardEvent.onCopyString(oldClipboardContent, stringContent); clipboardEvent.onCopyText(oldClipboardContent, stringContent);
} }
} }

@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit;
import me.goudham.domain.MyClipboardContent; import me.goudham.domain.MyClipboardContent;
import static me.goudham.domain.Contents.IMAGE; 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 { class MacClipboardListener extends ClipboardListener {
@ -23,7 +23,7 @@ class MacClipboardListener extends ClipboardListener {
*/ */
void checkText(Transferable newClipboardContents, MyClipboardContent<?>[] myClipboardContents) { void checkText(Transferable newClipboardContents, MyClipboardContent<?>[] myClipboardContents) {
if (isTextMonitored()) { if (isTextMonitored()) {
if (STRING.isAvailable(clipboard)) { if (TEXT.isAvailable(clipboard)) {
String newStringContent = getStringContent(newClipboardContents); String newStringContent = getStringContent(newClipboardContents);
String oldStringContent = (String) myClipboardContents[0].getOldContent(); String oldStringContent = (String) myClipboardContents[0].getOldContent();
if (!newStringContent.equals(oldStringContent)) { if (!newStringContent.equals(oldStringContent)) {
@ -41,7 +41,7 @@ class MacClipboardListener extends ClipboardListener {
* @param myClipboardContents {@link MyClipboardContent[]} of Unknown {@link Class} containing previous contents * @param myClipboardContents {@link MyClipboardContent[]} of Unknown {@link Class} containing previous contents
*/ */
void checkImages(Transferable newClipboardContents, MyClipboardContent<?>[] myClipboardContents) { void checkImages(Transferable newClipboardContents, MyClipboardContent<?>[] myClipboardContents) {
if (isImagesMonitored()) { if (isImageMonitored()) {
if (IMAGE.isAvailable(clipboard)) { if (IMAGE.isAvailable(clipboard)) {
BufferedImage bufferedImageContent = getImageContent(newClipboardContents); BufferedImage bufferedImageContent = getImageContent(newClipboardContents);
Dimension newDimensionContent = new Dimension(bufferedImageContent.getWidth(), bufferedImageContent.getHeight()); Dimension newDimensionContent = new Dimension(bufferedImageContent.getWidth(), bufferedImageContent.getHeight());

@ -4,7 +4,7 @@ import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
public enum Contents { public enum Contents {
STRING(DataFlavor.stringFlavor) { TEXT(DataFlavor.stringFlavor) {
@Override @Override
public boolean isAvailable(Clipboard clipboard) { public boolean isAvailable(Clipboard clipboard) {
return clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor); return clipboard.isDataFlavorAvailable(DataFlavor.stringFlavor);

@ -6,7 +6,7 @@ import java.util.List;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.OldClipboardContent;
public interface ClipboardEvent { public interface ClipboardEvent {
void onCopyString(OldClipboardContent oldContent, String newContent); void onCopyText(OldClipboardContent oldContent, String newContent);
void onCopyImage(OldClipboardContent oldContent, BufferedImage newContent); void onCopyImage(OldClipboardContent oldContent, BufferedImage newContent);
void onCopyFiles(OldClipboardContent oldContent, List<File> newContent); void onCopyFiles(OldClipboardContent oldContent, List<File> newContent);
} }

Loading…
Cancel
Save