import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.ClipboardOwner; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.DataFlavor; import java.awt.Toolkit; class ClipboardApi implements Transferable, ClipboardOwner { private static final ClipboardApi instance = new ClipboardApi(); private static String string; // ---%-@-%--- public static void serve(String string) { assert string != null; instance.string = string; Toolkit tk = Toolkit.getDefaultToolkit(); Clipboard cb = tk.getSystemClipboard(); cb.setContents(instance, instance); } // - -%- - public String getTransferData(DataFlavor flavour) { assert flavour == DataFlavor.stringFlavor; return string; } public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { DataFlavor.stringFlavor }; /* * We should probably also support javaJVMLocalObjectMimeType, * so that the compose window can ask for the List. * Although also like, if we don't store emoji shortcodes in * the image segments, there is no point. Anyways, what is * important is the string format first, allowing us to * copy links or large lengths of text. */ } public boolean isDataFlavorSupported(DataFlavor flavour) { return flavour == DataFlavor.stringFlavor; } public void lostOwnership(Clipboard clipboard, Transferable contents) { } }