Changeset 191 in josm for src/org/openstreetmap/josm


Ignore:
Timestamp:
2007-01-08T06:18:17+01:00 (17 years ago)
Author:
imi
Message:
  • added search to toolbar (configurable in preferences)
  • added QuickSearch with geonames access (not finished)
Location:
src/org/openstreetmap/josm
Files:
4 added
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/Main.java

    r178 r191  
    3030import org.openstreetmap.josm.actions.DownloadAction.DownloadTask;
    3131import org.openstreetmap.josm.actions.mapmode.MapMode;
     32import org.openstreetmap.josm.actions.search.SearchAction;
    3233import org.openstreetmap.josm.data.Bounds;
    3334import org.openstreetmap.josm.data.Preferences;
     
    3940import org.openstreetmap.josm.gui.PleaseWaitDialog;
    4041import org.openstreetmap.josm.gui.MapView.LayerChangeListener;
    41 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
    4242import org.openstreetmap.josm.gui.layer.Layer;
    4343import org.openstreetmap.josm.gui.layer.OsmDataLayer;
     
    322322                if (args.containsKey("selection"))
    323323                        for (String s : args.get("selection"))
    324                                 SelectionListDialog.search(s, SelectionListDialog.SearchMode.add);
     324                                SearchAction.search(s, SearchAction.SearchMode.add);
    325325        }
    326326
  • src/org/openstreetmap/josm/actions/search/SearchCompiler.java

    r186 r191  
    1 package org.openstreetmap.josm.tools;
     1package org.openstreetmap.josm.actions.search;
    22
    33import java.io.IOException;
  • src/org/openstreetmap/josm/data/Bounds.java

    r86 r191  
    4040
    4141        /**
     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        /**
    4252         * Extend the bounds if necessary to include the given point.
    4353         */
  • src/org/openstreetmap/josm/gui/MainMenu.java

    r186 r191  
    2929import org.openstreetmap.josm.actions.UnselectAllAction;
    3030import org.openstreetmap.josm.actions.UploadAction;
     31import org.openstreetmap.josm.actions.search.SearchAction;
    3132
    3233/**
     
    4445        public final Action selectAll = new SelectAllAction();
    4546        public final Action unselectAll = new UnselectAllAction();
     47        public final Action search = new SearchAction();
    4648        public final NewAction newAction = new NewAction();
    4749        public final OpenAction open = new OpenAction();
     
    8890                editMenu.add(unselectAll);
    8991                editMenu.addSeparator();
     92                editMenu.add(search);
     93                editMenu.addSeparator();
    9094                editMenu.add(reverseSegment);
    9195                editMenu.add(splitWay);
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r160 r191  
    44
    55import java.awt.BorderLayout;
    6 import java.awt.GridBagLayout;
    76import java.awt.GridLayout;
    87import java.awt.event.ActionEvent;
     
    1110import java.awt.event.MouseAdapter;
    1211import 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;
    1812import java.util.Arrays;
    1913import java.util.Collection;
    2014import java.util.LinkedList;
    21 import java.util.Map;
    2215
    23 import javax.swing.ButtonGroup;
    2416import javax.swing.DefaultListModel;
    2517import javax.swing.JButton;
    26 import javax.swing.JLabel;
    2718import javax.swing.JList;
    28 import javax.swing.JOptionPane;
    2919import javax.swing.JPanel;
    30 import javax.swing.JRadioButton;
    3120import javax.swing.JScrollPane;
    32 import javax.swing.JTextField;
    3321import javax.swing.ListSelectionModel;
    3422
     
    3725import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3826import 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;
    4327import org.openstreetmap.josm.tools.ImageProvider;
    44 import org.openstreetmap.josm.tools.SearchCompiler;
    45 import org.xml.sax.SAXException;
    4628
    4729/**
     
    5335 */
    5436public 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                                                 else
    82                                                         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         }
    10237
    10338        /**
     
    13873                }));
    13974
    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));
    18076
    18177                add(buttonPanel, BorderLayout.SOUTH);
     
    229125                Main.ds.setSelected(sel);
    230126        }
    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                                 else
    247                                         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         }
    255127}
Note: See TracChangeset for help on using the changeset viewer.