Changeset 17407 in osm for applications/editors/josm/plugins/wmsplugin
- Timestamp:
- 2009-08-31T14:40:43+02:00 (15 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin/src/wmsplugin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSGrabber.java
r17403 r17407 34 34 35 35 public class WMSGrabber extends Grabber { 36 public static boolean isUrlWithPatterns(String url) { 37 return url != null && url.contains("{") && url.contains("}"); 38 } 39 36 40 protected String baseURL; 37 41 private final boolean urlWithPatterns; … … 41 45 this.baseURL = layer.baseURL; 42 46 /* URL containing placeholders? */ 43 urlWithPatterns = baseURL != null && baseURL.contains("{") && baseURL.contains("}");47 urlWithPatterns = isUrlWithPatterns(baseURL); 44 48 } 45 49 … … 104 108 + getProjection(baseURL, false) 105 109 + "&width=" + wi + "&height=" + ht; 110 if (!(baseURL.endsWith("&") || baseURL.endsWith("?"))) { 111 System.out.println(tr("Warning: The base URL ''{0}'' for a WMS service doesn't have a trailing '&' or a trailing '?'.", baseURL)); 112 System.out.println(tr("Warning: Fetching WMS tiles is likely to fail. Please check you preference settings.")); 113 System.out.println(tr("Warning: The complete URL is ''{0}''.", str)); 114 } 106 115 } 107 116 return new URL(str.replace(" ", "%20")); -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java
r17397 r17407 65 65 private ExecutorService executor = null; 66 66 67 /** set to true if this layer uses an invalid base url */ 68 private boolean usesInvalidUrl = false; 69 /** set to true if the user confirmed to use an potentially invalid WMS base url */ 70 private boolean isInvalidUrlConfirmed = false; 71 67 72 public WMSLayer() { 68 73 this(tr("Blank Layer"), null, null); … … 84 89 85 90 executor = Executors.newFixedThreadPool(3); 91 if (!baseURL.startsWith("html:") && !WMSGrabber.isUrlWithPatterns(baseURL)) { 92 if (!(baseURL.endsWith("&") || baseURL.endsWith("?"))) { 93 if (!confirmMalformedUrl(baseURL)) { 94 System.out.println(tr("Warning: WMS layer deactivated because of malformed base url ''{0}''", baseURL)); 95 usesInvalidUrl = true; 96 setName(getName() + tr("(deactivated)")); 97 return; 98 } else { 99 isInvalidUrlConfirmed = true; 100 } 101 } 102 } 86 103 } 87 104 88 105 @Override 89 public void destroy() { 106 public void destroy() { 90 107 try { 91 executor.shutdown ();108 executor.shutdownNow(); 92 109 // Might not be initalized, so catch NullPointer as well 93 } catch(Exception x) {} 110 } catch(Exception x) { 111 x.printStackTrace(); 112 } 94 113 } 95 114 … … 138 157 @Override public void paint(Graphics g, final MapView mv) { 139 158 if(baseURL == null) return; 159 if (usesInvalidUrl && !isInvalidUrlConfirmed) return; 140 160 141 161 if( !startstop.isSelected() || (pixelPerDegree / getPPD() > minZoom) ){ //don't download when it's too outzoomed … … 155 175 } 156 176 177 protected boolean confirmMalformedUrl(String url) { 178 if (isInvalidUrlConfirmed) 179 return true; 180 String msg = tr("<html>The base URL<br>" 181 + "''{0}''<br>" 182 + "for this WML layer does neither end with a ''&'' nor with a ''?''.<br>" 183 + "This is likely to lead to invalid WMS request. You should check your<br>" 184 + "preference settings.<br>" 185 + "Do you want to fetch WMS tiles anyway?", 186 url); 187 String [] options = new String[] { 188 tr("Yes, fetch images"), 189 tr("No, abort") 190 }; 191 int ret = JOptionPane.showOptionDialog( 192 Main.parent, 193 msg, 194 tr("Invalid URL?"), 195 JOptionPane.YES_NO_OPTION, 196 JOptionPane.WARNING_MESSAGE, 197 null, 198 options, options[1] 199 ); 200 switch(ret) { 201 case JOptionPane.YES_OPTION: return true; 202 default: return false; 203 } 204 } 157 205 protected void downloadAndPaintVisible(Graphics g, final MapView mv){ 206 if (usesInvalidUrl) 207 return; 158 208 ProjectionBounds bounds = mv.getProjectionBounds(); 159 209 int bminx= (int)Math.floor ((bounds.min.east() * pixelPerDegree ) / ImageSize ); … … 170 220 ); 171 221 return; 172 } 173 222 } 223 174 224 for(int x = bminx; x<bmaxx; ++x) { 175 225 for(int y = bminy; y<bmaxy; ++y){ -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java
r17390 r17407 28 28 29 29 public class WMSPreferenceEditor implements PreferenceSetting { 30 private Map<String,String> orig;31 30 private DefaultTableModel model; 32 31 private JComboBox browser; … … 54 53 }; 55 54 JScrollPane scrolldef = new JScrollPane(listdef); 56 p.add(scrolldef, GBC.eol().insets(0,5,0,0).fill(GBC.BOTH)); 55 // scrolldef is added after the buttons so it's clearer the buttons 56 // control the top list and not the default one 57 57 scrolldef.setPreferredSize(new Dimension(200,200)); 58 58 … … 100 100 }); 101 101 102 JButton copy = new JButton(tr("Copy Default"));102 JButton copy = new JButton(tr("Copy Selected Default(s)")); 103 103 buttonPanel.add(copy, GBC.std().insets(0,5,0,0)); 104 104 copy.addActionListener(new ActionListener(){ 105 105 public void actionPerformed(ActionEvent e) { 106 Integer line = listdef.getSelectedRow();107 if (line == -1)106 int[] lines = listdef.getSelectedRows(); 107 if (lines.length == 0) { 108 108 JOptionPane.showMessageDialog( 109 109 gui, 110 tr("Please select the row to copy."),110 tr("Please select at least one row to copy."), 111 111 tr("Information"), 112 112 JOptionPane.INFORMATION_MESSAGE 113 113 ); 114 else 115 { 116 model.addRow(new String[]{modeldef.getValueAt(line, 0).toString(), 117 modeldef.getValueAt(line, 1).toString()}); 114 return; 115 } 116 117 outer: for(int i = 0; i < lines.length; i++) { 118 String c1 = modeldef.getValueAt(lines[i], 0).toString(); 119 String c2 = modeldef.getValueAt(lines[i], 1).toString(); 120 121 // Check if an entry with exactly the same values already 122 // exists 123 for(int j = 0; j < model.getRowCount(); j++) { 124 if(c1.equals(model.getValueAt(j, 0).toString()) 125 && c2.equals(model.getValueAt(j, 1).toString())) { 126 // Select the already existing row so the user has 127 // some feedback in case an entry exists 128 list.getSelectionModel().setSelectionInterval(j, j); 129 list.scrollRectToVisible(list.getCellRect(j, 0, true)); 130 continue outer; 131 } 132 } 133 134 model.addRow(new String[] {c1, c2}); 135 int lastLine = model.getRowCount() - 1; 136 list.getSelectionModel().setSelectionInterval(lastLine, lastLine); 137 list.scrollRectToVisible(list.getCellRect(lastLine, 0, true)); 118 138 } 119 139 } … … 122 142 p.add(buttonPanel); 123 143 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GBC.HORIZONTAL)); 144 // Add default item list 145 p.add(scrolldef, GBC.eol().insets(0,5,0,0).fill(GBC.BOTH)); 146 124 147 browser = new JComboBox(new String[]{ 125 148 "webkit-image {0}",
Note:
See TracChangeset
for help on using the changeset viewer.