5751N/A/*
5751N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
5751N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5751N/A *
5751N/A * This code is free software; you can redistribute it and/or modify it
5751N/A * under the terms of the GNU General Public License version 2 only, as
5751N/A * published by the Free Software Foundation.
5751N/A *
5751N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5751N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5751N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5751N/A * version 2 for more details (a copy is included in the LICENSE file that
5751N/A * accompanied this code).
5751N/A *
5751N/A * You should have received a copy of the GNU General Public License version
5751N/A * 2 along with this work; if not, write to the Free Software Foundation,
5751N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5751N/A *
5751N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5751N/A * or visit www.oracle.com if you need additional information or have any
5751N/A * questions.
5751N/A */
5751N/A
5751N/Aimport java.awt.datatransfer.*;
5751N/Aimport java.io.IOException;
5751N/A
5751N/Aclass MyTransferable implements Transferable {
5751N/A
5751N/A public static final String TEST_DATA = "<b>Test</b>";
5751N/A private DataFlavor[] dataFlavors;
5751N/A
5751N/A public MyTransferable() {
5751N/A dataFlavors = new DataFlavor[]{DataFlavorSearcher.getByteDataFlavorForNative(DataFlavorSearcher.HTML_NAMES),
5751N/A DataFlavorSearcher.getByteDataFlavorForNative(DataFlavorSearcher.RICH_TEXT_NAMES)};
5751N/A }
5751N/A
5751N/A
5751N/A @Override
5751N/A public DataFlavor[] getTransferDataFlavors() {
5751N/A return dataFlavors;
5751N/A }
5751N/A
5751N/A @Override
5751N/A public boolean isDataFlavorSupported(DataFlavor flavor) {
5751N/A for (DataFlavor f : dataFlavors) {
5751N/A if (f.equals(flavor)) {
5751N/A return true;
5751N/A }
5751N/A }
5751N/A return false;
5751N/A }
5751N/A
5751N/A @Override
5751N/A public Object getTransferData(DataFlavor flavor)
5751N/A throws UnsupportedFlavorException, IOException {
5751N/A if (isDataFlavorSupported(flavor)) {
5751N/A return TEST_DATA.getBytes("UTF-16");
5751N/A } else {
5751N/A throw new UnsupportedFlavorException(flavor);
5751N/A }
5751N/A }
5751N/A}