Add Helper method for retrieving old clipboard contents

MYC-Refactor
Hammy 3 years ago
parent 96f54330e5
commit 535e35d3e8

@ -9,6 +9,7 @@ import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
import me.goudham.domain.MyClipboardContent; import me.goudham.domain.MyClipboardContent;
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.STRING;
@ -32,6 +33,22 @@ class ClipboardUtils {
return myClipboardContent; return myClipboardContent;
} }
static OldClipboardContent getOldClipboardContent(Transferable oldContents) {
OldClipboardContent oldClipboardContent = null;
try {
if (oldContents.isDataFlavorSupported(STRING.getDataFlavor())) {
oldClipboardContent = new OldClipboardContent((String) oldContents.getTransferData(STRING.getDataFlavor()));
} else if (oldContents.isDataFlavorSupported(IMAGE.getDataFlavor())) {
oldClipboardContent = new OldClipboardContent(convertToBufferedImage((Image) oldContents.getTransferData(IMAGE.getDataFlavor())));
}
} catch (UnsupportedFlavorException | IOException exp) {
exp.printStackTrace();
}
return oldClipboardContent;
}
static BufferedImage convertToBufferedImage(Image image) { static BufferedImage convertToBufferedImage(Image image) {
BufferedImage newImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB); BufferedImage newImage = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_ARGB);

Loading…
Cancel
Save