< prev index next >

modules/graphics/src/main/java/javafx/scene/input/Clipboard.java

Print this page


   1 /*
   2  * Copyright (c) 2000, 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.  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 javafx.scene.input;
  27 

  28 import java.io.File;
  29 import java.security.AccessControlContext;
  30 import java.security.AccessController;
  31 import java.security.Permission;
  32 import java.util.List;
  33 import java.util.Map;
  34 import java.util.Set;
  35 
  36 import javafx.scene.image.Image;
  37 import javafx.util.Pair;
  38 
  39 import com.sun.javafx.tk.PermissionHelper;
  40 import com.sun.javafx.tk.TKClipboard;
  41 import com.sun.javafx.tk.Toolkit;
  42 
  43 /**
  44  * Represents an operating system clipboard, on which data may be placed during, for
  45  * example, cut, copy, and paste operations.
  46  * <p>
  47  * To access the general system clipboard, use the following code:


 103  * The DataFormat class defines an immutable object, and there are a number of static final
 104  * fields for common DataFormat types. Of course application specific DataFormat types can also be
 105  * declared and used. The following two methods are equivalent (and the second call
 106  * will override the first!)
 107  * <pre><code>
 108  *     ClipboardContent content = new ClipboardContent();
 109  *     content.putString("some text");
 110  *     content.put(DataFormat.PLAIN_TEXT, "other text");
 111  * </pre></code>
 112  * <p>
 113  * On embedded platforms that do not have their own windowing system, the
 114  * Clipboard returned from Clipboard.getSystemClipboard() might not be
 115  * accessible from outside the JavaFX application. In this case, the clipboard
 116  * returned by Clipboard.getSystemClipboard() can be used for exchange of data
 117  * between different parts of one JavaFX application but cannot be used to
 118  * exchange data between multiple applications.
 119  * @since JavaFX 2.0
 120  */
 121 public class Clipboard {
 122 












 123     /**
 124      * Whether user has put something on this clipboard. Needed for DnD.
 125      */
 126     private boolean contentPut = false;
 127 
 128     // future:
 129     /*
 130      * JavaFX supports the concept of multiple independently named clipboards. There is a
 131      * predefined clipboard which represents the main system clipboard, but it is possible
 132      * to create custom clipboards if you so desire. Some platforms, such as Mac OS X,
 133      * define a number of different named clipboards. You can access these from JavaFX by
 134      * simply creating a Clipboard with the correct name. Typically there is no need to do
 135      * so in your applications since the UI Controls will use the correct System clipboards,
 136      * if applicable.
 137      * <p>
 138      *
 139      * Sometimes you may want to put a reference to a data representation on the clipboard
 140      *
 141      * rather than the data itself. For example, the user may have selected a large block of
 142      * text, and wants to copy this to the clipboard. Instead of having to actually produce


 379      * Gets whether an List of Files (DataFormat.FILES) has been registered
 380      * on this Clipboard.
 381      * @return true if hasContent(DataFormat.FILES) returns true, false otherwise
 382      */
 383     public final boolean hasFiles() {
 384         return hasContent(DataFormat.FILES);
 385     }
 386 
 387     /**
 388      * Gets the List of Files from the clipboard which had previously
 389      * been registered. This is equivalent to invoking
 390      * <code>getContent(DataFormat.FILES)</code>. If no such entry exists,
 391      * null is returned.
 392      * @return The List of Files on the clipboard associated with DataFormat.FILES,
 393      * or null if there is not one.
 394      */
 395     public final List<File> getFiles() {
 396         return (List<File>) getContent(DataFormat.FILES);
 397     }
 398 
 399     /**
 400      * @treatAsPrivate implementation detail
 401      * @deprecated This is an internal API that is not intended for use and will be removed in the next version
 402      */
 403     @Deprecated
 404     public boolean impl_contentPut() {
 405         return contentPut;
 406     }
 407 
 408     private static Clipboard systemClipboard;
 409 
 410     private static synchronized Clipboard getSystemClipboardImpl() {
 411         if (systemClipboard == null) {
 412             systemClipboard =
 413                     new Clipboard(Toolkit.getToolkit().getSystemClipboard());
 414         }
 415         return systemClipboard;
 416     }
 417 
 418     private static Clipboard localClipboard;
 419 
 420     private static synchronized Clipboard getLocalClipboardImpl() {
 421         if (localClipboard == null) {
 422             localClipboard =
 423                     new Clipboard(Toolkit.getToolkit().createLocalClipboard());
 424         }
   1 /*
   2  * Copyright (c) 2000, 2016, 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 javafx.scene.input;
  27 
  28 import com.sun.javafx.scene.input.ClipboardHelper;
  29 import java.io.File;
  30 import java.security.AccessControlContext;
  31 import java.security.AccessController;
  32 import java.security.Permission;
  33 import java.util.List;
  34 import java.util.Map;
  35 import java.util.Set;
  36 
  37 import javafx.scene.image.Image;
  38 import javafx.util.Pair;
  39 
  40 import com.sun.javafx.tk.PermissionHelper;
  41 import com.sun.javafx.tk.TKClipboard;
  42 import com.sun.javafx.tk.Toolkit;
  43 
  44 /**
  45  * Represents an operating system clipboard, on which data may be placed during, for
  46  * example, cut, copy, and paste operations.
  47  * <p>
  48  * To access the general system clipboard, use the following code:


 104  * The DataFormat class defines an immutable object, and there are a number of static final
 105  * fields for common DataFormat types. Of course application specific DataFormat types can also be
 106  * declared and used. The following two methods are equivalent (and the second call
 107  * will override the first!)
 108  * <pre><code>
 109  *     ClipboardContent content = new ClipboardContent();
 110  *     content.putString("some text");
 111  *     content.put(DataFormat.PLAIN_TEXT, "other text");
 112  * </pre></code>
 113  * <p>
 114  * On embedded platforms that do not have their own windowing system, the
 115  * Clipboard returned from Clipboard.getSystemClipboard() might not be
 116  * accessible from outside the JavaFX application. In this case, the clipboard
 117  * returned by Clipboard.getSystemClipboard() can be used for exchange of data
 118  * between different parts of one JavaFX application but cannot be used to
 119  * exchange data between multiple applications.
 120  * @since JavaFX 2.0
 121  */
 122 public class Clipboard {
 123 
 124     static {
 125         // This is used by classes in different packages to get access to
 126         // private and package private methods.
 127         ClipboardHelper.setClipboardAccessor(new ClipboardHelper.ClipboardAccessor() {
 128 
 129             @Override
 130             public boolean contentPut(Clipboard clipboard) {
 131                 return clipboard.contentPut();
 132             }
 133         });
 134     }
 135 
 136     /**
 137      * Whether user has put something on this clipboard. Needed for DnD.
 138      */
 139     private boolean contentPut = false;
 140 
 141     // future:
 142     /*
 143      * JavaFX supports the concept of multiple independently named clipboards. There is a
 144      * predefined clipboard which represents the main system clipboard, but it is possible
 145      * to create custom clipboards if you so desire. Some platforms, such as Mac OS X,
 146      * define a number of different named clipboards. You can access these from JavaFX by
 147      * simply creating a Clipboard with the correct name. Typically there is no need to do
 148      * so in your applications since the UI Controls will use the correct System clipboards,
 149      * if applicable.
 150      * <p>
 151      *
 152      * Sometimes you may want to put a reference to a data representation on the clipboard
 153      *
 154      * rather than the data itself. For example, the user may have selected a large block of
 155      * text, and wants to copy this to the clipboard. Instead of having to actually produce


 392      * Gets whether an List of Files (DataFormat.FILES) has been registered
 393      * on this Clipboard.
 394      * @return true if hasContent(DataFormat.FILES) returns true, false otherwise
 395      */
 396     public final boolean hasFiles() {
 397         return hasContent(DataFormat.FILES);
 398     }
 399 
 400     /**
 401      * Gets the List of Files from the clipboard which had previously
 402      * been registered. This is equivalent to invoking
 403      * <code>getContent(DataFormat.FILES)</code>. If no such entry exists,
 404      * null is returned.
 405      * @return The List of Files on the clipboard associated with DataFormat.FILES,
 406      * or null if there is not one.
 407      */
 408     public final List<File> getFiles() {
 409         return (List<File>) getContent(DataFormat.FILES);
 410     }
 411 
 412     private boolean contentPut() {





 413         return contentPut;
 414     }
 415 
 416     private static Clipboard systemClipboard;
 417 
 418     private static synchronized Clipboard getSystemClipboardImpl() {
 419         if (systemClipboard == null) {
 420             systemClipboard =
 421                     new Clipboard(Toolkit.getToolkit().getSystemClipboard());
 422         }
 423         return systemClipboard;
 424     }
 425 
 426     private static Clipboard localClipboard;
 427 
 428     private static synchronized Clipboard getLocalClipboardImpl() {
 429         if (localClipboard == null) {
 430             localClipboard =
 431                     new Clipboard(Toolkit.getToolkit().createLocalClipboard());
 432         }
< prev index next >