5830N/A/*
5830N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
5830N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5830N/A *
5830N/A * This code is free software; you can redistribute it and/or modify it
5830N/A * under the terms of the GNU General Public License version 2 only, as
5830N/A * published by the Free Software Foundation.
5830N/A *
5830N/A * This code is distributed in the hope that it will be useful, but WITHOUT
5830N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5830N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
5830N/A * version 2 for more details (a copy is included in the LICENSE file that
5830N/A * accompanied this code).
5830N/A *
5830N/A * You should have received a copy of the GNU General Public License version
5830N/A * 2 along with this work; if not, write to the Free Software Foundation,
5830N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5830N/A *
5830N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5830N/A * or visit www.oracle.com if you need additional information or have any
5830N/A * questions.
5830N/A */
5830N/A
5830N/A/* @test
5830N/A @bug 6877495
5830N/A @summary JTextField and JTextArea does not support supplementary characters
5830N/A @author Alexander Scherbatiy
5830N/A @run main SuplementaryCharactersTransferTest
5830N/A*/
5830N/A
5830N/A
5830N/Aimport java.io.*;
5830N/Aimport java.util.*;
5830N/Aimport java.awt.*;
5830N/Aimport java.awt.datatransfer.*;
5830N/Aimport sun.awt.datatransfer.*;
5830N/Aimport sun.awt.datatransfer.DataTransferer.ReencodingInputStream;
5830N/A
5830N/Apublic class SuplementaryCharactersTransferTest {
5830N/A
5830N/A public static final long TEXT_FORMAT = 13;
5830N/A
5830N/A public static void main(String[] args) throws Exception {
5830N/A
5830N/A DataTransferer dataTransferer = new TestDataTransferer();
5830N/A dataTransferer.registerTextFlavorProperties("UNICODE TEXT", "utf-16le", "\r\n", "2");
5830N/A ByteTransferable transferable = new ByteTransferable();
5830N/A ReencodingInputStream is = dataTransferer.new ReencodingInputStream(transferable.getByteInputStream(), TEXT_FORMAT,
5830N/A DataTransferer.getTextCharset(transferable.getDataFlavor()), transferable);
5830N/A
5830N/A byte[] bytes = transferable.getBytes();
5830N/A byte[] result = new byte[bytes.length];
5830N/A
5830N/A is.read(result);
5830N/A
5830N/A for (int i = 0; i < bytes.length; i++) {
5830N/A if (bytes[i] != result[i]) {
5830N/A throw new RuntimeException("Characters are not equal!");
5830N/A }
5830N/A }
5830N/A
5830N/A }
5830N/A
5830N/A static class ByteTransferable implements Transferable, ClipboardOwner {
5830N/A
5830N/A private final DataFlavor dataFlavor;
5830N/A
5830N/A public ByteTransferable() throws Exception {
5830N/A dataFlavor = DataFlavor.getTextPlainUnicodeFlavor();
5830N/A }
5830N/A
5830N/A public DataFlavor getDataFlavor() {
5830N/A return dataFlavor;
5830N/A }
5830N/A
5830N/A public DataFlavor[] getTransferDataFlavors() {
5830N/A return new DataFlavor[]{dataFlavor};
5830N/A }
5830N/A
5830N/A public boolean isDataFlavorSupported(DataFlavor flavor) {
5830N/A return flavor.equals(dataFlavor);
5830N/A }
5830N/A
5830N/A public byte[] getBytes() {
5830N/A return new byte[]{97, 0, 64, -40, 32, -36, 98, 0};
5830N/A }
5830N/A
5830N/A public InputStream getByteInputStream() {
5830N/A return new ByteArrayInputStream(getBytes());
5830N/A }
5830N/A
5830N/A public Object getTransferData(DataFlavor flavor)
5830N/A throws UnsupportedFlavorException, IOException {
5830N/A if (flavor.equals(dataFlavor)) {
5830N/A return getByteInputStream();
5830N/A } else {
5830N/A throw new UnsupportedFlavorException(flavor);
5830N/A }
5830N/A }
5830N/A
5830N/A public void lostOwnership(Clipboard clipboard, Transferable contents) {
5830N/A }
5830N/A }
5830N/A
5830N/A static class TestDataTransferer extends DataTransferer {
5830N/A
5830N/A @Override
5830N/A public String getDefaultUnicodeEncoding() {
5830N/A throw new UnsupportedOperationException("Not supported yet.");
5830N/A }
5830N/A
5830N/A @Override
5830N/A public boolean isLocaleDependentTextFormat(long format) {
5830N/A return false;
5830N/A }
5830N/A
5830N/A @Override
5830N/A public boolean isFileFormat(long format) {
5830N/A throw new UnsupportedOperationException("Not supported yet.");
5830N/A }
5830N/A
5830N/A @Override
5830N/A public boolean isImageFormat(long format) {
5830N/A throw new UnsupportedOperationException("Not supported yet.");
5830N/A }
5830N/A
5830N/A @Override
5830N/A protected Long getFormatForNativeAsLong(String str) {
5830N/A return TEXT_FORMAT;
5830N/A }
5830N/A
5830N/A @Override
5830N/A protected String getNativeForFormat(long format) {
5830N/A throw new UnsupportedOperationException("Not supported yet.");
5830N/A }
5830N/A
5830N/A @Override
5830N/A protected ByteArrayOutputStream convertFileListToBytes(
5830N/A ArrayList<String> fileList) throws IOException {
5830N/A throw new UnsupportedOperationException("Not supported yet.");
5830N/A }
5830N/A
5830N/A @Override
5830N/A protected String[] dragQueryFile(byte[] bytes) {
5830N/A throw new UnsupportedOperationException("Not supported yet.");
5830N/A }
5830N/A
5830N/A @Override
5830N/A protected Image platformImageBytesOrStreamToImage(InputStream str,
5830N/A byte[] bytes, long format) throws IOException {
5830N/A throw new UnsupportedOperationException("Not supported yet.");
5830N/A }
5830N/A
5830N/A @Override
5830N/A protected byte[] imageToPlatformBytes(Image image, long format)
5830N/A throws IOException {
5830N/A throw new UnsupportedOperationException("Not supported yet.");
5830N/A }
5830N/A
5830N/A @Override
5830N/A public ToolkitThreadBlockedHandler getToolkitThreadBlockedHandler() {
5830N/A throw new UnsupportedOperationException("Not supported yet.");
5830N/A }
5830N/A }
5830N/A}