Changeset 23325 in osm for applications/editors/josm/plugins/wmsplugin
- Timestamp:
- 2010-09-23T23:26:08+02:00 (14 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin/src/wmsplugin
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSInfo.java
r23207 r23325 3 3 import java.util.ArrayList; 4 4 import java.util.Collection; 5 6 import org.openstreetmap.josm.Main;7 5 8 6 /** … … 16 14 String url=null; 17 15 String cookies = null; 16 String eulaAcceptanceRequired = null; 18 17 boolean html = false; 19 18 double pixelPerDegree = 0.0; … … 28 27 } 29 28 30 public WMSInfo(String name, String url, String cookies) { 29 public WMSInfo(String name, String url, String eulaAcceptanceRequired) { 30 this.name=name; 31 setURL(url); 32 this.eulaAcceptanceRequired = eulaAcceptanceRequired; 33 } 34 35 public WMSInfo(String name, String url, String eulaAcceptanceRequired, String cookies) { 31 36 this.name=name; 32 37 setURL(url); -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayerInfo.java
r23207 r23325 4 4 5 5 import java.io.BufferedReader; 6 import java.io.IOException; 6 7 import java.io.InputStreamReader; 7 import java.io.IOException;8 8 import java.io.UnsupportedEncodingException; 9 9 import java.util.ArrayList; 10 10 import java.util.Arrays; 11 import java.util.ArrayList;12 11 import java.util.Collection; 13 12 import java.util.Collections; … … 103 102 { 104 103 String val[] = line.split(";"); 105 if(!line.startsWith("#") && val.length == 3) {104 if(!line.startsWith("#") && (val.length == 3 || val.length == 4)) { 106 105 boolean force = "true".equals(val[0]); 107 106 String name = tr(val[1]); 108 107 String url = val[2]; 109 110 defaultLayers.add(new WMSInfo(name, url)); 108 String eulaAcceptanceRequired = null; 109 if (val.length == 4) { 110 // 4th parameter optional for license agreement (EULA) 111 eulaAcceptanceRequired = val[3]; 112 } 113 defaultLayers.add(new WMSInfo(name, url, eulaAcceptanceRequired)); 111 114 112 115 if(force) { -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java
r23207 r23325 10 10 import java.awt.event.ActionListener; 11 11 import java.awt.event.MouseEvent; 12 import java.util.ArrayList; 13 import java.util.HashMap; 14 import java.util.Map; 12 import java.io.IOException; 13 import java.net.MalformedURLException; 14 import java.net.URL; 15 import java.util.Locale; 15 16 16 17 import javax.swing.Box; … … 18 19 import javax.swing.JCheckBox; 19 20 import javax.swing.JComboBox; 21 import javax.swing.JEditorPane; 20 22 import javax.swing.JLabel; 21 23 import javax.swing.JOptionPane; … … 58 60 JScrollPane scroll = new JScrollPane(list); 59 61 p.add(scroll, GBC.eol().fill(GridBagConstraints.BOTH)); 60 scroll.setPreferredSize(new Dimension(200, 200));62 scroll.setPreferredSize(new Dimension(200, 200)); 61 63 62 64 final WMSDefaultLayerTableModel modeldef = new WMSDefaultLayerTableModel(); … … 71 73 // scrolldef is added after the buttons so it's clearer the buttons 72 74 // control the top list and not the default one 73 scrolldef.setPreferredSize(new Dimension(200, 200));75 scrolldef.setPreferredSize(new Dimension(200, 200)); 74 76 75 77 TableColumnModel mod = listdef.getColumnModel(); … … 84 86 85 87 JButton add = new JButton(tr("Add")); 86 buttonPanel.add(add, GBC.std().insets(0, 5,0,0));87 add.addActionListener(new ActionListener() {88 buttonPanel.add(add, GBC.std().insets(0, 5, 0, 0)); 89 add.addActionListener(new ActionListener() { 88 90 public void actionPerformed(ActionEvent e) { 89 91 AddWMSLayerPanel p = new AddWMSLayerPanel(); … … 99 101 100 102 JButton delete = new JButton(tr("Delete")); 101 buttonPanel.add(delete, GBC.std().insets(0, 5,0,0));102 delete.addActionListener(new ActionListener() {103 buttonPanel.add(delete, GBC.std().insets(0, 5, 0, 0)); 104 delete.addActionListener(new ActionListener() { 103 105 public void actionPerformed(ActionEvent e) { 104 106 if (list.getSelectedRow() == -1) 105 107 JOptionPane.showMessageDialog(gui, tr("Please select the row to delete.")); 106 else 107 { 108 else { 108 109 Integer i; 109 110 while ((i = list.getSelectedRow()) != -1) … … 114 115 115 116 JButton copy = new JButton(tr("Copy Selected Default(s)")); 116 buttonPanel.add(copy, GBC.std().insets(0, 5,0,0));117 copy.addActionListener(new ActionListener() {117 buttonPanel.add(copy, GBC.std().insets(0, 5, 0, 0)); 118 copy.addActionListener(new ActionListener() { 118 119 public void actionPerformed(ActionEvent e) { 119 120 int[] lines = listdef.getSelectedRows(); … … 123 124 tr("Please select at least one row to copy."), 124 125 tr("Information"), 125 JOptionPane.INFORMATION_MESSAGE 126 ); 126 JOptionPane.INFORMATION_MESSAGE); 127 127 return; 128 128 } 129 129 130 outer: for (int i = 0; i < lines.length; i++) {130 outer: for (int i = 0; i < lines.length; i++) { 131 131 WMSInfo info = modeldef.getRow(lines[i]); 132 132 133 133 // Check if an entry with exactly the same values already 134 134 // exists 135 for (int j = 0; j < model.getRowCount(); j++) {136 if (info.equalsBaseValues(model.getRow(j))) {135 for (int j = 0; j < model.getRowCount(); j++) { 136 if (info.equalsBaseValues(model.getRow(j))) { 137 137 // Select the already existing row so the user has 138 138 // some feedback in case an entry exists … … 143 143 } 144 144 145 if (info.eulaAcceptanceRequired != null) { 146 if (!confirmeEulaAcceptance(gui, info.eulaAcceptanceRequired)) 147 continue outer; 148 } 149 145 150 model.addRow(new WMSInfo(info)); 146 151 int lastLine = model.getRowCount() - 1; … … 154 159 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 155 160 // Add default item list 156 p.add(scrolldef, GBC.eol().insets(0, 5,0,0).fill(GridBagConstraints.BOTH));157 158 browser = new JComboBox(new String[] {161 p.add(scrolldef, GBC.eol().insets(0, 5, 0, 0).fill(GridBagConstraints.BOTH)); 162 163 browser = new JComboBox(new String[] { 159 164 "webkit-image {0}", 160 165 "gnome-web-photo --mode=photo --format=png {0} /dev/stdout", … … 166 171 p.add(browser); 167 172 168 // Overlap173 // Overlap 169 174 p.add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 170 175 171 overlapCheckBox = new JCheckBox(tr("Overlap tiles"), plugin.PROP_OVERLAP.get() 176 overlapCheckBox = new JCheckBox(tr("Overlap tiles"), plugin.PROP_OVERLAP.get()); 172 177 JLabel labelEast = new JLabel(tr("% of east:")); 173 178 JLabel labelNorth = new JLabel(tr("% of north:")); … … 193 198 p.add(overlapPanelSimConn, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 194 199 195 196 200 allowRemoteControl = Main.pref.getBoolean("wmsplugin.remotecontrol", true); 197 remoteCheckBox = new JCheckBox(tr("Allow remote control (reqires remotecontrol plugin)"), allowRemoteControl 201 remoteCheckBox = new JCheckBox(tr("Allow remote control (reqires remotecontrol plugin)"), allowRemoteControl); 198 202 JPanel remotePanel = new JPanel(new FlowLayout()); 199 203 remotePanel.add(remoteCheckBox); … … 214 218 Main.pref.put("wmsplugin.browser", browser.getEditor().getItem().toString()); 215 219 216 Main.pref.put("wmsplugin.remotecontrol", 220 Main.pref.put("wmsplugin.remotecontrol", String.valueOf(allowRemoteControl)); 217 221 return false; 218 222 } … … 221 225 * Updates a server URL in the preferences dialog. Used by other plugins. 222 226 * 223 * @param server The server name 224 * @param url The server URL 227 * @param server 228 * The server name 229 * @param url 230 * The server URL 225 231 */ 226 public void setServerUrl(String server, String url) 227 { 228 for (int i = 0; i < model.getRowCount(); i++) 229 { 230 if( server.equals(model.getValueAt(i,0).toString()) ) 231 { 232 public void setServerUrl(String server, String url) { 233 for (int i = 0; i < model.getRowCount(); i++) { 234 if (server.equals(model.getValueAt(i, 0).toString())) { 232 235 model.setValueAt(url, i, 1); 233 236 return; 234 237 } 235 238 } 236 model.addRow(new String[] {server, url});239 model.addRow(new String[] { server, url }); 237 240 } 238 241 … … 240 243 * Gets a server URL in the preferences dialog. Used by other plugins. 241 244 * 242 * @param server The server name 245 * @param server 246 * The server name 243 247 * @return The server URL 244 248 */ 245 public String getServerUrl(String server) 246 { 247 for (int i = 0; i < model.getRowCount(); i++) 248 { 249 if( server.equals(model.getValueAt(i,0).toString()) ) 250 { 251 return model.getValueAt(i,1).toString(); 249 public String getServerUrl(String server) { 250 for (int i = 0; i < model.getRowCount(); i++) { 251 if (server.equals(model.getValueAt(i, 0).toString())) { 252 return model.getValueAt(i, 1).toString(); 252 253 } 253 254 } … … 261 262 class WMSLayerTableModel extends DefaultTableModel { 262 263 public WMSLayerTableModel() { 263 setColumnIdentifiers(new String[] {tr("Menu Name"), tr("WMS URL"), trc("layer", "Zoom")});264 setColumnIdentifiers(new String[] { tr("Menu Name"), tr("WMS URL"), trc("layer", "Zoom") }); 264 265 } 265 266 … … 270 271 public void addRow(WMSInfo i) { 271 272 plugin.info.add(i); 272 int p = getRowCount()-1; 273 fireTableRowsInserted(p,p); 274 } 275 273 int p = getRowCount() - 1; 274 fireTableRowsInserted(p, p); 275 } 276 277 @Override 276 278 public void removeRow(int i) { 277 279 plugin.info.remove(getRow(i)); 278 fireTableRowsDeleted(i, i);280 fireTableRowsDeleted(i, i); 279 281 } 280 282 … … 287 289 public Object getValueAt(int row, int column) { 288 290 WMSInfo info = plugin.info.layers.get(row); 289 switch(column) { 290 case 0: return info.name; 291 case 1: return info.getFullURL(); 292 case 2: return info.pixelPerDegree == 0.0 ? "" : info.pixelPerDegree; 291 switch (column) { 292 case 0: 293 return info.name; 294 case 1: 295 return info.getFullURL(); 296 case 2: 297 return info.pixelPerDegree == 0.0 ? "" : info.pixelPerDegree; 293 298 } 294 299 return null; … … 307 312 class WMSDefaultLayerTableModel extends DefaultTableModel { 308 313 public WMSDefaultLayerTableModel() { 309 setColumnIdentifiers(new String[] {tr("Menu Name (Default)"), tr("WMS URL (Default)")});314 setColumnIdentifiers(new String[] { tr("Menu Name (Default)"), tr("WMS URL (Default)") }); 310 315 } 311 316 … … 322 327 public Object getValueAt(int row, int column) { 323 328 WMSInfo info = plugin.info.defaultLayers.get(row); 324 switch(column) { 325 case 0: return info.name; 326 case 1: return info.getFullURL(); 329 switch (column) { 330 case 0: 331 return info.name; 332 case 1: 333 return info.getFullURL(); 327 334 } 328 335 return null; … … 334 341 } 335 342 } 343 344 private boolean confirmeEulaAcceptance(PreferenceTabbedPane gui, String eulaUrl) { 345 URL url = null; 346 try { 347 url = new URL(eulaUrl.replaceAll("\\{lang\\}", Locale.getDefault().toString())); 348 JEditorPane htmlPane = null; 349 try { 350 htmlPane = new JEditorPane(url); 351 } catch (IOException e1) { 352 // give a second chance with a default Locale 'en' 353 try { 354 url = new URL(eulaUrl.replaceAll("\\{lang\\}", "en")); 355 htmlPane = new JEditorPane(url); 356 } catch (IOException e2) { 357 JOptionPane.showMessageDialog(gui ,tr("EULA license URL not available: {0}", eulaUrl)); 358 return false; 359 } 360 } 361 Box box = Box.createVerticalBox(); 362 htmlPane.setEditable(false); 363 JScrollPane scrollPane = new JScrollPane(htmlPane); 364 scrollPane.setPreferredSize(new Dimension(400, 400)); 365 box.add(scrollPane); 366 int option = JOptionPane.showConfirmDialog(Main.parent, box, tr("Please abort if you are not sure"), JOptionPane.YES_NO_OPTION, 367 JOptionPane.WARNING_MESSAGE); 368 if (option == JOptionPane.YES_OPTION) { 369 return true; 370 } 371 } catch (MalformedURLException e2) { 372 JOptionPane.showMessageDialog(gui ,tr("Malformed URL for the EULA licence: {0}", eulaUrl)); 373 } 374 return false; 375 } 336 376 }
Note:
See TracChangeset
for help on using the changeset viewer.