Ignore:
Timestamp:
2016-07-23T14:54:19+02:00 (4 years ago)
Author:
Don-vip
Message:

fix #12478, fix #12565, fix #11114 - Use ​Swing Copy/Paste instead of CopyAction/PasteAction with custom buffer (patch by michael2402, modified) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
3 edited

Legend:

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

    r10378 r10604  
    1919import org.openstreetmap.josm.Main;
    2020import org.openstreetmap.josm.gui.ExtendedDialog;
     21import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    2122import org.openstreetmap.josm.gui.help.HelpUtil;
    2223import org.openstreetmap.josm.gui.widgets.UrlLabel;
     
    291292        if (r == 0) r = 2;
    292293        // clean clipboard if user asked
    293         if (r == 3) Utils.copyToClipboard("");
     294        if (r == 3) ClipboardUtils.copyString("");
    294295        return r;
    295296    }
     
    326327        int r = ed.getValue();
    327328        // clean clipboard if user asked
    328         if (r == 2) Utils.copyToClipboard("");
     329        if (r == 2) ClipboardUtils.copyString("");
    329330    }
    330331}
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r10600 r10604  
    88import java.awt.Color;
    99import java.awt.Font;
    10 import java.awt.HeadlessException;
    11 import java.awt.Toolkit;
    1210import java.awt.datatransfer.Clipboard;
    13 import java.awt.datatransfer.ClipboardOwner;
    14 import java.awt.datatransfer.DataFlavor;
    15 import java.awt.datatransfer.StringSelection;
    1611import java.awt.datatransfer.Transferable;
    17 import java.awt.datatransfer.UnsupportedFlavorException;
    1812import java.awt.font.FontRenderContext;
    1913import java.awt.font.GlyphVector;
     
    7367import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
    7468import org.openstreetmap.josm.Main;
     69import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    7570import org.w3c.dom.Document;
    7671import org.xml.sax.InputSource;
     
    645640     * @param s string to be copied to clipboard.
    646641     * @return true if succeeded, false otherwise.
    647      */
     642     * @deprecated Use {@link ClipboardUtils#copyString(String)}. To be removed end of 2016.
     643     */
     644    @Deprecated
    648645    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);
    661647    }
    662648
     
    666652     * @return clipboard contents if available, {@code null} otherwise.
    667653     * @since 8429
    668      */
     654     * @deprecated Use {@link ClipboardUtils#getClipboardContent(Clipboard)} instead. To be removed end of 2016.
     655     */
     656    @Deprecated
    669657    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);
    688659    }
    689660
     
    691662     * Extracts clipboard content as string.
    692663     * @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
    694667    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();
    705669    }
    706670
  • trunk/src/org/openstreetmap/josm/tools/bugreport/DebugTextDisplay.java

    r10585 r10604  
    66import javax.swing.JScrollPane;
    77
     8import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
    89import org.openstreetmap.josm.gui.widgets.JosmTextArea;
    910import org.openstreetmap.josm.tools.Utils;
     
    6162
    6263    /**
    63      * Copies the debug text to the clippboard. This includes the code tags for trac.
     64     * Copies the debug text to the clipboard. This includes the code tags for trac.
    6465     * @return <code>true</code> if copy was successful
    6566     */
    6667    public boolean copyToClippboard() {
    67         return Utils.copyToClipboard(String.format(CODE_PATTERN, text));
     68        return ClipboardUtils.copyString(String.format(CODE_PATTERN, text));
    6869    }
    6970
Note: See TracChangeset for help on using the changeset viewer.