src/share/classes/sun/awt/datatransfer/ClipboardTransferable.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 2005, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  80         try {
  81             long[] formats = clipboard.getClipboardFormats();
  82 
  83             if (formats != null && formats.length > 0) {
  84                 // Since the SystemFlavorMap will specify many DataFlavors
  85                 // which map to the same format, we should cache data as we
  86                 // read it.
  87                 HashMap cached_data = new HashMap(formats.length, 1.0f);
  88 
  89                 Map flavorsForFormats = DataTransferer.getInstance().
  90                     getFlavorsForFormats(formats, SunClipboard.flavorMap);
  91                 for (Iterator iter = flavorsForFormats.keySet().iterator();
  92                      iter.hasNext(); )
  93                 {
  94                     DataFlavor flavor = (DataFlavor)iter.next();
  95                     Long lFormat = (Long)flavorsForFormats.get(flavor);
  96 
  97                     fetchOneFlavor(clipboard, flavor, lFormat, cached_data);
  98                 }
  99 
 100                 flavors = DataTransferer.getInstance().
 101                     setToSortedDataFlavorArray(flavorsToData.keySet());
 102             }
 103         } finally {
 104             clipboard.closeClipboard();
 105         }
 106     }
 107 
 108     private boolean fetchOneFlavor(SunClipboard clipboard, DataFlavor flavor,
 109                                    Long lFormat, HashMap cached_data)
 110     {
 111         if (!flavorsToData.containsKey(flavor)) {
 112             long format = lFormat.longValue();
 113             Object data = null;
 114 
 115             if (!cached_data.containsKey(lFormat)) {
 116                 try {
 117                     data = clipboard.getClipboardData(format);
 118                 } catch (IOException e) {
 119                     data = e;
 120                 } catch (Throwable e) {
 121                     e.printStackTrace();


   1 /*
   2  * Copyright (c) 2000, 2014, 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.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  80         try {
  81             long[] formats = clipboard.getClipboardFormats();
  82 
  83             if (formats != null && formats.length > 0) {
  84                 // Since the SystemFlavorMap will specify many DataFlavors
  85                 // which map to the same format, we should cache data as we
  86                 // read it.
  87                 HashMap cached_data = new HashMap(formats.length, 1.0f);
  88 
  89                 Map flavorsForFormats = DataTransferer.getInstance().
  90                     getFlavorsForFormats(formats, SunClipboard.flavorMap);
  91                 for (Iterator iter = flavorsForFormats.keySet().iterator();
  92                      iter.hasNext(); )
  93                 {
  94                     DataFlavor flavor = (DataFlavor)iter.next();
  95                     Long lFormat = (Long)flavorsForFormats.get(flavor);
  96 
  97                     fetchOneFlavor(clipboard, flavor, lFormat, cached_data);
  98                 }
  99 
 100                 flavors = DataTransferer.setToSortedDataFlavorArray(flavorsToData.keySet());

 101             }
 102         } finally {
 103             clipboard.closeClipboard();
 104         }
 105     }
 106 
 107     private boolean fetchOneFlavor(SunClipboard clipboard, DataFlavor flavor,
 108                                    Long lFormat, HashMap cached_data)
 109     {
 110         if (!flavorsToData.containsKey(flavor)) {
 111             long format = lFormat.longValue();
 112             Object data = null;
 113 
 114             if (!cached_data.containsKey(lFormat)) {
 115                 try {
 116                     data = clipboard.getClipboardData(format);
 117                 } catch (IOException e) {
 118                     data = e;
 119                 } catch (Throwable e) {
 120                     e.printStackTrace();