@Override
  public void updatePage(IServiceModel model) {
    if (getPager() == null) { // maybe null during init
      return;
    }
    if (model instanceof Song) {
      Song song = (Song) model;
      if (album.getActiveSong() == null) {
        updateBlink(null);
      }
      if (song.isActive()) {
        Node container = getNodeForSong(song);
        updateBlink(container);
      }

      if (lastSongSelection != null) {
        lastSongSelection.setStyle(STYLE_INACTIVE);
      }

      if (songBox != null) {
        final ObservableList<Node> children = songBox.getChildren();
        for (Node node : children) {
          String id = node.getId();
          if (getPager().getActiveModel() instanceof Song) {
            if (id.equals(String.valueOf(((Song) getPager().getActiveModel()).getMID()))) {
              lastSongSelection = node;
              lastSongSelection.setStyle(STYLE_ACTIVE);
            }
          }
        }
      }
    }
  }
  /**
   * Update background, tick and gridline colors
   *
   * @param cfg cfg[0] Background, cfg[1] Chart background, cfg[2] y cfg[3] gridline
   */
  public void updateChartColors(String[] cfg) {
    strBackgroundColor = cfg[0];
    for (Node le : legendFrame.getChildren()) {
      if (le instanceof LegendAxis) {
        le.setStyle("-fx-background-color:" + strBackgroundColor);
        ((LegendAxis) le).selected = false;
      }
    }
    chart.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));
    chartPanel.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createLineBorder(
                scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)))));
    chartPanel.setBackground(scene2awtColor(javafx.scene.paint.Color.web(strBackgroundColor)));

    legendFrame.setStyle("marco: " + strBackgroundColor + ";-fx-background-color: marco;");

    strChartBackgroundColor = cfg[1];
    ;
    plot.setBackgroundPaint(scene2awtColor(javafx.scene.paint.Color.web(strChartBackgroundColor)));

    for (Node le : legendFrame.getChildren()) {
      if (le instanceof LegendAxis) {
        le.setStyle("-fx-background-color:" + strBackgroundColor);
        ((LegendAxis) le).selected = false;
        for (Node nn : ((LegendAxis) le).getChildren()) {
          if (nn instanceof Label) {
            ((Label) nn)
                .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");
          }
        }
      }
    }

    strGridlineColor = cfg[2];
    ;
    plot.setDomainGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));
    plot.setRangeGridlinePaint(scene2awtColor(javafx.scene.paint.Color.web(strGridlineColor)));

    strTickColor = cfg[3];
    ;
    abcissaAxis.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    abcissaAxis.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    for (NumberAxis ejeOrdenada : AxesList) {
      ejeOrdenada.setLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
      ejeOrdenada.setTickLabelPaint(scene2awtColor(javafx.scene.paint.Color.web(strTickColor)));
    }
  }
  /**
   * @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;
      }
    }
  }
Exemplo n.º 4
0
  public void showPersonOverview() {
    try {
      // Load person overview.
      FXMLLoader loader1 = new FXMLLoader();
      loader1.setLocation(ChessFx.class.getResource("view/javafx/ChessBoard.fxml"));
      GridPane chessBoard = loader1.load();
      chessBoard.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);

      for (Node node : chessBoard.getChildren()) {
        Integer x = GridPane.getRowIndex(node);
        Integer y = GridPane.getColumnIndex(node);
        int row = x == null ? 0 : x;
        int col = y == null ? 0 : y;
        if (node instanceof Pane) {
          node.setId("pane" + row + "_" + col);
        }
        row = 8 - row - 1;

        if ((row + col) % 2 == 1) {
          node.setStyle("-fx-background-color: rgb(255,255,255);");
        } else {
          node.setStyle("-fx-background-color: rgb(128,128,128);");
        }

        if (row == 1) {
          ImageView img =
              new ImageView(new Image(ChessFx.class.getResourceAsStream("view/images/bpawn.png")));
          if (node instanceof Pane) {
            ((Pane) node).getChildren().add(img);
          }
        } else if (row == 6) {
          ImageView img =
              new ImageView(new Image(ChessFx.class.getResourceAsStream("view/images/wpawn.png")));
          if (node instanceof Pane) {
            ((Pane) node).getChildren().add(img);
          }
        } else if (row == 0) {
          if (col == 0 || col == 7) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/brook.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          } else if (col == 1 || col == 6) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/bknight.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          } else if (col == 2 || col == 5) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/bbishop.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          } else if (col == 4) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/bking.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          } else if (col == 3) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/bqueen.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          }

        } else if (row == 7) {
          if (col == 0 || col == 7) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/wrook.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          } else if (col == 1 || col == 6) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/wknight.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          } else if (col == 2 || col == 5) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/wbishop.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          } else if (col == 4) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/wking.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          } else if (col == 3) {
            ImageView img =
                new ImageView(
                    new Image(ChessFx.class.getResourceAsStream("view/images/wqueen.png")));
            if (node instanceof Pane) {
              ((Pane) node).getChildren().add(img);
            }
          }
        } else {
          ImageView img = new ImageView();
          if (node instanceof Pane) {
            ((Pane) node).getChildren().add(img);
          }
        }
      }

      rootLayout.setCenter(chessBoard);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }