public void start(Stage primaryStage) { primaryStage.setTitle("Lines"); Group root = new Group(); Scene scene = new Scene(root, 300, 150, Color.GRAY); Line redLine = new Line(10, 10, 200, 10); redLine.setStroke(Color.RED); redLine.setStrokeWidth(10); redLine.setStrokeLineCap(StrokeLineCap.BUTT); redLine.getStrokeDashArray().addAll(10d, 5d, 15d, 5d, 20d); redLine.setStrokeDashOffset(0); root.getChildren().add(redLine); Line whiteLine = new Line(10, 30, 200, 30); whiteLine.setStroke(Color.WHITE); whiteLine.setStrokeWidth(10); whiteLine.setStrokeLineCap(StrokeLineCap.ROUND); root.getChildren().add(whiteLine); Line blueLine = new Line(10, 50, 200, 50); blueLine.setStroke(Color.BLUE); blueLine.setStrokeWidth(10); root.getChildren().add(blueLine); Slider slider = new Slider(0, 100, 0); slider.setLayoutX(10); slider.setLayoutY(95); redLine.strokeDashOffsetProperty().bind(slider.valueProperty()); root.getChildren().add(slider); Text offsetText = new Text("Stroke Dash Offset: 0.0"); offsetText.setX(10); offsetText.setY(80); offsetText.setStroke(Color.WHITE); slider .valueProperty() .addListener( (ov, curVal, newVal) -> offsetText.setText("Stroke Dash Offset: " + slider.getValue())); root.getChildren().add(offsetText); primaryStage.setScene(scene); primaryStage.show(); }
private Slider createSlider(Scene scene) { Slider slider = SliderBuilder.create() .min(0) .max(100) .value(1) .showTickLabels(true) .showTickMarks(true) .build(); slider .valueProperty() .addListener( new ChangeListener<Number>() { public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { if (paused) { long dur = newValue.intValue() * 1000; mediaPlayer.seek(new Duration(dur)); } } }); slider.translateYProperty().bind(scene.heightProperty().subtract(30)); return slider; }
/* * Function that creates a volume slider, adds the relevant event handlers to it, and * adds it to the MediaControl bar. */ void setVolumeSlider() { // Create a new volume slider volumeSlider = new Slider(); volumeSlider.setManaged(true); volumeSlider.setMaxWidth(mpWidth / 6); volumeSlider.setMinWidth(20); // Detect the change in volume slider bar and sets the MediaPlayer's volume accordingly volumeSlider .valueProperty() .addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { if (volumeSlider.isValueChanging()) { // If the slider is being dragged set volume to that requested mp.setVolume(volumeSlider.getValue() / 100.0); } // Update the text labels to display updateValues(); } }); // Add the volume slider to MediaControl bar mediaBar.getChildren().add(volumeSlider); }
private void initUI(Stage stage) { VBox root = new VBox(30); root.setPadding(new Insets(10)); DoubleProperty azimuth = new SimpleDoubleProperty(0); Light.Distant light = new Light.Distant(); light.setAzimuth(0); Lighting lighting = new Lighting(light); lighting.setSurfaceScale(5.0); Text text = new Text(); text.setText("test"); text.setFill(Color.LIGHTSKYBLUE); text.setFont(Font.font(null, FontWeight.BOLD, 60)); Slider slider = new Slider(1, 360, 0); azimuth.bind(slider.valueProperty()); slider .valueProperty() .addListener( event -> { light.setAzimuth(azimuth.get()); lighting.setLight(light); text.setEffect(lighting); }); text.setEffect(lighting); root.getChildren().addAll(slider, text); Scene scene = new Scene(root, 300, 250, Color.WHITESMOKE); stage.setTitle("Lighting"); stage.setScene(scene); stage.show(); }
public void initialize(URL location, ResourceBundle resources) { txtFieldGeldEingabe.textProperty().bindBidirectional(viewModel.geldEingabe()); txtFieldZeitEingabe.textProperty().bindBidirectional(viewModel.zeitEinagabe()); labelQualitaet.textProperty().bindBidirectional(viewModel.qualitaetText()); labelZeit.textProperty().bindBidirectional(viewModel.zeitText()); labelSkill.textProperty().bindBidirectional(viewModel.skillText()); labelGehalt.textProperty().bindBidirectional(viewModel.gehaltText()); labelGeld.textProperty().bindBidirectional(viewModel.geldText()); labelGesundheit.textProperty().bindBidirectional(viewModel.gesundheitText()); labelMotivation.textProperty().bindBidirectional(viewModel.motivationText()); SliderGehalt.valueProperty().bindBidirectional(viewModel.gehaltProperty()); SliderGehalt.setValue(1500); SliderGehalt.setShowTickMarks(false); SliderGehalt.setMajorTickUnit(1); SliderGehalt.setMinorTickCount(0); SliderGehalt.setBlockIncrement(100); SliderGehalt.setSnapToTicks(true); labelNeuesGehalt.textProperty().bind(SliderGehalt.valueProperty().asString("%.0f")); buttonStart.setOnAction( event -> { buttonNachsteRunde.setDisable(false); buttonStart.setDisable(true); txtFieldGeldEingabe.setDisable(true); txtFieldZeitEingabe.setDisable(true); viewModel.startRound(); }); buttonNachsteRunde.setOnAction( event -> { RadioButton rb = (RadioButton) ToggleGroupSelect.getSelectedToggle(); viewModel.nextRound(rb.getText()); }); viewModel.setButtonNaechsteRunde(buttonNachsteRunde); viewModel.setButtonStart(buttonStart); viewModel.setTxtFieldGeldEingabe(txtFieldGeldEingabe); viewModel.setTxtFieldZeitEingabe(txtFieldZeitEingabe); }
@Override public void start(Stage stage) { if (!Platform.isSupported(ConditionalFeature.SCENE3D)) { throw new RuntimeException("*** ERROR: common conditional SCENE3D is not supported"); } stage.setTitle("JavaFX SubScene And Scene Anti-aliasing Test"); Group root = new Group(); Scene scene = new Scene(root, 1000, 800); scene.setFill(Color.color(0.2, 0.2, 0.2, 1.0)); HBox hbox = new HBox(); hbox.setLayoutX(75); hbox.setLayoutY(200); PhongMaterial phongMaterial = new PhongMaterial(Color.color(1.0, 0.7, 0.8)); Cylinder cylinder1 = new Cylinder(100, 200); cylinder1.setMaterial(phongMaterial); SubScene noMsaa = createSubScene( "Scene Anti-aliasing = false", cylinder1, Color.TRANSPARENT, new PerspectiveCamera(), false); hbox.getChildren().add(noMsaa); Cylinder cylinder2 = new Cylinder(100, 200); cylinder2.setMaterial(phongMaterial); SubScene msaa = createSubScene( "Scene Anti-aliasing = true", cylinder2, Color.TRANSPARENT, new PerspectiveCamera(), true); hbox.getChildren().add(msaa); Slider slider = new Slider(0, 360, 0); slider.setBlockIncrement(1); slider.setTranslateX(425); slider.setTranslateY(625); cylinder1.rotateProperty().bind(slider.valueProperty()); cylinder2.rotateProperty().bind(slider.valueProperty()); root.getChildren().addAll(hbox, slider); stage.setScene(scene); stage.show(); }
/** Initializes the Slider */ private void initializeSlider() { sliderSubsToRemove .valueProperty() .addListener( new ChangeListener<Number>() { @Override public void changed( ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { percentageToRemove = (int) sliderSubsToRemove.getValue(); labelEffectivePercent.setText(Integer.toString(percentageToRemove) + " %"); pieChartSubsToRemove.getData().get(0).setPieValue(100 - percentageToRemove); pieChartSubsToRemove.getData().get(1).setPieValue(percentageToRemove); } }); }
private void initSettingsPane() { trainTroopsSlider.setMin(0); trainTroopsSlider.setMax(Settings.MAX_TRAIN_TROOPS); trainTroopsSlider.setBlockIncrement(1); trainTroopsSlider .valueProperty() .addListener( (observable, oldValue, newValue) -> { trainTroopsSliderPreview.setText( String.format("%d", MainController.toInt(newValue.doubleValue()))); }); final Troop[] availableTroops = model.getAvailableTroops(); rax1ComboBox.getItems().addAll(availableTroops); rax2ComboBox.getItems().addAll(availableTroops); rax3ComboBox.getItems().addAll(availableTroops); rax4ComboBox.getItems().addAll(availableTroops); rax5ComboBox.getItems().addAll(availableTroops); rax6ComboBox.getItems().addAll(availableTroops); autoAttackComboBox.getItems().addAll(Attack.noStrategy()); autoAttackComboBox.getItems().addAll(Attack.getAvailableStrategies()); autoAttackComboBox.setValue(autoAttackComboBox.getItems().get(0)); final ChangeListener<String> intFieldListener = (observable, oldValue, newValue) -> { try { if (!newValue.isEmpty()) { Integer.parseInt(newValue); } } catch (final NumberFormatException e) { ((TextField) ((StringProperty) observable).getBean()).setText(oldValue); } }; goldField.textProperty().addListener(intFieldListener); elixirField.textProperty().addListener(intFieldListener); deField.textProperty().addListener(intFieldListener); maxThField.textProperty().addListener(intFieldListener); logLevelComboBox .getItems() .addAll( Level.FINEST, Level.FINER, Level.FINE, Level.CONFIG, Level.INFO, Level.WARNING, Level.SEVERE); logLevelComboBox.setValue(logLevelComboBox.getItems().get(1)); updateUI(); }
public void start() { movie = new MediaPlayer(path); movie.play(); VIEW.setMediaPlayer(movie); movie .currentTimeProperty() .addListener( new ChangeListener<javafx.util.Duration>() { @Override public void changed( ObservableValue<? extends javafx.util.Duration> observable, javafx.util.Duration duration, javafx.util.Duration current) { timeSlider.setValue(current.toSeconds()); } }); movie.setOnReady( new Runnable() { @Override public void run() { timeSlider.setMin(0); timeSlider.setValue(0.0); timeSlider.setMax(movie.getTotalDuration().toSeconds()); volumeSlider.setMin(0); volumeSlider.setValue(0.5); } }); timeSlider.setOnMouseClicked( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { movie.seek(javafx.util.Duration.seconds(timeSlider.getValue())); } }); volumeSlider .valueProperty() .addListener( new InvalidationListener() { @Override public void invalidated(Observable observable) { if (volumeSlider.isValueChanging()) { movie.setVolume(volumeSlider.getValue() / 100); } } }); }
@Override public void initialize(URL url, ResourceBundle rb) { player = GameController.getGameData().getPlayer(); dailyCost = 0; selectedSkill = pilot_button; pilot_button.requestFocus(); checkForHire(); Button[] buttons = { pilot_button, fighter_button, engineer_button, trader_button, investor_button }; for (Button b : buttons) { b.setOnMouseClicked( (MouseEvent t) -> { selectedSkill = b; generateCostAndStat(); }); } name_field.addEventFilter( KeyEvent.KEY_TYPED, (KeyEvent event) -> { if (name_field.getText().length() >= 18) { event.consume(); } }); power_slider .valueProperty() .addListener( (ObservableValue<? extends Number> ov, Number old_val, Number new_val) -> { generateCostAndStat(); }); hire_button.setOnMouseClicked( (MouseEvent t) -> { Mercenary merc = new Mercenary(name_field.getText(), selectedSkill.getText(), power, dailyCost); player.getShip().addCrew(merc); checkForHire(); }); }
/** * Constructs a new SliderBlock * * @param pane The parent pane this Block resides on. * @param isIntegral wWhether this slider represent an integral value. */ public SliderBlock(ToplevelPane pane, boolean isIntegral) { super( "SliderBlock", pane, pane.getEnvInstance().buildType(isIntegral ? "Num a => a" : "Fractional a => a")); this.isIntegral = isIntegral; this.baseValue = 0; this.slider.setValue(0); this.updateValue(); slider.getStyleClass().add("inactive"); slider.setOnMousePressed(e -> slider.getStyleClass().removeAll("inactive")); slider.setOnMouseReleased(e -> slider.getStyleClass().add("inactive")); slider.setOnTouchPressed(e -> slider.getStyleClass().removeAll("inactive")); slider.setOnTouchReleased(e -> slider.getStyleClass().add("inactive")); slider.valueProperty().addListener(ev -> this.updateValue()); slider.valueChangingProperty().addListener(ev -> this.toggleSliding()); slider.addEventHandler(TouchEvent.TOUCH_MOVED, event -> event.consume()); }
@Override public void start(Stage primaryStage) throws Exception { Pane pane = new Pane(); Circle circle = new Circle(250, 250, 50); circle.setStroke(Color.BLACK); Slider slider = new Slider(0, 250, 0); slider.setTranslateY(390); slider .valueProperty() .addListener( (observable, oldValue, newValue) -> { circle.setStrokeWidth(newValue.intValue()); }); pane.getChildren().addAll(slider, circle); Scene scene = new Scene(pane, 500, 500); primaryStage.setScene(scene); primaryStage.setOnCloseRequest(event -> System.exit(0)); primaryStage.show(); }
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); }
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); }
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); }
@Override public void start(Stage primaryStage) { FXFormPane formPane = new FXFormPane(); formPane.addChild( createLabel("First 0, 0 / Butter", "fce94f"), formPane.createConstraint(0, 0)); formPane.addChild( createLabel("Second 1, 0 / Orange", "fcaf3e"), formPane.createConstraint(1, 0)); formPane.addChild( createLabel("Third 2, 0 / Chocolate", "e9b96e"), formPane.createConstraint(2, 0)); formPane.addChild( createLabel("Fourth 3, 0 / Butter", "fce94f"), formPane.createConstraint(3, 0)); formPane.addChild( createLabel("Right aligned -1, 0 / Chameleon", "8ae234"), formPane.createConstraint(-1, 0)); formPane.addChild( createLabel("Next line 0, 1 / Sky Blue", "729fcf"), formPane.createConstraint(0, 1)); formPane.addChild( createLabel("Right aligned -1, 1 / Plum", "ad7fa8"), formPane.createConstraint(-1, 1)); formPane.addChild( createLabel("Next line 0, 2 / Sky Blue", "729fcf"), formPane.createConstraint(0, 2)); formPane.addChild( createLabel("Right aligned -1, 2 / Plum", "ad7fa8"), formPane.createConstraint(-1, 2)); formPane.addChild( createLabel("Centered 0, 3, -1, -4 / Aluminium", "eeeeec"), formPane.createConstraint(0, 3, -1, -4)); formPane.addChild( createLabel("Bottom 0, -3 / Scarlet Red", "ef2929"), formPane.createConstraint(0, -3)); formPane.addChild( createLabel("Bottom and Right aligned -1, -3 / Butter", "c4a000"), formPane.createConstraint(-1, -3)); formPane.addChild( createLabel("Bottom 0, -2 / Scarlet Red", "ef2929"), formPane.createConstraint(0, -2)); formPane.addChild( createLabel("Bottom and Right aligned -1, -2 / Butter", "c4a000"), formPane.createConstraint(-1, -2)); formPane.addChild( createLabel("Bottom 0, -1 / Scarlet Red", "ef2929"), formPane.createConstraint(0, -1)); formPane.addChild( createLabel("Bottom and Right aligned -1, -1 / Butter", "c4a000"), formPane.createConstraint(-1, -1)); Slider hgapSlider = new Slider(0, 100, formPane.getHGap()); formPane.hGapProperty().bind(hgapSlider.valueProperty()); Slider vgapSlider = new Slider(0, 100, formPane.getVGap()); formPane.vGapProperty().bind(vgapSlider.valueProperty()); FXFormPane controlPane = new FXFormPane(); controlPane.setNewlineCount(7); controlPane.addChild(hgapSlider); controlPane.addChild(vgapSlider); BorderPane root = new BorderPane(); root.setBottom(createLabel("- - Bottom - -", "888a85")); root.setCenter(formPane); root.setLeft(createLabel(" | \n\n | \n\n Left \n\n | \n\n | \n\n", "babdb6")); root.setRight(createLabel(" | \n\n | \n\n Right \n\n | \n\n | \n\n", "555753")); root.setTop(controlPane); BorderPane.setAlignment(root.getBottom(), Pos.CENTER); BorderPane.setAlignment(root.getCenter(), Pos.CENTER); BorderPane.setAlignment(root.getLeft(), Pos.CENTER); BorderPane.setAlignment(root.getRight(), Pos.CENTER); BorderPane.setAlignment(root.getTop(), Pos.CENTER); primaryStage.setScene(new Scene(root)); primaryStage.setTitle("JavaFX FormPane Test"); primaryStage.show(); }
/** * Called after the controls have been parsed from the XML. Sets up logic and components that * could not be set up using the GUI builder. */ @Override public void initialize(URL url, ResourceBundle rb) { // the transformedTrajectory provides a view of the trajectory that reflects the selected // transformedTrajectory transformedTrajectory = new Cacheable<double[][]>() { private int eachKthPoint; private int embeddingDimension, embeddingDelay; private double noiseRatio; private int getSubsampleLength() { int prefixLength = (int) (subsampleLengthSlider.getValue() * trajectory[0].length); // per started block of k elements, one output element will be generated int k = getEachKthPoint(); // full blocks + 1 block if there is a fractional block return prefixLength / k + (prefixLength % k > 0 ? 1 : 0); } @Override public synchronized boolean isValid() { if (cachedValue == null) return false; if (eachKthPoint != getEachKthPoint()) return false; // any embedding dimension <= 0 signifies that no embedding should be used, thus the // actual dimension does not matter if (getEmbeddingDimension() > 0 && (embeddingDimension != getEmbeddingDimension())) return false; // for an embedding dimension of <= 1, the delay is insignificant if (getEmbeddingDimension() > 1 && (embeddingDelay != getEmbeddingDelay())) return false; if (getNoiseRatio() != noiseRatio) return false; return trajectory == null || cachedValue == null || getSubsampleLength() == cachedValue[0].length; } @Override public synchronized void recompute() { if (trajectory == null) cachedValue = null; else { // create an empty array with the desired number of dimensions cachedValue = new double[trajectory.length][]; eachKthPoint = getEachKthPoint(); // crop to sampling size int newLength = getSubsampleLength(); for (int dimIdx = 0; dimIdx < trajectory.length; dimIdx++) { cachedValue[dimIdx] = new double[newLength]; // Arrays.copyOf(trajectory[dimIdx], newLength); for (int i = 0, t = 0; i < newLength; i++, t += eachKthPoint) { cachedValue[dimIdx][i] = trajectory[dimIdx][t]; } } int dim = getEmbeddingDimension(); int tau = getEmbeddingDelay(); double noiseRatio = getNoiseRatio(); if (dim > 0 && tau > 0) { cachedValue = PhaseSpaceReconstructed.embed(cachedValue[0], dim, tau); } cachedValue = TimeSeriesGenerator.addNoise(cachedValue, 0.05, noiseRatio); this.noiseRatio = noiseRatio; this.embeddingDimension = dim; this.embeddingDelay = tau; } } }; // sync recurrence threshold slider and text field Bindings.bindBidirectional( recurrenceThresholdTextField.textProperty(), recurrenceThresholdSlider.valueProperty(), DecimalFormat.getInstance()); // sync GUI and model recurrence threshold Bindings.bindBidirectional( recurrenceThresholdTextField.textProperty(), recurrenceThresholdProperty(), DecimalFormat.getInstance()); // sync GUI and model embedding parameters Bindings.bindBidirectional( embeddingDimensionTextField.textProperty(), embeddingDimensionProperty(), DecimalFormat.getIntegerInstance()); Bindings.bindBidirectional( embeddingDelayTextField.textProperty(), embeddingDelayProperty(), DecimalFormat.getIntegerInstance()); // sync GUI and noise parameter Bindings.bindBidirectional(noiseSlider.valueProperty(), noiseRatioProperty()); Bindings.bindBidirectional( eachKthPointTextField.textProperty(), eachKthPointProperty(), DecimalFormat.getIntegerInstance()); // enable the compute button only if the auto-update checkbox is not on. computeRPButton.disableProperty().bind(sliderAutoUpdate.selectedProperty()); // recompute RP on parameter changes subsampleLengthSlider.valueProperty().addListener(this::parametersChanged); eachKthPointTextField .textProperty() .addListener( (obs, ov, nv) -> { parametersChanged(null, null, null); }); recurrenceThresholdProperty().addListener(this::parametersChanged); embeddingDimensionProperty().addListener(this::parametersChanged); embeddingDelayProperty().addListener(this::parametersChanged); noiseRatioProperty().addListener(this::parametersChanged); // Make CRT controls update the computation // size of the CRT histogram crtLimit .textProperty() .addListener( new ChangeListener<String>() { @Override public void changed( ObservableValue<? extends String> observable, String oldValue, String newValue) { parametersChanged(null, Integer.parseInt(oldValue), Integer.parseInt(newValue)); } }); // CRT log scale option logScaleCheckBox .selectedProperty() .addListener( new ChangeListener<Boolean>() { @Override public void changed( ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) { if (oldValue != newValue) parametersChanged(null, 0, 0); } }); // make the CRT image use all the available vertical space crtImageView.fitWidthProperty().bind(crtTabPane.widthProperty().subtract(20)); crtImageView.fitHeightProperty().bind(crtTabPane.heightProperty()); // swap the data of the line length histogram upon selecting another line type lineLengthTypeSelector.setItems( FXCollections.observableArrayList( "DIAGONAL", "VERTICAL", "WHITE_VERTICAL", "ORTHOGONAL")); // DRQA.LineType.DIAGONAL, DRQA.LineType.VERTICAL, // DRQA.LineType.WHITE_VERTICAL, DRQA.LineType.ORTHOGONAL lineLengthTypeSelector .getSelectionModel() .selectedIndexProperty() .addListener(this::updateLineLengthHistogram); lineLengthTypeSelector.getSelectionModel().select(0); distanceDistributionSelector.setItems(FXCollections.observableArrayList("SUBSEQ", "PAIRWISE")); distanceDistributionSelector .getSelectionModel() .selectedIndexProperty() .addListener((obs, ov, nv) -> updateDistanceDistributionChart()); distanceDistributionSelector.getSelectionModel().select(0); useDRQA .selectedProperty() .addListener( (obs, ov, nv) -> updateLineLengthHistogram( null, null, lineLengthTypeSelector.getSelectionModel().getSelectedIndex())); }
/** * Verbindet ein Textfeld bidirektional mit einem Slider und sorgt für Validierung der Eingaben. * * @param textField Textfeld * @param slider Slider * @param maxValue Maximalwert für das Textfeld */ private void bindTextInputListenersAndSlider( final TextField textField, final Slider slider, final long maxValue) { final StringProperty textProperty = textField.textProperty(); // Eingaben auf Zahlen beschränken textField.addEventFilter( KeyEvent.KEY_TYPED, new EventHandler<KeyEvent>() { public void handle(final KeyEvent keyEvent) { if (!"0123456789".contains(keyEvent.getCharacter())) { keyEvent.consume(); } } }); textProperty.addListener( new ChangeListener<String>() { public void changed( final ObservableValue<? extends String> property, final String oldValue, final String newValue) { // Wert auf gültigen Bereich beschränken try { final long parsedNumber = Long.parseLong(newValue); if (parsedNumber < MIN_VALUE) { textProperty.setValue(getTwoDigitValue(MIN_VALUE)); } else if (parsedNumber > maxValue) { textProperty.setValue(getTwoDigitValue(maxValue)); } else if (newValue.length() > 2) { textProperty.setValue(getTwoDigitValue(parsedNumber)); } else { textProperty.setValue(newValue); } // Änderung an Zeit-Property durchstellen timeProperty.set(getValue()); } catch (final NumberFormatException e) { // alten Wert wieder setzen (sinnvoll bei Änderung per Copy & Paste) textProperty.setValue(oldValue); } } }); // bei Verlassen des Feldes sicherstellen, dass Wert zweistellig textField .focusedProperty() .addListener( new ChangeListener<Boolean>() { public void changed( final ObservableValue<? extends Boolean> property, final Boolean oldValue, final Boolean newValue) { if (Boolean.FALSE.equals(newValue)) { try { textProperty.setValue(getTwoDigitValue(Long.parseLong(textProperty.get()))); } catch (final NumberFormatException e) { textProperty.setValue(getTwoDigitValue(MIN_VALUE)); } } } }); // Textfeld mit Slider koppeln if (slider != null) { slider.setMax(maxValue); textProperty.bindBidirectional( slider.valueProperty(), new StringConverter<Number>() { public String toString(final Number number) { return getTwoDigitValue(number.longValue()); } public Number fromString(final String string) { return Long.parseLong(string); } }); } // auf Scroll-Ereignis im Textfeld reagieren textField.setOnScroll( new EventHandler<ScrollEvent>() { public void handle(final ScrollEvent event) { // Scrollen über Feld ohne Fokus hat keine Auswirkung if (!textField.isFocused()) { return; } final double change = event.getDeltaY() > 0 ? 1 : -1; slider.setValue(slider.getValue() + change); event.consume(); } }); }
protected void setControls(PropDesc... properties) { GridPane grid = new GridPane(); grid.getStyleClass().add("sample-control-grid"); grid.setVgap(10); grid.setHgap(10); int row = 0; for (PropDesc property : properties) { final PropDesc prop = property; Label propName = new Label(prop.name + ":"); propName.getStyleClass().add("sample-control-grid-prop-label"); GridPane.setConstraints(propName, 0, row); grid.getChildren().add(propName); if (prop.valueModel instanceof DoubleProperty) { final Label valueLabel = new Label(twoDp.format(prop.initialValue)); GridPane.setConstraints(valueLabel, 2, row); final Slider slider = new Slider(); slider.setMin(prop.min); slider.setMax(prop.max); slider.setValue(((Number) prop.initialValue).doubleValue()); GridPane.setConstraints(slider, 1, row); slider.setMaxWidth(Double.MAX_VALUE); slider .valueProperty() .addListener( new InvalidationListener() { @Override public void invalidated(Observable ov) { set(prop.valueModel, slider.getValue()); valueLabel.setText(twoDp.format(slider.getValue())); } }); grid.getChildren().addAll(slider, valueLabel); } else { // if (prop.property.getType() == Color.class || prop.property.getType() == // Paint.class) { // FIXME we assume anything that isn't a double property is now a colour property final Rectangle colorRect = new Rectangle(20, 20, (Color) prop.initialValue); colorRect.setStroke(Color.GRAY); final Label valueLabel = new Label(formatWebColor((Color) prop.initialValue)); valueLabel.setGraphic(colorRect); valueLabel.setContentDisplay(ContentDisplay.LEFT); GridPane.setConstraints(valueLabel, 2, row); final ColorPicker colorPicker = new ColorPicker(); GridPane.setConstraints(colorPicker, 1, row); colorPicker .getColor() .addListener( new InvalidationListener() { @Override public void invalidated(Observable valueModel) { Color c = colorPicker.getColor().get(); set(prop.valueModel, c); valueLabel.setText(formatWebColor(c)); colorRect.setFill(c); } }); grid.getChildren().addAll(colorPicker, valueLabel); } row++; } controls = grid; }
public DoubleProperty valueProperty() { return slider.valueProperty(); }
private void onPlay() { playButton.setImage(new Image("icon/PlayPause_button/pause.png")); mp.setOnReady( () -> { duration = mp.getMedia().getDuration(); updateValues(); }); mp.currentTimeProperty() .addListener( (Observable ov) -> { Stage stage = (Stage) root.getScene().getWindow(); if (stage.isFullScreen() == false) { full = false; } updateValues(); }); mp.setOnPaused( () -> { playButton.setImage(new Image("icon/PlayPause_button/play.png")); }); mp.setOnEndOfMedia( () -> { switch (repeat) { case 0: if (fileList.size() - 1 == 0) { mp.stop(); mp.seek(mp.getStartTime()); } else { listView.getSelectionModel().selectNext(); } break; case 1: mp.seek(Duration.ZERO); mp.setCycleCount(MediaPlayer.INDEFINITE); break; case 2: if (j == fileList.size() - 1) { if (fileList.size() - 1 == 0) { mp.setCycleCount(MediaPlayer.INDEFINITE); } else { listView.getSelectionModel().selectFirst(); } } else { listView.getSelectionModel().selectNext(); } break; } atEndOfMedia = true; }); timeSlider .valueProperty() .addListener( (Observable ov) -> { if (timeSlider.isValueChanging()) { progressBar.setProgress(timeSlider.getValue() / 100); mp.seek(duration.multiply(timeSlider.getValue() / 100.0)); } }); volumeSlider .valueProperty() .addListener( (ObservableValue<? extends Number> ov, Number old_val, Number new_val) -> { mp.setVolume(new_val.doubleValue()); volumeBar.setProgress(new_val.doubleValue()); }); play = true; volumeSlider.setMouseTransparent(!play); timeSlider.setMouseTransparent(!play); }
/* * Creates a time slider, adds the relevant event handlers for it, and adds it to * the appropiate MediaControl bar. Handles both normal viewing mode, and fullscreen * mode. */ void setTimeSlider() { // Create a new time slide timeSlider = new Slider(); timeSlider.setMaxWidth((2 * mpWidth) / 3); HBox.setHgrow(timeSlider, Priority.ALWAYS); // Allow the user to drag and position the slider timeSlider .valueProperty() .addListener( new InvalidationListener() { @Override public void invalidated(Observable ov) { // If the value is changing perform an action if (timeSlider.isValueChanging()) { // If the duration of video is not null, move to requested time if (duration != null) { mp.seek(duration.multiply(timeSlider.getValue() / 100.0)); } } } }); // Allow the user to click on the slider to jump to the desired timing timeSlider.setOnMousePressed( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { mp.seek(duration.multiply(timeSlider.getValue() / 100.0)); } }); // Create a new time slider for fullscreen mode timeSliderFS = new Slider(); timeSliderFS.setMinWidth(bounds.getWidth() - 100); timeSliderFS .valueProperty() .addListener( new InvalidationListener() { @Override public void invalidated(Observable ov) { // If the value is changing perform an action if (timeSliderFS.isValueChanging()) { // If the duration of video is not null, move to requested time if (duration != null) { mp.seek(duration.multiply(timeSliderFS.getValue() / 100.0)); } } } }); // If mouse enters time slider in fullscreen mode handle it timeSliderFS.setOnMousePressed( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { // Stop the fade transition and move to requested time fadeTransition.stop(); mp.seek(duration.multiply(timeSliderFS.getValue() / 100.0)); } }); // Add the time slider to MediaControl bar mediaBar.getChildren().add(timeSlider); }
@Override public void initialize(URL location, ResourceBundle resources) { AppController.instance = this; this.res = resources; ObservableList<String> modeItems = FXCollections.observableArrayList( Settings.MODE_NEXT, Settings.MODE_RANDOM, Settings.MODE_SAME); modeList.setItems(modeItems); modeList.getSelectionModel().select(Settings.currentMode); modeList .valueProperty() .addListener( (ObservableValue ov, Object oldVal, Object newVal) -> { Settings.currentMode = (String) newVal; }); setupPlaylistsView(); setupPlaylistsContextMenu(); setupTracksView(); tracksView.setContextMenu(tracksContextMenu); tracksView.setOnContextMenuRequested( (ContextMenuEvent evt) -> { setupTracksContextMenu(); evt.consume(); }); tracksView .getSelectionModel() .selectedItemProperty() .addListener( (ObservableValue observable, Object oldValue, Object newValue) -> { Settings.lastTrackId = newValue != null ? ((Track) newValue).getId() : null; }); playlistsView .getSelectionModel() .selectedItemProperty() .addListener( (ObservableValue observable, Object oldValue, Object newValue) -> { loadSelectedPlaylist(); Settings.lastPlaylistId = newValue != null ? ((Playlist) newValue).getId() : null; searching = false; searchText.setText(StringUtils.EMPTY); }); volumeSlider.setCursor(Cursor.HAND); volumeSlider .valueProperty() .addListener( (ObservableValue<? extends Number> ov, Number oldVal, Number newVal) -> { if (player != null) { player.setVolume(newVal.doubleValue()); } Settings.currentVolume = newVal.doubleValue(); volumeLabel.setText( String.valueOf((int) Math.ceil(newVal.doubleValue() * 100)) + "%"); }); volumeSlider.setValue(Settings.currentVolume); imagePlay = new ImageView(new Image(getClass().getResourceAsStream("/images/button_play.png"))); imagePlay.setScaleX(0.40); imagePlay.setScaleY(0.40); imagePause = new ImageView(new Image(getClass().getResourceAsStream("/images/button_pause.png"))); imagePause.setScaleX(0.5); imagePause.setScaleY(0.5); imageSettings = new ImageView(new Image(getClass().getResourceAsStream("/images/settings.png"))); imageSettings.setScaleX(0.5); imageSettings.setScaleY(0.5); imageUpdate = new ImageView(new Image(getClass().getResourceAsStream("/images/refresh.png"))); imageUpdate.setScaleX(0.5); imageUpdate.setScaleY(0.5); imageAdd = new ImageView(new Image(getClass().getResourceAsStream("/images/add.png"))); imageAdd.setScaleX(0.5); imageAdd.setScaleY(0.5); imageRename = new ImageView(new Image(getClass().getResourceAsStream("/images/rename.png"))); imageRename.setScaleX(0.5); imageRename.setScaleY(0.5); imageDelete = new ImageView(new Image(getClass().getResourceAsStream("/images/delete.png"))); imageDelete.setScaleX(0.5); imageDelete.setScaleY(0.5); stateButton.setGraphic(imagePlay); settingsButton.setGraphic(imageSettings); refreshButton.setGraphic(imageUpdate); refreshButton.setTooltip(new Tooltip(res.getString("tooltip_sync"))); addButton.setGraphic(imageAdd); addButton.setOnAction((evt) -> createOfflinePlaylist()); addButton.setTooltip(new Tooltip(res.getString("tooltip_add_offline"))); renameButton.setGraphic(imageRename); renameButton.setOnAction(evt -> renamePlaylist()); renameButton.setTooltip(new Tooltip(res.getString("rename_playlist"))); deleteButton.setGraphic(imageDelete); deleteButton.setOnAction(evt -> deletePlaylist()); deleteButton.setTooltip(new Tooltip(res.getString("delete_playlist"))); loadProgressBar.setCursor(Cursor.HAND); volumeSlider.setCursor(Cursor.HAND); updatePlaylists(); if (Settings.lastPlaylistId != null) { currentPlaylist = ((ObservableList<Playlist>) playlistsView.getItems()) .stream() .filter((playlist) -> playlist.getId().equals(Settings.lastPlaylistId)) .findFirst() .orElse(null); playlistsView.getSelectionModel().select(currentPlaylist); playlistsView.scrollTo(currentPlaylist); Platform.runLater( () -> { if (Settings.lastTrackId != null) { currentTrack = ((ObservableList<Track>) tracksView.getItems()) .stream() .filter((track) -> track.getId().equals(Settings.lastTrackId)) .findFirst() .orElse(null); tracksView.getSelectionModel().select(currentTrack); tracksView.scrollTo(currentTrack); } }); } new Timer() .scheduleAtFixedRate( new TimerTask() { @Override public void run() { updatePlayProgress(); } }, 100, 100); setupTracksContextMenu(); setupShortcuts(); Platform.runLater( () -> { tracksView.requestFocus(); }); }
@FXML private void initialize() { duringInitialization = true; ResourceBundle bundle = util.getBundle(); EmulationSection emulationSection = util.getConfig().getEmulationSection(); mainFilters = FXCollections.<String>observableArrayList(); mainFilter.setItems(mainFilters); secondFilters = FXCollections.<String>observableArrayList(); secondFilter.setItems(secondFilters); thirdFilters = FXCollections.<String>observableArrayList(); thirdFilter.setItems(thirdFilters); NumberToString<Double> doubleToString = new NumberToString<Double>(1); mainBalance.setValue(util.getConfig().getAudioSection().getMainBalance()); mainBalance.setLabelFormatter(doubleToString); mainBalance .valueProperty() .addListener( (observable, oldValue, newValue) -> { util.getConfig().getAudioSection().setMainBalance(newValue.floatValue()); util.getPlayer().configureMixer(m -> m.setBalance(0, newValue.floatValue())); }); secondBalance.setValue(util.getConfig().getAudioSection().getSecondBalance()); secondBalance.setLabelFormatter(doubleToString); secondBalance .valueProperty() .addListener( (observable, oldValue, newValue) -> { util.getConfig().getAudioSection().setSecondBalance(newValue.floatValue()); util.getPlayer().configureMixer(m -> m.setBalance(1, newValue.floatValue())); }); thirdBalance.setValue(util.getConfig().getAudioSection().getThirdBalance()); thirdBalance.setLabelFormatter(doubleToString); thirdBalance .valueProperty() .addListener( (observable, oldValue, newValue) -> { util.getConfig().getAudioSection().setThirdBalance(newValue.floatValue()); util.getPlayer().configureMixer(m -> m.setBalance(2, newValue.floatValue())); }); mainVolume.setValue(util.getConfig().getAudioSection().getMainVolume()); mainVolume .valueProperty() .addListener( (observable, oldValue, newValue) -> { util.getConfig().getAudioSection().setMainVolume(newValue.floatValue()); util.getPlayer().configureMixer(m -> m.setVolume(0, newValue.floatValue())); }); secondVolume.setValue(util.getConfig().getAudioSection().getSecondVolume()); secondVolume .valueProperty() .addListener( (observable, oldValue, newValue) -> { util.getConfig().getAudioSection().setSecondVolume(newValue.floatValue()); util.getPlayer().configureMixer(b -> b.setVolume(1, newValue.floatValue())); }); thirdVolume.setValue(util.getConfig().getAudioSection().getThirdVolume()); thirdVolume .valueProperty() .addListener( (observable, oldValue, newValue) -> { util.getConfig().getAudioSection().setThirdVolume(newValue.floatValue()); util.getPlayer().configureMixer(b -> b.setVolume(2, newValue.floatValue())); }); stereoModes = FXCollections.<StereoMode>observableArrayList(StereoMode.values()); stereoMode.setConverter(new EnumToString<StereoMode>(bundle)); stereoMode.setItems(stereoModes); baseAddress.setText(String.format("0x%4x", emulationSection.getDualSidBase())); thirdAddress.setText(String.format("0x%4x", emulationSection.getThirdSIDBase())); sidReads = FXCollections.<SidReads>observableArrayList(SidReads.values()); sidToRead.setConverter(new EnumToString<SidReads>(bundle)); sidToRead.setItems(sidReads); sidToRead.getSelectionModel().select(emulationSection.getSidNumToRead()); sid1Emulations = FXCollections.<Emulation>observableArrayList(Emulation.values()); sid1Emulation.setConverter(new EnumToString<Emulation>(bundle)); sid1Emulation.setItems(sid1Emulations); sid1Emulation.getSelectionModel().select(emulationSection.getUserEmulation()); sid2Emulations = FXCollections.<Emulation>observableArrayList(Emulation.values()); sid2Emulation.setConverter(new EnumToString<Emulation>(bundle)); sid2Emulation.setItems(sid2Emulations); sid2Emulation.getSelectionModel().select(emulationSection.getStereoEmulation()); sid3Emulations = FXCollections.<Emulation>observableArrayList(Emulation.values()); sid3Emulation.setConverter(new EnumToString<Emulation>(bundle)); sid3Emulation.setItems(sid3Emulations); sid3Emulation.getSelectionModel().select(emulationSection.getThirdEmulation()); sid1Models = FXCollections.<ChipModel>observableArrayList(ChipModel.values()); sid1Model.setConverter(new EnumToString<ChipModel>(bundle)); sid1Model.setItems(sid1Models); sid1Model.getSelectionModel().select(emulationSection.getUserSidModel()); sid2Models = FXCollections.<ChipModel>observableArrayList(ChipModel.values()); sid2Model.setConverter(new EnumToString<ChipModel>(bundle)); sid2Model.setItems(sid2Models); sid2Model.getSelectionModel().select(emulationSection.getStereoSidModel()); sid3Models = FXCollections.<ChipModel>observableArrayList(ChipModel.values()); sid3Model.setConverter(new EnumToString<ChipModel>(bundle)); sid3Model.setItems(sid3Models); sid3Model.getSelectionModel().select(emulationSection.getThirdSIDModel()); defaultModels = FXCollections.<ChipModel>observableArrayList(ChipModel.MOS6581, ChipModel.MOS8580); defaultModel.setConverter(new EnumToString<ChipModel>(bundle)); defaultModel.setItems(defaultModels); defaultModel.getSelectionModel().select(emulationSection.getDefaultSidModel()); defaultEmulations = FXCollections.<Emulation>observableArrayList(Emulation.RESID, Emulation.RESIDFP); defaultEmulation.setConverter(new EnumToString<Emulation>(bundle)); defaultEmulation.setItems(defaultEmulations); defaultEmulation.getSelectionModel().select(emulationSection.getDefaultEmulation()); boosted8580.setSelected(emulationSection.isDigiBoosted8580()); emulationChange = new EmulationChange(); util.getPlayer().stateProperty().addListener(emulationChange); Platform.runLater( () -> { updateSettingsForTune(util.getPlayer().getTune()); duringInitialization = false; }); }