コード例 #1
0
  /**
   * Builds the element that lets the user add this exercise
   *
   * @param screenWidth
   * @param screenHeight
   * @param sourceFile
   * @param workoutBuilder
   */
  public ExerciseContent(
      double screenWidth, double screenHeight, File sourceFile, CreateWorkout workoutBuilder) {

    // get the exercise details
    this.sourceFile = sourceFile;
    XMLParser parser = new XMLParser(sourceFile.getName());

    exerciseLabel = new Label(parser.getDocumentInfo().getTitle());
    exerciseLabel.setMinWidth(screenWidth * 0.1);
    exerciseLabel.setMinWidth(screenWidth * 0.075);

    descriptionLabel = new Label(parser.getDocumentInfo().getComment());
    descriptionLabel.setMinWidth(screenWidth * 0.2);
    descriptionLabel.setMaxWidth(screenWidth * 0.2);
    descriptionLabel.setWrapText(true);

    repAmount = new TextField();
    repAmount.setPrefWidth(screenWidth * 0.05);

    setAmount = new TextField();
    setAmount.setPrefWidth(screenWidth * 0.05);

    addExercise = new Button("ADD");
    addExercise.setPrefSize(screenWidth * 0.05, screenHeight * 0.025);

    setNodeCursor(addExercise);

    // add the exercise to the selected exercise list
    addExercise.setOnAction(
        new EventHandler<ActionEvent>() {

          public void handle(ActionEvent event) {

            if ((isInt(setAmount.getText())) && (isInt(repAmount.getText()))) {
              workoutBuilder.addToList(
                  sourceFile.getName(),
                  exerciseLabel.getText(),
                  Integer.parseInt(setAmount.getText()),
                  Integer.parseInt(repAmount.getText()));
            }
          }
        });

    getChildren().addAll(exerciseLabel, descriptionLabel, repAmount, setAmount, addExercise);
    setWidth(screenWidth * 0.4);
    setHeight(screenHeight * 0.2);
    setSpacing(screenWidth * 0.01);
    setPadding(new Insets(0, 0, 0, screenWidth * 0.01));
  }
コード例 #2
0
  private GridPane buildRecordingGrid(Recording recording) {
    GridPane grid = new GridPane();
    grid.setHgap(5);
    grid.setVgap(5);

    Label status = new Label();
    status.setAlignment(Pos.CENTER);
    status.setMinWidth(STATUS_MIN_WIDTH);
    updateStatusIcon(recording, status);
    recording
        .fileExistsActionProperty()
        .addListener(observable -> updateStatusIcon(recording, status));

    Label title = new Label();
    title.setMinWidth(TITLE_MIN_WIDTH);
    title.textProperty().bind(recording.fullTitleProperty());

    Label destination = new Label();
    destination.getStyleClass().add("destination");
    destination.textProperty().bind(recording.destinationProperty().asString());
    LocalDate dateArchived = recording.getDateArchived();
    if (dateArchived != null) {
      String dateArchivedText =
          String.format("Archived %s", DateUtils.formatArchivedOnDate(dateArchived));
      Tooltip tooltip = new Tooltip(dateArchivedText);
      title.setTooltip(tooltip);
      destination.setTooltip(tooltip);
    }

    ReplaceOrRenameActionBar actionBar = new ReplaceOrRenameActionBar(recording, userPrefs);
    actionBar.setMinWidth(ACTION_BAR_MIN_WIDTH);
    GridPane.setHalignment(actionBar, HPos.RIGHT);
    GridPane.setHgrow(actionBar, Priority.ALWAYS);
    GridPane.setMargin(actionBar, new Insets(0, 0, 0, 10));

    grid.add(status, 0, 0, 1, 2);
    grid.add(title, 1, 0);
    grid.add(destination, 1, 1);
    grid.add(actionBar, 2, 0, 1, 2);

    return grid;
  }
コード例 #3
0
  public TablePropertyRow(TableProperty<V> property) {
    this.labelView = new Label();
    this.property = requireNonNull(property);

    labelView.textProperty().bind(property.nameProperty());
    labelView.setPadding(new Insets(4));
    labelView.setMinWidth(320);
    property.getValueGraphic().maxWidth(Double.MAX_VALUE);

    setSpacing(16);
    setAlignment(Pos.CENTER_LEFT);

    getChildren().add(labelView);
    getChildren().add(property.getValueGraphic());
  }
