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

Print this page




 133                 contentsContext.removePropertyChangeListener
 134                     (AppContext.DISPOSED_PROPERTY_NAME, this);
 135             }
 136             contentsContext = context;
 137         }
 138     }
 139 
 140     public synchronized Transferable getContents(Object requestor) {
 141         if (contents != null) {
 142             return contents;
 143         }
 144         return new ClipboardTransferable(this);
 145     }
 146 
 147 
 148     /**
 149      * @return the contents of this clipboard if it has been set from the same
 150      *         AppContext as it is currently retrieved or null otherwise
 151      * @since 1.5
 152      */
 153     private synchronized Transferable getContextContents() {
 154         AppContext context = AppContext.getAppContext();
 155         return (context == contentsContext) ? contents : null;
 156     }
 157 
 158 
 159     /**
 160      * @see java.awt.Clipboard#getAvailableDataFlavors
 161      * @since 1.5
 162      */
 163     public DataFlavor[] getAvailableDataFlavors() {
 164         Transferable cntnts = getContextContents();
 165         if (cntnts != null) {
 166             return cntnts.getTransferDataFlavors();
 167         }
 168 
 169         long[] formats = getClipboardFormatsOpenClose();
 170 
 171         return DataTransferer.getInstance().
 172             getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable());
 173     }


 264     protected void lostOwnershipImpl() {
 265         lostOwnershipLater(null);
 266     }
 267 
 268     /**
 269      * Clears the clipboard state (contents, owner and contents context) and
 270      * notifies the current owner that ownership is lost. Does nothing if the
 271      * argument is not <code>null</code> and is not equal to the current
 272      * contents context.
 273      *
 274      * @param disposedContext the AppContext that is disposed or
 275      *        <code>null</code> if the ownership is lost because another
 276      *        application acquired ownership.
 277      */
 278     protected void lostOwnershipLater(final AppContext disposedContext) {
 279         final AppContext context = this.contentsContext;
 280         if (context == null) {
 281             return;
 282         }
 283 
 284         final Runnable runnable = new Runnable() {
 285                 public void run() {



 286                     final SunClipboard sunClipboard = SunClipboard.this;
 287                     ClipboardOwner owner = null;
 288                     Transferable contents = null;
 289 
 290                     synchronized (sunClipboard) {
 291                         final AppContext context = sunClipboard.contentsContext;
 292 
 293                         if (context == null) {
 294                             return;
 295                         }
 296 
 297                         if (disposedContext == null || context == disposedContext) {
 298                             owner = sunClipboard.owner;
 299                             contents = sunClipboard.contents;
 300                             sunClipboard.contentsContext = null;
 301                             sunClipboard.owner = null;
 302                             sunClipboard.contents = null;
 303                             sunClipboard.clearNativeContext();
 304                             context.removePropertyChangeListener
 305                                 (AppContext.DISPOSED_PROPERTY_NAME, sunClipboard);
 306                         } else {
 307                             return;
 308                         }
 309                     }
 310                     if (owner != null) {
 311                         owner.lostOwnership(sunClipboard, contents);
 312                     }
 313                 }
 314             };
 315 
 316         SunToolkit.postEvent(context, new PeerEvent(this, runnable,
 317                                                     PeerEvent.PRIORITY_EVENT));
 318     }
 319 
 320     protected abstract void clearNativeContext();
 321 
 322     protected abstract void setContentsNative(Transferable contents);
 323 
 324     /**
 325      * @since 1.5
 326      */
 327     protected long[] getClipboardFormatsOpenClose() {
 328         try {
 329             openClipboard(null);
 330             return getClipboardFormats();
 331         } finally {
 332             closeClipboard();
 333         }
 334     }
 335 
 336     /**
 337      * Returns zero-length array (not null) if the number of available formats is zero.
 338      *




 133                 contentsContext.removePropertyChangeListener
 134                     (AppContext.DISPOSED_PROPERTY_NAME, this);
 135             }
 136             contentsContext = context;
 137         }
 138     }
 139 
 140     public synchronized Transferable getContents(Object requestor) {
 141         if (contents != null) {
 142             return contents;
 143         }
 144         return new ClipboardTransferable(this);
 145     }
 146 
 147 
 148     /**
 149      * @return the contents of this clipboard if it has been set from the same
 150      *         AppContext as it is currently retrieved or null otherwise
 151      * @since 1.5
 152      */
 153     protected synchronized Transferable getContextContents() {
 154         AppContext context = AppContext.getAppContext();
 155         return (context == contentsContext) ? contents : null;
 156     }
 157 
 158 
 159     /**
 160      * @see java.awt.Clipboard#getAvailableDataFlavors
 161      * @since 1.5
 162      */
 163     public DataFlavor[] getAvailableDataFlavors() {
 164         Transferable cntnts = getContextContents();
 165         if (cntnts != null) {
 166             return cntnts.getTransferDataFlavors();
 167         }
 168 
 169         long[] formats = getClipboardFormatsOpenClose();
 170 
 171         return DataTransferer.getInstance().
 172             getFlavorsForFormatsAsArray(formats, getDefaultFlavorTable());
 173     }


 264     protected void lostOwnershipImpl() {
 265         lostOwnershipLater(null);
 266     }
 267 
 268     /**
 269      * Clears the clipboard state (contents, owner and contents context) and
 270      * notifies the current owner that ownership is lost. Does nothing if the
 271      * argument is not <code>null</code> and is not equal to the current
 272      * contents context.
 273      *
 274      * @param disposedContext the AppContext that is disposed or
 275      *        <code>null</code> if the ownership is lost because another
 276      *        application acquired ownership.
 277      */
 278     protected void lostOwnershipLater(final AppContext disposedContext) {
 279         final AppContext context = this.contentsContext;
 280         if (context == null) {
 281             return;
 282         }
 283 
 284         SunToolkit.postEvent(context, new PeerEvent(this, () -> lostOwnershipNow(disposedContext),
 285                                                     PeerEvent.PRIORITY_EVENT));
 286     }
 287 
 288     protected void lostOwnershipNow(final AppContext disposedContext) {
 289         final SunClipboard sunClipboard = SunClipboard.this;
 290         ClipboardOwner owner = null;
 291         Transferable contents = null;
 292 
 293         synchronized (sunClipboard) {
 294             final AppContext context = sunClipboard.contentsContext;
 295 
 296             if (context == null) {
 297                 return;
 298             }
 299 
 300             if (disposedContext == null || context == disposedContext) {
 301                 owner = sunClipboard.owner;
 302                 contents = sunClipboard.contents;
 303                 sunClipboard.contentsContext = null;
 304                 sunClipboard.owner = null;
 305                 sunClipboard.contents = null;
 306                 sunClipboard.clearNativeContext();
 307                 context.removePropertyChangeListener
 308                         (AppContext.DISPOSED_PROPERTY_NAME, sunClipboard);
 309             } else {
 310                 return;
 311             }
 312         }
 313         if (owner != null) {
 314             owner.lostOwnership(sunClipboard, contents);
 315         }
 316     }

 317 



 318 
 319     protected abstract void clearNativeContext();
 320 
 321     protected abstract void setContentsNative(Transferable contents);
 322 
 323     /**
 324      * @since 1.5
 325      */
 326     protected long[] getClipboardFormatsOpenClose() {
 327         try {
 328             openClipboard(null);
 329             return getClipboardFormats();
 330         } finally {
 331             closeClipboard();
 332         }
 333     }
 334 
 335     /**
 336      * Returns zero-length array (not null) if the number of available formats is zero.
 337      *