Changeset 10767 in osm for applications/editors/josm
- Timestamp:
- 2008-09-18T09:43:02+02:00 (16 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
r10382 r10767 8 8 * @author Frederik Ramm <frederik@remote.org> 9 9 */ 10 public class WMSInfo {10 public class WMSInfo implements Comparable { 11 11 12 12 String name; … … 23 23 Main.pref.put("wmsplugin.url." + prefid + ".url", url); 24 24 } 25 25 public int compareTo(Object c) 26 { 27 Integer i = 0; 28 if(c instanceof WMSInfo) 29 { 30 WMSInfo in = (WMSInfo)c; 31 i = name.compareTo(in.name); 32 if(i == 0) 33 i = url.compareTo(in.url); 34 if(i == 0) 35 i = prefid-in.prefid; 36 } 37 return i; 38 } 26 39 } -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java
r10645 r10767 7 7 import java.awt.event.KeyEvent; 8 8 import java.util.ArrayList; 9 import java.util.Collections; 9 10 import java.util.Map; 10 11 import java.util.TreeSet; … … 39 40 static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>(); 40 41 41 42 42 // remember state of menu item to restore on changed preferences 43 static private boolean menuEnabled = false; 43 44 44 45 public WMSPlugin() { … … 82 83 String url = null; 83 84 int lastid = -1; 84 boolean isYahoo = false;85 85 for (String key : keys) { 86 86 String[] elements = key.split("\\."); … … 92 92 } 93 93 if (prefid != lastid) { 94 if ((name != null) && (url != null)) { 95 wmsList.add(new WMSInfo(name, url, prefid)); 96 if(url.startsWith("yahoo://")) isYahoo = true; 97 } 98 name = null; url = null; lastid = prefid; 94 name = url = null; lastid = prefid; 99 95 } 100 if (elements[3].equals("name")) {101 name =prefs.get(key);102 } else if (elements[3].equals("url")) {96 if (elements[3].equals("name")) 97 name = prefs.get(key); 98 else if (elements[3].equals("url")) 103 99 url = prefs.get(key); 104 } 100 if (name != null && url != null) 101 wmsList.add(new WMSInfo(name, url, prefid)); 105 102 } 106 if ((name != null) && (url != null)) {107 wmsList.add(new WMSInfo(name, url, prefid));108 if(url.startsWith("yahoo://")) isYahoo = true;109 }103 setDefault(tr("Landsat"), "http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&"+ 104 "layers=global_mosaic&styles=&srs=EPSG:4326&format=image/jpeg"); 105 setDefault(tr("NPE Maps"), "http://nick.dev.openstreetmap.org/openpaths/freemap.php?layers=npe&"); 106 setDefault(tr("YAHOO"), "yahoo://gnome-web-photo --mode=photo --format=png {0} /dev/stdout"); 110 107 111 // if no (valid) prefs are set, initialize to a sensible default. 112 if (wmsList.isEmpty()) { 113 WMSInfo landsatInfo = new WMSInfo(tr("Landsat"), 114 "http://onearth.jpl.nasa.gov/wms.cgi?request=GetMap&"+ 115 "layers=global_mosaic&styles=&srs=EPSG:4326&"+ 116 "format=image/jpeg", 1); 117 landsatInfo.save(); 118 wmsList.add(landsatInfo); 119 120 WMSInfo npeInfo = new WMSInfo(tr("NPE Maps"), 121 "http://nick.dev.openstreetmap.org/openpaths/freemap.php?layers=npe&", 2); 122 npeInfo.save(); 123 wmsList.add(npeInfo); 124 } 125 if(!isYahoo){ //add Yahoo to the list, if there isn't 126 int maxKey = 0; 127 for(WMSInfo in : wmsList) 128 if(maxKey < in.prefid)maxKey = in.prefid; 129 WMSInfo yahooInfo = new WMSInfo(tr("YAHOO"), 130 "yahoo://gnome-web-photo --mode=photo --format=png {0} /dev/stdout", maxKey+1); 131 yahooInfo.save(); 132 wmsList.add(yahooInfo); 133 } 134 108 Collections.sort(wmsList); 135 109 JMenuBar menu = Main.main.menu; 136 110 … … 159 133 wmsJMenu.addSeparator(); 160 134 wmsJMenu.add(new JMenuItem(new Help_WMSmenuAction())); 161 setEnabledAll(menuEnabled); 135 setEnabledAll(menuEnabled); 136 } 137 138 /* add a default entry in case the URL does not yet exist */ 139 private static void setDefault(String name, String url) 140 { 141 String testurl = url.replaceAll("=", "_"); 142 if(!Main.pref.getBoolean("wmsplugin.default."+testurl)) 143 { 144 Main.pref.put("wmsplugin.default."+testurl, true); 145 int id = -1; 146 for(WMSInfo i : wmsList) 147 { 148 if(url.equals(i.url)) 149 return; 150 if(i.prefid > id) 151 id = i.prefid; 152 } 153 WMSInfo newinfo = new WMSInfo(name, url, id+1); 154 newinfo.save(); 155 wmsList.add(newinfo); 156 } 162 157 } 163 158 -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPreferenceEditor.java
r8721 r10767 30 30 private Map<String,String> orig; 31 31 private DefaultTableModel model; 32 private int highestIdUsed = 0;33 32 private HashMap<Integer, WMSInfo> oldValues = new HashMap<Integer, WMSInfo>(); 34 33 … … 36 35 JPanel p = gui.createPreferenceTab("wms", tr("WMS Plugin Preferences"), tr("Modify list of WMS servers displayed in the WMS plugin menu")); 37 36 38 model = new DefaultTableModel(new String[]{"#", tr("Menu Name"), tr("WMS URL")}, 0) { 39 @Override public boolean isCellEditable(int row, int column) { 40 return column != 0; 41 } 42 }; 37 model = new DefaultTableModel(new String[]{tr("Menu Name"), tr("WMS URL")}, 0); 43 38 final JTable list = new JTable(model); 44 list.getColumnModel().removeColumn(list.getColumnModel().getColumn(0));45 39 JScrollPane scroll = new JScrollPane(list); 46 40 p.add(scroll, GBC.eol().fill(GBC.BOTH)); … … 49 43 for (WMSInfo i : WMSPlugin.wmsList) { 50 44 oldValues.put(i.prefid, i); 51 model.addRow(new String[]{Integer.toString(i.prefid), i.name, i.url}); 52 if (i.prefid > highestIdUsed) highestIdUsed = i.prefid; 45 model.addRow(new String[]{i.name, i.url}); 53 46 } 54 47 … … 67 60 int answer = JOptionPane.showConfirmDialog(gui, p, tr("Enter a menu name and WMS URL"), JOptionPane.OK_CANCEL_OPTION); 68 61 if (answer == JOptionPane.OK_OPTION) { 69 highestIdUsed++; 70 model.addRow(new String[]{Integer.toString(highestIdUsed), key.getText(), value.getText()}); 62 model.addRow(new String[]{key.getText(), value.getText()}); 71 63 } 72 64 } 73 65 }); 74 66 75 67 JButton delete = new JButton(tr("Delete")); 76 68 p.add(delete, GBC.std().insets(0,5,0,0)); 77 69 delete.addActionListener(new ActionListener(){ 78 70 public void actionPerformed(ActionEvent e) { 79 if (list.getSelectedRow Count() == 0) {71 if (list.getSelectedRow() == -1) 80 72 JOptionPane.showMessageDialog(gui, tr("Please select the row to delete.")); 81 return; 73 else 74 { 75 Integer i; 76 while ((i = list.getSelectedRow()) != -1) 77 model.removeRow(i); 82 78 } 83 while (list.getSelectedRow() != -1)84 model.removeRow(list.getSelectedRow());85 79 } 86 80 }); … … 90 84 boolean change = false; 91 85 for (int i = 0; i < model.getRowCount(); ++i) { 92 int id = Integer.parseInt(model.getValueAt(i, 0).toString());93 String name= model.getValueAt(i,1).toString();94 String url = model.getValueAt(i,2).toString(); 95 96 WMSInfo origValue = oldValues.get(id);97 if (origValue == null){98 new WMSInfo(name, url, i d).save();86 String name = model.getValueAt(i,0).toString(); 87 String url = model.getValueAt(i,1).toString(); 88 89 WMSInfo origValue = oldValues.get(i); 90 if (origValue == null) 91 { 92 new WMSInfo(name, url, i).save(); 99 93 change = true; 100 } else { 101 if (origValue.name.equals(name) && origValue.url.equals(url)) { 102 // no change 103 } else { 94 } 95 else 96 { 97 if (!origValue.name.equals(name) || !origValue.url.equals(url)) 98 { 104 99 origValue.name = name; 105 100 origValue.url = url; … … 107 102 change = true; 108 103 } 109 oldValues.remove(i d);104 oldValues.remove(i); 110 105 } 111 106 } 112 107 113 // using null values instead of empty string really deletes 114 // the preferences entry 115 for (WMSInfo i : oldValues.values()) { 116 i.url = null; 117 i.name = null; 108 // using null values instead of empty string really deletes 109 // the preferences entry 110 for (WMSInfo i : oldValues.values()) 111 { 112 i.url = null; 113 i.name = null; 118 114 i.save(); 119 115 change = true; 120 116 } 121 117 122 118 if (change) WMSPlugin.refreshMenu(); 123 119 } … … 133 129 for (int i = 0; i < model.getRowCount(); i++) 134 130 { 135 String name = model.getValueAt(i,1).toString(); 136 if( name.equals(server) ) 131 if( server.equals(model.getValueAt(i,0).toString()) ) 137 132 { 138 model.setValueAt(url, i, 2);133 model.setValueAt(url, i, 1); 139 134 return; 140 135 } 141 } 136 } 137 model.addRow(new String[]{server, url}); 138 } 142 139 143 highestIdUsed++;144 model.addRow(new String[]{Integer.toString(highestIdUsed), server, url});145 }146 147 140 /** 148 141 * Gets a server URL in the preferences dialog. Used by other plugins. 149 * 142 * 150 143 * @param server The server name 151 144 * @return The server URL … … 155 148 for (int i = 0; i < model.getRowCount(); i++) 156 149 { 157 String name = model.getValueAt(i,1).toString(); 158 if( name.equals(server) ) 150 if( server.equals(model.getValueAt(i,0).toString()) ) 159 151 { 160 String url = model.getValueAt(i,2).toString(); 161 return url; 152 return model.getValueAt(i,1).toString(); 162 153 } 163 154 } 164 165 155 return null; 166 156 }
Note:
See TracChangeset
for help on using the changeset viewer.