コード例 #4
0
    public MediaControl(final MediaPlayer mp) {
      this.mp = mp;
      setStyle("-fx-background-color: #bfc2c7;"); // TODO: Use css file
      mediaView = new MediaView(mp);
      mvPane = new Pane();
      mvPane.getChildren().add(mediaView);
      mvPane.setStyle("-fx-background-color: black;"); // TODO: Use css file
      setCenter(mvPane);
      mediaBar = new HBox(5.0);
      mediaBar.setPadding(new Insets(5, 10, 5, 10));
      mediaBar.setAlignment(Pos.CENTER_LEFT);
      BorderPane.setAlignment(mediaBar, Pos.CENTER);

      final Button playButton = ButtonBuilder.create().minWidth(Control.USE_PREF_SIZE).build();

      playButton.setGraphic(imageViewPlay);
      playButton.setOnAction(
          new EventHandler<ActionEvent>() {
            public void handle(ActionEvent e) {
              updateValues();
              MediaPlayer.Status status = mp.getStatus();
              if (status == MediaPlayer.Status.UNKNOWN || status == MediaPlayer.Status.HALTED) {
                // don't do anything in these states
                return;
              }

              if (status == MediaPlayer.Status.PAUSED
                  || status == MediaPlayer.Status.READY
                  || status == MediaPlayer.Status.STOPPED) {
                // rewind the movie if we're sitting at the end
                if (atEndOfMedia) {
                  mp.seek(mp.getStartTime());
                  atEndOfMedia = false;
                  playButton.setGraphic(imageViewPlay);
                  // playButton.setText(">");
                  updateValues();
                }
                mp.play();
                playButton.setGraphic(imageViewPause);
                // playButton.setText("||");
              } else {
                mp.pause();
              }
            }
          });
      mp.currentTimeProperty()
          .addListener(
              new ChangeListener<Duration>() {
                @Override
                public void changed(
                    ObservableValue<? extends Duration> observable,
                    Duration oldValue,
                    Duration newValue) {
                  updateValues();
                }
              });
      mp.setOnPlaying(
          new Runnable() {
            public void run() {

              if (stopRequested) {
                mp.pause();
                stopRequested = false;
              } else {
                playButton.setGraphic(imageViewPause);
                // playButton.setText("||");
              }
            }
          });
      mp.setOnPaused(
          new Runnable() {
            public void run() {

              playButton.setGraphic(imageViewPlay);
              // playButton.setText("||");
            }
          });
      mp.setOnReady(
          new Runnable() {
            public void run() {
              duration = mp.getMedia().getDuration();
              updateValues();
            }
          });

      mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1);
      mp.setOnEndOfMedia(
          new Runnable() {
            public void run() {
              if (!repeat) {
                playButton.setGraphic(imageViewPlay);
                // playButton.setText(">");
                stopRequested = true;
                atEndOfMedia = true;
              }
            }
          });
      mediaBar.getChildren().add(playButton);

      // Time label
      Label timeLabel = new Label("Time");
      timeLabel.setMinWidth(Control.USE_PREF_SIZE);
      mediaBar.getChildren().add(timeLabel);

      // Time slider
      timeSlider = SliderBuilder.create().minWidth(30).maxWidth(Double.MAX_VALUE).build();
      HBox.setHgrow(timeSlider, Priority.ALWAYS);
      timeSlider
          .valueProperty()
          .addListener(
              new InvalidationListener() {
                public void invalidated(Observable ov) {
                  if (timeSlider.isValueChanging()) {
                    // multiply duration by percentage calculated by slider position
                    if (duration != null) {
                      mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
                    }
                    updateValues();
                  }
                }
              });
      mediaBar.getChildren().add(timeSlider);

      // Play label
      playTime =
          LabelBuilder.create()
              // .prefWidth(130)
              .minWidth(Control.USE_PREF_SIZE)
              .build();

      mediaBar.getChildren().add(playTime);

      // Fullscreen button

      Button buttonFullScreen =
          ButtonBuilder.create().text("Full Screen").minWidth(Control.USE_PREF_SIZE).build();

      buttonFullScreen.setOnAction(
          new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
              if (!fullScreen) {
                newStage = new Stage();
                newStage
                    .fullScreenProperty()
                    .addListener(
                        new ChangeListener<Boolean>() {
                          @Override
                          public void changed(
                              ObservableValue<? extends Boolean> ov, Boolean t, Boolean t1) {
                            onFullScreen();
                          }
                        });
                final BorderPane borderPane =
                    new BorderPane() {
                      @Override
                      protected void layoutChildren() {
                        if (mediaView != null && getBottom() != null) {
                          mediaView.setFitWidth(getWidth());
                          mediaView.setFitHeight(getHeight() - getBottom().prefHeight(-1));
                        }
                        super.layoutChildren();
                        if (mediaView != null) {
                          mediaView.setTranslateX(
                              (((Pane) getCenter()).getWidth() - mediaView.prefWidth(-1)) / 2);
                          mediaView.setTranslateY(
                              (((Pane) getCenter()).getHeight() - mediaView.prefHeight(-1)) / 2);
                        }
                      };
                    };

                setCenter(null);
                setBottom(null);
                borderPane.setCenter(mvPane);
                borderPane.setBottom(mediaBar);

                Scene newScene = new Scene(borderPane);
                newStage.setScene(newScene);
                // Workaround for disposing stage when exit fullscreen
                newStage.setX(-100000);
                newStage.setY(-100000);

                newStage.setFullScreen(true);
                fullScreen = true;
                newStage.show();

              } else {
                // toggle FullScreen
                fullScreen = false;
                newStage.setFullScreen(false);
              }
            }
          });
      mediaBar.getChildren().add(buttonFullScreen);

      // Volume label
      Label volumeLabel = new Label("Vol");
      volumeLabel.setMinWidth(Control.USE_PREF_SIZE);
      mediaBar.getChildren().add(volumeLabel);

      // Volume slider
      volumeSlider =
          SliderBuilder.create().prefWidth(70).minWidth(30).maxWidth(Region.USE_PREF_SIZE).build();
      volumeSlider
          .valueProperty()
          .addListener(
              new InvalidationListener() {
                public void invalidated(Observable ov) {}
              });
      volumeSlider
          .valueProperty()
          .addListener(
              new ChangeListener<Number>() {
                @Override
                public void changed(
                    ObservableValue<? extends Number> observable,
                    Number oldValue,
                    Number newValue) {
                  if (volumeSlider.isValueChanging()) {
                    mp.setVolume(volumeSlider.getValue() / 100.0);
                  }
                }
              });
      mediaBar.getChildren().add(volumeSlider);

      setBottom(mediaBar);
    }
