Move inner classes up to higher level

pull/2/head
Hammy 3 years ago
parent fb0bfa2bff
commit 9b29ea29fd

@ -3,12 +3,8 @@ package me.goudham;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -138,60 +134,4 @@ abstract class ClipboardListener {
void setFileMonitored(boolean fileMonitored) {
this.fileMonitored = fileMonitored;
}
static class TransferableFileList implements Transferable {
private final List<File> fileList;
public TransferableFileList(@NotNull List<File> fileList) {
this.fileList = fileList;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.equals(DataFlavor.javaFileListFlavor)) {
return fileList;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { DataFlavor.javaFileListFlavor };
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor == DataFlavor.javaFileListFlavor;
}
}
static class TransferableImage implements Transferable {
private final Image image;
public TransferableImage(@NotNull Image image) {
this.image = image;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.equals(DataFlavor.imageFlavor)) {
return image;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { DataFlavor.imageFlavor };
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor == DataFlavor.imageFlavor;
}
}
}

@ -11,6 +11,8 @@ import java.util.concurrent.TimeUnit;
import me.goudham.domain.ClipboardContent;
import me.goudham.domain.GenericClipboardContent;
import me.goudham.domain.MyBufferedImage;
import me.goudham.domain.TransferableFile;
import me.goudham.domain.TransferableImage;
import static java.lang.Thread.sleep;
import static me.goudham.Contents.FILE;
@ -163,7 +165,7 @@ class MacClipboardListener extends ClipboardListener implements Runnable {
logger.error("Exception Thrown As Thread Cannot Sleep", ie);
}
clipboard.setContents(new TransferableFileList(fileContent), null);
clipboard.setContents(new TransferableFile(fileContent), null);
}
@Override

@ -11,6 +11,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import me.goudham.domain.ClipboardContent;
import me.goudham.domain.MyBufferedImage;
import me.goudham.domain.TransferableFile;
import me.goudham.domain.TransferableImage;
import static java.lang.Thread.currentThread;
import static java.lang.Thread.sleep;
@ -145,7 +147,7 @@ class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnab
}
try {
clipboard.setContents(new TransferableFileList(fileContent), this);
clipboard.setContents(new TransferableFile(fileContent), this);
} catch (IllegalStateException ise) {
logger.error("Exception Thrown As Clipboard Cannot Be Accessed", ise);
executorService.submit(this);

@ -0,0 +1,35 @@
package me.goudham.domain;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.util.List;
public class TransferableFile implements Transferable {
private final List<File> files;
public TransferableFile(List<File> files) {
this.files = files;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.equals(DataFlavor.javaFileListFlavor)) {
return files;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { DataFlavor.javaFileListFlavor };
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor == DataFlavor.javaFileListFlavor;
}
}

@ -0,0 +1,35 @@
package me.goudham.domain;
import java.awt.Image;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import org.jetbrains.annotations.NotNull;
public class TransferableImage implements Transferable {
private final Image image;
public TransferableImage(@NotNull Image image) {
this.image = image;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.equals(DataFlavor.imageFlavor)) {
return image;
} else {
throw new UnsupportedFlavorException(flavor);
}
}
@Override
public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] { DataFlavor.imageFlavor };
}
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
return flavor == DataFlavor.imageFlavor;
}
}

@ -12,6 +12,8 @@ import java.util.stream.Stream;
import me.goudham.domain.ClipboardContent;
import me.goudham.domain.GenericClipboardContent;
import me.goudham.domain.MyBufferedImage;
import me.goudham.domain.TransferableFile;
import me.goudham.domain.TransferableImage;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
@ -78,7 +80,7 @@ class ClipboardUtilsTest {
void successfullyGetImageContent() {
BufferedImage expectedBufferedImage = new BufferedImage(1, 1, BufferedImage.TYPE_INT_RGB);
MyBufferedImage expectedImageContent = new MyBufferedImage(expectedBufferedImage);
Transferable expectedTransferable = new ClipboardListener.TransferableImage(expectedBufferedImage);
Transferable expectedTransferable = new TransferableImage(expectedBufferedImage);
MyBufferedImage actualImageContent = sut.getImageContent(expectedTransferable);
@ -104,7 +106,7 @@ class ClipboardUtilsTest {
@Test
void successfullyGetFileContent() {
List<File> expectedFileContent = List.of(new File("testFile"));
Transferable expectedTransferable = new ClipboardListener.TransferableFileList(expectedFileContent);
Transferable expectedTransferable = new TransferableFile(expectedFileContent);
List<File> actualFileContent = sut.getFileContent(expectedTransferable);

Loading…
Cancel
Save