src/share/classes/java/awt/datatransfer/Clipboard.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 2006, 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


  37 
  38 /**
  39  * A class that implements a mechanism to transfer data using
  40  * cut/copy/paste operations.
  41  * <p>
  42  * {@link FlavorListener}s may be registered on an instance of the
  43  * Clipboard class to be notified about changes to the set of
  44  * {@link DataFlavor}s available on this clipboard (see
  45  * {@link #addFlavorListener}).
  46  *
  47  * @see java.awt.Toolkit#getSystemClipboard
  48  * @see java.awt.Toolkit#getSystemSelection
  49  *
  50  * @author      Amy Fowler
  51  * @author      Alexander Gerasimov
  52  */
  53 public class Clipboard {
  54 
  55     String name;
  56 



  57     protected ClipboardOwner owner;



  58     protected Transferable contents;
  59 
  60     /**
  61      * An aggregate of flavor listeners registered on this local clipboard.
  62      *
  63      * @since 1.5
  64      */
  65     private EventListenerAggregate flavorListeners;
  66 
  67     /**
  68      * A set of <code>DataFlavor</code>s that is available on
  69      * this local clipboard. It is used for tracking changes
  70      * of <code>DataFlavor</code>s available on this clipboard.
  71      *
  72      * @since 1.5
  73      */
  74     private Set<DataFlavor> currentDataFlavors;
  75 
  76     /**
  77      * Creates a clipboard object.
  78      *
  79      * @see java.awt.Toolkit#getSystemClipboard
  80      */
  81     public Clipboard(String name) {
  82         this.name = name;
  83     }
  84 
  85     /**
  86      * Returns the name of this clipboard object.

  87      *
  88      * @see java.awt.Toolkit#getSystemClipboard
  89      */
  90     public String getName() {
  91         return name;
  92     }
  93 
  94     /**
  95      * Sets the current contents of the clipboard to the specified
  96      * transferable object and registers the specified clipboard owner
  97      * as the owner of the new contents.
  98      * <p>
  99      * If there is an existing owner different from the argument
 100      * <code>owner</code>, that owner is notified that it no longer
 101      * holds ownership of the clipboard contents via an invocation
 102      * of <code>ClipboardOwner.lostOwnership()</code> on that owner.
 103      * An implementation of <code>setContents()</code> is free not
 104      * to invoke <code>lostOwnership()</code> directly from this method.
 105      * For example, <code>lostOwnership()</code> may be invoked later on
 106      * a different thread. The same applies to <code>FlavorListener</code>s


   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


  37 
  38 /**
  39  * A class that implements a mechanism to transfer data using
  40  * cut/copy/paste operations.
  41  * <p>
  42  * {@link FlavorListener}s may be registered on an instance of the
  43  * Clipboard class to be notified about changes to the set of
  44  * {@link DataFlavor}s available on this clipboard (see
  45  * {@link #addFlavorListener}).
  46  *
  47  * @see java.awt.Toolkit#getSystemClipboard
  48  * @see java.awt.Toolkit#getSystemSelection
  49  *
  50  * @author      Amy Fowler
  51  * @author      Alexander Gerasimov
  52  */
  53 public class Clipboard {
  54 
  55     String name;
  56 
  57     /**
  58      * The owner of the clipboard.
  59      */
  60     protected ClipboardOwner owner;
  61     /**
  62      * Contents of the clipboard.
  63      */
  64     protected Transferable contents;
  65 
  66     /**
  67      * An aggregate of flavor listeners registered on this local clipboard.
  68      *
  69      * @since 1.5
  70      */
  71     private EventListenerAggregate flavorListeners;
  72 
  73     /**
  74      * A set of <code>DataFlavor</code>s that is available on
  75      * this local clipboard. It is used for tracking changes
  76      * of <code>DataFlavor</code>s available on this clipboard.
  77      *
  78      * @since 1.5
  79      */
  80     private Set<DataFlavor> currentDataFlavors;
  81 
  82     /**
  83      * Creates a clipboard object.
  84      * @param name for the clipboard
  85      * @see java.awt.Toolkit#getSystemClipboard
  86      */
  87     public Clipboard(String name) {
  88         this.name = name;
  89     }
  90 
  91     /**
  92      * Returns the name of this clipboard object.
  93      * @return the name of this clipboard object
  94      *
  95      * @see java.awt.Toolkit#getSystemClipboard
  96      */
  97     public String getName() {
  98         return name;
  99     }
 100 
 101     /**
 102      * Sets the current contents of the clipboard to the specified
 103      * transferable object and registers the specified clipboard owner
 104      * as the owner of the new contents.
 105      * <p>
 106      * If there is an existing owner different from the argument
 107      * <code>owner</code>, that owner is notified that it no longer
 108      * holds ownership of the clipboard contents via an invocation
 109      * of <code>ClipboardOwner.lostOwnership()</code> on that owner.
 110      * An implementation of <code>setContents()</code> is free not
 111      * to invoke <code>lostOwnership()</code> directly from this method.
 112      * For example, <code>lostOwnership()</code> may be invoked later on
 113      * a different thread. The same applies to <code>FlavorListener</code>s