コード例 #5
0
    public MediaControl(final MediaPlayer mp) {
      this.mp = mp;
      setStyle("-fx-background-color: #bfc2c7;"); // TODO: Use css file
      mediaView = new MediaView(mp);
      Pane mvPane = new Pane() {};

      mvPane.getChildren().add(mediaView);
      mvPane.setStyle("-fx-background-color: black;"); // TODO: Use css file
      setCenter(mvPane);
      mediaBar = new HBox();
      mediaBar.setPadding(new Insets(5, 10, 5, 10));
      mediaBar.setAlignment(Pos.CENTER_LEFT);
      BorderPane.setAlignment(mediaBar, Pos.CENTER);

      final Button playButton = new Button();
      playButton.setGraphic(imageViewPlay);
      playButton.setOnAction(
          new EventHandler<ActionEvent>() {
            public void handle(ActionEvent e) {
              updateValues();
              Status status = mp.getStatus();
              if (status == Status.UNKNOWN || status == Status.HALTED) {
                // don't do anything in these states
                return;
              }

              if (status == Status.PAUSED || status == Status.READY || status == Status.STOPPED) {
                // rewind the movie if we're sitting at the end
                if (atEndOfMedia) {
                  mp.seek(mp.getStartTime());
                  atEndOfMedia = false;
                  playButton.setGraphic(imageViewPlay);
                  // playButton.setText(">");
                  updateValues();
                }
                mp.play();
                playButton.setGraphic(imageViewPause);
                // playButton.setText("||");
              } else {
                mp.pause();
              }
            }
          });
      mp.currentTimeProperty()
          .addListener(
              new ChangeListener<Duration>() {
                @Override
                public void changed(
                    ObservableValue<? extends Duration> observable,
                    Duration oldValue,
                    Duration newValue) {
                  updateValues();
                }
              });
      mp.setOnPlaying(
          new Runnable() {
            public void run() {
              // System.out.println("onPlaying");
              if (stopRequested) {
                mp.pause();
                stopRequested = false;
              } else {
                playButton.setGraphic(imageViewPause);
                // playButton.setText("||");
              }
            }
          });
      mp.setOnPaused(
          new Runnable() {
            public void run() {
              // System.out.println("onPaused");
              playButton.setGraphic(imageViewPlay);
              // playButton.setText("||");
            }
          });
      mp.setOnReady(
          new Runnable() {
            public void run() {
              duration = mp.getMedia().getDuration();
              updateValues();
            }
          });

      mp.setCycleCount(repeat ? MediaPlayer.INDEFINITE : 1);
      mp.setOnEndOfMedia(
          new Runnable() {
            public void run() {
              if (!repeat) {
                playButton.setGraphic(imageViewPlay);
                // playButton.setText(">");
                stopRequested = true;
                atEndOfMedia = true;
              }
            }
          });
      mediaBar.getChildren().add(playButton);
      // Add spacer
      Label spacer = new Label("   ");
      mediaBar.getChildren().add(spacer);
      // Time label
      Label timeLabel = new Label("Time: ");
      timeLabel.setMinWidth(Control.USE_PREF_SIZE);
      mediaBar.getChildren().add(timeLabel);
      // Time slider
      timeSlider = new Slider();
      HBox.setHgrow(timeSlider, Priority.ALWAYS);
      timeSlider.setMinWidth(50);
      timeSlider.setMaxWidth(Double.MAX_VALUE);
      timeSlider
          .valueProperty()
          .addListener(
              new InvalidationListener() {
                public void invalidated(Observable ov) {
                  if (timeSlider.isValueChanging()) {
                    // multiply duration by percentage calculated by slider position
                    if (duration != null) {
                      mp.seek(duration.multiply(timeSlider.getValue() / 100.0));
                    }
                    updateValues();
                  }
                }
              });
      mediaBar.getChildren().add(timeSlider);
      // Play label
      playTime = new Label();
      playTime.setPrefWidth(130);
      playTime.setMinWidth(50);
      mediaBar.getChildren().add(playTime);
      // Volume label
      Label volumeLabel = new Label("Vol: ");
      volumeLabel.setMinWidth(Control.USE_PREF_SIZE);
      mediaBar.getChildren().add(volumeLabel);
      // Volume slider
      volumeSlider = new Slider();
      volumeSlider.setPrefWidth(70);
      volumeSlider.setMaxWidth(Region.USE_PREF_SIZE);
      volumeSlider.setMinWidth(30);
      volumeSlider
          .valueProperty()
          .addListener(
              new InvalidationListener() {
                public void invalidated(Observable ov) {}
              });
      volumeSlider
          .valueProperty()
          .addListener(
              new ChangeListener<Number>() {
                @Override
                public void changed(
                    ObservableValue<? extends Number> observable,
                    Number oldValue,
                    Number newValue) {
                  if (volumeSlider.isValueChanging()) {
                    mp.setVolume(volumeSlider.getValue() / 100.0);
                  }
                }
              });
      mediaBar.getChildren().add(volumeSlider);
      setBottom(mediaBar);
    }
