/* copyright This file is part of JKomasto2. Written in 2022 by Usawashi This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . copyright */ 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) { } }