Rename OldClipboardContent.java to ClipboardContent.java

pull/2/head
Hammy 3 years ago
parent 4ed59cc691
commit cf598be605

@ -8,7 +8,7 @@ import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.ClipboardContent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -106,47 +106,47 @@ class ClipboardUtils {
} }
/** /**
* Store contents from the given {@link Transferable} into {@link OldClipboardContent} * Store contents from the given {@link Transferable} into {@link ClipboardContent}
* *
* @param oldContents The given {@link Transferable} which holds the clipboard contents * @param oldContents The given {@link Transferable} which holds the clipboard contents
* @return {@link OldClipboardContent} containing old clipboard contents * @return {@link ClipboardContent} containing old clipboard contents
*/ */
OldClipboardContent getOldClipboardContent(Transferable oldContents) { ClipboardContent getOldClipboardContent(Transferable oldContents) {
OldClipboardContent oldClipboardContent = null; ClipboardContent clipboardContent = null;
try { try {
if (oldContents.isDataFlavorSupported(TEXT.getDataFlavor())) { if (oldContents.isDataFlavorSupported(TEXT.getDataFlavor())) {
oldClipboardContent = new OldClipboardContent((String) oldContents.getTransferData(TEXT.getDataFlavor())); clipboardContent = new ClipboardContent((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()))); clipboardContent = new ClipboardContent(convertToBufferedImage((Image) oldContents.getTransferData(IMAGE.getDataFlavor())));
} else if (oldContents.isDataFlavorSupported(FILE.getDataFlavor())) { } else if (oldContents.isDataFlavorSupported(FILE.getDataFlavor())) {
oldClipboardContent = new OldClipboardContent((List<File>) oldContents.getTransferData(FILE.getDataFlavor())); clipboardContent = new ClipboardContent((List<File>) oldContents.getTransferData(FILE.getDataFlavor()));
} }
} catch (UnsupportedFlavorException | IOException exp) { } catch (UnsupportedFlavorException | IOException exp) {
logger.error("Exception Thrown When Retrieving Clipboard Contents", exp); logger.error("Exception Thrown When Retrieving Clipboard Contents", exp);
} }
return oldClipboardContent; return clipboardContent;
} }
/** /**
* Store contents from the given {@link Object} into {@link OldClipboardContent} * Store contents from the given {@link Object} into {@link ClipboardContent}
* *
* @param object The given {@link Object} which holds the clipboard contents * @param object The given {@link Object} which holds the clipboard contents
* @return {@link OldClipboardContent} containing old clipboard contents * @return {@link ClipboardContent} containing old clipboard contents
*/ */
OldClipboardContent getOldClipboardContent(Object object) { ClipboardContent getOldClipboardContent(Object object) {
OldClipboardContent oldClipboardContent = null; ClipboardContent clipboardContent = null;
if (object instanceof String) { if (object instanceof String) {
oldClipboardContent = new OldClipboardContent((String) object); clipboardContent = new ClipboardContent((String) object);
} else if (object instanceof MyBufferedImage) { } else if (object instanceof MyBufferedImage) {
oldClipboardContent = new OldClipboardContent(((MyBufferedImage) object).getBufferedImage()); clipboardContent = new ClipboardContent(((MyBufferedImage) object).getBufferedImage());
} else if (object instanceof List) { } else if (object instanceof List) {
oldClipboardContent = new OldClipboardContent((List<File>) object); clipboardContent = new ClipboardContent((List<File>) object);
} }
return oldClipboardContent; return clipboardContent;
} }
/** /**

@ -4,7 +4,7 @@ import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.ClipboardContent;
import me.goudham.event.FileEvent; import me.goudham.event.FileEvent;
import me.goudham.event.ImageEvent; import me.goudham.event.ImageEvent;
import me.goudham.event.TextEvent; import me.goudham.event.TextEvent;
@ -74,36 +74,36 @@ class EventManager {
/** /**
* Produces {@link String} change notifications to all consumers listening * Produces {@link String} change notifications to all consumers listening
* *
* @param oldClipboardContent The previous clipboard contents * @param clipboardContent The previous clipboard contents
* @param stringContent {@link String} to be consumed * @param stringContent {@link String} to be consumed
*/ */
void notifyTextEvent(OldClipboardContent oldClipboardContent, String stringContent) { void notifyTextEvent(ClipboardContent clipboardContent, String stringContent) {
for (TextEvent textEvent : textEventListener) { for (TextEvent textEvent : textEventListener) {
textEvent.onCopyText(oldClipboardContent, stringContent); textEvent.onCopyText(clipboardContent, stringContent);
} }
} }
/** /**
* Produces {@link BufferedImage} change notifications to all consumers listening * Produces {@link BufferedImage} change notifications to all consumers listening
* *
* @param oldClipboardContent The previous clipboard contents * @param clipboardContent The previous clipboard contents
* @param imageContent {@link BufferedImage} to be consumed * @param imageContent {@link BufferedImage} to be consumed
*/ */
void notifyImageEvent(OldClipboardContent oldClipboardContent, BufferedImage imageContent) { void notifyImageEvent(ClipboardContent clipboardContent, BufferedImage imageContent) {
for (ImageEvent imageEvent : imageEventListener) { for (ImageEvent imageEvent : imageEventListener) {
imageEvent.onCopyImage(oldClipboardContent, imageContent); imageEvent.onCopyImage(clipboardContent, imageContent);
} }
} }
/** /**
* Produces {@link List} of {@link File} change notifications to all consumers listening * Produces {@link List} of {@link File} change notifications to all consumers listening
* *
* @param oldClipboardContent The previous clipboard contents * @param clipboardContent The previous clipboard contents
* @param fileContent {@link List} of {@link File} to be consumed * @param fileContent {@link List} of {@link File} to be consumed
*/ */
void notifyFilesEvent(OldClipboardContent oldClipboardContent, List<File> fileContent) { void notifyFilesEvent(ClipboardContent clipboardContent, List<File> fileContent) {
for (FileEvent fileEvent : fileEventListener) { for (FileEvent fileEvent : fileEventListener) {
fileEvent.onCopyFiles(oldClipboardContent, fileContent); fileEvent.onCopyFiles(clipboardContent, fileContent);
} }
} }
} }

