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;
20 /** flag to remember whether the automatic deletion has been set to always */
21 private boolean _automaticallyDelete = false;
26 * @param inApp App object
28 public MarkPointsInRectangleFunction(App inApp)
33 /** @return name key */
34 public String getNameKey() {
35 return "menu.track.markrectangle";
39 * Set the coordinates of the rectangle
40 * @param inLon1 first longitude value
41 * @param inLat1 first latitude value
42 * @param inLon2 second longitude value
43 * @param inLat2 second latitude value
45 public void setRectCoords(double inLon1, double inLat1, double inLon2, double inLat2)
47 if (inLon1 == inLon2 || inLat1 == inLat2)
49 // Coordinates not valid
50 _minLat = _maxLat = _minLon = _maxLon = 0.0;
54 if (inLon2 > inLon1) {
55 _minLon = inLon1; _maxLon = inLon2;
58 _minLon = inLon2; _maxLon = inLon1;
60 if (inLat2 > inLat1) {
61 _minLat = inLat1; _maxLat = inLat2;
64 _minLat = inLat2; _maxLat = inLat1;
70 * Begin the function using the set parameters
74 if (_maxLon == _minLon || _maxLat == _minLat) {
78 // Loop over all points in track
79 final int numPoints = _app.getTrackInfo().getTrack().getNumPoints();
81 for (int i=0; i<numPoints; i++)
83 DataPoint point = _app.getTrackInfo().getTrack().getPoint(i);
84 // For each point, see if it's within the rectangle
85 final double pointLon = point.getLongitude().getDouble();
86 final double pointLat = point.getLatitude().getDouble();
87 final boolean insideRect = (pointLon >= _minLon && pointLon <= _maxLon
88 && pointLat >= _minLat && pointLat <= _maxLat);
89 // If so, then mark it
90 point.setMarkedForDeletion(insideRect);
96 // Inform subscribers to update display
97 UpdateMessageBroker.informSubscribers();
98 // Confirm message showing how many marked
101 // Allow calling of delete function with one click
102 final String[] buttonTexts = {I18nManager.getText("button.yes"), I18nManager.getText("button.no"),
103 I18nManager.getText("button.always")};
104 int answer = _automaticallyDelete ? JOptionPane.YES_OPTION :
105 JOptionPane.showOptionDialog(_parentFrame,
106 I18nManager.getTextWithNumber("dialog.compress.confirm", numMarked),
107 I18nManager.getText(getNameKey()), JOptionPane.YES_NO_CANCEL_OPTION,
108 JOptionPane.WARNING_MESSAGE, null, buttonTexts, buttonTexts[1]);
109 if (answer == JOptionPane.CANCEL_OPTION) {_automaticallyDelete = true;} // "always" is third option
110 if (_automaticallyDelete || answer == JOptionPane.YES_OPTION)
112 new Thread(new Runnable() {
114 _app.finishCompressTrack();