use of eu.hansolo.tilesfx.events.TileEvent in project tilesfx by HanSolo.
the class Tile method registerListeners.
private void registerListeners() {
disabledProperty().addListener(o -> setOpacity(isDisabled() ? 0.4 : 1));
valueProperty().addListener((o, ov, nv) -> oldValue.set(ov.doubleValue()));
currentValueProperty().addListener(o -> {
double currentValue = getCurrentValue();
if (currentValue > getMaxValue()) {
fireTileEvent(MAX_VALUE_EXCEEDED);
} else if (currentValue < getMinValue()) {
fireTileEvent(MIN_VALUE_UNDERRUN);
} else {
fireTileEvent(VALUE_IN_RANGE);
}
});
showing.addListener((o, ov, nv) -> {
if (nv) {
while (tileEventQueue.peek() != null) {
TileEvent event = tileEventQueue.poll();
for (TileEventListener listener : tileEventListeners) {
listener.onTileEvent(event);
}
}
}
});
}
use of eu.hansolo.tilesfx.events.TileEvent in project tilesfx by HanSolo.
the class BarChartTileSkin method initGraphics.
// ******************** Initialization ************************************
@Override
protected void initGraphics() {
super.initGraphics();
updateHandler = e -> updateChart();
paneSizeListener = o -> resizeItems();
handlerMap = new HashMap<>();
List<BarChartItem> barChartItems = tile.getBarChartItems().stream().sorted(Comparator.comparing(BarChartItem::getValue).reversed()).collect(Collectors.toList());
tile.getBarChartItems().forEach(item -> {
item.addChartDataEventListener(updateHandler);
EventHandler<MouseEvent> clickHandler = e -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, item.getChartData()));
handlerMap.put(item, clickHandler);
item.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
item.setMaxValue(tile.getMaxValue());
if (null == item.getFormatString() || item.getFormatString().isEmpty()) {
item.setFormatString(formatString);
}
});
barChartPane = new Pane();
barChartPane.getChildren().addAll(barChartItems);
titleText = new Text();
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
text = new Text(tile.getText());
text.setFill(tile.getUnitColor());
Helper.enableNode(text, tile.isTextVisible());
getPane().getChildren().addAll(titleText, text, barChartPane);
}
use of eu.hansolo.tilesfx.events.TileEvent in project tilesfx by HanSolo.
the class CountryTileSkin method initGraphics.
// ******************** Initialization ************************************
@Override
protected void initGraphics() {
super.initGraphics();
// poiLocations = FXCollections.observableHashMap();
// chartDataLocations = FXCollections.observableHashMap();
// circleHandlerMap = new HashMap<>();
country = tile.getCountry();
if (null == country) {
country = Country.DE;
}
clickHandler = event -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, new ChartData(country.getName(), country.getValue(), country.getColor())));
countryPaths = Helper.getHiresCountryPaths().get(country.name());
countryMinX = Helper.MAP_WIDTH;
countryMinY = Helper.MAP_HEIGHT;
countryMaxX = 0;
countryMaxY = 0;
countryPaths.forEach(path -> {
path.setFill(tile.getBarColor());
countryMinX = Math.min(countryMinX, path.getBoundsInParent().getMinX());
countryMinY = Math.min(countryMinY, path.getBoundsInParent().getMinY());
countryMaxX = Math.max(countryMaxX, path.getBoundsInParent().getMaxX());
countryMaxY = Math.max(countryMaxY, path.getBoundsInParent().getMaxY());
});
/*
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);
});
*/
titleText = new Text();
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
text = new Text(tile.getCountry().getDisplayName());
text.setFill(tile.getTextColor());
Helper.enableNode(text, tile.isTextVisible());
countryGroup = new Group();
countryGroup.getChildren().setAll(countryPaths);
countryContainer = new StackPane();
countryContainer.setMinSize(size * 0.9, tile.isTextVisible() ? size * 0.72 : size * 0.795);
countryContainer.setMaxSize(size * 0.9, tile.isTextVisible() ? size * 0.72 : size * 0.795);
countryContainer.setPrefSize(size * 0.9, tile.isTextVisible() ? size * 0.72 : size * 0.795);
countryContainer.getChildren().setAll(countryGroup);
valueText = new Text(String.format(locale, formatString, ((tile.getValue() - minValue) / range * 100)));
valueText.setFill(tile.getValueColor());
valueText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(valueText, tile.isValueVisible());
unitText = new Text(" " + tile.getUnit());
unitText.setFill(tile.getUnitColor());
unitText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(unitText, !tile.getUnit().isEmpty());
valueUnitFlow = new TextFlow(valueText, unitText);
valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);
valueUnitFlow.setMouseTransparent(true);
getPane().getChildren().addAll(titleText, countryContainer, valueUnitFlow, text);
// getPane().getChildren().addAll(poiLocations.values());
}
use of eu.hansolo.tilesfx.events.TileEvent in project tilesfx by HanSolo.
the class DonutChartTileSkin method initGraphics.
// ******************** Initialization ************************************
@Override
protected void initGraphics() {
super.initGraphics();
chartEventListener = e -> redraw();
tile.getChartData().forEach(chartData -> chartData.addChartDataEventListener(chartEventListener));
chartDataListener = c -> {
while (c.next()) {
if (c.wasAdded()) {
c.getAddedSubList().forEach(addedItem -> addedItem.addChartDataEventListener(chartEventListener));
} else if (c.wasRemoved()) {
c.getRemoved().forEach(removedItem -> removedItem.removeChartDataEventListener(chartEventListener));
}
}
drawChart();
drawLegend();
};
clickHandler = e -> {
double x = e.getX();
double y = e.getY();
double startAngle = 90;
double angle = 0;
List<ChartData> dataList = tile.isSortedData() ? tile.getChartData().stream().sorted(Comparator.comparingDouble(ChartData::getValue)).collect(Collectors.toList()) : tile.getChartData();
int noOfItems = dataList.size();
double sum = dataList.stream().mapToDouble(ChartData::getValue).sum();
double stepSize = 360.0 / sum;
double barWidth = chartCanvas.getWidth() * 0.1;
double ri = outerRadius - barWidth * 0.5;
double ro = outerRadius + barWidth * 0.5;
for (int i = 0; i < noOfItems; i++) {
ChartData data = dataList.get(i);
double value = data.getValue();
startAngle -= angle;
angle = value * stepSize;
boolean hit = Helper.isInRingSegment(x, y, centerX, centerY, ro, ri, startAngle, angle);
if (hit) {
String tooltipText = new StringBuilder(data.getName()).append("\n").append(String.format(locale, formatString, value)).toString();
Point2D popupLocation = new Point2D(e.getScreenX() - selectionTooltip.getWidth() * 0.5, e.getScreenY() - size * 0.025 - selectionTooltip.getHeight());
selectionTooltip.setText(tooltipText);
selectionTooltip.setX(popupLocation.getX());
selectionTooltip.setY(popupLocation.getY());
selectionTooltip.show(tile.getScene().getWindow());
tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, data));
break;
}
}
};
moveHandler = e -> selectionTooltip.hide();
titleText = new Text();
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
text = new Text(tile.getText());
text.setFill(tile.getTextColor());
Helper.enableNode(text, tile.isTextVisible());
chartCanvas = new Canvas(size * 0.9, tile.isTextVisible() ? height - size * 0.28 : height - size * 0.205);
chartCtx = chartCanvas.getGraphicsContext2D();
legendCanvas = new Canvas(size * 0.225, tile.isTextVisible() ? height - size * 0.28 : height - size * 0.205);
legendCtx = legendCanvas.getGraphicsContext2D();
selectionTooltip = new Tooltip("");
selectionTooltip.setWidth(60);
selectionTooltip.setHeight(48);
Tooltip.install(chartCanvas, selectionTooltip);
getPane().getChildren().addAll(titleText, legendCanvas, chartCanvas, text);
}
use of eu.hansolo.tilesfx.events.TileEvent in project tilesfx by HanSolo.
the class MatrixTileSkin method initGraphics.
// ******************** Initialization ************************************
@Override
protected void initGraphics() {
super.initGraphics();
matrix = PixelMatrixBuilder.create().pixelShape(PixelShape.SQUARE).useSpacer(true).squarePixels(false).colsAndRows(tile.getMatrixSize()).pixelOnColor(tile.getBarColor()).pixelOffColor(Helper.isDark(tile.getBackgroundColor()) ? tile.getBackgroundColor().brighter() : tile.getBackgroundColor().darker()).build();
if (!tile.getChartData().isEmpty() && tile.getChartData().size() > 2) {
matrix.setColsAndRows(tile.getChartData().size(), matrix.getRows());
}
chartEventListener = e -> updateMatrixWithChartData();
tile.getChartData().forEach(chartData -> chartData.addChartDataEventListener(chartEventListener));
chartDataListener = c -> {
while (c.next()) {
if (c.wasAdded()) {
c.getAddedSubList().forEach(addedItem -> addedItem.addChartDataEventListener(chartEventListener));
if (!tile.getChartData().isEmpty() && tile.getChartData().size() > 2) {
matrix.setColsAndRows(tile.getChartData().size(), matrix.getRows());
}
} else if (c.wasRemoved()) {
c.getRemoved().forEach(removedItem -> removedItem.removeChartDataEventListener(chartEventListener));
if (!tile.getChartData().isEmpty() && tile.getChartData().size() > 2) {
matrix.setColsAndRows(tile.getChartData().size(), matrix.getRows());
}
}
}
updateMatrixWithChartData();
};
matrixListener = e -> {
if (tile.getChartData().isEmpty()) {
return;
}
int column = e.getX();
ChartData data = tile.getChartData().get(column);
String tooltipText = new StringBuilder(data.getName()).append("\n").append(String.format(locale, formatString, data.getValue())).toString();
Point2D popupLocation = new Point2D(e.getMouseScreenX() - selectionTooltip.getWidth() * 0.5, e.getMouseScreenY() - size * 0.025 - selectionTooltip.getHeight());
selectionTooltip.setText(tooltipText);
selectionTooltip.setX(popupLocation.getX());
selectionTooltip.setY(popupLocation.getY());
selectionTooltip.show(tile.getScene().getWindow());
tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, data));
};
mouseHandler = e -> {
final javafx.event.EventType<? extends MouseEvent> TYPE = e.getEventType();
if (MouseEvent.MOUSE_CLICKED.equals(TYPE)) {
matrix.checkForClick(e);
} else if (MouseEvent.MOUSE_MOVED.equals(TYPE)) {
selectionTooltip.hide();
} else if (MouseEvent.MOUSE_EXITED.equals(TYPE)) {
selectionTooltip.hide();
}
};
titleText = new Text();
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
text = new Text(tile.getText());
text.setFill(tile.getTextColor());
Helper.enableNode(text, tile.isTextVisible());
selectionTooltip = new Tooltip("");
selectionTooltip.setWidth(60);
selectionTooltip.setHeight(48);
Tooltip.install(matrix, selectionTooltip);
getPane().getChildren().addAll(titleText, matrix, text);
}
Aggregations