Restructure classes to ensure classes are not unnecessarily public

MYC-Refactor
Hammy 3 years ago
parent fd7c39c6c4
commit 0ccfc56e98

@ -3,8 +3,12 @@ package me.goudham;
import java.awt.Image; import java.awt.Image;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard; 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.io.File;
import java.util.List; import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -102,4 +106,60 @@ abstract class ClipboardListener {
void setEventManager(EventManager eventManager) { void setEventManager(EventManager eventManager) {
this.eventManager = eventManager; this.eventManager = eventManager;
} }
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;
}
}
} }

@ -10,15 +10,13 @@ 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.MyClipboardContent;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.OldClipboardContent;
import me.goudham.domain.OldImage;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import static me.goudham.domain.Contents.FILELIST; import static me.goudham.Contents.FILELIST;
import static me.goudham.domain.Contents.IMAGE; import static me.goudham.Contents.IMAGE;
import static me.goudham.domain.Contents.TEXT; import static me.goudham.Contents.TEXT;
class ClipboardUtils { class ClipboardUtils {
protected static Logger logger = LoggerFactory.getLogger(ClipboardUtils.class); protected static Logger logger = LoggerFactory.getLogger(ClipboardUtils.class);

@ -1,9 +1,9 @@
package me.goudham.domain; package me.goudham;
import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
public enum Contents { enum Contents {
TEXT(DataFlavor.stringFlavor) { TEXT(DataFlavor.stringFlavor) {
@Override @Override
public boolean isAvailable(Clipboard clipboard) { public boolean isAvailable(Clipboard clipboard) {
@ -29,9 +29,9 @@ public enum Contents {
this.dataFlavor = dataFlavor; this.dataFlavor = dataFlavor;
} }
public DataFlavor getDataFlavor() { DataFlavor getDataFlavor() {
return dataFlavor; return dataFlavor;
} }
public abstract boolean isAvailable(Clipboard clipboard); abstract boolean isAvailable(Clipboard clipboard);
} }

@ -10,19 +10,15 @@ 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.MyClipboardContent;
import me.goudham.domain.OldClipboardContent; import me.goudham.domain.OldClipboardContent;
import me.goudham.domain.OldImage;
import me.goudham.domain.TransferableFileList;
import me.goudham.domain.TransferableImage;
import static java.lang.Thread.sleep; import static java.lang.Thread.sleep;
import static me.goudham.ClipboardUtils.getFileContent; import static me.goudham.ClipboardUtils.getFileContent;
import static me.goudham.ClipboardUtils.getImageContent; import static me.goudham.ClipboardUtils.getImageContent;
import static me.goudham.ClipboardUtils.getStringContent; import static me.goudham.ClipboardUtils.getStringContent;
import static me.goudham.domain.Contents.FILELIST; import static me.goudham.Contents.FILELIST;
import static me.goudham.domain.Contents.IMAGE; import static me.goudham.Contents.IMAGE;
import static me.goudham.domain.Contents.TEXT; import static me.goudham.Contents.TEXT;
class MacClipboardListener extends ClipboardListener implements Runnable { class MacClipboardListener extends ClipboardListener implements Runnable {
ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(); ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

@ -1,11 +1,11 @@
package me.goudham.domain; package me.goudham;
import java.util.Objects; import java.util.Objects;
public class MyClipboardContent<T> { class MyClipboardContent<T> {
private T oldContent; private T oldContent;
public MyClipboardContent() { MyClipboardContent() {
} }
public void setOldContent(Object oldContent) { public void setOldContent(Object oldContent) {

@ -1,14 +1,14 @@
package me.goudham.domain; package me.goudham;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.util.Objects; import java.util.Objects;
public class OldImage { class OldImage {
private BufferedImage oldBufferedImage; private BufferedImage oldBufferedImage;
private Dimension oldDimension; private Dimension oldDimension;
public OldImage(BufferedImage oldBufferedImage, Dimension oldDimension) { OldImage(BufferedImage oldBufferedImage, Dimension oldDimension) {
this.oldBufferedImage = oldBufferedImage; this.oldBufferedImage = oldBufferedImage;
this.oldDimension = oldDimension; this.oldDimension = oldDimension;
} }

@ -12,17 +12,15 @@ 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.OldClipboardContent;
import me.goudham.domain.TransferableFileList;
import me.goudham.domain.TransferableImage;
import static java.lang.Thread.currentThread; import static java.lang.Thread.currentThread;
import static java.lang.Thread.sleep; import static java.lang.Thread.sleep;
import static me.goudham.ClipboardUtils.getFileContent; import static me.goudham.ClipboardUtils.getFileContent;
import static me.goudham.ClipboardUtils.getImageContent; import static me.goudham.ClipboardUtils.getImageContent;
import static me.goudham.ClipboardUtils.getStringContent; import static me.goudham.ClipboardUtils.getStringContent;
import static me.goudham.domain.Contents.FILELIST; import static me.goudham.Contents.FILELIST;
import static me.goudham.domain.Contents.IMAGE; import static me.goudham.Contents.IMAGE;
import static me.goudham.domain.Contents.TEXT; import static me.goudham.Contents.TEXT;
class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnable, ClipboardOwner { class WindowsOrUnixClipboardListener extends ClipboardListener implements Runnable, ClipboardOwner {
private ExecutorService executorService = Executors.newSingleThreadExecutor(); private ExecutorService executorService = Executors.newSingleThreadExecutor();

@ -1,36 +0,0 @@
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;
import org.jetbrains.annotations.NotNull;
public 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;
}
}

@ -1,35 +0,0 @@
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;
}
}
Loading…
Cancel
Save