Changeset 10604 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2016-07-23T14:54:19+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/TextTagParser.java
r10378 r10604 19 19 import org.openstreetmap.josm.Main; 20 20 import org.openstreetmap.josm.gui.ExtendedDialog; 21 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 21 22 import org.openstreetmap.josm.gui.help.HelpUtil; 22 23 import org.openstreetmap.josm.gui.widgets.UrlLabel; … … 291 292 if (r == 0) r = 2; 292 293 // clean clipboard if user asked 293 if (r == 3) Utils.copyToClipboard("");294 if (r == 3) ClipboardUtils.copyString(""); 294 295 return r; 295 296 } … … 326 327 int r = ed.getValue(); 327 328 // clean clipboard if user asked 328 if (r == 2) Utils.copyToClipboard("");329 if (r == 2) ClipboardUtils.copyString(""); 329 330 } 330 331 } -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r10600 r10604 8 8 import java.awt.Color; 9 9 import java.awt.Font; 10 import java.awt.HeadlessException;11 import java.awt.Toolkit;12 10 import java.awt.datatransfer.Clipboard; 13 import java.awt.datatransfer.ClipboardOwner;14 import java.awt.datatransfer.DataFlavor;15 import java.awt.datatransfer.StringSelection;16 11 import java.awt.datatransfer.Transferable; 17 import java.awt.datatransfer.UnsupportedFlavorException;18 12 import java.awt.font.FontRenderContext; 19 13 import java.awt.font.GlyphVector; … … 73 67 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; 74 68 import org.openstreetmap.josm.Main; 69 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 75 70 import org.w3c.dom.Document; 76 71 import org.xml.sax.InputSource; … … 645 640 * @param s string to be copied to clipboard. 646 641 * @return true if succeeded, false otherwise. 647 */ 642 * @deprecated Use {@link ClipboardUtils#copyString(String)}. To be removed end of 2016. 643 */ 644 @Deprecated 648 645 public static boolean copyToClipboard(String s) { 649 try { 650 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(s), new ClipboardOwner() { 651 @Override 652 public void lostOwnership(Clipboard clpbrd, Transferable t) { 653 // Do nothing 654 } 655 }); 656 return true; 657 } catch (IllegalStateException | HeadlessException ex) { 658 Main.error(ex); 659 return false; 660 } 646 return ClipboardUtils.copyString(s); 661 647 } 662 648 … … 666 652 * @return clipboard contents if available, {@code null} otherwise. 667 653 * @since 8429 668 */ 654 * @deprecated Use {@link ClipboardUtils#getClipboardContent(Clipboard)} instead. To be removed end of 2016. 655 */ 656 @Deprecated 669 657 public static Transferable getTransferableContent(Clipboard clipboard) { 670 Transferable t = null; 671 for (int tries = 0; t == null && tries < 10; tries++) { 672 try { 673 t = clipboard.getContents(null); 674 } catch (IllegalStateException e) { 675 // Clipboard currently unavailable. 676 // On some platforms, the system clipboard is unavailable while it is accessed by another application. 677 try { 678 Thread.sleep(1); 679 } catch (InterruptedException ex) { 680 Main.warn("InterruptedException in "+Utils.class.getSimpleName()+" while getting clipboard content"); 681 } 682 } catch (NullPointerException e) { 683 // JDK-6322854: On Linux/X11, NPE can happen for unknown reasons, on all versions of Java 684 Main.error(e); 685 } 686 } 687 return t; 658 return ClipboardUtils.getClipboardContent(clipboard); 688 659 } 689 660 … … 691 662 * Extracts clipboard content as string. 692 663 * @return string clipboard contents if available, {@code null} otherwise. 693 */ 664 * @deprecated Use {@link ClipboardUtils#getClipboardStringContent()}. To be removed end of 2016 665 */ 666 @Deprecated 694 667 public static String getClipboardContent() { 695 try { 696 Transferable t = getTransferableContent(Toolkit.getDefaultToolkit().getSystemClipboard()); 697 if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { 698 return (String) t.getTransferData(DataFlavor.stringFlavor); 699 } 700 } catch (UnsupportedFlavorException | IOException | HeadlessException ex) { 701 Main.error(ex); 702 return null; 703 } 704 return null; 668 return ClipboardUtils.getClipboardStringContent(); 705 669 } 706 670 -
trunk/src/org/openstreetmap/josm/tools/bugreport/DebugTextDisplay.java
r10585 r10604 6 6 import javax.swing.JScrollPane; 7 7 8 import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils; 8 9 import org.openstreetmap.josm.gui.widgets.JosmTextArea; 9 10 import org.openstreetmap.josm.tools.Utils; … … 61 62 62 63 /** 63 * Copies the debug text to the clip pboard. This includes the code tags for trac.64 * Copies the debug text to the clipboard. This includes the code tags for trac. 64 65 * @return <code>true</code> if copy was successful 65 66 */ 66 67 public boolean copyToClippboard() { 67 return Utils.copyToClipboard(String.format(CODE_PATTERN, text));68 return ClipboardUtils.copyString(String.format(CODE_PATTERN, text)); 68 69 } 69 70
Note:
See TracChangeset
for help on using the changeset viewer.