@ -8,7 +8,7 @@ import java.util.List;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.ClipboardContent;
import static java.lang.Thread.sleep; import static java.lang.Thread.sleep;
import static me.goudham.Contents.FILE; import static me.goudham.Contents.FILE;
@ -38,8 +38,8 @@ class MacClipboardListener extends ClipboardListener implements Runnable {
if (isTextMonitored()) { if (isTextMonitored()) {
Object oldContent = genericClipboardContents[0].getOldContent(); Object oldContent = genericClipboardContents[0].getOldContent();
if (!newStringContent.equals(oldContent)) { if (!newStringContent.equals(oldContent)) {
OldClipboardContent oldClipboardContent = clipboardUtils.getOldClipboardContent(oldContent); ClipboardContent clipboardContent = clipboardUtils.getOldClipboardContent(oldContent);
eventManager.notifyTextEvent(oldClipboardContent, newStringContent); eventManager.notifyTextEvent(clipboardContent, newStringContent);
} }
} }
@ -60,8 +60,8 @@ class MacClipboardListener extends ClipboardListener implements Runnable {
if (isImageMonitored()) { if (isImageMonitored()) {
if (!bufferedImageContent.equals(genericClipboardContents[0].getOldContent())) { if (!bufferedImageContent.equals(genericClipboardContents[0].getOldContent())) {
OldClipboardContent oldClipboardContent = clipboardUtils.getOldClipboardContent(genericClipboardContents[0].getOldContent()); ClipboardContent clipboardContent = clipboardUtils.getOldClipboardContent(genericClipboardContents[0].getOldContent());
eventManager.notifyImageEvent(oldClipboardContent, bufferedImageContent.getBufferedImage()); eventManager.notifyImageEvent(clipboardContent, bufferedImageContent.getBufferedImage());
} }
} }
@ -83,8 +83,8 @@ class MacClipboardListener extends ClipboardListener implements Runnable {
if (isFileMonitored()) { if (isFileMonitored()) {
if (!fileListContent.equals(genericClipboardContents[0].getOldContent())) { if (!fileListContent.equals(genericClipboardContents[0].getOldContent())) {
OldClipboardContent oldClipboardContent = clipboardUtils.getOldClipboardContent(genericClipboardContents[0].getOldContent()); ClipboardContent clipboardContent = clipboardUtils.getOldClipboardContent(genericClipboardContents[0].getOldContent());
eventManager.notifyFilesEvent(oldClipboardContent, fileListContent); eventManager.notifyFilesEvent(clipboardContent, fileListContent);
} }
} }

@ -9,7 +9,7 @@ import java.io.File;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.ClipboardContent;
import static java.lang.Thread.currentThread; import static java.lang.Thread.currentThread;
import static java.lang.Thread.sleep; import static java.lang.Thread.sleep;
@ -44,13 +44,13 @@ class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnab
* @param newClipboardContents The new contents of the clipboard * @param newClipboardContents The new contents of the clipboard
*/ */
void processContents(Clipboard oldClipboard, Transferable oldClipboardContents, Transferable newClipboardContents) { void processContents(Clipboard oldClipboard, Transferable oldClipboardContents, Transferable newClipboardContents) {
OldClipboardContent oldClipboardContent = clipboardUtils.getOldClipboardContent(oldClipboardContents); ClipboardContent clipboardContent = clipboardUtils.getOldClipboardContent(oldClipboardContents);
if (isTextMonitored()) { if (isTextMonitored()) {
if (TEXT.isAvailable(oldClipboard) && !FILE.isAvailable(oldClipboard)) { if (TEXT.isAvailable(oldClipboard) && !FILE.isAvailable(oldClipboard)) {
String stringContent = clipboardUtils.getStringContent(newClipboardContents); String stringContent = clipboardUtils.getStringContent(newClipboardContents);
if (!stringContent.equals(oldClipboardContent.getOldText())) { if (!stringContent.equals(clipboardContent.getText())) {
eventManager.notifyTextEvent(oldClipboardContent, stringContent); eventManager.notifyTextEvent(clipboardContent, stringContent);
} }
} }
} }
@ -58,9 +58,9 @@ class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnab
if (isImageMonitored()) { if (isImageMonitored()) {
if (IMAGE.isAvailable(oldClipboard)) { if (IMAGE.isAvailable(oldClipboard)) {
MyBufferedImage bufferedImage = clipboardUtils.getImageContent(newClipboardContents); MyBufferedImage bufferedImage = clipboardUtils.getImageContent(newClipboardContents);
MyBufferedImage oldBufferedImage = new MyBufferedImage(oldClipboardContent.getOldImage()); MyBufferedImage oldBufferedImage = new MyBufferedImage(clipboardContent.getBufferedImage());
if (!bufferedImage.equals(oldBufferedImage)) { if (!bufferedImage.equals(oldBufferedImage)) {
eventManager.notifyImageEvent(oldClipboardContent, bufferedImage.getBufferedImage()); eventManager.notifyImageEvent(clipboardContent, bufferedImage.getBufferedImage());
} }
} }
} }
@ -68,8 +68,8 @@ class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnab
if (isFileMonitored()) { if (isFileMonitored()) {
if (FILE.isAvailable(oldClipboard)) { if (FILE.isAvailable(oldClipboard)) {
List<File> fileList = clipboardUtils.getFileContent(newClipboardContents); List<File> fileList = clipboardUtils.getFileContent(newClipboardContents);
if (!fileList.equals(oldClipboardContent.getOldFiles())) { if (!fileList.equals(clipboardContent.getFiles())) {
eventManager.notifyFilesEvent(oldClipboardContent, fileList); eventManager.notifyFilesEvent(clipboardContent, fileList);
} }
} }
} }

@ -0,0 +1,35 @@
package me.goudham.domain;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
public class ClipboardContent {
private String text;
private BufferedImage bufferedImage;
private List<File> files;
public ClipboardContent(String text) {
this.text = text;
}
public ClipboardContent(BufferedImage bufferedImage) {
this.bufferedImage = bufferedImage;
}
public ClipboardContent(List<File> files) {
this.files = files;
}
public BufferedImage getBufferedImage() {
return bufferedImage;
}
public String getText() {
return text;
}
public List<File> getFiles() {
return files;
}
}

@ -1,35 +0,0 @@
package me.goudham.domain;
import java.awt.image.BufferedImage;
import java.io.File;
import java.util.List;
public class OldClipboardContent {
private String oldText;
private BufferedImage oldImage;
private List<File> oldFiles;
public OldClipboardContent(String oldText) {
this.oldText = oldText;
}
public OldClipboardContent(BufferedImage oldImage) {
this.oldImage = oldImage;
}
public OldClipboardContent(List<File> oldFiles) {
this.oldFiles = oldFiles;
}
public BufferedImage getOldImage() {
return oldImage;
}
public String getOldText() {
return oldText;
}
public List<File> getOldFiles() {
return oldFiles;
}
}

@ -2,8 +2,8 @@ package me.goudham.event;
import java.io.File; import java.io.File;
import java.util.List; import java.util.List;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.ClipboardContent;
public interface FileEvent extends ClipboardEvent { public interface FileEvent extends ClipboardEvent {
void onCopyFiles(OldClipboardContent oldContent, List<File> newContent); void onCopyFiles(ClipboardContent oldContent, List<File> newContent);
} }

@ -1,8 +1,8 @@
package me.goudham.event; package me.goudham.event;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.ClipboardContent;
public interface ImageEvent extends ClipboardEvent { public interface ImageEvent extends ClipboardEvent {
void onCopyImage(OldClipboardContent oldContent, BufferedImage newContent); void onCopyImage(ClipboardContent oldContent, BufferedImage newContent);
} }

@ -1,7 +1,7 @@
package me.goudham.event; package me.goudham.event;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.ClipboardContent;
public interface TextEvent extends ClipboardEvent { public interface TextEvent extends ClipboardEvent {
void onCopyText(OldClipboardContent oldContent, String newContent); void onCopyText(ClipboardContent oldContent, String newContent);
} }

@ -9,7 +9,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.ClipboardContent;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
@ -143,22 +143,22 @@ class ClipboardUtilsTest {
when(transferableMock.isDataFlavorSupported(dataFlavor)).thenReturn(true); when(transferableMock.isDataFlavorSupported(dataFlavor)).thenReturn(true);
when(transferableMock.getTransferData(dataFlavor)).thenReturn(expectedContent); when(transferableMock.getTransferData(dataFlavor)).thenReturn(expectedContent);
OldClipboardContent actualOldClipboardContent = sut.getOldClipboardContent(transferableMock); ClipboardContent actualClipboardContent = sut.getOldClipboardContent(transferableMock);
assertThat(actualOldClipboardContent.getOldText(), is(expectedString)); assertThat(actualClipboardContent.getText(), is(expectedString));
assertThat(actualOldClipboardContent.getOldFiles(), is(expectedFiles)); assertThat(actualClipboardContent.getFiles(), is(expectedFiles));
assertThat(actualOldClipboardContent.getOldImage(), is(new BufferedImageMatcher(expectedImage))); assertThat(actualClipboardContent.getBufferedImage(), is(new BufferedImageMatcher(expectedImage)));
verifyNoInteractions(logger); verifyNoInteractions(logger);
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("provideArgumentsForOldClipboardContents") @MethodSource("provideArgumentsForOldClipboardContents")
void successfullyMarshallClipboardContentsIntoOldClipboardContent(Object expectedOldContent, String expectedString, BufferedImage expectedImage, List<File> expectedFiles) { void successfullyMarshallClipboardContentsIntoOldClipboardContent(Object expectedOldContent, String expectedString, BufferedImage expectedImage, List<File> expectedFiles) {
OldClipboardContent actualOldClipboardContent = sut.getOldClipboardContent(expectedOldContent); ClipboardContent actualClipboardContent = sut.getOldClipboardContent(expectedOldContent);
assertThat(actualOldClipboardContent.getOldText(), is(expectedString)); assertThat(actualClipboardContent.getText(), is(expectedString));
assertThat(actualOldClipboardContent.getOldImage(), is(expectedImage)); assertThat(actualClipboardContent.getBufferedImage(), is(expectedImage));
assertThat(actualOldClipboardContent.getOldFiles(), is(expectedFiles)); assertThat(actualClipboardContent.getFiles(), is(expectedFiles));
verifyNoInteractions(logger); verifyNoInteractions(logger);
} }

Loading…
Cancel
Save