Pastes from the clipboard and returns the pasted string. @return the pasted string, or null if none
(Consumer<String> whenDone)
| 2268 | * @return the pasted string, or null if none |
| 2269 | */ |
| 2270 | public static String paste(Consumer<String> whenDone) { |
| 2271 | if (isJS) { |
| 2272 | if (whenDone != null) |
| 2273 | jsutil.getClipboardText(whenDone); |
| 2274 | return null; |
| 2275 | } |
| 2276 | Transferable data = null; |
| 2277 | try { |
| 2278 | Clipboard clipboard = getClipboard(); |
| 2279 | data = clipboard.getContents(null); |
| 2280 | } catch (Exception e) { |
| 2281 | } |
| 2282 | if ((data != null) && data.isDataFlavorSupported(DataFlavor.stringFlavor)) { |
| 2283 | try { |
| 2284 | String s = (String) data.getTransferData(DataFlavor.stringFlavor); |
| 2285 | if (whenDone != null) |
| 2286 | whenDone.accept(s); |
| 2287 | return s; |
| 2288 | } catch (Exception ex) { |
| 2289 | ex.printStackTrace(); |
| 2290 | } |
| 2291 | } |
| 2292 | return null; |
| 2293 | } |
| 2294 | |
| 2295 | public static void copy(String s, ClipboardOwner owner) { |
| 2296 | StringSelection stringSelection = new StringSelection(s); |
no test coverage detected