Changeset 5221 in josm for trunk


Ignore:
Timestamp:
2012-05-08T01:59:53+02:00 (7 years ago)
Author:
Don-vip
Message:

should fix #7663 - Pasting in Windows gives "java.lang.IllegalStateException: cannot open system clipboard"

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r5159 r5221  
    2323import java.util.Iterator;
    2424import java.util.List;
    25 import org.openstreetmap.josm.data.osm.OsmPrimitive;
    2625
    2726/**
     
    327326     */
    328327    public static String getClipboardContent() {
    329         Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
     328        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     329        Transferable t = null;
     330        for (int tries = 0; t == null && tries < 10; tries++) {
     331            try {
     332                t = clipboard.getContents(null);
     333            } catch (IllegalStateException e) {
     334                // Clipboard currently unavailable. On some platforms, the system clipboard is unavailable while it is accessed by another application.
     335                try {
     336                    Thread.sleep(1);
     337                } catch (InterruptedException ex) {
     338                }
     339            }
     340        }
    330341        try {
    331342            if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
Note: See TracChangeset for help on using the changeset viewer.