Skip to content

Method: notifyError(UserNotification)

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 jakarta.inject.Inject;
30: import java.nio.file.Path;
31: import javafx.animation.FadeTransition;
32: import javafx.fxml.FXML;
33: import javafx.scene.control.Button;
34: import javafx.scene.control.Label;
35: import javafx.scene.control.Slider;
36: import javafx.scene.layout.AnchorPane;
37: import javafx.scene.layout.BorderPane;
38: import javafx.util.Duration;
39: import it.tidalwave.bluemarine3.mapviewer.spi.MapViewerPresentation;
40: import it.tidalwave.geo.Coordinates;
41: import it.tidalwave.geo.GeoTrack;
42: import it.tidalwave.geo.RectangularArea;
43: import it.tidalwave.mapviewer.OpenTopoMapTileSource;
44: import it.tidalwave.mapviewer.javafx.MapView;
45: import it.tidalwave.ui.core.UserNotification;
46: import it.tidalwave.ui.javafx.JavaFXBinder;
47: import static it.tidalwave.bluemarine3.mapviewer.impl.javafx.Converters.*;
48:
49: /***************************************************************************************************************************************************************
50: *
51: * @stereotype Presentation
52: * @author Fabrizio Giudici
53: *
54: **************************************************************************************************************************************************************/
55: public class JavaFXMapViewerPresentationDelegate implements MapViewerPresentation
56: {
57: private static final String TRACK_OVERLAY_NAME = "track";
58:
59: @FXML
60: private AnchorPane apAnchorPane;
61:
62: @FXML
63: private Slider slZoom;
64:
65: @FXML
66: private Button btZoomIn;
67:
68: @FXML
69: private Button btZoomOut;
70:
71: @FXML
72: private Button btReframe;
73:
74: @FXML
75: private Label lbCoordinates;
76:
77: @FXML
78: private BorderPane pnWaiting;
79:
80: private MapView mapView;
81:
82: @Inject
83: private JavaFXBinder binder;
84:
85: /***********************************************************************************************************************************************************
86: * {@inheritDoc}
87: **********************************************************************************************************************************************************/
88: @Override
89: public void initialize (@Nonnull final Bindings bindings, @Nonnull final Path cacheFolder)
90: {
91: mapView = new MapView(MapView.options().withCacheFolder(cacheFolder));
92: mapView.setTileSource(new OpenTopoMapTileSource());
93: AnchorPane.setLeftAnchor(mapView, 0.0);
94: AnchorPane.setRightAnchor(mapView, 0.0);
95: AnchorPane.setTopAnchor(mapView, 0.0);
96: AnchorPane.setBottomAnchor(mapView, 0.0);
97: apAnchorPane.getChildren().add(mapView);
98: mapView.setRecenterOnDoubleClick(true);
99: slZoom.minProperty().bind(mapView.minZoomProperty());
100: slZoom.maxProperty().bind(mapView.maxZoomProperty());
101: // slZoom.setBlockIncrement(0.1);
102: binder.bind(btZoomIn, bindings.zoomIn);
103: binder.bind(btZoomOut, bindings.zoomOut);
104: binder.bind(btReframe, bindings.reframe);
105: binder.bindBidirectionally(bindings.zoom, slZoom.valueProperty());
106: binder.bindBidirectionally(bindings.zoom, mapView.zoomProperty()); // FIXME: bindings.zoom can go out of the zoomProperty range
107: binder.bind(bindings.coordinatesUnderMouse, mapView.coordinatesUnderMouseProperty(), Converters::toCoordinates);
108: pnWaiting.setVisible(false);
109: }
110:
111: /***********************************************************************************************************************************************************
112: * {@inheritDoc}
113: **********************************************************************************************************************************************************/
114: @Override
115: public void renderMapAt (@Nonnull final Coordinates center, final int zoom)
116: {
117: mapView.setCenter(toMapCoordinates(center));
118: mapView.setZoom(zoom);
119: }
120:
121: /***********************************************************************************************************************************************************
122: * {@inheritDoc}
123: **********************************************************************************************************************************************************/
124: @Override
125: public void renderTrack (@Nonnull final GeoTrack track, @Nonnull final RectangularArea area)
126: {
127: mapView.fitArea(toMapArea(area));
128: mapView.removeAllOverlays();
129: mapView.addOverlay(TRACK_OVERLAY_NAME, new TrackOverlayCreator(track));
130: }
131:
132: /***********************************************************************************************************************************************************
133: * {@inheritDoc}
134: **********************************************************************************************************************************************************/
135: @Override
136: public void removeTrack()
137: {
138: mapView.removeOverlay(TRACK_OVERLAY_NAME);
139: }
140:
141: /***********************************************************************************************************************************************************
142: * {@inheritDoc}
143: **********************************************************************************************************************************************************/
144: @Override
145: public void renderCoordinates (@Nonnull final String coordinates)
146: {
147: lbCoordinates.setText(coordinates);
148: }
149:
150: /***********************************************************************************************************************************************************
151: * {@inheritDoc}
152: **********************************************************************************************************************************************************/
153: public void fitTo (@Nonnull final RectangularArea area)
154: {
155: mapView.fitArea(toMapArea(area));
156: }
157:
158: /***********************************************************************************************************************************************************
159: * {@inheritDoc}
160: **********************************************************************************************************************************************************/
161: @Override
162: public void showWaiting()
163: {
164: pnWaiting.setOpacity(1.0);
165: pnWaiting.setVisible(true);
166: }
167:
168: /***********************************************************************************************************************************************************
169: * {@inheritDoc}
170: **********************************************************************************************************************************************************/
171: @Override
172: public void hideWaiting()
173: {
174: final var transition = new FadeTransition(Duration.seconds(0.5), pnWaiting);
175: transition.setFromValue(1.0);
176: transition.setToValue(0.0);
177: transition.setOnFinished(ignored -> pnWaiting.setVisible(false));
178: transition.play();
179: }
180:
181: /***********************************************************************************************************************************************************
182: * {@inheritDoc}
183: **********************************************************************************************************************************************************/
184: @Override
185: public void notifyError (@Nonnull final UserNotification error)
186: {
187: binder.showInModalDialog(error);
188: }
189: }