Ticket #4609: 4609.patch

File 4609.patch, 19.1 KB (added by simon04, 21 months ago)
  • src/org/openstreetmap/josm/actions/CopyAction.java

    diff --git a/src/org/openstreetmap/josm/actions/CopyAction.java b/src/org/openstreetmap/josm/actions/CopyAction.java
    index 9cb0960..90190f5 100644
    a b package org.openstreetmap.josm.actions; 
    55import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 
    66import static org.openstreetmap.josm.tools.I18n.tr; 
    77 
    8 import java.awt.Toolkit; 
    9 import java.awt.datatransfer.Clipboard; 
    10 import java.awt.datatransfer.ClipboardOwner; 
    11 import java.awt.datatransfer.StringSelection; 
    12 import java.awt.datatransfer.Transferable; 
    138import java.awt.event.ActionEvent; 
    149import java.awt.event.KeyEvent; 
    1510import java.util.Collection; 
    import org.openstreetmap.josm.Main; 
    2015import org.openstreetmap.josm.data.osm.OsmPrimitive; 
    2116import org.openstreetmap.josm.gui.layer.OsmDataLayer; 
    2217import org.openstreetmap.josm.tools.Shortcut; 
     18import org.openstreetmap.josm.tools.Utils; 
    2319 
    2420public final class CopyAction extends JosmAction { 
    2521 
    public final class CopyAction extends JosmAction { 
    3026        putValue("help", ht("/Action/Copy")); 
    3127    } 
    3228 
     29    @Override 
    3330    public void actionPerformed(ActionEvent e) { 
    3431        if(isEmptySelection()) return; 
    3532        Collection<OsmPrimitive> selection = getCurrentDataSet().getSelected(); 
    public final class CopyAction extends JosmAction { 
    4138        /* copy ids to the clipboard */ 
    4239        StringBuilder idsBuilder = new StringBuilder(); 
    4340        for (OsmPrimitive p : primitives) { 
    44             idsBuilder.append(p.getId()+","); 
     41            idsBuilder.append(p.getId()).append(","); 
    4542        } 
    4643        String ids = idsBuilder.substring(0, idsBuilder.length() - 1); 
    47         try { 
    48             Toolkit.getDefaultToolkit().getSystemClipboard().setContents( 
    49                     new StringSelection(ids.toString()), new ClipboardOwner() { 
    50                         public void lostOwnership(Clipboard clipboard, Transferable contents) {} 
    51                     } 
    52             ); 
    53         } 
    54         catch (RuntimeException x) {} 
     44        Utils.copyToClipboard(ids); 
    5545 
    5646        Main.pasteBuffer.makeCopy(primitives); 
    5747        Main.pasteSource = source; 
  • src/org/openstreetmap/josm/actions/Map_Rectifier_WMSmenuAction.java

    diff --git a/src/org/openstreetmap/josm/actions/Map_Rectifier_WMSmenuAction.java b/src/org/openstreetmap/josm/actions/Map_Rectifier_WMSmenuAction.java
    index d4a308b..c964d2d 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
    66import java.awt.GridBagConstraints; 
    77import java.awt.GridBagLayout; 
    8 import java.awt.Toolkit; 
    9 import java.awt.datatransfer.DataFlavor; 
    10 import java.awt.datatransfer.Transferable; 
    118import java.awt.event.ActionEvent; 
    129import java.awt.event.KeyEvent; 
    1310import java.util.ArrayList; 
    import org.openstreetmap.josm.gui.layer.WMSLayer; 
    2825import org.openstreetmap.josm.tools.GBC; 
    2926import org.openstreetmap.josm.tools.Shortcut; 
    3027import org.openstreetmap.josm.tools.UrlLabel; 
     28import org.openstreetmap.josm.tools.Utils; 
    3129 
    3230public class Map_Rectifier_WMSmenuAction extends JosmAction { 
    3331    /** 
    public class Map_Rectifier_WMSmenuAction extends JosmAction { 
    117115 
    118116        JTextField tfWmsUrl = new JTextField(30); 
    119117 
    120         String clip = getClipboardContents(); 
     118        String clip = Utils.getClipboardContent(); 
     119        clip = clip == null ? "" : clip.trim(); 
    121120        ButtonGroup group = new ButtonGroup(); 
    122121 
    123122        JRadioButton firstBtn = null; 
    public class Map_Rectifier_WMSmenuAction extends JosmAction { 
    223222        Main.main.addLayer(new WMSLayer(new ImageryInfo(title, url))); 
    224223    } 
    225224 
    226     /** 
    227      * Helper function that extracts a String from the Clipboard if available. 
    228      * Returns an empty String otherwise 
    229      * @return String Clipboard contents if available 
    230      */ 
    231     private String getClipboardContents() { 
    232         String result = ""; 
    233         Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); 
    234  
    235         if(contents == null || !contents.isDataFlavorSupported(DataFlavor.stringFlavor)) 
    236             return ""; 
    237  
    238         try { 
    239             result = (String)contents.getTransferData(DataFlavor.stringFlavor); 
    240         } catch(Exception ex) { 
    241             return ""; 
    242         } 
    243         return result.trim(); 
    244     } 
    245  
    246225    @Override 
    247226    protected void updateEnabledState() { 
    248227        setEnabled(Main.map != null && Main.map.mapView != null && !Main.map.mapView.getAllLayers().isEmpty()); 
  • src/org/openstreetmap/josm/actions/ShowStatusReportAction.java

    diff --git a/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java b/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
    index cf80ac6..50b3b60 100644
    a b import static org.openstreetmap.josm.gui.help.HelpUtil.ht; 
    55import static org.openstreetmap.josm.tools.I18n.tr; 
    66 
    77import java.awt.Dimension; 
    8 import java.awt.Toolkit; 
    9 import java.awt.datatransfer.Clipboard; 
    10 import java.awt.datatransfer.ClipboardOwner; 
    11 import java.awt.datatransfer.StringSelection; 
    12 import java.awt.datatransfer.Transferable; 
    138import java.awt.event.ActionEvent; 
    149import java.awt.event.KeyEvent; 
    1510import java.io.BufferedReader; 
    import org.openstreetmap.josm.data.osm.DatasetConsistencyTest; 
    2621import org.openstreetmap.josm.gui.ExtendedDialog; 
    2722import org.openstreetmap.josm.plugins.PluginHandler; 
    2823import org.openstreetmap.josm.tools.Shortcut; 
     24import org.openstreetmap.josm.tools.Utils; 
    2925 
    3026/** 
    3127 * @author xeen 
    public final class ShowStatusReportAction extends JosmAction { 
    126122        ed.showDialog(); 
    127123 
    128124        if(ed.getValue() != 1) return; 
    129         try { 
    130             Toolkit.getDefaultToolkit().getSystemClipboard().setContents( 
    131                     new StringSelection(text.toString()), new ClipboardOwner() { 
    132                         public void lostOwnership(Clipboard clipboard, Transferable contents) {} 
    133                     } 
    134             ); 
    135         } 
    136         catch (RuntimeException x) {} 
     125        Utils.copyToClipboard(text.toString()); 
    137126    } 
    138127} 
  • src/org/openstreetmap/josm/gui/MainMenu.java

    diff --git a/src/org/openstreetmap/josm/gui/MainMenu.java b/src/org/openstreetmap/josm/gui/MainMenu.java
    index b8b5cf5..311f8d3 100644
    a b import org.openstreetmap.josm.actions.ChangesetManagerToggleAction; 
    2323import org.openstreetmap.josm.actions.CloseChangesetAction; 
    2424import org.openstreetmap.josm.actions.CombineWayAction; 
    2525import org.openstreetmap.josm.actions.CopyAction; 
     26import org.openstreetmap.josm.actions.CopyCoordinatesAction; 
    2627import org.openstreetmap.josm.actions.CreateCircleAction; 
    2728import org.openstreetmap.josm.actions.CreateMultipolygonAction; 
    2829import org.openstreetmap.josm.actions.DeleteAction; 
    public class MainMenu extends JMenuBar { 
    124125    public final UndoAction undo = new UndoAction(); 
    125126    public final RedoAction redo = new RedoAction(); 
    126127    public final JosmAction copy = new CopyAction(); 
     128    public final JosmAction copyCoordinates = new CopyCoordinatesAction(); 
    127129    public final PasteAction paste = new PasteAction(); 
    128130    public final JosmAction pasteTags = new PasteTagsAction(); 
    129131    public final JosmAction duplicate = new DuplicateAction(); 
    public class MainMenu extends JMenuBar { 
    256258        add(editMenu, redo); 
    257259        editMenu.addSeparator(); 
    258260        add(editMenu, copy); 
     261        add(editMenu, copyCoordinates); 
    259262        add(editMenu, paste); 
    260263        add(editMenu, pasteTags); 
    261264        add(editMenu, duplicate); 
  • src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java

    diff --git a/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java b/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
    index bc3d7a0..e3c14be 100644
    a b import java.awt.Color; 
    77import java.awt.Dimension; 
    88import java.awt.GridBagLayout; 
    99import java.awt.Toolkit; 
    10 import java.awt.datatransfer.DataFlavor; 
    1110import java.awt.datatransfer.FlavorEvent; 
    1211import java.awt.datatransfer.FlavorListener; 
    13 import java.awt.datatransfer.Transferable; 
    14 import java.awt.datatransfer.UnsupportedFlavorException; 
    1512import java.awt.event.ActionEvent; 
    1613import java.awt.event.ActionListener; 
    1714import java.awt.event.FocusAdapter; 
    1815import java.awt.event.FocusEvent; 
    1916import java.awt.event.MouseAdapter; 
    2017import java.awt.event.MouseEvent; 
    21 import java.io.IOException; 
    2218 
    2319import javax.swing.AbstractAction; 
    2420import javax.swing.BorderFactory; 
    import org.openstreetmap.josm.data.coor.LatLon; 
    3935import org.openstreetmap.josm.tools.GBC; 
    4036import org.openstreetmap.josm.tools.ImageProvider; 
    4137import org.openstreetmap.josm.tools.OsmUrlToBounds; 
     38import org.openstreetmap.josm.tools.Utils; 
    4239 
    4340/** 
    4441 * Bounding box selector. 
    public class BoundingBoxSelection implements DownloadSelection { 
    305302            Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(this); 
    306303        } 
    307304 
    308         protected String getClipboardContent() { 
    309             Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); 
    310             try { 
    311                 if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { 
    312                     String text = (String)t.getTransferData(DataFlavor.stringFlavor); 
    313                     return text; 
    314                 } 
    315             } catch (UnsupportedFlavorException ex) { 
    316                 ex.printStackTrace(); 
    317                 return null; 
    318             } catch (IOException ex) { 
    319                 ex.printStackTrace(); 
    320                 return null; 
    321             } 
    322             return null; 
    323         } 
    324  
    325305        public void actionPerformed(ActionEvent e) { 
    326             String content = getClipboardContent(); 
     306            String content = Utils.getClipboardContent(); 
    327307            if (content != null) { 
    328308                tfOsmUrl.setText(content); 
    329309            } 
    330310        } 
    331311 
    332312        protected void updateEnabledState() { 
    333             setEnabled(getClipboardContent() != null); 
     313            setEnabled(Utils.getClipboardContent() != null); 
    334314        } 
    335315 
    336316        public void flavorsChanged(FlavorEvent e) { 
  • src/org/openstreetmap/josm/gui/download/DownloadDialog.java

    diff --git a/src/org/openstreetmap/josm/gui/download/DownloadDialog.java b/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
    index a7b4264..3b29fbb 100644
    a b import java.awt.FlowLayout; 
    1212import java.awt.Font; 
    1313import java.awt.GridBagConstraints; 
    1414import java.awt.GridBagLayout; 
    15 import java.awt.Toolkit; 
    16 import java.awt.datatransfer.DataFlavor; 
    17 import java.awt.datatransfer.Transferable; 
    1815import java.awt.event.ActionEvent; 
    1916import java.awt.event.InputEvent; 
    2017import java.awt.event.KeyEvent; 
    import org.openstreetmap.josm.plugins.PluginHandler; 
    4340import org.openstreetmap.josm.tools.GBC; 
    4441import org.openstreetmap.josm.tools.ImageProvider; 
    4542import org.openstreetmap.josm.tools.OsmUrlToBounds; 
     43import org.openstreetmap.josm.tools.Utils; 
    4644import org.openstreetmap.josm.tools.WindowGeometry; 
    4745 
    4846/** 
    public class DownloadDialog extends JDialog { 
    182180 
    183181        getRootPane().getActionMap().put("checkClipboardContents", new AbstractAction() { 
    184182            public void actionPerformed(ActionEvent e) { 
    185                 checkClipboardContents(); 
     183                String clip = Utils.getClipboardContent(); 
     184                if (clip == null) { 
     185                    return; 
     186                } 
     187                Bounds b = OsmUrlToBounds.parse(clip); 
     188                if (b != null) { 
     189                    boundingBoxChanged(new Bounds(b), null); 
     190                } 
    186191            } 
    187192        }); 
    188193        HelpUtil.setHelpContext(getRootPane(), ht("/Dialog/Download")); 
    public class DownloadDialog extends JDialog { 
    190195        restoreSettings(); 
    191196    } 
    192197 
    193     private void checkClipboardContents() { 
    194         String result = ""; 
    195         Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); 
    196  
    197         if(contents == null || !contents.isDataFlavorSupported(DataFlavor.stringFlavor)) 
    198             return; 
    199  
    200         try { 
    201             result = (String)contents.getTransferData(DataFlavor.stringFlavor); 
    202         } 
    203         catch(Exception ex) { 
    204             return; 
    205         } 
    206  
    207         Bounds b = OsmUrlToBounds.parse(result); 
    208         if (b != null) { 
    209             boundingBoxChanged(new Bounds(b),null); 
    210         } 
    211     } 
    212  
    213198    private void updateSizeCheck() { 
    214199        if (currentBounds == null) { 
    215200            sizeCheck.setText(tr("No area selected yet")); 
  • src/org/openstreetmap/josm/gui/widgets/BoundingBoxSelectionPanel.java

    diff --git a/src/org/openstreetmap/josm/gui/widgets/BoundingBoxSelectionPanel.java b/src/org/openstreetmap/josm/gui/widgets/BoundingBoxSelectionPanel.java
    index 375b8e0..7ff4706 100644
    a b import java.awt.GridBagConstraints; 
    88import java.awt.GridBagLayout; 
    99import java.awt.Insets; 
    1010import java.awt.Toolkit; 
    11 import java.awt.datatransfer.DataFlavor; 
    1211import java.awt.datatransfer.FlavorEvent; 
    1312import java.awt.datatransfer.FlavorListener; 
    14 import java.awt.datatransfer.Transferable; 
    15 import java.awt.datatransfer.UnsupportedFlavorException; 
    1613import java.awt.event.ActionEvent; 
    1714import java.awt.event.MouseEvent; 
    18 import java.io.IOException; 
    1915 
    2016import javax.swing.AbstractAction; 
    2117import javax.swing.BorderFactory; 
    import org.openstreetmap.josm.gui.JMultilineLabel; 
    3430import org.openstreetmap.josm.tools.GBC; 
    3531import org.openstreetmap.josm.tools.ImageProvider; 
    3632import org.openstreetmap.josm.tools.OsmUrlToBounds; 
     33import org.openstreetmap.josm.tools.Utils; 
    3734 
    3835/** 
    3936 * 
    public class BoundingBoxSelectionPanel extends JPanel { 
    236233            Toolkit.getDefaultToolkit().getSystemClipboard().addFlavorListener(this); 
    237234        } 
    238235 
    239         protected String getClipboardContent() { 
    240             Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); 
    241             try { 
    242                 if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { 
    243                     String text = (String)t.getTransferData(DataFlavor.stringFlavor); 
    244                     return text; 
    245                 } 
    246             } catch (UnsupportedFlavorException ex) { 
    247                 ex.printStackTrace(); 
    248                 return null; 
    249             } catch (IOException ex) { 
    250                 ex.printStackTrace(); 
    251                 return null; 
    252             } 
    253             return null; 
    254         } 
    255  
    256236        public void actionPerformed(ActionEvent e) { 
    257             String content = getClipboardContent(); 
     237            String content = Utils.getClipboardContent(); 
    258238            if (content != null) { 
    259239                tfOsmUrl.setText(content); 
    260240            } 
    261241        } 
    262242 
    263243        protected void updateEnabledState() { 
    264             setEnabled(getClipboardContent() != null); 
     244            setEnabled(Utils.getClipboardContent() != null); 
    265245        } 
    266246 
    267247        public void flavorsChanged(FlavorEvent e) { 
  • src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java

    diff --git a/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java b/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
    index a088e96..d6b3338 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
    66import java.awt.Component; 
    77import java.awt.GridBagLayout; 
    8 import java.awt.Toolkit; 
    9 import java.awt.datatransfer.Clipboard; 
    10 import java.awt.datatransfer.ClipboardOwner; 
    11 import java.awt.datatransfer.StringSelection; 
    12 import java.awt.datatransfer.Transferable; 
    138import java.io.PrintWriter; 
    149import java.io.StringWriter; 
    1510import java.net.URL; 
    public final class BugReportExceptionHandler implements Thread.UncaughtException 
    126121                            tr("Alternatively, if that does not work you can manually fill in the information " + 
    127122                            "below at this URL:")), GBC.eol()); 
    128123                    p.add(new UrlLabel("http://josm.openstreetmap.de/newticket"), GBC.eop().insets(8,0,0,0)); 
    129                     try { 
    130                         Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(text), new ClipboardOwner(){ 
    131                             public void lostOwnership(Clipboard clipboard, Transferable contents) {} 
    132                         }); 
     124                    if (Utils.copyToClipboard(text)) { 
    133125                        p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop()); 
    134126                    } 
    135                     catch (RuntimeException x) {} 
    136127 
    137128                    JTextArea info = new JTextArea(text, 20, 60); 
    138129                    info.setCaretPosition(0); 
  • src/org/openstreetmap/josm/tools/Utils.java

    diff --git a/src/org/openstreetmap/josm/tools/Utils.java b/src/org/openstreetmap/josm/tools/Utils.java
    index ffabb45..20f07ce 100644
    a b  
    22package org.openstreetmap.josm.tools; 
    33 
    44import java.awt.Color; 
     5import java.awt.Toolkit; 
     6import java.awt.datatransfer.Clipboard; 
     7import java.awt.datatransfer.ClipboardOwner; 
     8import java.awt.datatransfer.DataFlavor; 
     9import java.awt.datatransfer.StringSelection; 
     10import java.awt.datatransfer.Transferable; 
     11import java.awt.datatransfer.UnsupportedFlavorException; 
    512import java.io.File; 
    613import java.io.IOException; 
    714import java.io.InputStream; 
    public class Utils { 
    263270    public static boolean equalsEpsilon(double a, double b) { 
    264271        return Math.abs(a - b) <= EPSILION; 
    265272    } 
     273 
     274    /** 
     275     * Copies the string {@code s} to system clipboard. 
     276     * @param s string to be copied to clipboard. 
     277     * @return true if succeeded, false otherwise. 
     278     */ 
     279    public static boolean copyToClipboard(String s) { 
     280        try { 
     281            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(s), new ClipboardOwner() { 
     282 
     283                @Override 
     284                public void lostOwnership(Clipboard clpbrd, Transferable t) { 
     285                } 
     286            }); 
     287            return true; 
     288        } catch (IllegalStateException ex) { 
     289            ex.printStackTrace(); 
     290            return false; 
     291        } 
     292    } 
     293 
     294    /** 
     295     * Extracts clipboard content as string. 
     296     * @return string clipboard contents if available, {@code null} otherwise. 
     297     */ 
     298    public static String getClipboardContent() { 
     299        Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); 
     300        try { 
     301            if (t != null && t.isDataFlavorSupported(DataFlavor.stringFlavor)) { 
     302                String text = (String) t.getTransferData(DataFlavor.stringFlavor); 
     303                return text; 
     304            } 
     305        } catch (UnsupportedFlavorException ex) { 
     306            ex.printStackTrace(); 
     307            return null; 
     308        } catch (IOException ex) { 
     309            ex.printStackTrace(); 
     310            return null; 
     311        } 
     312        return null; 
     313    } 
    266314}