X-Git-Url: https://gitweb.fperrin.net/?a=blobdiff_plain;f=tim%2Fprune%2Fgui%2FWaypointNameMatcher.java;fp=tim%2Fprune%2Fgui%2FWaypointNameMatcher.java;h=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hp=83a10bb7cd864e38198a126d86be30c7a40597a1;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465;p=GpsPrune.git diff --git a/tim/prune/gui/WaypointNameMatcher.java b/tim/prune/gui/WaypointNameMatcher.java deleted file mode 100644 index 83a10bb..0000000 --- a/tim/prune/gui/WaypointNameMatcher.java +++ /dev/null @@ -1,98 +0,0 @@ -package tim.prune.gui; - -import java.util.ArrayList; -import javax.swing.AbstractListModel; - -import tim.prune.data.DataPoint; -import tim.prune.data.Track; - -/** - * Class to deal with the matching of waypoint names - * and the representation in a list - */ -public class WaypointNameMatcher extends AbstractListModel -{ - private ArrayList _waypoints = null; - private int _numPoints = 0; - private String[] _waypointNames = null; - private ArrayList _matches = null; - - - /** - * Initialisation giving Track object - * @param inTrack Track object - */ - public void init(Track inTrack) - { - // Get list of waypoints from track - _waypoints = new ArrayList(); - inTrack.getWaypoints(_waypoints); - // Initialise match flags and waypoint names - _numPoints = _waypoints.size(); - _waypointNames = new String[_numPoints]; - for (int i=0; i<_numPoints; i++) { - _waypointNames[i] = _waypoints.get(i).getWaypointName().toLowerCase(); - } - _matches = new ArrayList(); - findMatches(null); - } - - /** - * Search for the given term and collect the matches - * @param inSearch string to search for - */ - public void findMatches(String inSearch) - { - // Reset array - _matches.clear(); - // Convert search to lower case to match name array - String search = null; - if (inSearch != null && !inSearch.equals("")) { - search = inSearch.toLowerCase(); - } - // Loop through waypoint names - for (int i=0; i<_numPoints; i++) - { - if (search == null || _waypointNames[i].indexOf(search) >= 0) - { - _matches.add(_waypoints.get(i)); - } - } - fireChanged(); - } - - /** - * @see javax.swing.ListModel#getSize() - */ - public int getSize() - { - if (_numPoints == 0) return 0; - return _matches.size(); - } - - /** - * @see javax.swing.ListModel#getElementAt(int) - */ - public String getElementAt(int inIndex) - { - return _matches.get(inIndex).getWaypointName(); - } - - /** - * Get the waypoint at the given index - * @param inIndex index number, starting at 0 - * @return DataPoint object - */ - public DataPoint getWaypoint(int inIndex) - { - return _matches.get(inIndex); - } - - /** - * Fire event to notify that contents have changed - */ - public void fireChanged() - { - this.fireContentsChanged(this, 0, getSize()-1); - } -}