Skip to content
Snippets Groups Projects
Commit 2a9ca324 authored by George Adrian Stoica's avatar George Adrian Stoica
Browse files

added tooltip to marker; this should fix issue #10

parent 57fa16fa
No related branches found
No related tags found
1 merge request!6Issue 11 allow user to enter and update metadata about the latlong points
Pipeline #52466 passed
package simpleex.ui; package simpleex.ui;
import java.util.Iterator;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import fxmapcontrol.Location; import fxmapcontrol.Location;
import fxmapcontrol.MapBase; import fxmapcontrol.MapBase;
...@@ -8,16 +10,22 @@ import fxmapcontrol.MapNode; ...@@ -8,16 +10,22 @@ import fxmapcontrol.MapNode;
import fxmapcontrol.MapProjection; import fxmapcontrol.MapProjection;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.geometry.Insets;
import javafx.geometry.Point2D; import javafx.geometry.Point2D;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.control.Alert; import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.HBox;
import javafx.util.Callback; import javafx.util.Callback;
import javafx.scene.control.ButtonType; import javafx.scene.control.ButtonType;
import javafx.scene.control.Label;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
import javafx.scene.control.ListView; import javafx.scene.control.ListView;
import javafx.scene.control.OverrunStyle;
import javafx.scene.control.Slider; import javafx.scene.control.Slider;
import javafx.scene.control.Tooltip;
import simpleex.core.LatLong; import simpleex.core.LatLong;
import simpleex.core.MetaData;
import simpleex.json.LatLongsModule; import simpleex.json.LatLongsModule;
/* /*
...@@ -66,6 +74,8 @@ public abstract class AbstractFxAppController { ...@@ -66,6 +74,8 @@ public abstract class AbstractFxAppController {
private MapMarker marker = null; private MapMarker marker = null;
private DraggableNodeController draggableMapController = null; private DraggableNodeController draggableMapController = null;
private DraggableNodeController draggableMarkerController = null; private DraggableNodeController draggableMarkerController = null;
private Tooltip markerTooltip = null;
@FXML @FXML
private Slider zoomSlider; private Slider zoomSlider;
...@@ -133,6 +143,71 @@ public abstract class AbstractFxAppController { ...@@ -133,6 +143,71 @@ public abstract class AbstractFxAppController {
mapView.setCenter(marker.getLocation()); mapView.setCenter(marker.getLocation());
} }
} }
prepareMarkerTooltip();
}
void prepareMarkerTooltip() {
if ((marker != null) && (this.markerTooltip != null)) {
Tooltip.uninstall(marker, markerTooltip);
}
Tooltip tooltip = new Tooltip();
tooltip.setPrefWidth(300.0);
tooltip.setWrapText(true);
tooltip.setTextOverrun(OverrunStyle.ELLIPSIS);
tooltip.setStyle(" -fx-background: rgba(255, 237, 131);\r\n" +
" -fx-text-fill: black;\r\n" +
" -fx-background-color: rgba(255, 237, 131, 0.8);\r\n" +
" -fx-background-radius: 6px;\r\n" +
" -fx-background-insets: 0;\r\n" +
" -fx-padding: 0.667em 0.75em 0.667em 0.75em; /* 10px */\r\n" +
" -fx-effect: dropshadow( three-pass-box , rgba(0,0,0,0.5) , 10, 0.0 , 0 , 3 );\r\n" +
" -fx-font-size: 0.85em;");
final int num = locationListView.getSelectionModel().getSelectedIndex();
if (num >= 0) {
final LatLong latLong = dataAccess.getLatLong(num);
String tooltipText = "";
if(latLong.hasMetaData()) {
if(latLong.getMetaData().hasProperty(MetaData.NAME_PROPERTY)) {
tooltipText += latLong.getMetaData().getProperty(MetaData.NAME_PROPERTY) +"\n";
}
tooltipText += latLong.toString()+"\n";
if(latLong.getMetaData().hasProperty(MetaData.DESCRIPTION_PROPERTY)) {
tooltipText += latLong.getMetaData().getProperty(MetaData.DESCRIPTION_PROPERTY) +"\n";
}
MetaData metaData = latLong.getMetaData();
final Iterator<String> props = metaData.propertyNames();
if (props.hasNext()) {
String propString = "\n";
while (props.hasNext()) {
String propName = props.next();
if((propName != MetaData.NAME_PROPERTY)
&&(propName != MetaData.DESCRIPTION_PROPERTY)) {
propString += propName + ":" + metaData.getProperty(propName) + "\n";
}
}
if(!propString.isBlank()) tooltipText += propString + "\n";
}
final Iterator<String> tags = metaData.tags();
if (tags.hasNext()) {
String tagString = "\n| ";
while (tags.hasNext()) {
tagString += tags.next() + " | ";
}
tooltipText += tagString + "\n";
}
} else {
tooltipText += latLong.toString();
}
tooltip.setText(tooltipText);
}
this.markerTooltip = tooltip;
Tooltip.install(marker, tooltip);
} }
@FXML @FXML
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment