Use custom OldImage instead of BufferedImage

MYC-Refactor
Hammy 3 years ago
parent 792eda1c53
commit 4c84c77197

@ -12,12 +12,16 @@ import java.io.IOException;
import java.util.List; import java.util.List;
import me.goudham.domain.MyClipboardContent; 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.LoggerFactory;
import static me.goudham.domain.Contents.FILELIST; import static me.goudham.domain.Contents.FILELIST;
import static me.goudham.domain.Contents.IMAGE; import static me.goudham.domain.Contents.IMAGE;
import static me.goudham.domain.Contents.TEXT; import static me.goudham.domain.Contents.TEXT;
class ClipboardUtils { class ClipboardUtils {
protected static Logger logger = LoggerFactory.getLogger(ClipboardUtils.class);
/** /**
* Try to unmarshal {@link Transferable} into {@link String} * Try to unmarshal {@link Transferable} into {@link String}
@ -34,6 +38,7 @@ class ClipboardUtils {
} }
} catch (UnsupportedFlavorException | IOException exp) { } catch (UnsupportedFlavorException | IOException exp) {
exp.printStackTrace(); exp.printStackTrace();
logger.info("Exception Thrown When Receiving String Content", exp);
} }
return newContent; return newContent;
@ -87,8 +92,8 @@ class ClipboardUtils {
myClipboardContent.setOldContent(contents.getTransferData(TEXT.getDataFlavor())); myClipboardContent.setOldContent(contents.getTransferData(TEXT.getDataFlavor()));
} else if (IMAGE.isAvailable(clipboard)) { } else if (IMAGE.isAvailable(clipboard)) {
BufferedImage bufferedImage = convertToBufferedImage((Image) contents.getTransferData(IMAGE.getDataFlavor())); BufferedImage bufferedImage = convertToBufferedImage((Image) contents.getTransferData(IMAGE.getDataFlavor()));
myClipboardContent.setOldContent(bufferedImage); Dimension imageDimension = new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight());
myClipboardContent.setOldDimensionContent(new Dimension(bufferedImage.getWidth(), bufferedImage.getHeight())); myClipboardContent.setOldContent(new OldImage(bufferedImage, imageDimension));
} else if (FILELIST.isAvailable(clipboard)) { } else if (FILELIST.isAvailable(clipboard)) {
myClipboardContent.setOldContent(contents.getTransferData(FILELIST.getDataFlavor())); myClipboardContent.setOldContent(contents.getTransferData(FILELIST.getDataFlavor()));
} }
@ -122,8 +127,8 @@ class ClipboardUtils {
if (object instanceof String) { if (object instanceof String) {
oldClipboardContent = new OldClipboardContent((String) object); oldClipboardContent = new OldClipboardContent((String) object);
} else if (object instanceof BufferedImage) { } else if (object instanceof OldImage) {
oldClipboardContent = new OldClipboardContent((BufferedImage) object); oldClipboardContent = new OldClipboardContent(((OldImage) object).getOldBufferedImage());
} else if (object instanceof List) { } else if (object instanceof List) {
oldClipboardContent = new OldClipboardContent((List<File>) object); oldClipboardContent = new OldClipboardContent((List<File>) object);
} }

Loading…
Cancel
Save