Changeset 30777 in osm for applications/editors
- Timestamp:
- 2014-10-29T20:09:47+01:00 (10 years ago)
- Location:
- applications/editors/josm/plugins/waypoint_search/src/org/openstreetmap/josm/plugins/waypointSearch
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/waypoint_search/src/org/openstreetmap/josm/plugins/waypointSearch/Engine.java
r30737 r30777 8 8 import java.util.regex.Pattern; 9 9 10 publicclass Engine {10 class Engine { 11 11 12 public List<Marker> searchGpxWaypoints(String waypointSearchPattern) { 12 private Engine() { 13 // Utility class 14 } 15 16 static List<Marker> searchGpxWaypoints(String waypointSearchPattern) { 13 17 List<Marker> returnList = new ArrayList<>(); 14 18 if (gpxLayersExist()) { 15 19 //Loop over marker (waypoint) layers.. it could be more than one 16 for (Iterator<MarkerLayer> layerIterator = Main.map.mapView.getLayersOfType(MarkerLayer.class).iterator(); layerIterator.hasNext();) {20 for (Iterator<MarkerLayer> it = Main.map.mapView.getLayersOfType(MarkerLayer.class).iterator(); it.hasNext();) { 17 21 //loop over each marker (waypoint) 18 for (Iterator<Marker> markerIterator = layerIterator.next().data.iterator(); markerIterator.hasNext();) {22 for (Iterator<Marker> markerIterator = it.next().data.iterator(); markerIterator.hasNext();) { 19 23 Marker marker = markerIterator.next(); 20 24 if (Pattern.matches(".*\\Q"+waypointSearchPattern.toLowerCase()+"\\E.*", marker.getText().toLowerCase())) { … … 26 30 return returnList; 27 31 } 28 29 30 31 32 32 33 34 35 36 public boolean gpxLayersExist() { 37 boolean rv = false; 38 if (Main.map != null) { 39 if (Main.map.mapView.hasLayers()) { 40 if (Main.map.mapView.getLayersOfType(MarkerLayer.class).size()>0) { 41 rv = true; 42 } 43 } 44 } 45 return rv; 33 static boolean gpxLayersExist() { 34 return Main.map != null && Main.map.mapView.hasLayers() && !Main.map.mapView.getLayersOfType(MarkerLayer.class).isEmpty(); 46 35 } 47 48 49 50 36 } -
applications/editors/josm/plugins/waypoint_search/src/org/openstreetmap/josm/plugins/waypointSearch/SelectWaypointDialog.java
r30737 r30777 17 17 import static org.openstreetmap.josm.tools.I18n.tr; 18 18 19 publicclass SelectWaypointDialog extends ToggleDialog implements KeyListener, MouseListener {19 class SelectWaypointDialog extends ToggleDialog implements KeyListener, MouseListener { 20 20 21 21 private JTextField searchPattern = new JTextField(20); 22 22 private DefaultListModel<String> listModel = new DefaultListModel<>(); 23 23 private JList<String> searchResult = new JList<>(listModel); 24 private List<Marker> SearchResultObjectCache = new ArrayList<>(); 25 private boolean first_time_search = true; 26 private Engine engine = new Engine(); 24 private List<Marker> searchResultObjectCache = new ArrayList<>(); 25 private boolean firstTimeSearch = true; 27 26 28 publicSelectWaypointDialog(String name, String iconName, String tooltip,27 SelectWaypointDialog(String name, String iconName, String tooltip, 29 28 Shortcut shortcut, int preferredHeight) { 30 29 super(name, iconName, tooltip, shortcut, preferredHeight); … … 58 57 } 59 58 60 public void updateSearchResults(){59 void updateSearchResults() { 61 60 String searchfor = ""; 62 61 listModel.clear(); 63 SearchResultObjectCache.clear();64 if (!first _time_search) {62 searchResultObjectCache.clear(); 63 if (!firstTimeSearch) { 65 64 searchfor = searchPattern.getText(); 66 65 } 67 for (Iterator<Marker> i = engine.searchGpxWaypoints(searchfor).iterator(); i.hasNext();) {66 for (Iterator<Marker> i = Engine.searchGpxWaypoints(searchfor).iterator(); i.hasNext();) { 68 67 Marker marker = i.next(); 69 68 listModel.addElement(marker.getText()); 70 SearchResultObjectCache.add(marker);69 searchResultObjectCache.add(marker); 71 70 } 72 71 } … … 74 73 @Override 75 74 public void keyPressed(KeyEvent arg0) { 76 // TODO Auto-generated method stub75 // Do nothing 77 76 } 78 77 79 78 @Override 80 79 public void keyReleased(KeyEvent arg0) { 81 // TODO Auto-generated method stub82 80 updateSearchResults(); 83 81 } … … 85 83 @Override 86 84 public void keyTyped(KeyEvent arg0) { 87 first _time_search = false;85 firstTimeSearch = false; 88 86 } 89 87 … … 92 90 if (e.getSource()==searchResult) { 93 91 //click on the search result box 94 Marker marker = SearchResultObjectCache.get(searchResult.getSelectedIndex());92 Marker marker = searchResultObjectCache.get(searchResult.getSelectedIndex()); 95 93 Main.map.mapView.zoomTo(marker.getCoor()); 96 94 } else { … … 101 99 @Override 102 100 public void mouseEntered(MouseEvent arg0) { 101 // Do nothing 103 102 } 104 103 105 104 @Override 106 105 public void mouseExited(MouseEvent arg0) { 106 // Do nothing 107 107 } 108 108 … … 116 116 @Override 117 117 public void mouseReleased(MouseEvent arg0) { 118 // Do nothing 118 119 } 119 120 } -
applications/editors/josm/plugins/waypoint_search/src/org/openstreetmap/josm/plugins/waypointSearch/WaypointSearchPlugin.java
r28624 r30777 10 10 import org.openstreetmap.josm.plugins.PluginInformation; 11 11 12 /** 13 * This plugin enables a user to search for waypoint imported from a gpx file. 14 * After the plugin is installed a new button is presented on the left side of the map window. 15 * Pressing this buttons open the search dialog on the right side. 16 * Click on one of the search results/waypoints to move the map. 17 */ 12 18 public class WaypointSearchPlugin extends Plugin implements LayerChangeListener { 13 /**14 * Will be invoked by JOSM to bootstrap the plugin15 *16 * @param info information about the plugin and its local installation17 */18 private final Engine engine = new Engine();19 19 private SelectWaypointDialog waypointDialog; 20 20 21 /** 22 * Will be invoked by JOSM to bootstrap the plugin 23 * 24 * @param info information about the plugin and its local installation 25 */ 21 26 public WaypointSearchPlugin(PluginInformation info) { 22 super(info);23 MapView.addLayerChangeListener(this);27 super(info); 28 MapView.addLayerChangeListener(this); 24 29 } 25 30 26 @Override 27 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 28 if (newFrame != null) { 29 newFrame.addToggleDialog(waypointDialog = new SelectWaypointDialog( 30 tr("Waypoint search"), "ToolbarIcon", tr("Search after waypoint. Click and move the map view to the waypoint."), null, 100)); 31 } else { 32 waypointDialog = null; 33 } 34 } 31 @Override 32 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 33 if (newFrame != null) { 34 waypointDialog = new SelectWaypointDialog( 35 tr("Waypoint search"), "ToolbarIcon", 36 tr("Search after waypoint. Click and move the map view to the waypoint."), null, 100); 37 newFrame.addToggleDialog(waypointDialog); 38 } else { 39 waypointDialog = null; 40 } 41 } 35 42 36 43 @Override 37 44 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 45 // Do nothing 38 46 } 39 47 … … 41 49 public void layerAdded(Layer newLayer) { 42 50 // update search 43 if (waypointDialog != null && engine.gpxLayersExist()) {51 if (waypointDialog != null && Engine.gpxLayersExist()) { 44 52 waypointDialog.updateSearchResults(); 45 53 } … … 48 56 @Override 49 57 public void layerRemoved(Layer oldLayer) { 50 if (waypointDialog != null && ! engine.gpxLayersExist()) {58 if (waypointDialog != null && !Engine.gpxLayersExist()) { 51 59 waypointDialog.updateSearchResults(); 52 60 }
Note:
See TracChangeset
for help on using the changeset viewer.