Changeset 4380 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-08-29T09:46:27+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/CopyAction.java
r3384 r4380 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 7 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;13 8 import java.awt.event.ActionEvent; 14 9 import java.awt.event.KeyEvent; … … 21 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 22 17 import org.openstreetmap.josm.tools.Shortcut; 18 import org.openstreetmap.josm.tools.Utils; 23 19 24 20 public final class CopyAction extends JosmAction { … … 31 27 } 32 28 29 @Override 33 30 public void actionPerformed(ActionEvent e) { 34 31 if(isEmptySelection()) return; … … 42 39 StringBuilder idsBuilder = new StringBuilder(); 43 40 for (OsmPrimitive p : primitives) { 44 idsBuilder.append(p.getId() +",");41 idsBuilder.append(p.getId()).append(","); 45 42 } 46 43 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); 55 45 56 46 Main.pasteBuffer.makeCopy(primitives); -
trunk/src/org/openstreetmap/josm/actions/Map_Rectifier_WMSmenuAction.java
r4253 r4380 6 6 import java.awt.GridBagConstraints; 7 7 import java.awt.GridBagLayout; 8 import java.awt.Toolkit;9 import java.awt.datatransfer.DataFlavor;10 import java.awt.datatransfer.Transferable;11 8 import java.awt.event.ActionEvent; 12 9 import java.awt.event.KeyEvent; … … 29 26 import org.openstreetmap.josm.tools.Shortcut; 30 27 import org.openstreetmap.josm.tools.UrlLabel; 28 import org.openstreetmap.josm.tools.Utils; 31 29 32 30 public class Map_Rectifier_WMSmenuAction extends JosmAction { … … 118 116 JTextField tfWmsUrl = new JTextField(30); 119 117 120 String clip = getClipboardContents(); 118 String clip = Utils.getClipboardContent(); 119 clip = clip == null ? "" : clip.trim(); 121 120 ButtonGroup group = new ButtonGroup(); 122 121 … … 224 223 } 225 224 226 /**227 * Helper function that extracts a String from the Clipboard if available.228 * Returns an empty String otherwise229 * @return String Clipboard contents if available230 */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 246 225 @Override 247 226 protected void updateEnabledState() { -
trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
r4146 r4380 6 6 7 7 import 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;13 8 import java.awt.event.ActionEvent; 14 9 import java.awt.event.KeyEvent; … … 27 22 import org.openstreetmap.josm.plugins.PluginHandler; 28 23 import org.openstreetmap.josm.tools.Shortcut; 24 import org.openstreetmap.josm.tools.Utils; 29 25 30 26 /** … … 127 123 128 124 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()); 137 126 } 138 127 } -
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r4266 r4380 24 24 import org.openstreetmap.josm.actions.CombineWayAction; 25 25 import org.openstreetmap.josm.actions.CopyAction; 26 import org.openstreetmap.josm.actions.CopyCoordinatesAction; 26 27 import org.openstreetmap.josm.actions.CreateCircleAction; 27 28 import org.openstreetmap.josm.actions.CreateMultipolygonAction; … … 125 126 public final RedoAction redo = new RedoAction(); 126 127 public final JosmAction copy = new CopyAction(); 128 public final JosmAction copyCoordinates = new CopyCoordinatesAction(); 127 129 public final PasteAction paste = new PasteAction(); 128 130 public final JosmAction pasteTags = new PasteTagsAction(); … … 257 259 editMenu.addSeparator(); 258 260 add(editMenu, copy); 261 add(editMenu, copyCoordinates); 259 262 add(editMenu, paste); 260 263 add(editMenu, pasteTags); -
trunk/src/org/openstreetmap/josm/gui/download/BoundingBoxSelection.java
r3424 r4380 8 8 import java.awt.GridBagLayout; 9 9 import java.awt.Toolkit; 10 import java.awt.datatransfer.DataFlavor;11 10 import java.awt.datatransfer.FlavorEvent; 12 11 import java.awt.datatransfer.FlavorListener; 13 import java.awt.datatransfer.Transferable;14 import java.awt.datatransfer.UnsupportedFlavorException;15 12 import java.awt.event.ActionEvent; 16 13 import java.awt.event.ActionListener; … … 19 16 import java.awt.event.MouseAdapter; 20 17 import java.awt.event.MouseEvent; 21 import java.io.IOException;22 18 23 19 import javax.swing.AbstractAction; … … 40 36 import org.openstreetmap.josm.tools.ImageProvider; 41 37 import org.openstreetmap.josm.tools.OsmUrlToBounds; 38 import org.openstreetmap.josm.tools.Utils; 42 39 43 40 /** … … 306 303 } 307 304 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 325 305 public void actionPerformed(ActionEvent e) { 326 String content = getClipboardContent();306 String content = Utils.getClipboardContent(); 327 307 if (content != null) { 328 308 tfOsmUrl.setText(content); … … 331 311 332 312 protected void updateEnabledState() { 333 setEnabled( getClipboardContent() != null);313 setEnabled(Utils.getClipboardContent() != null); 334 314 } 335 315 -
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r4191 r4380 13 13 import java.awt.GridBagConstraints; 14 14 import java.awt.GridBagLayout; 15 import java.awt.Toolkit;16 import java.awt.datatransfer.DataFlavor;17 import java.awt.datatransfer.Transferable;18 15 import java.awt.event.ActionEvent; 19 16 import java.awt.event.InputEvent; … … 44 41 import org.openstreetmap.josm.tools.ImageProvider; 45 42 import org.openstreetmap.josm.tools.OsmUrlToBounds; 43 import org.openstreetmap.josm.tools.Utils; 46 44 import org.openstreetmap.josm.tools.WindowGeometry; 47 45 … … 183 181 getRootPane().getActionMap().put("checkClipboardContents", new AbstractAction() { 184 182 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 } 186 191 } 187 192 }); … … 189 194 addWindowListener(new WindowEventHandler()); 190 195 restoreSettings(); 191 }192 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 196 } 212 197 -
trunk/src/org/openstreetmap/josm/gui/widgets/BoundingBoxSelectionPanel.java
r3083 r4380 9 9 import java.awt.Insets; 10 10 import java.awt.Toolkit; 11 import java.awt.datatransfer.DataFlavor;12 11 import java.awt.datatransfer.FlavorEvent; 13 12 import java.awt.datatransfer.FlavorListener; 14 import java.awt.datatransfer.Transferable;15 import java.awt.datatransfer.UnsupportedFlavorException;16 13 import java.awt.event.ActionEvent; 17 14 import java.awt.event.MouseEvent; 18 import java.io.IOException;19 15 20 16 import javax.swing.AbstractAction; … … 35 31 import org.openstreetmap.josm.tools.ImageProvider; 36 32 import org.openstreetmap.josm.tools.OsmUrlToBounds; 33 import org.openstreetmap.josm.tools.Utils; 37 34 38 35 /** … … 237 234 } 238 235 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 256 236 public void actionPerformed(ActionEvent e) { 257 String content = getClipboardContent();237 String content = Utils.getClipboardContent(); 258 238 if (content != null) { 259 239 tfOsmUrl.setText(content); … … 262 242 263 243 protected void updateEnabledState() { 264 setEnabled( getClipboardContent() != null);244 setEnabled(Utils.getClipboardContent() != null); 265 245 } 266 246 -
trunk/src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java
r3840 r4380 6 6 import java.awt.Component; 7 7 import 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;13 8 import java.io.PrintWriter; 14 9 import java.io.StringWriter; … … 127 122 "below at this URL:")), GBC.eol()); 128 123 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)) { 133 125 p.add(new JLabel(tr("(The text has already been copied to your clipboard.)")), GBC.eop()); 134 126 } 135 catch (RuntimeException x) {}136 127 137 128 JTextArea info = new JTextArea(text, 20, 60); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r4272 r4380 3 3 4 4 import java.awt.Color; 5 import java.awt.Toolkit; 6 import java.awt.datatransfer.Clipboard; 7 import java.awt.datatransfer.ClipboardOwner; 8 import java.awt.datatransfer.DataFlavor; 9 import java.awt.datatransfer.StringSelection; 10 import java.awt.datatransfer.Transferable; 11 import java.awt.datatransfer.UnsupportedFlavorException; 5 12 import java.io.File; 6 13 import java.io.IOException; … … 264 271 return Math.abs(a - b) <= EPSILION; 265 272 } 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 } 266 314 }
Note:
See TracChangeset
for help on using the changeset viewer.