Changeset 4531 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-10-20T14:12:47+02:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
r4172 r4531 5 5 6 6 import java.awt.event.ActionEvent; 7 8 import javax.swing.JOptionPane; 7 9 8 10 import org.openstreetmap.josm.Main; … … 25 27 public void actionPerformed(ActionEvent e) { 26 28 if (!isEnabled()) return; 27 Main.main.addLayer(ImageryLayer.create(info)); 29 try { 30 Main.main.addLayer(ImageryLayer.create(info)); 31 } catch (IllegalArgumentException ex) { 32 if (ex.getMessage() == null || ex.getMessage().isEmpty()) { 33 throw ex; 34 } else { 35 JOptionPane.showMessageDialog(Main.parent, 36 ex.getMessage(), tr("Error"), 37 JOptionPane.ERROR_MESSAGE); 38 } 39 } 28 40 } 29 41 -
trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
r4492 r4531 1 1 // License: GPL. See LICENSE file for details. 2 2 package org.openstreetmap.josm.gui.bbox; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.awt.Color; … … 18 20 import java.util.Vector; 19 21 import java.util.concurrent.CopyOnWriteArrayList; 22 23 import javax.swing.JOptionPane; 20 24 21 25 import org.openstreetmap.gui.jmapviewer.Coordinate; … … 37 41 import org.openstreetmap.josm.data.preferences.StringProperty; 38 42 import org.openstreetmap.josm.gui.layer.TMSLayer; 39 import org.openstreetmap.josm.tools.OpenBrowser;40 43 41 44 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser{ … … 114 117 continue; 115 118 } 116 TileSource source = TMSLayer.getTileSource(info); 117 if (source != null) { 118 sources.add(source); 119 try { 120 TileSource source = TMSLayer.getTileSource(info); 121 if (source != null) { 122 sources.add(source); 123 } 124 } catch (IllegalArgumentException ex) { 125 if (ex.getMessage() != null && !ex.getMessage().isEmpty()) { 126 JOptionPane.showMessageDialog(Main.parent, 127 ex.getMessage(), tr("Warning"), 128 JOptionPane.WARNING_MESSAGE); 129 } 119 130 } 120 131 } -
trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
r4529 r4531 24 24 import java.util.List; 25 25 import java.util.Map; 26 import java.util.regex.Matcher; 27 import java.util.regex.Pattern; 26 28 27 29 import javax.swing.AbstractAction; … … 222 224 } 223 225 224 public static TileSource getTileSource(ImageryInfo info) {226 public static TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException { 225 227 if (info.getImageryType() == ImageryType.TMS) { 228 checkUrl(info.getUrl()); 226 229 TMSTileSource t = new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom()); 227 230 info.setAttribution(t); … … 232 235 return new ScanexTileSource(info.getUrl()); 233 236 return null; 237 } 238 239 public static void checkUrl(String url) throws IllegalArgumentException { 240 if (url == null) { 241 throw new IllegalArgumentException(); 242 } else { 243 Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url); 244 while (m.find()) { 245 boolean isSupportedPattern = false; 246 for (String pattern : TemplatedTMSTileSource.ALL_PATTERNS) { 247 if (m.group().matches(pattern)) { 248 isSupportedPattern = true; 249 break; 250 } 251 } 252 if (!isSupportedPattern) { 253 throw new IllegalArgumentException(tr("{0} is not a valid TMS argument. Please check this server URL:\n{1}", m.group(), url)); 254 } 255 } 256 } 234 257 } 235 258 -
trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
r4524 r4531 70 70 import org.openstreetmap.josm.data.imagery.ImageryInfo; 71 71 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds; 72 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType; 72 73 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo; 73 74 import org.openstreetmap.josm.data.imagery.OffsetBookmark; … … 626 627 JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE); 627 628 if (answer == JOptionPane.OK_OPTION) { 628 model.addRow(new ImageryInfo(p.getUrlName(), p.getUrl())); 629 try { 630 ImageryInfo info = new ImageryInfo(p.getUrlName(), p.getUrl()); 631 if (ImageryType.TMS.equals(info.getImageryType())) { 632 TMSLayer.checkUrl(info.getUrl()); 633 } 634 model.addRow(info); 635 } catch (IllegalArgumentException ex) { 636 if (ex.getMessage() == null || ex.getMessage().isEmpty()) { 637 throw ex; 638 } else { 639 JOptionPane.showMessageDialog(Main.parent, 640 ex.getMessage(), tr("Error"), 641 JOptionPane.ERROR_MESSAGE); 642 } 643 } 629 644 } 630 645 }
Note:
See TracChangeset
for help on using the changeset viewer.