X-Git-Url: http://git.nikiroo.be/?a=blobdiff_plain;f=src%2Fjexer%2Fbits%2FClipboard.java;h=5c1ea9aa3efca5d12a8b7ddade2f139e64df4662;hb=d3ab274f9152618a8bc21a0a20caed1a8520b224;hp=114a732bee12d824318c2b4a5dddca7220500e80;hpb=54eaded07d2c1c37d9e1000abdcc97be09955867;p=nikiroo-utils.git diff --git a/src/jexer/bits/Clipboard.java b/src/jexer/bits/Clipboard.java index 114a732..5c1ea9a 100644 --- a/src/jexer/bits/Clipboard.java +++ b/src/jexer/bits/Clipboard.java @@ -62,6 +62,62 @@ public class Clipboard { */ private java.awt.datatransfer.Clipboard systemClipboard = null; + /** + * The image selection class. + */ + private ImageSelection imageSelection; + + /** + * ImageSelection is used to hold an image while on the clipboard. + */ + private class ImageSelection implements Transferable { + + /** + * Returns an array of DataFlavor objects indicating the flavors the + * data can be provided in. The array should be ordered according to + * preference for providing the data (from most richly descriptive to + * least descriptive). + * + * @return an array of data flavors in which this data can be + * transferred + */ + public DataFlavor[] getTransferDataFlavors() { + return new DataFlavor[] { DataFlavor.imageFlavor }; + } + + /** + * Returns whether or not the specified data flavor is supported for + * this object. + * + * @param flavor the requested flavor for the data + * @return boolean indicating whether or not the data flavor is + * supported + */ + public boolean isDataFlavorSupported(DataFlavor flavor) { + return DataFlavor.imageFlavor.equals(flavor); + } + + /** + * Returns an object which represents the data to be transferred. The + * class of the object returned is defined by the representation + * class of the flavor. + * + * @param flavor the requested flavor for the data + * @throws IOException if the data is no longer available in the + * requested flavor. + * @throws UnsupportedFlavorException if the requested data flavor is + * not supported. + */ + public Object getTransferData(DataFlavor flavor) + throws UnsupportedFlavorException, IOException { + + if (!DataFlavor.imageFlavor.equals(flavor)) { + throw new UnsupportedFlavorException(flavor); + } + return image; + } + } + // ------------------------------------------------------------------------ // Constructors ----------------------------------------------------------- // ------------------------------------------------------------------------ @@ -89,7 +145,8 @@ public class Clipboard { public void copyImage(final BufferedImage image) { this.image = image; if (systemClipboard != null) { - // TODO + ImageSelection imageSelection = new ImageSelection(); + systemClipboard.setContents(imageSelection, null); } }