Changeset 191 in josm for src/org/openstreetmap
- Timestamp:
- 2007-01-08T06:18:17+01:00 (18 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 4 added
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r178 r191 30 30 import org.openstreetmap.josm.actions.DownloadAction.DownloadTask; 31 31 import org.openstreetmap.josm.actions.mapmode.MapMode; 32 import org.openstreetmap.josm.actions.search.SearchAction; 32 33 import org.openstreetmap.josm.data.Bounds; 33 34 import org.openstreetmap.josm.data.Preferences; … … 39 40 import org.openstreetmap.josm.gui.PleaseWaitDialog; 40 41 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 41 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;42 42 import org.openstreetmap.josm.gui.layer.Layer; 43 43 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 322 322 if (args.containsKey("selection")) 323 323 for (String s : args.get("selection")) 324 Se lectionListDialog.search(s, SelectionListDialog.SearchMode.add);324 SearchAction.search(s, SearchAction.SearchMode.add); 325 325 } 326 326 -
src/org/openstreetmap/josm/actions/search/SearchCompiler.java
r186 r191 1 package org.openstreetmap.josm. tools;1 package org.openstreetmap.josm.actions.search; 2 2 3 3 import java.io.IOException; -
src/org/openstreetmap/josm/data/Bounds.java
r86 r191 40 40 41 41 /** 42 * @return Center of the bounding box. 43 */ 44 public LatLon center() { 45 // not sure, whether this calculation is right.. maybe there is some 46 // more complex calculation needed to get a center of a spherical 47 // dimension? 48 return new LatLon((min.lat()+max.lat())/2, (min.lon()+max.lon())/2); 49 } 50 51 /** 42 52 * Extend the bounds if necessary to include the given point. 43 53 */ -
src/org/openstreetmap/josm/gui/MainMenu.java
r186 r191 29 29 import org.openstreetmap.josm.actions.UnselectAllAction; 30 30 import org.openstreetmap.josm.actions.UploadAction; 31 import org.openstreetmap.josm.actions.search.SearchAction; 31 32 32 33 /** … … 44 45 public final Action selectAll = new SelectAllAction(); 45 46 public final Action unselectAll = new UnselectAllAction(); 47 public final Action search = new SearchAction(); 46 48 public final NewAction newAction = new NewAction(); 47 49 public final OpenAction open = new OpenAction(); … … 88 90 editMenu.add(unselectAll); 89 91 editMenu.addSeparator(); 92 editMenu.add(search); 93 editMenu.addSeparator(); 90 94 editMenu.add(reverseSegment); 91 95 editMenu.add(splitWay); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r160 r191 4 4 5 5 import java.awt.BorderLayout; 6 import java.awt.GridBagLayout;7 6 import java.awt.GridLayout; 8 7 import java.awt.event.ActionEvent; … … 11 10 import java.awt.event.MouseAdapter; 12 11 import java.awt.event.MouseEvent; 13 import java.io.IOException;14 import java.io.InputStream;15 import java.net.MalformedURLException;16 import java.net.URL;17 import java.net.URLConnection;18 12 import java.util.Arrays; 19 13 import java.util.Collection; 20 14 import java.util.LinkedList; 21 import java.util.Map;22 15 23 import javax.swing.ButtonGroup;24 16 import javax.swing.DefaultListModel; 25 17 import javax.swing.JButton; 26 import javax.swing.JLabel;27 18 import javax.swing.JList; 28 import javax.swing.JOptionPane;29 19 import javax.swing.JPanel; 30 import javax.swing.JRadioButton;31 20 import javax.swing.JScrollPane; 32 import javax.swing.JTextField;33 21 import javax.swing.ListSelectionModel; 34 22 … … 37 25 import org.openstreetmap.josm.data.osm.OsmPrimitive; 38 26 import org.openstreetmap.josm.gui.OsmPrimitivRenderer; 39 import org.openstreetmap.josm.gui.PleaseWaitRunnable;40 import org.openstreetmap.josm.io.OsmIdReader;41 import org.openstreetmap.josm.io.ProgressInputStream;42 import org.openstreetmap.josm.tools.GBC;43 27 import org.openstreetmap.josm.tools.ImageProvider; 44 import org.openstreetmap.josm.tools.SearchCompiler;45 import org.xml.sax.SAXException;46 28 47 29 /** … … 53 35 */ 54 36 public class SelectionListDialog extends ToggleDialog implements SelectionChangedListener { 55 public static enum SearchMode {replace, add, remove}56 57 private static class SelectionWebsiteLoader extends PleaseWaitRunnable {58 public final URL url;59 public Collection<OsmPrimitive> sel;60 private final SearchMode mode;61 private OsmIdReader idReader = new OsmIdReader();62 public SelectionWebsiteLoader(String urlStr, SearchMode mode) {63 super(tr("Load Selection"));64 this.mode = mode;65 URL u = null;66 try {u = new URL(urlStr);} catch (MalformedURLException e) {}67 this.url = u;68 }69 @Override protected void realRun() {70 Main.pleaseWaitDlg.currentAction.setText(tr("Contact {0}...", url.getHost()));71 sel = mode != SearchMode.remove ? new LinkedList<OsmPrimitive>() : Main.ds.allNonDeletedPrimitives();72 try {73 URLConnection con = url.openConnection();74 InputStream in = new ProgressInputStream(con, Main.pleaseWaitDlg);75 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading..."));76 Map<Long, String> ids = idReader.parseIds(in);77 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) {78 if (ids.containsKey(osm.id) && osm.getClass().getName().toLowerCase().endsWith(ids.get(osm.id))) {79 if (mode == SearchMode.remove)80 sel.remove(osm);81 else82 sel.add(osm);83 }84 }85 } catch (IOException e) {86 e.printStackTrace();87 JOptionPane.showMessageDialog(Main.parent, tr("Could not read from url: \"{0}\"",url));88 } catch (SAXException e) {89 e.printStackTrace();90 JOptionPane.showMessageDialog(Main.parent,tr("Parsing error in url: \"{0}\"",url));91 }92 }93 @Override protected void cancel() {94 sel = null;95 idReader.cancel();96 }97 @Override protected void finish() {98 if (sel != null)99 Main.ds.setSelected(sel);100 }101 }102 37 103 38 /** … … 138 73 })); 139 74 140 buttonPanel.add(createButton("Search", "dialogs/search", "Search for objects.", new ActionListener(){ 141 private String lastSearch = ""; 142 public void actionPerformed(ActionEvent e) { 143 JLabel label = new JLabel(tr("Please enter a search string.")); 144 final JTextField input = new JTextField(lastSearch); 145 input.setToolTipText(tr("<html>Fulltext search.<ul>" + 146 "<li><code>Baker Street</code> - 'Baker' and 'Street' in any key or name.</li>" + 147 "<li><code>\"Baker Street\"</code> - 'Baker Street' in any key or name.</li>" + 148 "<li><code>name:Bak</code> - 'Bak' anywhere in the name.</li>" + 149 "<li><code>-name:Bak</code> - not 'Bak' in the name.</li>" + 150 "<li><code>foot:</code> - key=foot set to any value." + 151 "</ul></html>")); 152 153 JRadioButton replace = new JRadioButton(tr("replace selection"), true); 154 JRadioButton add = new JRadioButton(tr("add to selection"), false); 155 JRadioButton remove = new JRadioButton(tr("remove from selection"), false); 156 ButtonGroup bg = new ButtonGroup(); 157 bg.add(replace); 158 bg.add(add); 159 bg.add(remove); 160 161 JPanel p = new JPanel(new GridBagLayout()); 162 p.add(label, GBC.eop()); 163 p.add(input, GBC.eop().fill(GBC.HORIZONTAL)); 164 p.add(replace, GBC.eol()); 165 p.add(add, GBC.eol()); 166 p.add(remove, GBC.eol()); 167 JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null){ 168 @Override public void selectInitialValue() { 169 input.requestFocusInWindow(); 170 } 171 }; 172 pane.createDialog(Main.parent,tr("Search")).setVisible(true); 173 if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue())) 174 return; 175 lastSearch = input.getText(); 176 SearchMode mode = replace.isSelected() ? SearchMode.replace : (add.isSelected() ? SearchMode.add : SearchMode.remove); 177 search(lastSearch, mode); 178 } 179 })); 75 buttonPanel.add(createButton("Search", "dialogs/search", "Search for objects.", Main.main.menu.search)); 180 76 181 77 add(buttonPanel, BorderLayout.SOUTH); … … 229 125 Main.ds.setSelected(sel); 230 126 } 231 232 public static void search(String search, SearchMode mode) {233 if (search.startsWith("http://") || search.startsWith("ftp://") || search.startsWith("https://") || search.startsWith("file:/")) {234 SelectionWebsiteLoader loader = new SelectionWebsiteLoader(search, mode);235 if (loader.url != null) {236 Main.worker.execute(loader);237 return;238 }239 }240 Collection<OsmPrimitive> sel = Main.ds.getSelected();241 SearchCompiler.Match matcher = SearchCompiler.compile(search);242 for (OsmPrimitive osm : Main.ds.allNonDeletedPrimitives()) {243 if (mode == SearchMode.replace) {244 if (matcher.match(osm))245 sel.add(osm);246 else247 sel.remove(osm);248 } else if (mode == SearchMode.add && !osm.selected && matcher.match(osm))249 sel.add(osm);250 else if (mode == SearchMode.remove && osm.selected && matcher.match(osm))251 sel.remove(osm);252 }253 Main.ds.setSelected(sel);254 }255 127 }
Note:
See TracChangeset
for help on using the changeset viewer.