1313 *******************************************************************************/
1414package org .eclipse .swt .dnd ;
1515
16+ import java .util .concurrent .*;
1617
1718import org .eclipse .swt .*;
1819import org .eclipse .swt .internal .cocoa .*;
@@ -199,6 +200,10 @@ public void dispose () {
199200 * clipboard. Refer to the specific subclass of <code>Transfer</code> to
200201 * determine the type of object returned.
201202 *
203+ * <p>This method may iterate the event loop to be able to complete. Use
204+ * {@link #getContentsAsync(Transfer)} to have control over when the event
205+ * loop runs.</p>
206+ *
202207 * <p>The following snippet shows text and RTF text being retrieved from the
203208 * clipboard:</p>
204209 *
@@ -225,6 +230,7 @@ public void dispose () {
225230 * </ul>
226231 *
227232 * @see Transfer
233+ * @see #getContentsAsync(Transfer)
228234 */
229235public Object getContents (Transfer transfer ) {
230236 return getContents (transfer , DND .CLIPBOARD );
@@ -235,6 +241,10 @@ public Object getContents(Transfer transfer) {
235241 * clipboard. Refer to the specific subclass of <code>Transfer</code> to
236242 * determine the type of object returned.
237243 *
244+ * <p>This method may iterate the event loop to be able to complete. Use
245+ * {@link #getContentsAsync(Transfer, int)} to have control over when the event
246+ * loop runs.</p>
247+ *
238248 * <p>The following snippet shows text and RTF text being retrieved from the
239249 * clipboard:</p>
240250 *
@@ -270,6 +280,7 @@ public Object getContents(Transfer transfer) {
270280 * @see Transfer
271281 * @see DND#CLIPBOARD
272282 * @see DND#SELECTION_CLIPBOARD
283+ * @see #getContentsAsync(Transfer, int)
273284 *
274285 * @since 3.1
275286 */
@@ -308,6 +319,90 @@ public Object getContents(Transfer transfer, int clipboards) {
308319 return null ;
309320}
310321
322+ /**
323+ * Retrieve the data of the specified type currently available on the system
324+ * clipboard. Refer to the specific subclass of <code>Transfer</code> to
325+ * determine the type of object returned.
326+ *
327+ * <p>This method is asynchronous and may require the SWT event loop to
328+ * iterate before the future will complete.</p>
329+ *
330+ * <p>The following snippet shows text being retrieved from the clipboard:</p>
331+ *
332+ * <pre><code>
333+ * Clipboard clipboard = new Clipboard(display);
334+ * TextTransfer textTransfer = TextTransfer.getInstance();
335+ * CompletableFuture<Object> future = clipboard.getContentsAsync(textTransfer);
336+ * future.thenAccept(textData -> System.out.println("Text is "+textData));
337+ * clipboard.dispose();
338+ * </code></pre>
339+ *
340+ * @param transfer the transfer agent for the type of data being requested
341+ * @return the future whose value will resolve to the data obtained from the
342+ * clipboard or will resolve to null if no data of this type is available
343+ *
344+ * @exception SWTException <ul>
345+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
346+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
347+ * </ul>
348+ * @exception IllegalArgumentException <ul>
349+ * <li>ERROR_NULL_ARGUMENT - if transfer is null</li>
350+ * </ul>
351+ *
352+ * @see Transfer
353+ * @since 3.132
354+ */
355+ public CompletableFuture <Object > getContentsAsync (Transfer transfer ) {
356+ return getContentsAsync (transfer , DND .CLIPBOARD );
357+ }
358+
359+ /**
360+ * Retrieve the data of the specified type currently available on the specified
361+ * clipboard. Refer to the specific subclass of <code>Transfer</code> to
362+ * determine the type of object returned.
363+ *
364+ * <p>This method is asynchronous and may require the SWT event loop to
365+ * iterate before the future will complete.</p>
366+ *
367+ * <p>The following snippet shows text being retrieved from the clipboard:</p>
368+ *
369+ * <pre><code>
370+ * Clipboard clipboard = new Clipboard(display);
371+ * TextTransfer textTransfer = TextTransfer.getInstance();
372+ * CompletableFuture<Object> future = clipboard.getContentsAsync(textTransfer, DND.CLIPBOARD);
373+ * future.thenAccept(textData -> System.out.println("Text is "+textData));
374+ * clipboard.dispose();
375+ * </code></pre>
376+ *
377+ * <p>The clipboards value is either one of the clipboard constants defined in
378+ * class <code>DND</code>, or must be built by <em>bitwise OR</em>'ing together
379+ * (that is, using the <code>int</code> "|" operator) two or more
380+ * of those <code>DND</code> clipboard constants.</p>
381+ *
382+ * @param transfer the transfer agent for the type of data being requested
383+ * @param clipboards on which to look for data
384+ *
385+ * @return the future whose value will resolve to the data obtained from the
386+ * clipboard or will resolve to null if no data of this type is available
387+ *
388+ * @exception SWTException <ul>
389+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
390+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
391+ * </ul>
392+ * @exception IllegalArgumentException <ul>
393+ * <li>ERROR_NULL_ARGUMENT - if transfer is null</li>
394+ * </ul>
395+ *
396+ * @see Transfer
397+ * @see DND#CLIPBOARD
398+ * @see DND#SELECTION_CLIPBOARD
399+ *
400+ * @since 3.132
401+ */
402+ public CompletableFuture <Object > getContentsAsync (Transfer transfer , int clipboards ) {
403+ return CompletableFuture .completedFuture (getContents (transfer , clipboards ));
404+ }
405+
311406/**
312407 * Returns <code>true</code> if the clipboard has been disposed,
313408 * and <code>false</code> otherwise.
0 commit comments