Merge commit '7a455971fed716123933d0f685a0d6eebcf3282b'
[nikiroo-utils.git] / src / jexer / bits / Clipboard.java
index 114a732bee12d824318c2b4a5dddca7220500e80..5c1ea9aa3efca5d12a8b7ddade2f139e64df4662 100644 (file)
@@ -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);
         }
     }