1 package tim.prune.function.compress;
3 import javax.swing.JOptionPane;
6 import tim.prune.GenericFunction;
7 import tim.prune.I18nManager;
8 import tim.prune.UpdateMessageBroker;
9 import tim.prune.data.DataPoint;
12 * Function to mark all the points in the selected rectangle
14 public class MarkPointsInRectangleFunction extends GenericFunction
16 /** Minimum and maximum latitude values of rectangle */
17 private double _minLat = 0.0, _maxLat = 0.0;
18 /** Minimum and maximum longitude values of rectangle */
19 private double _minLon = 0.0, _maxLon = 0.0;
24 * @param inApp App object
26 public MarkPointsInRectangleFunction(App inApp)
32 * Set the coordinates of the rectangle
33 * @param inLon1 first longitude value
34 * @param inLat1 first latitude value
35 * @param inLon2 second longitude value
36 * @param inLat2 second latitude value
38 public void setRectCoords(double inLon1, double inLat1, double inLon2, double inLat2)
40 if (inLon1 == inLon2 || inLat1 == inLat2)
42 // Coordinates not valid
43 _minLat = _maxLat = _minLon = _maxLon = 0.0;
47 if (inLon2 > inLon1) {
48 _minLon = inLon1; _maxLon = inLon2;
51 _minLon = inLon2; _maxLon = inLon1;
53 if (inLat2 > inLat1) {
54 _minLat = inLat1; _maxLat = inLat2;
57 _minLat = inLat2; _maxLat = inLat1;
63 * Begin the function using the set parameters
67 if (_maxLon == _minLon || _maxLat == _minLat) {
71 // Loop over all points in track
72 final int numPoints = _app.getTrackInfo().getTrack().getNumPoints();
74 for (int i=0; i<numPoints; i++)
76 DataPoint point = _app.getTrackInfo().getTrack().getPoint(i);
77 // For each point, see if it's within the rectangle
78 final double pointLon = point.getLongitude().getDouble();
79 final double pointLat = point.getLatitude().getDouble();
80 final boolean insideRect = (pointLon >= _minLon && pointLon <= _maxLon
81 && pointLat >= _minLat && pointLat <= _maxLat);
82 // If so, then mark it
83 point.setMarkedForDeletion(insideRect);
89 // Inform subscribers to update display
90 UpdateMessageBroker.informSubscribers();
91 // Confirm message showing how many marked
93 JOptionPane.showMessageDialog(_parentFrame, I18nManager.getText("dialog.compress.confirm1")
94 + " " + numMarked + " " + I18nManager.getText("dialog.compress.confirm2"),
95 I18nManager.getText(getNameKey()), JOptionPane.INFORMATION_MESSAGE);
99 /** @return name key */
100 public String getNameKey() {
101 return "menu.track.markrectangle";