コード例 #6
0
  public MusicSegmentController(final String name, float length, double width, String audioPath) {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/com/view/musicSegment.fxml"));
    fxmlLoader.setRoot(this);
    fxmlLoader.setController(this);

    this.setId(Controller.userName + Controller.musicSegmentIndex);
    this.setPadding(InsetsBuilder.create().left(10).top(10).build());

    this.audioPath = audioPath;
    this.name = name;
    this.length = length;
    this.width = width;

    try {
      fxmlLoader.load();
    } catch (IOException exception) {
      throw new RuntimeException(exception);
    }
    // this.setId(name + "MusicSegmentComponent");
    if (name != null) {
      musicSegmentName.setText("(" + length + " ms)");
    }
    musicSegmentRectangle.widthProperty().bind(this.widthProperty());
    // musicSegmentRectangle.setWidth(width);
    musicSegmentName.setMinWidth(width);
    musicSegmentName.setMaxWidth(width);
    this.setWidth(width);
    this.setMaxWidth(width);
    this.setMinWidth(width);
    dragRectangle =
        new Rectangle(
            musicSegmentRectangle.getWidth(),
            musicSegmentRectangle.getHeight(),
            musicSegmentRectangle.getFill());
    // this.setPadding(InsetsBuilder.create().left(10).right(10).build());

    this.setOnMouseEntered(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent mouseEvent) {
            musicSegmentActions.setVisible(true);
            FadeTransition fadeTransition =
                new FadeTransition(Duration.millis(200), musicSegmentActions);
            fadeTransition.setFromValue(0.0);
            fadeTransition.setToValue(1.0);
            fadeTransition.play();
          }
        });

    this.setOnMouseExited(
        new EventHandler<MouseEvent>() {

          public void handle(MouseEvent mouseEvent) {
            FadeTransition fadeTransition =
                new FadeTransition(Duration.millis(200), musicSegmentActions);
            fadeTransition.setFromValue(1.0);
            fadeTransition.setToValue(0.0);
            fadeTransition.play();
          }
        });

    this.setOnDragDetected(
        new EventHandler<MouseEvent>() {
          public void handle(MouseEvent event) {
            System.out.println("Drag entered music segment");

            /* drag was detected, start a drag-and-drop gesture*/
            /* allow any transfer mode */
            Dragboard db = musicSegmentName.startDragAndDrop(TransferMode.COPY);

            /* Put a string on a dragboard */
            ClipboardContent content = new ClipboardContent();
            content.putString(musicSegmentName.getText());
            db.setContent(content);

            event.consume();
          }
        });

    Media media = new Media(new File(audioPath).toURI().toString());
    mediaPlayer = MediaPlayerBuilder.create().media(media).build();

    btnPlayMusicSegment.setOnMouseClicked(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent mouseEvent) {
            mediaPlayer.play();
          }
        });

    btnStopMusicSegment.setOnMouseClicked(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent mouseEvent) {
            mediaPlayer.pause();
          }
        });

    btnDeleteMusicSegment.setOnMouseClicked(
        new EventHandler<MouseEvent>() {
          @Override
          public void handle(MouseEvent mouseEvent) {
            // Group group = (Group) getController().getParent();
            // group.getChildren().remove(getController());
            if (Controller.getTracksArea().getChildren().remove(getController())) {
              System.out.println("Music segment deleted");
            } else {
              System.out.println("music segment could not be deleted");
            }
          }
        });
  }
