Skip to content

Package: JavaFXMapViewerPresentationDelegate

JavaFXMapViewerPresentationDelegate

nameinstructionbranchcomplexitylinemethod
fitTo(RectangularArea)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
hideWaiting()
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
initialize(MapViewerPresentation.Bindings, Path)
M: 110 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 18 C: 0
0%
M: 1 C: 0
0%
lambda$hideWaiting$0(ActionEvent)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
notifyError(UserNotification)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
removeTrack()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
renderCoordinates(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
renderMapAt(Coordinates, int)
M: 11 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
renderTrack(GeoTrack, RectangularArea)
M: 17 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
showWaiting()
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * *************************************************************************************************************************************************************
3: *
4: * blueMarine III: Semantic DAM
5: * http://tidalwave.it/projects/bluemarine3
6: *
7: * Copyright (C) 2024 - 2025 by Tidalwave s.a.s. (http://tidalwave.it)
8: *
9: * *************************************************************************************************************************************************************
10: *
11: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
12: * You may obtain a copy of the License at
13: *
14: * http://www.apache.org/licenses/LICENSE-2.0
15: *
16: * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
17: * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
18: *
19: * *************************************************************************************************************************************************************
20: *
21: * git clone https://bitbucket.org/tidalwave/bluemarine3-src
22: * git clone https://github.com/tidalwave-it/bluemarine3-src
23: *
24: * *************************************************************************************************************************************************************
25: */
26: package it.tidalwave.bluemarine3.mapviewer.impl.javafx;
27:
28: import jakarta.annotation.Nonnull;
29: import java.nio.file.Path;
30: import javafx.animation.FadeTransition;
31: import javafx.fxml.FXML;
32: import javafx.scene.control.Button;
33: import javafx.scene.control.Label;
34: import javafx.scene.control.Slider;
35: import javafx.scene.layout.AnchorPane;
36: import javafx.scene.layout.BorderPane;
37: import javafx.util.Duration;
38: import it.tidalwave.bluemarine3.mapviewer.spi.MapViewerPresentation;
39: import it.tidalwave.geo.Coordinates;
40: import it.tidalwave.geo.GeoTrack;
41: import it.tidalwave.geo.RectangularArea;
42: import it.tidalwave.mapview.OpenTopoMapTileSource;
43: import it.tidalwave.mapview.javafx.MapView;
44: import it.tidalwave.ui.core.UserNotification;
45: import it.tidalwave.ui.javafx.JavaFXBinder;
46: import lombok.Getter;
47: import lombok.RequiredArgsConstructor;
48: import static it.tidalwave.bluemarine3.mapviewer.impl.javafx.Converters.*;
49: import static lombok.AccessLevel.PACKAGE;
50:
51: /***************************************************************************************************************************************************************
52: *
53: * @stereotype Presentation
54: * @author Fabrizio Giudici
55: *
56: **************************************************************************************************************************************************************/
57: @RequiredArgsConstructor @Getter(PACKAGE)
58: public class JavaFXMapViewerPresentationDelegate implements MapViewerPresentation
59: {
60: private static final String TRACK_OVERLAY_NAME = "track";
61:
62: private static final Duration FADE_DURATION = Duration.seconds(0.4);
63:
64: @FXML
65: private AnchorPane apAnchorPane;
66:
67: @FXML
68: private Slider slZoom;
69:
70: @FXML
71: private Button btZoomIn;
72:
73: @FXML
74: private Button btZoomOut;
75:
76: @FXML
77: private Button btReframe;
78:
79: @FXML
80: private Label lbCoordinates;
81:
82: @FXML
83: private BorderPane pnWaiting;
84:
85: private MapView mapView;
86:
87: @Nonnull
88: private final JavaFXBinder binder;
89:
90: /***********************************************************************************************************************************************************
91: * {@inheritDoc}
92: **********************************************************************************************************************************************************/
93: @Override
94: public void initialize (@Nonnull final Bindings bindings, @Nonnull final Path tileCacheFolder)
95: {
96: mapView = new MapView(MapView.options().withCacheFolder(tileCacheFolder));
97: mapView.setTileSource(new OpenTopoMapTileSource());
98: AnchorPane.setLeftAnchor(mapView, 0.0);
99: AnchorPane.setRightAnchor(mapView, 0.0);
100: AnchorPane.setTopAnchor(mapView, 0.0);
101: AnchorPane.setBottomAnchor(mapView, 0.0);
102: apAnchorPane.getChildren().add(mapView);
103: mapView.setDoubleClickBehaviour(MapView.RECENTER);
104: slZoom.minProperty().bind(mapView.minZoomProperty());
105: slZoom.maxProperty().bind(mapView.maxZoomProperty());
106: // slZoom.setBlockIncrement(0.1);
107: binder.bind(btZoomIn, bindings.zoomIn);
108: binder.bind(btZoomOut, bindings.zoomOut);
109: binder.bind(btReframe, bindings.reframe);
110: binder.bindBidirectionally(bindings.zoom, slZoom.valueProperty());
111: binder.bindBidirectionally(bindings.zoom, mapView.zoomProperty()); // FIXME: bindings.zoom can go out of the zoomProperty range
112: binder.bind(bindings.mouseCoordinates, mapView.mouseCoordinatesProperty(), Converters::toCoordinates);
113: pnWaiting.setVisible(false);
114: }
115:
116: /***********************************************************************************************************************************************************
117: * {@inheritDoc}
118: **********************************************************************************************************************************************************/
119: @Override
120: public void renderMapAt (@Nonnull final Coordinates center, final int zoom)
121: {
122: mapView.setCenter(toMapCoordinates(center));
123: mapView.setZoom(zoom);
124: }
125:
126: /***********************************************************************************************************************************************************
127: * {@inheritDoc}
128: **********************************************************************************************************************************************************/
129: @Override
130: public void renderTrack (@Nonnull final GeoTrack track, @Nonnull final RectangularArea area)
131: {
132: mapView.fitArea(toMapArea(area));
133: mapView.removeAllOverlays();
134: mapView.addOverlay(TRACK_OVERLAY_NAME, new TrackOverlayCreator(track));
135: }
136:
137: /***********************************************************************************************************************************************************
138: * {@inheritDoc}
139: **********************************************************************************************************************************************************/
140: @Override
141: public void removeTrack()
142: {
143: mapView.removeOverlay(TRACK_OVERLAY_NAME);
144: }
145:
146: /***********************************************************************************************************************************************************
147: * {@inheritDoc}
148: **********************************************************************************************************************************************************/
149: @Override
150: public void renderCoordinates (@Nonnull final String coordinates)
151: {
152: lbCoordinates.setText(coordinates);
153: }
154:
155: /***********************************************************************************************************************************************************
156: * {@inheritDoc}
157: **********************************************************************************************************************************************************/
158: public void fitTo (@Nonnull final RectangularArea area)
159: {
160: mapView.fitArea(toMapArea(area));
161: }
162:
163: /***********************************************************************************************************************************************************
164: * {@inheritDoc}
165: **********************************************************************************************************************************************************/
166: @Override
167: public void showWaiting()
168: {
169: pnWaiting.setOpacity(1.0);
170: pnWaiting.setVisible(true);
171: }
172:
173: /***********************************************************************************************************************************************************
174: * {@inheritDoc}
175: **********************************************************************************************************************************************************/
176: @Override
177: public void hideWaiting()
178: {
179: final var transition = new FadeTransition(FADE_DURATION, pnWaiting);
180: transition.setFromValue(1.0);
181: transition.setToValue(0.0);
182: transition.setOnFinished(ignored -> pnWaiting.setVisible(false));
183: transition.play();
184: }
185:
186: /***********************************************************************************************************************************************************
187: * {@inheritDoc}
188: **********************************************************************************************************************************************************/
189: @Override
190: public void notifyError (@Nonnull final UserNotification notification)
191: {
192: binder.showInModalDialog(notification);
193: }
194: }