eu.hansolo.fx.countries.DemoWorldPane Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of countries Show documentation
Show all versions of countries Show documentation
Countries is a JavaFX library containing controls and info for countries and cities
package eu.hansolo.fx.countries;
import eu.hansolo.fx.countries.tools.Helper;
import eu.hansolo.fx.countries.tools.OpacityDistribution;
import eu.hansolo.fx.countries.tools.Poi;
import eu.hansolo.fx.countries.tools.PoiBuilder;
import eu.hansolo.fx.countries.tools.Point;
import eu.hansolo.fx.countries.tools.PointSize;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
public class DemoWorldPane extends Application {
public static final String VERSION = PropertyManager.INSTANCE.getVersionNumber();
private WorldPane worldPane;
@Override public void init() {
List capitals = Helper.getCapitals()
.stream()
.map(city -> PoiBuilder.create().lat(city.lat()).lon(city.lon()).name(city.name()).fill(Color.web("#D86875")).pointSize(PointSize.NORMAL).build())
.collect(Collectors.toList());
List heatmapSpots = new ArrayList<>();
Helper.getCities()
.stream()
//.filter(city -> city.country() == Country.DE)
.filter(city -> city.population() > 1_000_000)
.forEach(city -> heatmapSpots.add(new Point(city.lon(), city.lat()))); // Keep in mind that longitude == x and latitude == y
worldPane = WorldPaneBuilder.create()
.poisVisible(true)
.poiTextVisible(true)
.heatmapVisible(true)
.heatmapSpotRadius(3)
.heatmapOpacityDistribution(OpacityDistribution.LINEAR)
.heatmapSpots(heatmapSpots)
.pois(capitals)
.hoverEnabled(true)
.selectionEnabled(true)
.build();
worldPane.selectedCountryProperty().addListener((o, ov, nv) -> System.out.println(nv));
}
@Override public void start(final Stage stage) {
StackPane pane = new StackPane(worldPane);
pane.setPrefSize(800, 400);
pane.setPadding(new Insets(10));
Scene scene = new Scene(pane);
stage.setTitle("WorldPane Version: " + VERSION);
stage.setScene(scene);
stage.show();
stage.centerOnScreen();
}
@Override public void stop() {
// Remove event handlers
// Shutdown
Platform.exit();
System.exit(0);
}
// ******************** Launching *******************************
public static void main(final String[] args) {
launch(args);
}
}