Reformat TransferableImage.java

Add @NotNull annotation to Image to ensure that image can never be null,
this allows for a simpler if check within getTransferData()
osx
Hammy 3 years ago
parent 9ca4de4a86
commit c43e424f2b

@ -1,5 +1,7 @@
package me.goudham.model; package me.goudham.model;
import org.jetbrains.annotations.NotNull;
import java.awt.Image; import java.awt.Image;
import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable; import java.awt.datatransfer.Transferable;
@ -7,24 +9,27 @@ import java.awt.datatransfer.UnsupportedFlavorException;
public class TransferableImage implements Transferable { public class TransferableImage implements Transferable {
private final Image i; private final Image image;
public TransferableImage(Image i) { public TransferableImage(@NotNull Image image) {
this.i = i; this.image = image;
} }
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
if (flavor.equals(DataFlavor.imageFlavor) && i != null) { if (flavor.equals(DataFlavor.imageFlavor)) {
return i; return image;
} else { } else {
throw new UnsupportedFlavorException(flavor); throw new UnsupportedFlavorException(flavor);
} }
} }
@Override
public DataFlavor[] getTransferDataFlavors() { public DataFlavor[] getTransferDataFlavors() {
return new DataFlavor[] {DataFlavor.imageFlavor}; return new DataFlavor[] { DataFlavor.imageFlavor };
} }
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) { public boolean isDataFlavorSupported(DataFlavor flavor) {
DataFlavor[] flavors = getTransferDataFlavors(); DataFlavor[] flavors = getTransferDataFlavors();
for (DataFlavor dataFlavor : flavors) { for (DataFlavor dataFlavor : flavors) {

Loading…
Cancel
Save