Example usage for javafx.scene.control Label setOnMouseClicked

List of usage examples for javafx.scene.control Label setOnMouseClicked

Introduction

In this page you can find the example usage for javafx.scene.control Label setOnMouseClicked.

Prototype

public final void setOnMouseClicked(EventHandler<? super MouseEvent> value) 

Source Link

Usage

From source file:com.chart.SwingChart.java

/**
 * /*from  w ww  .  j a va  2 s  .c o m*/
 * @param axis Axis name to wich the new series belongs
 * @param cs Series Coinfiguration
 */
@Override
public final void addSeries(String axis, SimpleSeriesConfiguration cs) {
    for (int i = 0; i < axes.size(); i++) {
        if (axes.get(i).getName().equals(axis)) {
            String strColor;
            javafx.scene.paint.Color color;
            int indice = seriesList.size();
            if (cs.getColor() == null) {
                color = getColor(indice);
            } else {
                color = cs.getColor();
            }
            strColor = color.toString();

            XYSeriesCollection dataset = datasetList.get(i);
            Series series = new Series(cs.getName(), "color: " + strColor + ";width: "
                    + String.valueOf(cs.getLineWidth()) + ";shape: " + cs.getShapeName() + ";", i,
                    dataset.getSeriesCount());
            dataset.addSeries(series);

            XYItemRenderer renderer = plot.getRenderer(i);
            renderer.setSeriesPaint(dataset.getSeriesCount() - 1, scene2awtColor(color));

            SeriesShape simb = new SeriesShape(cs.getShapeName(),
                    javafx.scene.paint.Color.web(strColor.replace("#", "0x")));

            if (cs.getLineWidth() > 0) {
                ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(dataset.getSeriesCount() - 1, true);
                renderer.setSeriesStroke(dataset.getSeriesCount() - 1, new BasicStroke(cs.getLineWidth()));
            } else {
                ((XYLineAndShapeRenderer) renderer).setSeriesLinesVisible(dataset.getSeriesCount() - 1, false);
            }

            if (cs.getShapeName().equals("null")) {
                renderer.setSeriesShape(dataset.getSeriesCount() - 1, null);
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(dataset.getSeriesCount() - 1, false);
            } else {
                renderer.setSeriesShape(dataset.getSeriesCount() - 1, simb.getShapeAWT());
                ((XYLineAndShapeRenderer) renderer).setSeriesShapesVisible(dataset.getSeriesCount() - 1, true);
                if (cs.getShapeName().contains("empty")) {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(dataset.getSeriesCount() - 1,
                            false);
                } else {
                    ((XYLineAndShapeRenderer) renderer).setSeriesShapesFilled(dataset.getSeriesCount() - 1,
                            true);
                }
            }

            if (i == 0) {
                plot.setRenderer(renderer);
            } else {
                plot.setRenderer(i, renderer);
            }

            seriesList.add(series);

            final LegendAxis le = getLegendAxis(axis);
            final Label label = new Label(cs.toString());
            Platform.runLater(() -> {
                label.setStyle("fondo: " + strChartBackgroundColor
                        + ";-fx-background-color: fondo;-fx-text-fill: ladder(fondo, white 49%, black 50%);-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                        + String.valueOf(fontSize) + "px");
            });

            label.setOnMouseClicked((MouseEvent t) -> {
                if (t.getClickCount() == 2) {
                    for (int i1 = 0; i1 < seriesList.size(); i1++) {
                        if (seriesList.get(i1).getKey().toString().equals(label.getText())) {
                            editSeries(seriesList.get(i1));
                            break;
                        }
                    }
                }
            });
            label.setOnMouseExited((MouseEvent t) -> {
                label.setStyle(
                        label.getStyle().replace("-fx-background-color: blue", "-fx-background-color: fondo"));
            });
            label.setOnMouseEntered((MouseEvent t) -> {
                label.setStyle(
                        label.getStyle().replace("-fx-background-color: fondo", "-fx-background-color: blue"));
                for (Node le1 : legendFrame.getChildren()) {
                    if (le1 instanceof LegendAxis) {
                        le1.setStyle("-fx-background-color:" + strBackgroundColor);
                        ((LegendAxis) le1).selected = false;
                    }
                }
            });
            label.setStyle("fondo: " + strChartBackgroundColor
                    + ";-fx-text-fill: white;-fx-background-color: fondo;-fx-padding:5px;-fx-background-radius: 5;-fx-font-size: "
                    + String.valueOf(fontSize) + "px");

            le.getChildren().add(label);
            label.setGraphic(simb.getShapeGraphic());

            break;
        }
    }
}