Skip to content

Commit

Permalink
[2D Map] Reposition tour info icon according to the tour breadcrumbs.
Browse files Browse the repository at this point in the history
There is a lot of code for just this simple feature but map and tourmap view are separated
  • Loading branch information
wolfgang-ch committed Dec 29, 2021
1 parent cb5b606 commit 51b27ce
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 130 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*******************************************************************************
* Copyright (C) 2005, 2015 Wolfgang Schramm and Contributors
*
* Copyright (C) 2005, 2022 Wolfgang Schramm and Contributors
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation version 2 of the License.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
Expand All @@ -19,10 +19,9 @@

public interface IHoveredArea {

/**
* @return Returns an image which is displayed when the hovered area is hovered with the mouse,
* can be <code>null</code> when an image is not available.
*/
Image getHoveredImage();

/**
* @return Returns an image which is displayed when the hovered area is hovered with the mouse,
* can be <code>null</code> when an image is not available.
*/
Image getHoveredImage();
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*******************************************************************************
* Copyright (C) 2005, 2015 Wolfgang Schramm and Contributors
*
* Copyright (C) 2005, 2022 Wolfgang Schramm and Contributors
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation version 2 of the License.
*
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
Expand All @@ -26,57 +26,57 @@
*/
public interface ITourToolTipProvider extends IToolTipProvider {

/**
* This method is called after the tool tip is hidden. This method can be used to cleanup
* resources.
*/
public void afterHideToolTip();
/**
* This method is called after the tool tip is hidden. This method can be used to cleanup
* resources.
*/
public void afterHideToolTip();

/**
* * Creates the content area of the the tooltip.
*
* @param event
* the event that triggered the activation of the tooltip
* @param parent
* the parent of the content area
* @return the content area created
*/
public Composite createToolTipContentArea(Event event, Composite parent);
/**
* * Creates the content area of the the tooltip.
*
* @param event
* the event that triggered the activation of the tooltip
* @param parent
* the parent of the content area
* @return the content area created
*/
public Composite createToolTipContentArea(Event event, Composite parent);

/**
* Paints the tool tip icon in the control
*
* @param gc
* @param rectangle
* Client area where the tool tip can be painted
*/
public void paint(GC gc, Rectangle clientArea);
/**
* Paints the tool tip icon in the control
*
* @param gc
* @param rectangle
* Client area where the tool tip can be painted
*/
public void paint(GC gc, Rectangle clientArea);

/**
* Set location where the mouse is hovering the client area.
*
* @param x
* @param y
* @return Returns <code>true</code> when the mouse is hovering a hovered location.
*/
public boolean setHoveredLocation(int x, int y);
/**
* Set location where the mouse is hovering the client area.
*
* @param x
* @param y
* @return Returns <code>true</code> when the mouse is hovering a hovered location.
*/
public boolean setHoveredLocation(int x, int y);

/**
* Sets the {@link TourToolTip} into the tour tool tip provider. When set to <code>null</code>
* the tool tip provider is detached from the tour tool tip control.
*
* @param tourToolTip
* can be <code>null</code>
*/
public void setTourToolTip(TourToolTip tourToolTip);
/**
* Sets the {@link TourToolTip} into the tour tool tip provider. When set to <code>null</code>
* the tool tip provider is detached from the tour tool tip control.
*
* @param tourToolTip
* can be <code>null</code>
*/
public void setTourToolTip(TourToolTip tourToolTip);

/**
* This method is called when the tool tip control is requesting the tool tip should be
* displayed.
*
* @param point
* Position for the mouse pointer
*/
public void show(Point point);
/**
* This method is called when the tool tip control is requesting the tool tip should be
* displayed.
*
* @param point
* Position for the mouse pointer
*/
public void show(Point point);

}
68 changes: 42 additions & 26 deletions bundles/net.tourbook/src/de/byteholder/geoclipse/map/Map.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
package de.byteholder.geoclipse.map;

import de.byteholder.geoclipse.Messages;
import de.byteholder.geoclipse.map.event.IBreadcrumbListener;
import de.byteholder.geoclipse.map.event.IHoveredTourListener;
import de.byteholder.geoclipse.map.event.IMapGridListener;
import de.byteholder.geoclipse.map.event.IMapInfoListener;
Expand Down Expand Up @@ -365,7 +366,7 @@ public class Map extends Canvas {
_nfLatLon.setMinimumFractionDigits(4);
_nfLatLon.setMaximumFractionDigits(4);
}
private final TextWrapPainter _textWrapper = new TextWrapPainter();
private final TextWrapPainter _textWrapper = new TextWrapPainter();

/**
* cache for overlay images
Expand All @@ -375,7 +376,7 @@ public class Map extends Canvas {
/**
* This queue contains tiles which overlay image must be painted
*/
private final ConcurrentLinkedQueue<Tile> _tileOverlayPaintQueue = new ConcurrentLinkedQueue<>();
private final ConcurrentLinkedQueue<Tile> _tileOverlayPaintQueue = new ConcurrentLinkedQueue<>();

private boolean _isRunningDrawOverlay;

Expand All @@ -386,7 +387,7 @@ public class Map extends Canvas {
*/
private IDirectPainter _directMapPainter;

private final DirectPainterContext _directMapPainterContext = new DirectPainterContext();
private final DirectPainterContext _directMapPainterContext = new DirectPainterContext();

/**
* When <code>true</code> the overlays are painted
Expand All @@ -413,7 +414,7 @@ public class Map extends Canvas {
* !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
* <br>
*/
private Point2D _worldPixel_MapCenter = null;
private Point2D _worldPixel_MapCenter = null;

/**
* Viewport in the map where the {@link #_mapImage} is painted <br>
Expand Down Expand Up @@ -454,13 +455,14 @@ public class Map extends Canvas {
*/
private Rectangle _clientArea;

private final ListenerList<IMapGridListener> _allMapGridListener = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IMapInfoListener> _allMapInfoListener = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IMapPositionListener> _allMapPositionListener = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<ITourSelectionListener> _allTourSelectionListener = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IPositionListener> _mousePositionListeners = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IPOIListener> _poiListeners = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IHoveredTourListener> _hoveredTourListeners = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IBreadcrumbListener> _allBreadcrumbListener = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IHoveredTourListener> _allHoveredTourListeners = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IMapGridListener> _allMapGridListener = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IMapInfoListener> _allMapInfoListener = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IMapPositionListener> _allMapPositionListener = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IPositionListener> _allMousePositionListeners = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<IPOIListener> _allPOIListeners = new ListenerList<>(ListenerList.IDENTITY);
private final ListenerList<ITourSelectionListener> _allTourSelectionListener = new ListenerList<>(ListenerList.IDENTITY);

// measurement system
private float _distanceUnitValue = 1;
Expand Down Expand Up @@ -824,6 +826,10 @@ public void controlResized(final ControlEvent e) {
addTraverseListener(traverseEvent -> traverseEvent.doit = true);
}

public void addBreadcrumbListener(final IBreadcrumbListener listener) {
_allBreadcrumbListener.add(listener);
}

/**
* Set map as drop target
*/
Expand Down Expand Up @@ -869,7 +875,7 @@ public void drop(final DropTargetEvent event) {
}

public void addHoveredTourListener(final IHoveredTourListener hoveredTourListener) {
_hoveredTourListeners.add(hoveredTourListener);
_allHoveredTourListeners.add(hoveredTourListener);
}

public void addMapGridBoxListener(final IMapGridListener mapListener) {
Expand All @@ -885,7 +891,7 @@ public void addMapPositionListener(final IMapPositionListener mapPanListener) {
}

public void addMousePositionListener(final IPositionListener mapListener) {
_mousePositionListeners.add(mapListener);
_allMousePositionListeners.add(mapListener);
}

/**
Expand All @@ -904,7 +910,7 @@ public void addOverlayPainter(final MapPainter overlay) {
}

public void addPOIListener(final IPOIListener poiListener) {
_poiListeners.add(poiListener);
_allPOIListeners.add(poiListener);
}

public void addTourSelectionListener(final ITourSelectionListener iTourSelectionListener) {
Expand Down Expand Up @@ -1198,26 +1204,33 @@ private void fireEvent_MousePosition() {
final GeoPosition geoPosition = _mp.pixelToGeo(new Point2D.Double(worldMouseX, worldMouseY), _mapZoomLevel);
final MapPositionEvent event = new MapPositionEvent(geoPosition, _mapZoomLevel);

final Object[] listeners = _mousePositionListeners.getListeners();
final Object[] listeners = _allMousePositionListeners.getListeners();
for (final Object listener : listeners) {
((IPositionListener) listener).setPosition(event);
}
}

private void fireEvent_TourSelection(final ISelection selection) {
private void fireEvent_POI(final GeoPosition geoPosition, final String poiText) {

for (final Object selectionListener : _allTourSelectionListener.getListeners()) {
((ITourSelectionListener) selectionListener).onSelection(selection);
final MapPOIEvent event = new MapPOIEvent(geoPosition, _mapZoomLevel, poiText);

final Object[] listeners = _allPOIListeners.getListeners();
for (final Object listener : listeners) {
((IPOIListener) listener).setPOI(event);
}
}

private void firePOIEvent(final GeoPosition geoPosition, final String poiText) {
private void fireEvent_TourBreadcrumb() {

final MapPOIEvent event = new MapPOIEvent(geoPosition, _mapZoomLevel, poiText);
for (final Object selectionListener : _allBreadcrumbListener.getListeners()) {
((IBreadcrumbListener) selectionListener).updateBreadcrumb();
}
}

final Object[] listeners = _poiListeners.getListeners();
for (final Object listener : listeners) {
((IPOIListener) listener).setPOI(event);
private void fireEvent_TourSelection(final ISelection selection) {

for (final Object selectionListener : _allTourSelectionListener.getListeners()) {
((ITourSelectionListener) selectionListener).onSelection(selection);
}
}

Expand Down Expand Up @@ -2353,7 +2366,7 @@ private boolean isTourHovered() {
* Above there are return statements which do not fire this event !!!
*/
final MapHoveredTourEvent event = new MapHoveredTourEvent(getHoveredTourId());
for (final Object listener : _hoveredTourListeners.getListeners()) {
for (final Object listener : _allHoveredTourListeners.getListeners()) {
((IHoveredTourListener) listener).setHoveredTourId(event);
}

Expand Down Expand Up @@ -2709,6 +2722,9 @@ private void onMouse_Down(final MouseEvent mouseEvent) {

_tourBreadcrumb.removeAllCrumbs();

// set tour info icon position in the map
fireEvent_TourBreadcrumb();

redraw();

} else if (_tourBreadcrumb.isAction_UpliftLastCrumb()) {
Expand Down Expand Up @@ -5742,7 +5758,7 @@ private boolean parsePOIText(String text) {

_isPoiVisible = true;

firePOIEvent(poiGeoPosition, poiText);
fireEvent_POI(poiGeoPosition, poiText);

return true;
}
Expand Down Expand Up @@ -5803,7 +5819,7 @@ public void recenterToAddressLocation() {
}

public void removeMousePositionListener(final IPositionListener listener) {
_mousePositionListeners.remove(listener);
_allMousePositionListeners.remove(listener);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,24 @@ public ArrayList<Long> getHoveredCrumbedTours_WithReset() {
return allCrumbTours;
}

public int getVisibleBreadcrumbs() {
public int getUsedCrumbs() {
return _allCrumbsWithAllTours.size();
}

public int getVisibleCrumbs() {
return _numVisibleCrumbs;
}

public boolean isAction_RemoveAllCrumbs() {

return _isAction_RemoveAll_Selected;
}

public boolean isAction_UpliftLastCrumb() {

return _isAction_UpliftLastCrumb_Selected;
}

private boolean isCollectionContainedInAllBreadcrums(final ArrayList<TourData> allTourData) {

if (_allCrumbsWithAllTours.isEmpty()) {
Expand Down Expand Up @@ -238,16 +252,6 @@ public boolean isCrumbHovered() {
|| _isAction_UpliftLastCrumb_Hovered;
}

public boolean isAction_RemoveAllCrumbs() {

return _isAction_RemoveAll_Selected;
}

public boolean isAction_UpliftLastCrumb() {

return _isAction_UpliftLastCrumb_Selected;
}

/**
* @param devMousePosition
* @return Returns <code>true</code> when a bread crumb is hit
Expand Down

0 comments on commit 51b27ce

Please sign in to comment.