Changeset 8429 in josm
- Timestamp:
- 2015-05-26T21:30:33+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/TagEditHelper.java
r8426 r8429 468 468 // select combobox with saving unix system selection (middle mouse paste) 469 469 Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection(); 470 if (sysSel != null) {471 Transferable old = sysSel.getContents(null);470 if (sysSel != null) { 471 Transferable old = Utils.getTransferableContent(sysSel); 472 472 cb.requestFocusInWindow(); 473 473 cb.getEditor().selectAll(); -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingComboBox.java
r8268 r8429 26 26 import org.openstreetmap.josm.Main; 27 27 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 28 import org.openstreetmap.josm.tools.Utils; 28 29 29 30 /** … … 134 135 // save unix system selection (middle mouse paste) 135 136 Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection(); 136 if (sysSel != null) {137 Transferable old = sysSel.getContents(null);137 if (sysSel != null) { 138 Transferable old = Utils.getTransferableContent(sysSel); 138 139 editorComponent.select(start, end); 139 140 sysSel.setContents(old, null); … … 198 199 // save unix system selection (middle mouse paste) 199 200 Clipboard sysSel = Toolkit.getDefaultToolkit().getSystemSelection(); 200 if (sysSel != null) {201 Transferable old = sysSel.getContents(null);201 if (sysSel != null) { 202 Transferable old = Utils.getTransferableContent(sysSel); 202 203 editorComponent.selectAll(); 203 204 sysSel.setContents(old, null); -
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.