< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/WClipboard.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 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
  23  * questions.
  24  */
  25 
  26 package sun.awt.windows;
  27 
  28 import java.awt.datatransfer.DataFlavor;
  29 import java.awt.datatransfer.Transferable;
  30 import java.awt.datatransfer.UnsupportedFlavorException;
  31 import java.io.IOException;
  32 import java.util.Map;
  33 
  34 import sun.awt.datatransfer.DataTransferer;
  35 import sun.awt.datatransfer.SunClipboard;
  36 
  37 
  38 /**
  39  * A class which interfaces with the Windows clipboard in order to support
  40  * data transfer via Clipboard operations. Most of the work is provided by
  41  * sun.awt.datatransfer.DataTransferer.
  42  *
  43  * @author Tom Ball
  44  * @author David Mendenhall
  45  * @author Danila Sinopalnikov
  46  * @author Alexander Gerasimov
  47  *
  48  * @since 1.1
  49  */
  50 final class WClipboard extends SunClipboard {
  51 
  52     private boolean isClipboardViewerRegistered;
  53 


  54     WClipboard() {
  55         super("System");
  56     }
  57 
  58     @Override
  59     public long getID() {
  60         return 0;
  61     }
  62 
  63     @Override
  64     protected void setContentsNative(Transferable contents) {
  65         // Don't use delayed Clipboard rendering for the Transferable's data.
  66         // If we did that, we would call Transferable.getTransferData on
  67         // the Toolkit thread, which is a security hole.
  68         //
  69         // Get all of the target formats into which the Transferable can be
  70         // translated. Then, for each format, translate the data and post
  71         // it to the Clipboard.
  72         Map <Long, DataFlavor> formatMap = WDataTransferer.getInstance().
  73             getFormatsForTransferable(contents, getDefaultFlavorTable());
  74 
  75         openClipboard(this);
  76 
  77         try {
  78             for (Long format : formatMap.keySet()) {
  79                 DataFlavor flavor = formatMap.get(format);
  80 
  81                 try {
  82                     byte[] bytes = WDataTransferer.getInstance().
  83                         translateTransferable(contents, flavor, format);
  84                     publishClipboardData(format, bytes);
  85                 } catch (IOException e) {
  86                     // Fix 4696186: don't print exception if data with
  87                     // javaJVMLocalObjectMimeType failed to serialize.
  88                     // May remove this if-check when 5078787 is fixed.
  89                     if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
  90                           e instanceof java.io.NotSerializableException)) {
  91                         e.printStackTrace();
  92                     }
  93                 }
  94             }
  95         } finally {
  96             closeClipboard();
  97         }
  98     }
  99 
 100     private void lostSelectionOwnershipImpl() {
 101         lostOwnershipImpl();
 102     }
 103 
 104     /**
 105      * Currently delayed data rendering is not used for the Windows clipboard,
 106      * so there is no native context to clear.
 107      */
 108     @Override
 109     protected void clearNativeContext() {}
 110 
 111     /**


   1 /*
   2  * Copyright (c) 1996, 2020, 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
  23  * questions.
  24  */
  25 
  26 package sun.awt.windows;
  27 
  28 import java.awt.datatransfer.DataFlavor;
  29 import java.awt.datatransfer.Transferable;
  30 import java.awt.datatransfer.UnsupportedFlavorException;
  31 import java.io.IOException;
  32 import java.util.Map;
  33 
  34 import sun.awt.datatransfer.DataTransferer;
  35 import sun.awt.datatransfer.SunClipboard;
  36 import sun.util.logging.PlatformLogger;
  37 
  38 /**
  39  * A class which interfaces with the Windows clipboard in order to support
  40  * data transfer via Clipboard operations. Most of the work is provided by
  41  * sun.awt.datatransfer.DataTransferer.
  42  *
  43  * @author Tom Ball
  44  * @author David Mendenhall
  45  * @author Danila Sinopalnikov
  46  * @author Alexander Gerasimov
  47  *
  48  * @since 1.1
  49  */
  50 final class WClipboard extends SunClipboard {
  51 
  52     private boolean isClipboardViewerRegistered;
  53 
  54     private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.windows.WClipboard");
  55 
  56     WClipboard() {
  57         super("System");
  58     }
  59 
  60     @Override
  61     public long getID() {
  62         return 0;
  63     }
  64 
  65     @Override
  66     protected void setContentsNative(Transferable contents) {
  67         // Don't use delayed Clipboard rendering for the Transferable's data.
  68         // If we did that, we would call Transferable.getTransferData on
  69         // the Toolkit thread, which is a security hole.
  70         //
  71         // Get all of the target formats into which the Transferable can be
  72         // translated. Then, for each format, translate the data and post
  73         // it to the Clipboard.
  74         Map <Long, DataFlavor> formatMap = WDataTransferer.getInstance().
  75             getFormatsForTransferable(contents, getDefaultFlavorTable());
  76 
  77         openClipboard(this);
  78 
  79         try {
  80             for (Long format : formatMap.keySet()) {
  81                 DataFlavor flavor = formatMap.get(format);

  82                 try {
  83                     byte[] bytes = WDataTransferer.getInstance().
  84                         translateTransferable(contents, flavor, format);
  85                     publishClipboardData(format, bytes);
  86                 } catch (IOException e) {
  87                     if (log.isLoggable(PlatformLogger.Level.WARNING)) {
  88                         log.warning("Registered service providers failed to encode ", e);




  89                     }
  90                 }
  91             }
  92         } finally {
  93             closeClipboard();
  94         }
  95     }
  96 
  97     private void lostSelectionOwnershipImpl() {
  98         lostOwnershipImpl();
  99     }
 100 
 101     /**
 102      * Currently delayed data rendering is not used for the Windows clipboard,
 103      * so there is no native context to clear.
 104      */
 105     @Override
 106     protected void clearNativeContext() {}
 107 
 108     /**


< prev index next >