use of eu.hansolo.tilesfx.chart.PixelMatrix.PixelShape in project tilesfx by HanSolo.
the class PixelMatrixBuilder method build.
public final PixelMatrix build() {
final PixelMatrix CONTROL;
if (properties.keySet().contains("cols") && properties.keySet().contains("rows")) {
int cols = ((IntegerProperty) properties.get("cols")).get();
int rows = ((IntegerProperty) properties.get("rows")).get();
CONTROL = new PixelMatrix(cols, rows);
} else {
CONTROL = new PixelMatrix();
}
for (String key : properties.keySet()) {
if ("prefSize".equals(key)) {
Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get();
CONTROL.setPrefSize(dim.getWidth(), dim.getHeight());
} else if ("minSize".equals(key)) {
Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get();
CONTROL.setMinSize(dim.getWidth(), dim.getHeight());
} else if ("maxSize".equals(key)) {
Dimension2D dim = ((ObjectProperty<Dimension2D>) properties.get(key)).get();
CONTROL.setMaxSize(dim.getWidth(), dim.getHeight());
} else if ("prefWidth".equals(key)) {
CONTROL.setPrefWidth(((DoubleProperty) properties.get(key)).get());
} else if ("prefHeight".equals(key)) {
CONTROL.setPrefHeight(((DoubleProperty) properties.get(key)).get());
} else if ("minWidth".equals(key)) {
CONTROL.setMinWidth(((DoubleProperty) properties.get(key)).get());
} else if ("minHeight".equals(key)) {
CONTROL.setMinHeight(((DoubleProperty) properties.get(key)).get());
} else if ("maxWidth".equals(key)) {
CONTROL.setMaxWidth(((DoubleProperty) properties.get(key)).get());
} else if ("maxHeight".equals(key)) {
CONTROL.setMaxHeight(((DoubleProperty) properties.get(key)).get());
} else if ("scaleX".equals(key)) {
CONTROL.setScaleX(((DoubleProperty) properties.get(key)).get());
} else if ("scaleY".equals(key)) {
CONTROL.setScaleY(((DoubleProperty) properties.get(key)).get());
} else if ("layoutX".equals(key)) {
CONTROL.setLayoutX(((DoubleProperty) properties.get(key)).get());
} else if ("layoutY".equals(key)) {
CONTROL.setLayoutY(((DoubleProperty) properties.get(key)).get());
} else if ("translateX".equals(key)) {
CONTROL.setTranslateX(((DoubleProperty) properties.get(key)).get());
} else if ("translateY".equals(key)) {
CONTROL.setTranslateY(((DoubleProperty) properties.get(key)).get());
} else if ("padding".equals(key)) {
CONTROL.setPadding(((ObjectProperty<Insets>) properties.get(key)).get());
} else if ("pixelOnColor".equals(key)) {
CONTROL.setPixelOnColor(((ObjectProperty<Color>) properties.get(key)).get());
} else if ("pixelOffColor".equals(key)) {
CONTROL.setPixelOffColor(((ObjectProperty<Color>) properties.get(key)).get());
} else if ("pixelShape".equals(key)) {
CONTROL.setPixelShape(((ObjectProperty<PixelShape>) properties.get(key)).get());
} else if ("matrixFont".equals(key)) {
CONTROL.setMatrixFont(((ObjectProperty<MatrixFont>) properties.get(key)).get());
} else if ("useSpacer".equals(key)) {
CONTROL.setUseSpacer(((BooleanProperty) properties.get(key)).get());
} else if ("spacerSizeFactor".equals(key)) {
CONTROL.setSpacerSizeFactor(((DoubleProperty) properties.get(key)).get());
} else if ("squarePixels".equals(key)) {
CONTROL.setSquarePixels(((BooleanProperty) properties.get(key)).get());
}
}
return CONTROL;
}
use of eu.hansolo.tilesfx.chart.PixelMatrix.PixelShape 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