From: Frédéric Perrin Date: Sat, 30 Nov 2019 20:50:20 +0000 (+0000) Subject: Merge branch 'allow-removing-altitudes' into fp-integration X-Git-Tag: v19.2.fp1~2 X-Git-Url: https://gitweb.fperrin.net/?a=commitdiff_plain;h=a31ee8e107fd7ea6413c1a998072da3c3cfcc3b7;hp=cba8e9495b9785fd22e30f41ddcf790e98901086;p=GpsPrune.git Merge branch 'allow-removing-altitudes' into fp-integration --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e9e794 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*.class +*.jar diff --git a/buildtools/build.sh b/buildtools/build.sh old mode 100644 new mode 100755 index b38e2ce..c7fcf3d --- a/buildtools/build.sh +++ b/buildtools/build.sh @@ -1,3 +1,4 @@ +set -e # Build script # Version number PRUNENAME=gpsprune_19.2 diff --git a/src/tim/prune/App.java b/src/tim/prune/App.java index 1bef98b..54f1e98 100644 --- a/src/tim/prune/App.java +++ b/src/tim/prune/App.java @@ -775,6 +775,8 @@ public class App + " '" + inSourceInfo.getName() + "'"); // update menu _menuManager.informFileLoaded(); + // recentre viewport on new file data + _viewport.recentreViewport(); // Remove busy lock _busyLoading = false; // load next file if there's a queue diff --git a/src/tim/prune/function/edit/PointEditor.java b/src/tim/prune/function/edit/PointEditor.java index c66201b..546a65e 100644 --- a/src/tim/prune/function/edit/PointEditor.java +++ b/src/tim/prune/function/edit/PointEditor.java @@ -307,10 +307,23 @@ public class PointEditor if (_model.getChanged(i)) { Field field = fieldList.getField(i); + if (field == field.WAYPT_NAME) { + if (wasNameAdded(_model.getValue(i))) { + _app.createPoint(_point.clonePoint()); + } + } editList.addEdit(new FieldEdit(field, _model.getValue(i))); undoList.addEdit(new FieldEdit(field, _point.getFieldValue(field))); } } _app.completePointEdit(editList, undoList); } + + private boolean wasNameAdded(String newName) + { + String prevName = _point.getWaypointName(); + boolean prevNull = (prevName == null || prevName.equals("")); + boolean newNull = (newName == null || newName.equals("")); + return (prevNull && !newNull); + } } diff --git a/src/tim/prune/function/edit/PointNameEditor.java b/src/tim/prune/function/edit/PointNameEditor.java index 53e1f83..9e6e343 100644 --- a/src/tim/prune/function/edit/PointNameEditor.java +++ b/src/tim/prune/function/edit/PointNameEditor.java @@ -206,7 +206,11 @@ public class PointNameEditor extends GenericFunction // Check whether name has really changed if (hasNameChanged()) { - // Make lists for edit and undo, and add the changed field + // If a new name has been added, changing the point + // from trackpoint to waypoint, duplicate it + _app.createPoint(_point.clonePoint()); + + // make lists for edit and undo, and add the changed field FieldEditList editList = new FieldEditList(); FieldEditList undoList = new FieldEditList(); editList.addEdit(new FieldEdit(Field.WAYPT_NAME, _nameField.getText().trim())); @@ -231,4 +235,17 @@ public class PointNameEditor extends GenericFunction || (!prevNull && newNull) || (!prevNull && !newNull && !prevName.equals(newName)); } + + /** + * Check whether a new name has been added + * @return true if it has indeed + */ + private boolean wasNameAdded() + { + String prevName = _point.getWaypointName(); + String newName = _nameField.getText().trim(); + boolean prevNull = (prevName == null || prevName.equals("")); + boolean newNull = (newName == null || newName.equals("")); + return (prevNull && !newNull); + } } diff --git a/src/tim/prune/gui/DisplayUtils.java b/src/tim/prune/gui/DisplayUtils.java index 25640d8..2300296 100644 --- a/src/tim/prune/gui/DisplayUtils.java +++ b/src/tim/prune/gui/DisplayUtils.java @@ -36,7 +36,8 @@ public abstract class DisplayUtils if (inNumSecs < 86400L) return "" + (inNumSecs / 60 / 60) + I18nManager.getText("display.range.time.hours") + " " + ((inNumSecs / 60) % 60) + I18nManager.getText("display.range.time.mins"); if (inNumSecs < 432000L) return "" + (inNumSecs / 86400L) + I18nManager.getText("display.range.time.days") - + " " + (inNumSecs / 60 / 60) % 24 + I18nManager.getText("display.range.time.hours"); + + " " + (inNumSecs / 60 / 60) % 24 + I18nManager.getText("display.range.time.hours") + + " " + ((inNumSecs / 60) % 60) + I18nManager.getText("display.range.time.mins"); if (inNumSecs < 86400000L) return "" + (inNumSecs / 86400L) + I18nManager.getText("display.range.time.days"); return "big"; } diff --git a/src/tim/prune/gui/Viewport.java b/src/tim/prune/gui/Viewport.java index 25eba2f..aec78a6 100644 --- a/src/tim/prune/gui/Viewport.java +++ b/src/tim/prune/gui/Viewport.java @@ -40,4 +40,12 @@ public class Viewport double maxLon = MapUtils.getLongitudeFromX(mapPosition.getXFromPixels(width, width)); return new double[] {minLat, minLon, maxLat, maxLon}; } + + /** + * Recentre the viewport on the data + */ + public void recentreViewport() + { + _mapCanvas.zoomToFit(); + } } diff --git a/src/tim/prune/gui/map/MapCanvas.java b/src/tim/prune/gui/map/MapCanvas.java index aa25dbc..ad38d81 100644 --- a/src/tim/prune/gui/map/MapCanvas.java +++ b/src/tim/prune/gui/map/MapCanvas.java @@ -92,7 +92,7 @@ public class MapCanvas extends JPanel implements MouseListener, MouseMotionListe WpIconDefinition _waypointIconDefinition = null; /** Constant for click sensitivity when selecting nearest point */ - private static final int CLICK_SENSITIVITY = 10; + private static final int CLICK_SENSITIVITY = 30; /** Constant for pan distance from key presses */ private static final int PAN_DISTANCE = 20; /** Constant for pan distance from autopan */ @@ -259,8 +259,8 @@ public class MapCanvas extends JPanel implements MouseListener, MouseMotionListe // add control panels to this one setLayout(new BorderLayout()); - _topPanel.setVisible(false); - _sidePanel.setVisible(false); + _topPanel.setVisible(true); + _sidePanel.setVisible(true); add(_topPanel, BorderLayout.NORTH); add(_sidePanel, BorderLayout.WEST); add(_scaleBar, BorderLayout.SOUTH); @@ -337,16 +337,19 @@ public class MapCanvas extends JPanel implements MouseListener, MouseMotionListe /** * Zoom to fit the current data area */ - private void zoomToFit() + public void zoomToFit() { + int maxZoom = (_track.getNumPoints() == 0)?2:_tileManager.getMaxZoomLevel(); _latRange = _track.getLatRange(); _lonRange = _track.getLonRange(); _xRange = new DoubleRange(MapUtils.getXFromLongitude(_lonRange.getMinimum()), MapUtils.getXFromLongitude(_lonRange.getMaximum())); _yRange = new DoubleRange(MapUtils.getYFromLatitude(_latRange.getMinimum()), MapUtils.getYFromLatitude(_latRange.getMaximum())); - _mapPosition.zoomToXY(_xRange.getMinimum(), _xRange.getMaximum(), _yRange.getMinimum(), _yRange.getMaximum(), - getWidth(), getHeight()); + _mapPosition.zoomToXY( + _xRange.getMinimum(), _xRange.getMaximum(), + _yRange.getMinimum(), _yRange.getMaximum(), + getWidth(), getHeight(), maxZoom); } @@ -360,70 +363,59 @@ public class MapCanvas extends JPanel implements MouseListener, MouseMotionListe if (_mapImage != null && (_mapImage.getWidth() != getWidth() || _mapImage.getHeight() != getHeight())) { _mapImage = null; } - if (_track.getNumPoints() > 0) + // Check for autopan if enabled / necessary + if (_autopanCheckBox.isSelected()) { - // Check for autopan if enabled / necessary - if (_autopanCheckBox.isSelected()) + int selectedPoint = _selection.getCurrentPointIndex(); + if (selectedPoint >= 0 && _dragFromX == -1 && selectedPoint != _prevSelectedPoint) { - int selectedPoint = _selection.getCurrentPointIndex(); - if (selectedPoint >= 0 && _dragFromX == -1 && selectedPoint != _prevSelectedPoint) - { - autopanToPoint(selectedPoint); - } - _prevSelectedPoint = selectedPoint; + autopanToPoint(selectedPoint); } + _prevSelectedPoint = selectedPoint; + } - // Draw the map contents if necessary - if (_mapImage == null || _recalculate) - { - paintMapContents(); - _scaleBar.updateScale(_mapPosition.getZoom(), _mapPosition.getYFromPixels(0, 0)); - } - // Draw the prepared image onto the panel - if (_mapImage != null) { - inG.drawImage(_mapImage, 0, 0, getWidth(), getHeight(), null); - } + // Draw the map contents if necessary + if (_mapImage == null || _recalculate) + { + paintMapContents(); + _scaleBar.updateScale(_mapPosition.getZoom(), _mapPosition.getYFromPixels(0, 0)); + } + // Draw the prepared image onto the panel + if (_mapImage != null) { + inG.drawImage(_mapImage, 0, 0, getWidth(), getHeight(), null); + } - switch (_drawMode) - { - case MODE_DRAG_POINT: - drawDragLines(inG, _selection.getCurrentPointIndex()-1, _selection.getCurrentPointIndex()+1); - break; + switch (_drawMode) + { + case MODE_DRAG_POINT: + drawDragLines(inG, _selection.getCurrentPointIndex()-1, _selection.getCurrentPointIndex()+1); + break; - case MODE_CREATE_MIDPOINT: - drawDragLines(inG, _clickedPoint-1, _clickedPoint); - break; + case MODE_CREATE_MIDPOINT: + drawDragLines(inG, _clickedPoint-1, _clickedPoint); + break; - case MODE_ZOOM_RECT: - case MODE_MARK_RECTANGLE: - if (_dragFromX != -1 && _dragFromY != -1) - { - // Draw the zoom rectangle if necessary - inG.setColor(Color.RED); - inG.drawLine(_dragFromX, _dragFromY, _dragFromX, _dragToY); - inG.drawLine(_dragFromX, _dragFromY, _dragToX, _dragFromY); - inG.drawLine(_dragToX, _dragFromY, _dragToX, _dragToY); - inG.drawLine(_dragFromX, _dragToY, _dragToX, _dragToY); - } - break; - - case MODE_DRAW_POINTS_CONT: - // draw line to mouse position to show drawing mode - inG.setColor(Config.getColourScheme().getColour(ColourScheme.IDX_POINT)); - int prevIndex = _track.getNumPoints()-1; - int px = getWidth() / 2 + _mapPosition.getXFromCentre(_track.getX(prevIndex)); - int py = getHeight() / 2 + _mapPosition.getYFromCentre(_track.getY(prevIndex)); - inG.drawLine(px, py, _dragToX, _dragToY); - break; - } - } - else - { - inG.setColor(Config.getColourScheme().getColour(ColourScheme.IDX_BACKGROUND)); - inG.fillRect(0, 0, getWidth(), getHeight()); - inG.setColor(COLOR_MESSAGES); - inG.drawString(I18nManager.getText("display.nodata"), 50, getHeight()/2); - _scaleBar.updateScale(-1, 0); + case MODE_ZOOM_RECT: + case MODE_MARK_RECTANGLE: + if (_dragFromX != -1 && _dragFromY != -1) + { + // Draw the zoom rectangle if necessary + inG.setColor(Color.RED); + inG.drawLine(_dragFromX, _dragFromY, _dragFromX, _dragToY); + inG.drawLine(_dragFromX, _dragFromY, _dragToX, _dragFromY); + inG.drawLine(_dragToX, _dragFromY, _dragToX, _dragToY); + inG.drawLine(_dragFromX, _dragToY, _dragToX, _dragToY); + } + break; + + case MODE_DRAW_POINTS_CONT: + // draw line to mouse position to show drawing mode + inG.setColor(Config.getColourScheme().getColour(ColourScheme.IDX_POINT)); + int prevIndex = _track.getNumPoints()-1; + int px = getWidth() / 2 + _mapPosition.getXFromCentre(_track.getX(prevIndex)); + int py = getHeight() / 2 + _mapPosition.getYFromCentre(_track.getY(prevIndex)); + inG.drawLine(px, py, _dragToX, _dragToY); + break; } // Draw slider etc on top paintChildren(inG); @@ -1074,66 +1066,63 @@ public class MapCanvas extends JPanel implements MouseListener, MouseMotionListe */ public void mouseClicked(MouseEvent inE) { - if (_track != null && _track.getNumPoints() > 0) + // select point if it's a left-click + if (!inE.isMetaDown()) { - // select point if it's a left-click - if (!inE.isMetaDown()) + if (inE.getClickCount() == 1) { - if (inE.getClickCount() == 1) + // single click + if (_drawMode == MODE_DEFAULT) { - // single click - if (_drawMode == MODE_DEFAULT) + int pointIndex = _clickedPoint; + if (pointIndex == INDEX_UNKNOWN) { - int pointIndex = _clickedPoint; - if (pointIndex == INDEX_UNKNOWN) - { - // index hasn't been calculated yet - pointIndex = _track.getNearestPointIndex( - _mapPosition.getXFromPixels(inE.getX(), getWidth()), - _mapPosition.getYFromPixels(inE.getY(), getHeight()), - _mapPosition.getBoundsFromPixels(CLICK_SENSITIVITY), false); - } - // Extend selection for shift-click - if (inE.isShiftDown()) { - _trackInfo.extendSelection(pointIndex); - } - else { - _trackInfo.selectPoint(pointIndex); - } + // index hasn't been calculated yet + pointIndex = _track.getNearestPointIndex( + _mapPosition.getXFromPixels(inE.getX(), getWidth()), + _mapPosition.getYFromPixels(inE.getY(), getHeight()), + _mapPosition.getBoundsFromPixels(CLICK_SENSITIVITY), false); } - else if (_drawMode == MODE_DRAW_POINTS_START) - { - _app.createPoint(createPointFromClick(inE.getX(), inE.getY())); - _dragToX = inE.getX(); - _dragToY = inE.getY(); - _drawMode = MODE_DRAW_POINTS_CONT; + // Extend selection for shift-click + if (inE.isShiftDown()) { + _trackInfo.extendSelection(pointIndex); } - else if (_drawMode == MODE_DRAW_POINTS_CONT) - { - DataPoint point = createPointFromClick(inE.getX(), inE.getY()); - _app.createPoint(point, false); // not a new segment + else { + _trackInfo.selectPoint(pointIndex); } } - else if (inE.getClickCount() == 2) + else if (_drawMode == MODE_DRAW_POINTS_START) { - // double click - if (_drawMode == MODE_DEFAULT) { - panMap(inE.getX() - getWidth()/2, inE.getY() - getHeight()/2); - zoomIn(); - } - else if (_drawMode == MODE_DRAW_POINTS_START || _drawMode == MODE_DRAW_POINTS_CONT) { - _drawMode = MODE_DEFAULT; - } + _app.createPoint(createPointFromClick(inE.getX(), inE.getY())); + _dragToX = inE.getX(); + _dragToY = inE.getY(); + _drawMode = MODE_DRAW_POINTS_CONT; + } + else if (_drawMode == MODE_DRAW_POINTS_CONT) + { + DataPoint point = createPointFromClick(inE.getX(), inE.getY()); + _app.createPoint(point, false); // not a new segment } } - else + else if (inE.getClickCount() == 2) { - // show the popup menu for right-clicks - _popupMenuX = inE.getX(); - _popupMenuY = inE.getY(); - _popup.show(this, _popupMenuX, _popupMenuY); + // double click + if (_drawMode == MODE_DEFAULT) { + panMap(inE.getX() - getWidth()/2, inE.getY() - getHeight()/2); + zoomIn(); + } + else if (_drawMode == MODE_DRAW_POINTS_START || _drawMode == MODE_DRAW_POINTS_CONT) { + _drawMode = MODE_DEFAULT; + } } } + else + { + // show the popup menu for right-clicks + _popupMenuX = inE.getX(); + _popupMenuY = inE.getY(); + _popup.show(this, _popupMenuX, _popupMenuY); + } // Reset app mode _app.setCurrentMode(App.AppMode.NORMAL); if (_drawMode == MODE_MARK_RECTANGLE) _drawMode = MODE_DEFAULT; @@ -1408,10 +1397,6 @@ public class MapCanvas extends JPanel implements MouseListener, MouseMotionListe } } repaint(); - // enable or disable components - boolean hasData = _track.getNumPoints() > 0; - _topPanel.setVisible(hasData); - _sidePanel.setVisible(hasData); // grab focus for the key presses this.requestFocus(); } diff --git a/src/tim/prune/gui/map/MapPosition.java b/src/tim/prune/gui/map/MapPosition.java index 25f05fc..71ab6cd 100644 --- a/src/tim/prune/gui/map/MapPosition.java +++ b/src/tim/prune/gui/map/MapPosition.java @@ -30,14 +30,14 @@ public class MapPosition * @param inWidth width of display * @param inHeight height of display */ - public void zoomToXY(double inMinX, double inMaxX, double inMinY, double inMaxY, int inWidth, int inHeight) + public void zoomToXY(double inMinX, double inMaxX, double inMinY, double inMaxY, int inWidth, int inHeight, int maxZoom) { // System.out.println("Zooming to " + inMinX + ", " + inMaxX + ", " + inMinY + ", " + inMaxY + "; width=" + inWidth + ", height=" + inHeight); double diffX = Math.abs(inMaxX - inMinX); double diffY = Math.abs(inMaxY - inMinY); // Find out what zoom level to go to int requiredZoom = -1; - for (int currZoom = MAX_ZOOM; currZoom >= 2; currZoom--) + for (int currZoom = maxZoom; currZoom >= 2; currZoom--) { if (transformToPixels(diffX, currZoom) < inWidth && transformToPixels(diffY, currZoom) < inHeight) diff --git a/src/tim/prune/gui/map/MapTileManager.java b/src/tim/prune/gui/map/MapTileManager.java index f7370c5..d1e0047 100644 --- a/src/tim/prune/gui/map/MapTileManager.java +++ b/src/tim/prune/gui/map/MapTileManager.java @@ -70,10 +70,19 @@ public class MapTileManager implements ImageObserver * @return true if zoom is too high for tiles */ public boolean isOverzoomed() + { + return _zoom > getMaxZoomLevel(); + } + + /** + * @return the maximum useable zoom level for tiles + */ + public int getMaxZoomLevel() { // Ask current map source what maximum zoom is int maxZoom = (_mapSource == null?0:_mapSource.getMaxZoomLevel()); - return (_zoom > maxZoom); + return maxZoom; + } /**