コード例 #7
0
  public ColorPickerPopover() {

    getStyleClass().add("color-picker-popover");
    popup.setAutoHide(true);

    // add this to popup
    popup.getContent().add(this);

    // load stylesheet
    getStylesheets().add(ColorPicker.class.getResource("ColorPicker.css").toString());

    // create popover path for main shape
    final Path p = new Path();
    p.getElements()
        .addAll(
            new MoveTo(PICKER_PADDING, PICKER_PADDING + ARROW_SIZE + RADIUS),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + RADIUS,
                PICKER_PADDING + ARROW_SIZE,
                false,
                true),
            new LineTo(PICKER_PADDING + ARROW_X - (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE),
            new LineTo(PICKER_PADDING + ARROW_X, PICKER_PADDING),
            new LineTo(PICKER_PADDING + ARROW_X + (ARROW_SIZE * 0.8), PICKER_PADDING + ARROW_SIZE),
            new LineTo(PICKER_PADDING + PICKER_WIDTH - RADIUS, PICKER_PADDING + ARROW_SIZE),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + PICKER_WIDTH,
                PICKER_PADDING + ARROW_SIZE + RADIUS,
                false,
                true),
            new LineTo(
                PICKER_PADDING + PICKER_WIDTH,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING + PICKER_WIDTH - RADIUS,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT,
                false,
                true),
            new LineTo(PICKER_PADDING + RADIUS, PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT),
            new ArcTo(
                RADIUS,
                RADIUS,
                90,
                PICKER_PADDING,
                PICKER_PADDING + ARROW_SIZE + PICKER_HEIGHT - RADIUS,
                false,
                true),
            new ClosePath());
    p.setFill(
        new LinearGradient(
            0,
            0,
            0,
            1,
            true,
            CycleMethod.NO_CYCLE,
            new Stop(0, Color.web("#313131")),
            new Stop(0.5, Color.web("#5f5f5f")),
            new Stop(1, Color.web("#313131"))));
    p.setStroke(null);
    p.setEffect(new DropShadow(15, 0, 1, Color.gray(0, 0.6)));
    p.setCache(true);

    // create rectangle to capture mouse events to hide
    Rectangle windowClickRect =
        RectangleBuilder.create()
            .width(PICKER_PADDING + PICKER_WIDTH + PICKER_PADDING)
            .height(PICKER_PADDING + PICKER_HEIGHT + PICKER_PADDING)
            .fill(Color.TRANSPARENT)
            .onMouseClicked(
                new EventHandler<MouseEvent>() {

                  @Override
                  public void handle(MouseEvent event) {

                    System.out.println("x= " + event.getX());
                    System.out.println(
                        "p.contains(event.getX(), event.getY()) = "
                            + p.contains(event.getX(), event.getY()));
                    if (!p.contains(event.getX(), event.getY())) {
                      hide();
                    }
                  }
                })
            .build();

    final Circle colorRectIndicator =
        CircleBuilder.create()
            .centerX(60)
            .centerY(60)
            .radius(5)
            .stroke(Color.WHITE)
            .fill(null)
            .effect(new DropShadow(2, 0, 1, Color.BLACK))
            .build();

    colorRectIndicator
        .centerXProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(sat);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + 10) + (RECT_SIZE * (sat.get() / 100));
              }
            });

    colorRectIndicator
        .centerYProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(bright);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + ARROW_SIZE + 10)
                    + (RECT_SIZE * (1 - (bright.get() / 100)));
              }
            });

    final Rectangle colorRect =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .build();
    colorRect
        .fillProperty()
        .bind(
            new ObjectBinding<Paint>() {

              {
                bind(color);
              }

              @Override
              protected Paint computeValue() {

                return Color.hsb(hue.getValue(), 1, 1);
              }
            });

    Rectangle colorRectOverlayOne =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .fill(
                new LinearGradient(
                    0,
                    0,
                    1,
                    0,
                    true,
                    CycleMethod.NO_CYCLE,
                    new Stop(0, Color.rgb(255, 255, 255, 1)),
                    new Stop(1, Color.rgb(255, 255, 255, 0))))
            .build();

    EventHandler<MouseEvent> rectMouseHandler =
        new EventHandler<MouseEvent>() {

          @Override
          public void handle(MouseEvent event) {

            final double x = event.getX() - colorRect.getX();
            final double y = event.getY() - colorRect.getY();
            sat.set(clamp(x / RECT_SIZE) * 100);
            bright.set(100 - (clamp(y / RECT_SIZE) * 100));
          }
        };

    Rectangle colorRectOverlayTwo =
        RectangleBuilder.create()
            .x(PICKER_PADDING + 10)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(RECT_SIZE)
            .height(RECT_SIZE)
            .fill(
                new LinearGradient(
                    0,
                    0,
                    0,
                    1,
                    true,
                    CycleMethod.NO_CYCLE,
                    new Stop(0, Color.rgb(0, 0, 0, 0)),
                    new Stop(1, Color.rgb(0, 0, 0, 1))))
            .onMouseDragged(rectMouseHandler)
            .onMouseClicked(rectMouseHandler)
            .build();
    final Rectangle colorBar =
        RectangleBuilder.create()
            .x(PICKER_PADDING + PICKER_WIDTH - 30)
            .y(PICKER_PADDING + ARROW_SIZE + 10)
            .width(20)
            .height(RECT_SIZE)
            .fill(createHueGradient())
            .build();
    final Rectangle colorBarIndicator =
        RectangleBuilder.create()
            .x(PICKER_PADDING + PICKER_WIDTH - 32)
            .y(PICKER_PADDING + ARROW_SIZE + 15)
            .width(24)
            .height(10)
            .arcWidth(4)
            .arcHeight(4)
            .stroke(Color.WHITE)
            .fill(null)
            .effect(new DropShadow(2, 0, 1, Color.BLACK))
            .build();

    colorBarIndicator
        .yProperty()
        .bind(
            new DoubleBinding() {

              {
                bind(hue);
              }

              @Override
              protected double computeValue() {

                return (PICKER_PADDING + ARROW_SIZE + 5) + (RECT_SIZE * (hue.get() / 360));
              }
            });
    EventHandler<MouseEvent> barMouseHandler =
        new EventHandler<MouseEvent>() {

          @Override
          public void handle(MouseEvent event) {

            final double y = event.getY() - colorBar.getY();
            hue.set(clamp(y / RECT_SIZE) * 360);
          }
        };
    colorBar.setOnMouseDragged(barMouseHandler);
    colorBar.setOnMouseClicked(barMouseHandler);

    Label brightnessLabel = new Label("Brightness:");
    brightnessLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(brightnessLabel, 0, 0);

    Slider brightnessSlider = SliderBuilder.create().min(0).max(100).id("BrightnessSlider").build();
    brightnessSlider.valueProperty().bindBidirectional(bright);
    GridPane.setConstraints(brightnessSlider, 1, 0);

    IntegerField brightnessField = new IntegerField();
    brightnessField.valueProperty().bindBidirectional(bright);
    brightnessField.setPrefColumnCount(7);
    GridPane.setConstraints(brightnessField, 2, 0);

    Label saturationLabel = new Label("Saturation:");
    saturationLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(saturationLabel, 0, 1);

    Slider saturationSlider = SliderBuilder.create().min(0).max(100).id("SaturationSlider").build();
    saturationSlider.valueProperty().bindBidirectional(sat);
    GridPane.setConstraints(saturationSlider, 1, 1);

    saturationSlider
        .styleProperty()
        .bind(
            new StringBinding() {

              {
                bind(color);
              }

              @Override
              protected String computeValue() {

                return "picker-color: hsb(" + hue.get() + ",100%,100%);";
              }
            });

    IntegerField saturationField = new IntegerField();
    saturationField.valueProperty().bindBidirectional(sat);
    saturationField.setPrefColumnCount(7);
    GridPane.setConstraints(saturationField, 2, 1);

    Label webLabel = new Label("Web:");
    webLabel.setMinWidth(Control.USE_PREF_SIZE);
    GridPane.setConstraints(webLabel, 0, 2);

    WebColorField webField = new WebColorField();
    webField.valueProperty().bindBidirectional(color);
    GridPane.setConstraints(webField, 1, 2, 2, 1);

    GridPane controls = new GridPane();
    controls.setVgap(5);
    controls.setHgap(5);
    controls
        .getChildren()
        .addAll(
            brightnessLabel,
            brightnessSlider,
            brightnessField,
            saturationLabel,
            saturationSlider,
            saturationField,
            webLabel,
            webField);
    controls.setManaged(false);
    controls.resizeRelocate(
        PICKER_PADDING + 10,
        PICKER_PADDING + ARROW_SIZE + 10 + 170 + 10,
        PICKER_WIDTH - 20,
        controls.getPrefHeight());

    getChildren()
        .addAll(
            windowClickRect,
            p,
            colorRect,
            colorRectOverlayOne,
            colorRectOverlayTwo,
            colorBar,
            colorRectIndicator,
            colorBarIndicator,
            controls);
  }
