Changeset 8429 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2015-05-26T21:30:33+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/Utils.java
r8419 r8429 499 499 try { 500 500 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(s), new ClipboardOwner() { 501 502 501 @Override 503 502 public void lostOwnership(Clipboard clpbrd, Transferable t) { 503 // Do nothing 504 504 } 505 505 }); … … 512 512 513 513 /** 514 * Extracts clipboard content as string. 515 * @return string clipboard contents if available, {@code null} otherwise. 516 */ 517 public static String getClipboardContent() { 518 Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); 514 * Extracts clipboard content as {@code Transferable} object. 515 * @param clipboard clipboard from which contents are retrieved 516 * @return clipboard contents if available, {@code null} otherwise. 517 * @since 8429 518 */ 519 public static Transferable getTransferableContent(Clipboard clipboard) { 519 520 Transferable t = null; 520 521 for (int tries = 0; t == null && tries < 10; tries++) { … … 522 523 t = clipboard.getContents(null); 523 524 } catch (IllegalStateException e) { 524 // Clipboard currently unavailable. On some platforms, the system clipboard is unavailable while it is accessed by another application. 525 // Clipboard currently unavailable. 526 // On some platforms, the system clipboard is unavailable while it is accessed by another application. 525 527 try { 526 528 Thread.sleep(1); … … 528 530 Main.warn("InterruptedException in "+Utils.class.getSimpleName()+" while getting clipboard content"); 529 531 } 530 } 531 } 532 } catch (NullPointerException e) { 533 // JDK-6322854: On Linux/X11, NPE can happen for unknown reasons, on all versions of Java 534 Main.error(e); 535 } 536 } 537 return t; 538 } 539 540 /** 541 * Extracts clipboard content as string. 542 * @return string clipboard contents if available, {@code null} otherwise. 543 */ 544 public static String getClipboardContent() { 545 Transferable t = getTransferableContent(Toolkit.getDefaultToolkit().getSystemClipboard()); 532 546 try { 533 547 if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { … … 547 561 */ 548 562 public static String md5Hex(String data) { 549 byte[] byteData = data.getBytes(StandardCharsets.UTF_8);550 563 MessageDigest md = null; 551 564 try { … … 554 567 throw new RuntimeException(e); 555 568 } 569 byte[] byteData = data.getBytes(StandardCharsets.UTF_8); 556 570 byte[] byteDigest = md.digest(byteData); 557 571 return toHexString(byteDigest);
Note:
See TracChangeset
for help on using the changeset viewer.