Changeset 26639 in osm for applications/editors
- Timestamp:
- 2011-09-11T12:48:35+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/utilsplugin2
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/build.xml
r26624 r26639 30 30 <project name="utilsplugin2" default="dist" basedir="."> 31 31 <!-- enter the SVN commit message --> 32 <property name="commit.message" value="Utilsplugin2: added setting tab"/>32 <property name="commit.message" value="Utilsplugin2: configuring custom URLs"/> 33 33 <!-- enter the *lowest* JOSM version this plugin is currently compatible with --> 34 34 <property name="plugin.main.version" value="4395"/> -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/OpenPageAction.java
r26624 r26639 10 10 import java.awt.event.KeyEvent; 11 11 import java.net.URLEncoder; 12 import java.util.ArrayList;13 12 import java.util.Collection; 14 13 14 import java.util.List; 15 15 import java.util.regex.Matcher; 16 16 17 17 import java.util.regex.Pattern; 18 18 import javax.swing.BorderFactory; 19 import javax.swing.JComboBox; 19 20 import javax.swing.JOptionPane; 20 21 … … 63 64 return; 64 65 } 66 if (Main.pref.getBoolean("utilsplugin2.askurl",false)==true) 67 ChooseURLAction.showConfigDialog(); 65 68 66 69 String addr = Main.pref.get("utilsplugin2.customurl", defaultURL); … … 122 125 setEnabled(selection != null ); 123 126 } 127 124 128 } -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPlugin2.java
r26624 r26639 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.actions.JosmAction; 12 13 import org.openstreetmap.josm.gui.MainMenu; 13 14 import org.openstreetmap.josm.gui.MapFrame; … … 42 43 JMenuItem selModifiedWays; 43 44 45 JMenuItem selectURL; 46 44 47 public UtilsPlugin2(PluginInformation info) { 45 48 super(info); … … 73 76 selModifiedWays = MainMenu.add(selectionMenu, new SelectModWaysAction()); 74 77 undoSelection = MainMenu.add(selectionMenu, new UndoSelectionAction()); 78 79 selectURL = MainMenu.add(toolsMenu, new ChooseURLAction()); 80 81 75 82 } 76 83 … … 102 109 selModifiedWays.setEnabled(enabled); 103 110 undoSelection.setEnabled(enabled); 111 selectURL.setEnabled(enabled); 104 112 } 105 113 @Override -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/UtilsPluginPreferences.java
r26626 r26639 5 5 package utilsplugin2; 6 6 7 import java.util.Scanner; 8 import java.awt.event.ActionEvent; 9 import javax.swing.JButton; 7 10 import java.util.List; 8 11 import javax.swing.table.TableModel; … … 16 19 import javax.swing.event.TableModelEvent; 17 20 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.gui.ExtendedDialog;19 21 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 20 22 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 21 23 import java.awt.GridBagConstraints; 24 import java.awt.event.ActionListener; 25 import java.io.BufferedReader; 26 import java.io.BufferedWriter; 27 import java.io.File; 28 import java.io.FileReader; 29 import java.io.FileWriter; 30 import java.io.PrintWriter; 22 31 import javax.swing.JPanel; 23 32 import javax.swing.ListSelectionModel; … … 35 44 HistoryComboBox combo1=new HistoryComboBox(); 36 45 JTable table; 46 JButton resetButton; 47 JButton loadButton; 48 JButton saveButton; 37 49 38 50 @Override … … 46 58 // FIXME: get rid of hardcoded URLS 47 59 List<String> items = (List<String>) Main.pref.getCollection("utilsplugin2.urlHistory"); 48 if (items==null || items.size()==0) { 49 items= new ArrayList<String>(); 50 items.add("Wikipedia"); 51 items.add("http://en.wikipedia.org/w/index.php?search={name}&fulltext=Search"); 52 items.add("Wikipedia RU"); 53 items.add(defaultURL); 54 items.add("LatLon buildings"); 55 items.add("http://latlon.org/buildings?zoom=17&lat={#lat}&lon={#lon}&layers=B"); 56 items.add("AMDMi3 Russian streets"); 57 items.add("http://addresses.amdmi3.ru/?zoom=11&lat={#lat}&lon={#lon}&layers=B00"); 58 items.add("Element history"); 59 items.add("http://www.openstreetmap.org/browse/{#type}/{#id}/history"); 60 items.add("Browse element"); 61 items.add("http://www.openstreetmap.org/browse/{#type}/{#id}"); 60 if (items==null) { 61 items = resetURLList(); 62 fillRows(items); 62 63 } 63 64 String addr = Main.pref.get("utilsplugin2.customurl", defaultURL); 64 65 //System.out.println("pref:"+addr); 66 67 resetButton = new JButton(tr("Reset")); 68 resetButton.addActionListener(new ActionListener() { 69 public void actionPerformed(ActionEvent e) { 70 fillRows(resetURLList()); 71 } 72 }); 73 74 saveButton = new JButton(tr("Save to file")); 75 saveButton.addActionListener(new ActionListener() { 76 public void actionPerformed(ActionEvent e) { 77 saveURLList(); 78 } 79 }); 80 81 loadButton = new JButton(tr("Load from file")); 82 loadButton.addActionListener(new ActionListener() { 83 public void actionPerformed(ActionEvent e) { 84 fillRows(loadURLList()); 85 } 86 }); 65 87 66 88 table=new JTable(new DefaultTableModel(null,new String[]{"Title","URL"})); … … 71 93 + " <b>{#id}</b> is replaced with the element ID<br/>" 72 94 + " <b>{#type}</b> is replaced with \"node\",\"way\" or \"relation\" <br/>" 73 + " <b>{#lat} , {#lon}</b> is replaced with element latitude/longitude")); 74 //help.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.)); 75 76 all.add(new JLabel(tr("Custom URL configuration")),GBC.eop().insets(5,10,0,0)); 95 + " <b>{#lat} , {#lon}</b> is replaced with element latitude/longitude <br/>" 96 + " Your can manually load settings from file <b>customurl.txt</b> in JOSM folder")); 97 98 all.add(new JLabel(tr("Custom URL configuration")),GBC.std().insets(5,10,0,0)); 99 all.add(resetButton,GBC.std().insets(25,10,0,0)); 100 all.add(loadButton,GBC.std().insets(25,10,0,0)); 101 all.add(saveButton,GBC.eol().insets(25,10,0,0)); 77 102 all.add(help,GBC.eop().insets(5,10,0,0)); 78 103 … … 87 112 int column = e.getColumn(); 88 113 DefaultTableModel model = (DefaultTableModel)(e.getSource()); 89 String columnName = model.getColumnName(column);90 114 if (row<0 || column<0) return; 91 115 String data = (String)model.getValueAt(row, column); … … 100 124 101 125 private void fillRows(List<String> items) { 126 if (items==null) return; 102 127 int p=0,row=0; 103 128 String name, url; 104 String data[][] = new String[][] {{"",""}};105 129 DefaultTableModel model = (DefaultTableModel) table.getModel(); 130 model.setRowCount(0); 106 131 int n=items.size(); 107 132 while (true) { … … 123 148 public boolean ok() { 124 149 String addr=combo1.getText(); 150 List<String> lst = readItemsFromTable(); 151 Main.pref.putCollection("utilsplugin2.urlHistory",lst); 152 try { 153 Main.pref.save(); 154 } catch (IOException ex) { 155 Logger.getLogger(UtilsPluginPreferences.class.getName()).log(Level.SEVERE, null, ex); 156 } 157 return false; 158 } 159 160 private List<String> resetURLList() { 161 ArrayList<String> items=new ArrayList<String>(); 162 items= new ArrayList<String>(); 163 items.add("Wikipedia"); 164 items.add("http://en.wikipedia.org/w/index.php?search={name}&fulltext=Search"); 165 items.add("Wikipedia RU"); 166 items.add(defaultURL); 167 items.add("LatLon buildings"); 168 items.add("http://latlon.org/buildings?zoom=17&lat={#lat}&lon={#lon}&layers=B"); 169 items.add("AMDMi3 Russian streets"); 170 items.add("http://addresses.amdmi3.ru/?zoom=11&lat={#lat}&lon={#lon}&layers=B00"); 171 items.add("Element history [demo, =Ctrl-Shift-H]"); 172 items.add("http://www.openstreetmap.org/browse/{#type}/{#id}/history"); 173 items.add("Browse element [demo, =Ctrl-Shift-I]"); 174 items.add("http://www.openstreetmap.org/browse/{#type}/{#id}"); 175 Main.pref.putCollection("utilsplugin2.urlHistory",items); 176 return items; 177 } 178 179 private List<String> loadURLList() { 180 ArrayList<String> items=new ArrayList<String>(); 181 BufferedReader fr=null; 182 try { 183 File f = new File (Main.pref.getPreferencesDir(),"customurl.txt"); 184 fr = new BufferedReader(new FileReader(f)); 185 String s; 186 while ((s = fr.readLine()) !=null ) items.add(s); 187 } catch (IOException e) { 188 e.printStackTrace(); 189 } finally { 190 try { if (fr!=null) fr.close(); } catch (Exception e) {} 191 } 192 return items; 193 194 } 195 196 private void saveURLList() { 197 List<String> items=readItemsFromTable(); 198 File f = new File (Main.pref.getPreferencesDir(),"customurl.txt"); 199 PrintWriter fw=null; 200 try { 201 fw=new PrintWriter(f); 202 for (String s : items) { 203 fw.println(s); 204 } 205 } catch (IOException e) { 206 e.printStackTrace(); 207 } finally { 208 try { if (fw!=null) fw.close(); } catch (Exception e) {} 209 } 210 } 211 212 private List<String> readItemsFromTable() { 125 213 TableModel model = (table.getModel()); 126 214 String v; … … 134 222 lst.add(v); 135 223 } 136 Main.pref.putCollection("utilsplugin2.urlHistory",lst);137 224 int row=table.getSelectedRow(); 138 225 if (row!=-1) { … … 140 227 Main.pref.put("utilsplugin2.customurl",v); 141 228 } 142 143 try { 144 Main.pref.save(); 145 } catch (IOException ex) { 146 Logger.getLogger(UtilsPluginPreferences.class.getName()).log(Level.SEVERE, null, ex); 147 } 148 return false; 149 } 150 151 229 return lst; 230 } 152 231 } -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/selection/IntersectedWaysRecursiveAction.java
r25876 r26639 25 25 super(tr("All intersecting ways"), "intwayall", tr("Select all intersecting ways"), 26 26 Shortcut.registerShortcut("tools:intwayall", tr("Tool: {0}","All intersecting ways"), 27 KeyEvent.VK_I, Shortcut.GROUP_MENU, KeyEvent. SHIFT_DOWN_MASK|KeyEvent.CTRL_DOWN_MASK), true);27 KeyEvent.VK_I, Shortcut.GROUP_MENU, KeyEvent.CTRL_DOWN_MASK|KeyEvent.ALT_DOWN_MASK), true); 28 28 putValue("help", ht("/Action/SelectAllIntersectingWays")); 29 29
Note:
See TracChangeset
for help on using the changeset viewer.