ConstructFlavoredObjectTest.java revision 14851:980da45565c8
1/* 2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23import java.awt.Toolkit; 24import java.awt.datatransfer.Clipboard; 25import java.awt.datatransfer.DataFlavor; 26import java.awt.datatransfer.SystemFlavorMap; 27import java.io.IOException; 28import java.io.Reader; 29import javax.swing.JLabel; 30import javax.swing.TransferHandler; 31/* 32 * @test 33 * @key headful 34 * @bug 8130329 35 * @summary Audit Core Reflection in module java.desktop AWT/Miscellaneous area 36 * for places that will require changes to work with modules 37 * @author Alexander Scherbatiy 38 */ 39public class ConstructFlavoredObjectTest { 40 41 private static final String TEST_MIME_TYPE = "text/plain;class=" 42 + MyStringReader.class.getName(); 43 44 public static void main(String[] args) throws Exception { 45 46 final DataFlavor dataFlavor = new DataFlavor(TEST_MIME_TYPE); 47 SystemFlavorMap systemFlavorMap = (SystemFlavorMap) SystemFlavorMap. 48 getDefaultFlavorMap(); 49 systemFlavorMap.addUnencodedNativeForFlavor(dataFlavor, "TEXT"); 50 systemFlavorMap.addFlavorForUnencodedNative("TEXT", dataFlavor); 51 52 TransferHandler transferHandler = new TransferHandler("Test Handler"); 53 54 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 55 transferHandler.exportToClipboard(new JLabel("Test"), clipboard, 56 TransferHandler.COPY); 57 58 Object clipboardData = clipboard.getData(dataFlavor); 59 60 if (!(clipboardData instanceof MyStringReader)) { 61 throw new RuntimeException("Wrong clipboard data!"); 62 } 63 } 64 65 public static class MyStringReader extends Reader { 66 67 public MyStringReader(Reader reader) { 68 } 69 70 @Override 71 public int read(char[] cbuf, int off, int len) throws IOException { 72 throw new UnsupportedOperationException("Not supported yet."); 73 } 74 75 @Override 76 public void close() throws IOException { 77 throw new UnsupportedOperationException("Not supported yet."); 78 } 79 } 80} 81