Remove the need for Clipboard as param

MYC-Refactor
Hammy 3 years ago
parent e537f092ef
commit bf3a473d89

@ -83,17 +83,23 @@ class ClipboardUtils {
return fileList; return fileList;
} }
MyClipboardContent<?> getClipboardContents(Transferable contents, Clipboard clipboard) { /**
* Store contents from the given {@link Transferable} into {@link MyClipboardContent}
*
* @param contents The {@link Transferable} which holds the clipboard contents
* @return {@link MyClipboardContent} containing clipboard contents
*/
MyClipboardContent<?> getClipboardContents(Transferable contents) {
MyClipboardContent<?> myClipboardContent = new MyClipboardContent<>(); MyClipboardContent<?> myClipboardContent = new MyClipboardContent<>();
try { try {
if (TEXT.isAvailable(clipboard)) { if (contents.isDataFlavorSupported(TEXT.getDataFlavor())) {
myClipboardContent.setOldContent(contents.getTransferData(TEXT.getDataFlavor())); myClipboardContent.setOldContent(contents.getTransferData(TEXT.getDataFlavor()));
} else if (IMAGE.isAvailable(clipboard)) { } else if (contents.isDataFlavorSupported(IMAGE.getDataFlavor())) {
BufferedImage bufferedImage = convertToBufferedImage((Image) contents.getTransferData(IMAGE.getDataFlavor())); BufferedImage bufferedImage = convertToBufferedImage((Image) contents.getTransferData(IMAGE.getDataFlavor()));
Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight()); Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight());
myClipboardContent.setOldContent(new OldImage(bufferedImage, imageDimension)); myClipboardContent.setOldContent(new OldImage(bufferedImage, imageDimension));
} else if (FILELIST.isAvailable(clipboard)) { } else if (contents.isDataFlavorSupported(FILELIST.getDataFlavor())) {
myClipboardContent.setOldContent(contents.getTransferData(FILELIST.getDataFlavor())); myClipboardContent.setOldContent(contents.getTransferData(FILELIST.getDataFlavor()));
} }
} catch (UnsupportedFlavorException | IOException exp) { } catch (UnsupportedFlavorException | IOException exp) {

@ -25,7 +25,7 @@ class MacClipboardListener extends ClipboardListener implements Runnable {
MacClipboardListener() { MacClipboardListener() {
super(); super();
Transferable oldClipboardContents = clipboard.getContents(null); Transferable oldClipboardContents = clipboard.getContents(null);
myClipboardContents = new MyClipboardContent[] { clipboardUtils.getClipboardContents(oldClipboardContents, clipboard) }; myClipboardContents = new MyClipboardContent[] { clipboardUtils.getClipboardContents(oldClipboardContents) };
} }
/** /**

Loading…
Cancel
Save