Search in sources :

Example 6 with LocationEvent

use of eu.hansolo.tilesfx.events.LocationEvent in project tilesfx by HanSolo.

the class WorldMapTileSkin method initGraphics.

// ******************** Initialization ************************************
@Override
protected void initGraphics() {
    super.initGraphics();
    poiLocations = FXCollections.observableHashMap();
    chartDataLocations = FXCollections.observableHashMap();
    handlerMap = new HashMap<>();
    circleHandlerMap = new HashMap<>();
    countryPaths = tile.getCountryPaths();
    String formatString = new StringBuilder("%.").append(tile.getDecimals()).append("f").toString();
    poiListener = new WeakListChangeListener<>(change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                change.getAddedSubList().forEach(addedPoi -> {
                    String tooltipText = new StringBuilder(addedPoi.getName()).append("\n").append(addedPoi.getInfo()).toString();
                    EventHandler<MouseEvent> handler = e -> addedPoi.fireLocationEvent(new LocationEvent(addedPoi));
                    Circle circle = new Circle(3, addedPoi.getColor());
                    Tooltip.install(circle, new Tooltip(tooltipText));
                    circleHandlerMap.put(circle, handler);
                    poiLocations.put(addedPoi, circle);
                    circle.setOnMousePressed(handler);
                    getPane().getChildren().add(circle);
                });
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedPoi -> {
                    if (circleHandlerMap.get(removedPoi) != null) {
                        poiLocations.get(removedPoi).removeEventHandler(MouseEvent.MOUSE_PRESSED, circleHandlerMap.get(removedPoi));
                    }
                    getPane().getChildren().remove(removedPoi);
                });
            }
        }
        resize();
    });
    chartDataListener = new WeakListChangeListener<>(change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                change.getAddedSubList().forEach(addedData -> {
                    String tooltipText = new StringBuilder(addedData.getName()).append("\n").append(String.format(Locale.US, formatString, addedData.getValue())).toString();
                    EventHandler<MouseEvent> handler = e -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, addedData));
                    Circle circle = new Circle(3, addedData.getLocation().getColor());
                    Tooltip.install(circle, new Tooltip(tooltipText));
                    circleHandlerMap.put(circle, handler);
                    chartDataLocations.put(addedData.getLocation(), circle);
                    circle.setOnMousePressed(handler);
                    getPane().getChildren().add(circle);
                });
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedData -> {
                    if (circleHandlerMap.get(removedData) != null) {
                        chartDataLocations.get(removedData).removeEventHandler(MouseEvent.MOUSE_PRESSED, circleHandlerMap.get(removedData));
                    }
                    getPane().getChildren().remove(removedData);
                });
            }
        }
        resize();
    });
    tile.getPoiList().forEach(poi -> {
        String tooltipText = new StringBuilder(poi.getName()).append("\n").append(poi.getInfo()).toString();
        Circle circle = new Circle(3, poi.getColor());
        circle.setOnMousePressed(e -> poi.fireLocationEvent(new LocationEvent(poi)));
        Tooltip.install(circle, new Tooltip(tooltipText));
        poiLocations.put(poi, circle);
    });
    tile.getChartData().stream().filter(chartData -> chartData.getLocation() != null).forEach(chartData -> {
        String tooltipText = new StringBuilder(chartData.getName()).append("\n").append(String.format(Locale.US, formatString, chartData.getValue())).toString();
        Circle circle = new Circle(3, chartData.getLocation().getColor());
        circle.setOnMousePressed(e -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, chartData)));
        Tooltip.install(circle, new Tooltip(tooltipText));
        chartDataLocations.put(chartData.getLocation(), circle);
    });
    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());
    text = new Text(tile.getUnit());
    text.setFill(tile.getUnitColor());
    Helper.enableNode(text, tile.isTextVisible());
    Color fill = tile.getForegroundColor();
    Color stroke = tile.getBackgroundColor();
    worldPane = new Pane();
    countryPaths.forEach((name, pathList) -> {
        Country country = Country.valueOf(name);
        pathList.forEach(path -> {
            path.setFill(null == country.getColor() ? fill : country.getColor());
            path.setStroke(stroke);
            path.setStrokeWidth(0.2);
        });
        worldPane.getChildren().addAll(pathList);
    });
    group = new Group(worldPane);
    getPane().getChildren().addAll(group, titleText, text);
    getPane().getChildren().addAll(chartDataLocations.values());
    getPane().getChildren().addAll(poiLocations.values());
}
Also used : EventHandler(javafx.event.EventHandler) Fonts(eu.hansolo.tilesfx.fonts.Fonts) Location(eu.hansolo.tilesfx.tools.Location) CacheHint(javafx.scene.CacheHint) MouseEvent(javafx.scene.input.MouseEvent) EventType(eu.hansolo.tilesfx.events.TileEvent.EventType) FXCollections(javafx.collections.FXCollections) HashMap(java.util.HashMap) CountryPath(eu.hansolo.tilesfx.tools.CountryPath) ChartData(eu.hansolo.tilesfx.chart.ChartData) Helper(eu.hansolo.tilesfx.tools.Helper) ListChangeListener(javafx.collections.ListChangeListener) Locale(java.util.Locale) Country(eu.hansolo.tilesfx.tools.Country) Map(java.util.Map) Helper.clamp(eu.hansolo.tilesfx.tools.Helper.clamp) Circle(javafx.scene.shape.Circle) Tooltip(javafx.scene.control.Tooltip) Pane(javafx.scene.layout.Pane) Tile(eu.hansolo.tilesfx.Tile) Color(javafx.scene.paint.Color) TextSize(eu.hansolo.tilesfx.Tile.TextSize) Font(javafx.scene.text.Font) ObservableMap(javafx.collections.ObservableMap) Group(javafx.scene.Group) Text(javafx.scene.text.Text) List(java.util.List) TileEvent(eu.hansolo.tilesfx.events.TileEvent) LocationEvent(eu.hansolo.tilesfx.events.LocationEvent) WeakListChangeListener(javafx.collections.WeakListChangeListener) Circle(javafx.scene.shape.Circle) TileEvent(eu.hansolo.tilesfx.events.TileEvent) Group(javafx.scene.Group) Tooltip(javafx.scene.control.Tooltip) Color(javafx.scene.paint.Color) EventHandler(javafx.event.EventHandler) Text(javafx.scene.text.Text) Pane(javafx.scene.layout.Pane) Country(eu.hansolo.tilesfx.tools.Country) LocationEvent(eu.hansolo.tilesfx.events.LocationEvent)

