Ignore:
Timestamp:
2014-10-29T20:09:47+01:00 (10 years ago)
Author:
donvip
Message:

[josm_waypoint_search] fix sonar issues

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  
    88import java.util.regex.Pattern;
    99
    10 public class Engine {
     10class Engine {
    1111   
    12     public List<Marker> searchGpxWaypoints(String waypointSearchPattern) {
     12    private Engine() {
     13        // Utility class
     14    }
     15
     16    static List<Marker> searchGpxWaypoints(String waypointSearchPattern) {
    1317        List<Marker> returnList = new ArrayList<>();
    1418        if (gpxLayersExist()) {
    1519            //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();) {
    1721                //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();) {
    1923                    Marker marker = markerIterator.next();
    2024                    if (Pattern.matches(".*\\Q"+waypointSearchPattern.toLowerCase()+"\\E.*", marker.getText().toLowerCase())) {
     
    2630        return returnList;
    2731    }   
    28        
    29        
    30        
    3132   
    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();
    4635    }
    47    
    48    
    49    
    5036}
  • applications/editors/josm/plugins/waypoint_search/src/org/openstreetmap/josm/plugins/waypointSearch/SelectWaypointDialog.java

    r30737 r30777  
    1717import static org.openstreetmap.josm.tools.I18n.tr;
    1818
    19 public class SelectWaypointDialog extends ToggleDialog implements KeyListener, MouseListener {
     19class SelectWaypointDialog extends ToggleDialog implements KeyListener, MouseListener {
    2020
    2121    private JTextField searchPattern = new JTextField(20);
    2222    private DefaultListModel<String> listModel = new DefaultListModel<>();
    2323    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;
    2726   
    28     public SelectWaypointDialog(String name, String iconName, String tooltip,
     27    SelectWaypointDialog(String name, String iconName, String tooltip,
    2928            Shortcut shortcut, int preferredHeight) {
    3029        super(name, iconName, tooltip, shortcut, preferredHeight);
     
    5857    }
    5958   
    60     public void updateSearchResults(){
     59    void updateSearchResults() {
    6160        String searchfor = "";
    6261        listModel.clear();
    63         SearchResultObjectCache.clear();
    64         if (!first_time_search) {
     62        searchResultObjectCache.clear();
     63        if (!firstTimeSearch) {
    6564            searchfor = searchPattern.getText();
    6665        }
    67         for (Iterator<Marker> i = engine.searchGpxWaypoints(searchfor).iterator(); i.hasNext();) {
     66        for (Iterator<Marker> i = Engine.searchGpxWaypoints(searchfor).iterator(); i.hasNext();) {
    6867            Marker marker = i.next();
    6968            listModel.addElement(marker.getText());
    70             SearchResultObjectCache.add(marker);
     69            searchResultObjectCache.add(marker);
    7170        }
    7271    }
     
    7473    @Override
    7574    public void keyPressed(KeyEvent arg0) {
    76         // TODO Auto-generated method stub
     75        // Do nothing
    7776    }
    7877
    7978    @Override
    8079    public void keyReleased(KeyEvent arg0) {
    81         // TODO Auto-generated method stub
    8280        updateSearchResults();
    8381    }
     
    8583    @Override
    8684    public void keyTyped(KeyEvent arg0) {
    87         first_time_search = false;
     85        firstTimeSearch = false;
    8886    }
    8987
     
    9290        if (e.getSource()==searchResult) {
    9391            //click on the search result box
    94             Marker marker = SearchResultObjectCache.get(searchResult.getSelectedIndex());
     92            Marker marker = searchResultObjectCache.get(searchResult.getSelectedIndex());
    9593            Main.map.mapView.zoomTo(marker.getCoor());
    9694        } else {
     
    10199    @Override
    102100    public void mouseEntered(MouseEvent arg0) {
     101        // Do nothing
    103102    }
    104103
    105104    @Override
    106105    public void mouseExited(MouseEvent arg0) {
     106        // Do nothing
    107107    }
    108108
     
    116116    @Override
    117117    public void mouseReleased(MouseEvent arg0) {
     118        // Do nothing
    118119    }
    119120}
  • applications/editors/josm/plugins/waypoint_search/src/org/openstreetmap/josm/plugins/waypointSearch/WaypointSearchPlugin.java

    r28624 r30777  
    1010import org.openstreetmap.josm.plugins.PluginInformation;
    1111
     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 */
    1218public class WaypointSearchPlugin extends Plugin implements LayerChangeListener  {
    13     /**
    14     * Will be invoked by JOSM to bootstrap the plugin
    15     *
    16     * @param info  information about the plugin and its local installation   
    17     */
    18     private final Engine engine = new Engine();
    1919    private SelectWaypointDialog waypointDialog;
    2020   
     21    /**
     22     * Will be invoked by JOSM to bootstrap the plugin
     23     *
     24     * @param info  information about the plugin and its local installation   
     25     */
    2126    public WaypointSearchPlugin(PluginInformation info) {
    22        super(info);
    23        MapView.addLayerChangeListener(this);
     27        super(info);
     28        MapView.addLayerChangeListener(this);
    2429    }
    2530     
    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    }
    3542
    36         @Override
     43    @Override
    3744    public void activeLayerChange(Layer oldLayer, Layer newLayer) {
     45        // Do nothing
    3846    }
    3947   
     
    4149    public void layerAdded(Layer newLayer) {
    4250        // update search
    43         if (waypointDialog != null && engine.gpxLayersExist()) {
     51        if (waypointDialog != null && Engine.gpxLayersExist()) {
    4452            waypointDialog.updateSearchResults();
    4553        }
     
    4856    @Override
    4957    public void layerRemoved(Layer oldLayer) {
    50         if (waypointDialog != null && !engine.gpxLayersExist()) {
     58        if (waypointDialog != null && !Engine.gpxLayersExist()) {
    5159            waypointDialog.updateSearchResults();
    5260        }   
Note: See TracChangeset for help on using the changeset viewer.