コード例 #8
0
ファイル: MediaControl.java プロジェクト: john-caine/SWENG
  /*
   * Constructor for the MediaControl class. Accepts optional parameters from PWS.
   * Creates a visual control bar with a play/pause button, a stop button, and a
   * fullscreen button, which is overlayed onto the MediaPlayer. Also handles
   * entering into the fullscreen viewing mode.
   *
   * @param mp The MediaPlayer object instantiated by the VideoHandler class
   * @param width The PWS optional width for the MediaPlayer
   * @param height The PWS optional height for the MediaPlayer
   * @param loop The PWS optional loop value for the video
   * @param startTime The PWS optional startTime to delay the video starting to play
   * @param playDuration The PWS optional duration to play the video for
   */
  public MediaControl(
      final MediaPlayer mp,
      Integer width,
      Integer height,
      Boolean loop,
      Integer startTime,
      Integer playDuration) {

    this.mp = mp;
    this.startTime = startTime;
    this.playDuration = playDuration;
    mediaView = new MediaView(mp);

    // Retrieve the size of the Screen
    bounds = Screen.getPrimary().getVisualBounds();

    // Assign loop variable as necessary
    if (loop == null) {
      this.mpLoop = false;
    } else {
      this.mpLoop = loop;
    }

    // Set the MediaPlayer cycle count based on the value of loop
    setLoop(mpLoop);

    if (width != null && height != null) {
      // Set the height and width of the MediaPlayer based on the values
      this.mpWidth = width;
      this.mpHeight = height;
      mediaView.setPreserveRatio(false);
      mediaView.setFitWidth(mpWidth);
      mediaView.setFitHeight(mpHeight - 35);
    } else {
      // Set a default size of the MediaPlayer when no height and width are being indicated
      this.mpWidth = (int) (bounds.getWidth() / 2);
      this.mpHeight = (int) (bounds.getHeight() / 4);
      mediaView.setPreserveRatio(true);
      mediaView.setFitWidth(mpWidth);
    }

    if (startTime == null) {
      // Set start time to be 0 when no startTime is being indicated
      this.startTime = 0;
      new Thread(startTimerThread).start();
    } else {
      // Start the startTimerThread based on the startTime indicated
      new Thread(startTimerThread).start();
    }

    // A VBox that contains the MediaView and Control Panel of the MediaPlayer
    overallBox = new VBox();
    overallBox.setMaxSize(mpWidth, mpHeight);
    mediaView.setFitHeight(mpHeight - 35);
    overallBox.getChildren().add(mediaView);

    // A HBox that contains all the Controls of the MediaPlayer
    mediaBar = new HBox();
    mediaBar.setMaxWidth(mpWidth);
    mediaBar.setPadding(new Insets(5, 10, 5, 10));

    try {
      // Get and load images for buttons on MediaControl bar.
      inputStream = new FileInputStream("../Resources/play.png");
      playImage = new Image(inputStream);
      inputStream = new FileInputStream("../Resources/pause.png");
      pauseImage = new Image(inputStream);
      inputStream = new FileInputStream("../Resources/stop.png");
      stopImage = new Image(inputStream);
      inputStream = new FileInputStream("../Resources/fullscreen.png");
      fullscreenImage = new Image(inputStream);
    } catch (FileNotFoundException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    // Handle the play button
    setPlayButton();

    // Handle the stop button
    setStopButton();

    // Handle the fullscreen button
    setFullScreenButton();

    // Label to show the length of the video
    Label timeLabel = new Label("   Time: ");
    timeLabel.setTextFill(Color.WHITE);
    timeLabel.setMinWidth(Control.USE_PREF_SIZE);
    mediaBar.getChildren().add(timeLabel);

    // Handle the time slider
    setTimeSlider();

    // Label to show the current time position of the video
    playTime = new Label();
    playTime.setMinWidth(50);
    playTime.setTextFill(Color.WHITE);
    mediaBar.getChildren().add(playTime);

    // Label to show the current volume of the media
    Label volumeLabel = new Label(" Vol: ");
    volumeLabel.setTextFill(Color.WHITE);
    volumeLabel.setMinWidth(Control.USE_PREF_SIZE);
    mediaBar.getChildren().add(volumeLabel);

    // Handle the volume slider
    setVolumeSlider();

    // Label for play time in full screen mode
    playTimeFS = new Label();
    playTimeFS.setMinWidth(50);
    playTimeFS.setTextFill(Color.WHITE);

    // Add components to Control Panel during fullscreen mode
    fullscreenMediaBar = new HBox();
    fullscreenMediaBar.getChildren().add(playButtonFS);
    fullscreenMediaBar.getChildren().add(timeSliderFS);
    fullscreenMediaBar.getChildren().add(playTimeFS);
    fullscreenMediaBar.setLayoutY(bounds.getHeight() - 20);

    // Add the mediaBar "box" to the overall MediaControl "bar"
    overallBox.getChildren().add(mediaBar);
  }