Example 7 with LocationEvent

use of eu.hansolo.tilesfx.events.LocationEvent in project tilesfx by HanSolo.

the class Location method setLongitude.

public void setLongitude(final double LONGITUDE) {
    longitude = LONGITUDE;
    fireLocationEvent(new LocationEvent(Location.this));
}
Also used : LocationEvent(eu.hansolo.tilesfx.events.LocationEvent)

Example 8 with LocationEvent

use of eu.hansolo.tilesfx.events.LocationEvent in project tilesfx by HanSolo.

the class Location method set.

public void set(final double LATITUDE, final double LONGITUDE) {
    latitude = LATITUDE;
    longitude = LONGITUDE;
    timestamp = Instant.now();
    fireLocationEvent(new LocationEvent(Location.this));
}
Also used : LocationEvent(eu.hansolo.tilesfx.events.LocationEvent)

Example 9 with LocationEvent

use of eu.hansolo.tilesfx.events.LocationEvent in project tilesfx by HanSolo.

the class Location method setColor.

public void setColor(final Color COLOR) {
    color = COLOR;
    fireLocationEvent(new LocationEvent(Location.this));
}
Also used : LocationEvent(eu.hansolo.tilesfx.events.LocationEvent)

Example 10 with LocationEvent

use of eu.hansolo.tilesfx.events.LocationEvent in project tilesfx by HanSolo.

the class Location method set.

public void set(final double LATITUDE, final double LONGITUDE, final double ALTITUDE, final Instant TIMESTAMP, final String INFO) {
    latitude = LATITUDE;
    longitude = LONGITUDE;
    altitude = ALTITUDE;
    timestamp = TIMESTAMP;
    info = INFO;
    fireLocationEvent(new LocationEvent(Location.this));
}
Also used : LocationEvent(eu.hansolo.tilesfx.events.LocationEvent)

Aggregations

LocationEvent (eu.hansolo.tilesfx.events.LocationEvent)10 Tile (eu.hansolo.tilesfx.Tile)1 TextSize (eu.hansolo.tilesfx.Tile.TextSize)1 ChartData (eu.hansolo.tilesfx.chart.ChartData)1 TileEvent (eu.hansolo.tilesfx.events.TileEvent)1 EventType (eu.hansolo.tilesfx.events.TileEvent.EventType)1 Fonts (eu.hansolo.tilesfx.fonts.Fonts)1 Country (eu.hansolo.tilesfx.tools.Country)1 CountryPath (eu.hansolo.tilesfx.tools.CountryPath)1 Helper (eu.hansolo.tilesfx.tools.Helper)1 Helper.clamp (eu.hansolo.tilesfx.tools.Helper.clamp)1 Location (eu.hansolo.tilesfx.tools.Location)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Locale (java.util.Locale)1 Map (java.util.Map)1 FXCollections (javafx.collections.FXCollections)1 ListChangeListener (javafx.collections.ListChangeListener)1 ObservableMap (javafx.collections.ObservableMap)1 WeakListChangeListener (javafx.collections.WeakListChangeListener)1