Search in sources :

Example 1 with PixelShape

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;
}
Also used : ObjectProperty(javafx.beans.property.ObjectProperty) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) IntegerProperty(javafx.beans.property.IntegerProperty) SimpleIntegerProperty(javafx.beans.property.SimpleIntegerProperty) Dimension2D(javafx.geometry.Dimension2D) Color(javafx.scene.paint.Color) DoubleProperty(javafx.beans.property.DoubleProperty) SimpleDoubleProperty(javafx.beans.property.SimpleDoubleProperty) PixelShape(eu.hansolo.tilesfx.chart.PixelMatrix.PixelShape)

Example 2 with PixelShape

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);
}
Also used : Tile(eu.hansolo.tilesfx.Tile) EventHandler(javafx.event.EventHandler) Color(javafx.scene.paint.Color) Fonts(eu.hansolo.tilesfx.fonts.Fonts) PixelShape(eu.hansolo.tilesfx.chart.PixelMatrix.PixelShape) MouseEvent(javafx.scene.input.MouseEvent) PixelMatrixEventListener(eu.hansolo.tilesfx.events.PixelMatrixEventListener) Font(javafx.scene.text.Font) ChartDataEventListener(eu.hansolo.tilesfx.events.ChartDataEventListener) EventType(eu.hansolo.tilesfx.events.TileEvent.EventType) Text(javafx.scene.text.Text) ChartData(eu.hansolo.tilesfx.chart.ChartData) List(java.util.List) PixelMatrixBuilder(eu.hansolo.tilesfx.chart.PixelMatrixBuilder) Helper(eu.hansolo.tilesfx.tools.Helper) ListChangeListener(javafx.collections.ListChangeListener) TileEvent(eu.hansolo.tilesfx.events.TileEvent) Point2D(javafx.geometry.Point2D) Tooltip(javafx.scene.control.Tooltip) PixelMatrix(eu.hansolo.tilesfx.chart.PixelMatrix) TileEvent(eu.hansolo.tilesfx.events.TileEvent) ChartData(eu.hansolo.tilesfx.chart.ChartData) Point2D(javafx.geometry.Point2D) Tooltip(javafx.scene.control.Tooltip) Text(javafx.scene.text.Text)

Aggregations

PixelShape (eu.hansolo.tilesfx.chart.PixelMatrix.PixelShape)2 Color (javafx.scene.paint.Color)2 Tile (eu.hansolo.tilesfx.Tile)1 ChartData (eu.hansolo.tilesfx.chart.ChartData)1 PixelMatrix (eu.hansolo.tilesfx.chart.PixelMatrix)1 PixelMatrixBuilder (eu.hansolo.tilesfx.chart.PixelMatrixBuilder)1 ChartDataEventListener (eu.hansolo.tilesfx.events.ChartDataEventListener)1 PixelMatrixEventListener (eu.hansolo.tilesfx.events.PixelMatrixEventListener)1 TileEvent (eu.hansolo.tilesfx.events.TileEvent)1 EventType (eu.hansolo.tilesfx.events.TileEvent.EventType)1 Fonts (eu.hansolo.tilesfx.fonts.Fonts)1 Helper (eu.hansolo.tilesfx.tools.Helper)1 List (java.util.List)1 DoubleProperty (javafx.beans.property.DoubleProperty)1 IntegerProperty (javafx.beans.property.IntegerProperty)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleDoubleProperty (javafx.beans.property.SimpleDoubleProperty)1 SimpleIntegerProperty (javafx.beans.property.SimpleIntegerProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 ListChangeListener (javafx.collections.ListChangeListener)1