List of usage examples for javafx.scene.shape Rectangle Rectangle
public Rectangle(double x, double y, double width, double height)
From source file:Main.java
@Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 260, 80); stage.setScene(scene);/*from ww w . j a va2 s. c o m*/ VBox vb = new VBox(); Rectangle rect = new Rectangle(100, 40, 100, 100); rect.setArcHeight(50); rect.setArcWidth(50); rect.setFill(Color.VIOLET); RotateTransition rt = new RotateTransition(Duration.millis(3000), rect); rt.setByAngle(180); rt.setAutoReverse(true); SequentialTransition seqTransition = new SequentialTransition(new PauseTransition(Duration.millis(1000)), // wait a second rt); seqTransition.play(); vb.getChildren().add(rect); scene.setRoot(vb); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { VBox box = new VBox(); final Scene scene = new Scene(box, 300, 250); scene.setFill(null);//from ww w . ja v a 2 s.c o m Stop[] stops = new Stop[] { new Stop(0, Color.BLACK), new Stop(1, Color.RED) }; LinearGradient lg1 = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops); Rectangle r1 = new Rectangle(0, 0, 100, 100); r1.setFill(lg1); box.getChildren().add(r1); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Scene scene = new Scene(new Group()); stage.setTitle("Sample"); stage.setWidth(300);//from ww w . j ava2 s.c o m stage.setHeight(190); VBox vbox = new VBox(); vbox.setLayoutX(20); vbox.setLayoutY(20); Rectangle rect = new Rectangle(100, 40, 100, 100); rect.setArcHeight(50); rect.setArcWidth(50); rect.setFill(Color.VIOLET); TranslateTransition tt = new TranslateTransition(Duration.millis(2000), rect); tt.setByX(200f); tt.setAutoReverse(true); tt.play(); vbox.getChildren().add(rect); vbox.setSpacing(10); ((Group) scene.getRoot()).getChildren().add(vbox); stage.setScene(scene); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { final Group group = new Group(); Scene scene = new Scene(group, 300, 150); stage.setScene(scene);// w w w. j a va 2s. c o m stage.setTitle("Sample"); Stop[] stops = { new Stop(0, Color.WHITE), new Stop(1, Color.BLACK) }; LinearGradient lg = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops); Rectangle r = new Rectangle(20, 20, 200, 200); r.setFill(lg); group.getChildren().add(r); stage.show(); }
From source file:Main.java
@Override public void start(Stage stage) { Group root = new Group(); Scene scene = new Scene(root, 260, 80); stage.setScene(scene);/*from w w w. ja v a2 s . c om*/ VBox vb = new VBox(); Rectangle rect = new Rectangle(100, 40, 100, 100); rect.setArcHeight(50); rect.setArcWidth(50); rect.setFill(Color.VIOLET); final Duration SEC_2 = Duration.millis(2000); final Duration SEC_3 = Duration.millis(3000); FadeTransition ft = new FadeTransition(SEC_3); ft.setFromValue(1.0f); ft.setToValue(0.3f); ft.setAutoReverse(true); TranslateTransition tt = new TranslateTransition(SEC_2); tt.setFromX(-100f); tt.setToX(100f); tt.setAutoReverse(true); RotateTransition rt = new RotateTransition(SEC_3); rt.setByAngle(180f); rt.setAutoReverse(true); ScaleTransition st = new ScaleTransition(SEC_2); st.setByX(1.5f); st.setByY(1.5f); st.setAutoReverse(true); ParallelTransition pt = new ParallelTransition(rect, ft, tt, rt, st); pt.play(); vb.getChildren().add(rect); scene.setRoot(vb); stage.show(); }
From source file:nl.rivm.cib.episim.model.disease.infection.MSEIRSPlot.java
@Override public void start(final Stage stage) { final SIRConfig conf = ConfigFactory.create(SIRConfig.class); final double[] t = conf.t(); final long[] pop = conf.population(); final double n0 = Arrays.stream(pop).sum(); final String[] colors = conf.colors(), colors2 = conf.colors2(); final Pane plot = new Pane(); plot.setPrefSize(400, 300);// ww w . ja v a 2 s .c o m plot.setMinSize(50, 50); final NumberAxis xAxis = new NumberAxis(t[0], t[1], (t[1] - t[0]) / 10); final NumberAxis yAxis = new NumberAxis(0, n0, n0 / 10); final Pane axes = new Pane(); axes.prefHeightProperty().bind(plot.heightProperty()); axes.prefWidthProperty().bind(plot.widthProperty()); xAxis.setSide(Side.BOTTOM); xAxis.setMinorTickVisible(false); xAxis.setPrefWidth(axes.getPrefWidth()); xAxis.prefWidthProperty().bind(axes.widthProperty()); xAxis.layoutYProperty().bind(axes.heightProperty()); yAxis.setSide(Side.LEFT); yAxis.setMinorTickVisible(false); yAxis.setPrefHeight(axes.getPrefHeight()); yAxis.prefHeightProperty().bind(axes.heightProperty()); yAxis.layoutXProperty().bind(Bindings.subtract(1, yAxis.widthProperty())); axes.getChildren().setAll(xAxis, yAxis); final Label lbl = new Label(String.format("R0=%.1f, recovery=%.1ft\nSIR(0)=%s", conf.reproduction(), conf.recovery(), Arrays.toString(pop))); lbl.setTextAlignment(TextAlignment.CENTER); lbl.setTextFill(Color.WHITE); final Path[] deterministic = { new Path(), new Path(), new Path() }; IntStream.range(0, pop.length).forEach(i -> { final Color color = Color.valueOf(colors[i]); final Path path = deterministic[i]; path.setStroke(color.deriveColor(0, 1, 1, 0.6)); path.setStrokeWidth(2); path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight())); }); plot.getChildren().setAll(axes); // fill paths with integration estimates final double xl = xAxis.getLowerBound(), sx = plot.getPrefWidth() / (xAxis.getUpperBound() - xl), yh = plot.getPrefHeight(), sy = yh / (yAxis.getUpperBound() - yAxis.getLowerBound()); final TreeMap<Double, Integer> iDeterministic = new TreeMap<>(); MSEIRSTest.deterministic(conf, () -> new DormandPrince853Integrator(1.0E-8, 10, 1.0E-20, 1.0E-20)) .subscribe(yt -> { iDeterministic.put(yt.getKey(), deterministic[0].getElements().size()); final double[] y = yt.getValue(); final double x = (yt.getKey() - xl) * sx; for (int i = 0; i < y.length; i++) { final double yi = yh - y[i] * sy; final PathElement di = deterministic[i].getElements().isEmpty() ? new MoveTo(x, yi) : new LineTo(x, yi); deterministic[i].getElements().add(di); } }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(deterministic)); final Path[] stochasticTau = { new Path(), new Path(), new Path() }; IntStream.range(0, pop.length).forEach(i -> { final Color color = Color.valueOf(colors[i]); final Path path = stochasticTau[i]; path.setStroke(color); path.setStrokeWidth(1); path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight())); }); final TreeMap<Double, Integer> iStochasticTau = new TreeMap<>(); MSEIRSTest.stochasticGillespie(conf).subscribe(yt -> { final double x = (yt.getKey() - xl) * sx; iStochasticTau.put(yt.getKey(), stochasticTau[0].getElements().size()); final long[] y = yt.getValue(); for (int i = 0; i < y.length; i++) { final double yi = yh - y[i] * sy; final ObservableList<PathElement> path = stochasticTau[i].getElements(); if (path.isEmpty()) { path.add(new MoveTo(x, yi)); // first } else { final PathElement last = path.get(path.size() - 1); final double y_prev = last instanceof MoveTo ? ((MoveTo) last).getY() : ((LineTo) last).getY(); path.add(new LineTo(x, y_prev)); path.add(new LineTo(x, yi)); } } }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(stochasticTau)); final Path[] stochasticRes = { new Path(), new Path(), new Path() }; IntStream.range(0, pop.length).forEach(i -> { final Color color = Color.valueOf(colors2[i]); final Path path = stochasticRes[i]; path.setStroke(color); path.setStrokeWidth(1); path.setClip(new Rectangle(0, 0, plot.getPrefWidth(), plot.getPrefHeight())); }); final TreeMap<Double, Integer> iStochasticRes = new TreeMap<>(); MSEIRSTest.stochasticSellke(conf).subscribe(yt -> { final double x = (yt.getKey() - xl) * sx; iStochasticRes.put(yt.getKey(), stochasticRes[0].getElements().size()); final long[] y = yt.getValue(); for (int i = 0; i < y.length; i++) { final double yi = yh - y[i] * sy; final ObservableList<PathElement> path = stochasticRes[i].getElements(); if (path.isEmpty()) { path.add(new MoveTo(x, yi)); // first } else { final PathElement last = path.get(path.size() - 1); final double y_prev = last instanceof MoveTo ? ((MoveTo) last).getY() : ((LineTo) last).getY(); path.add(new LineTo(x, y_prev)); path.add(new LineTo(x, yi)); } } }, e -> LOG.error("Problem", e), () -> plot.getChildren().addAll(stochasticRes)); // auto-scale on stage/plot resize // FIXME scaling around wrong origin, use ScatterChart? // xAxis.widthProperty() // .addListener( (ChangeListener<Number>) ( observable, // oldValue, newValue ) -> // { // final double scale = ((Double) newValue) // / plot.getPrefWidth(); // plot.getChildren().filtered( n -> n instanceof Path ) // .forEach( n -> // { // final Path path = (Path) n; // path.setScaleX( scale ); // path.setTranslateX( (path // .getBoundsInParent().getWidth() // - path.getLayoutBounds().getWidth()) // / 2 ); // } ); // } ); // plot.heightProperty() // .addListener( (ChangeListener<Number>) ( observable, // oldValue, newValue ) -> // { // final double scale = ((Double) newValue) // / plot.getPrefHeight(); // plot.getChildren().filtered( n -> n instanceof Path ) // .forEach( n -> // { // final Path path = (Path) n; // path.setScaleY( scale ); // path.setTranslateY( // (path.getBoundsInParent() // .getHeight() * (scale - 1)) // / 2 ); // } ); // } ); final StackPane layout = new StackPane(lbl, plot); layout.setAlignment(Pos.TOP_CENTER); layout.setPadding(new Insets(50)); layout.setStyle("-fx-background-color: rgb(35, 39, 50);"); final Line vertiCross = new Line(); vertiCross.setStroke(Color.SILVER); vertiCross.setStrokeWidth(1); vertiCross.setVisible(false); axes.getChildren().add(vertiCross); final Tooltip tip = new Tooltip(""); tip.setAutoHide(false); tip.hide(); axes.setOnMouseExited(ev -> tip.hide()); axes.setOnMouseMoved(ev -> { final Double x = (Double) xAxis.getValueForDisplay(ev.getX()); if (x > xAxis.getUpperBound() || x < xAxis.getLowerBound()) { tip.hide(); vertiCross.setVisible(false); return; } final Double y = (Double) yAxis.getValueForDisplay(ev.getY()); if (y > yAxis.getUpperBound() || y < yAxis.getLowerBound()) { tip.hide(); vertiCross.setVisible(false); return; } final double xs = xAxis.getDisplayPosition(x); vertiCross.setStartX(xs); vertiCross.setStartY(yAxis.getDisplayPosition(0)); vertiCross.setEndX(xs); vertiCross.setEndY(yAxis.getDisplayPosition(yAxis.getUpperBound())); vertiCross.setVisible(true); final int i = (iDeterministic.firstKey() > x ? iDeterministic.firstEntry() : iDeterministic.floorEntry(x)).getValue(); final Object[] yi = Arrays.stream(deterministic).mapToDouble(p -> getY(p, i)) .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 1)).toArray(); final int j = (iStochasticTau.firstKey() > x ? iStochasticTau.firstEntry() : iStochasticTau.floorEntry(x)).getValue(); final Object[] yj = Arrays.stream(stochasticTau).mapToDouble(p -> getY(p, j)) .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 0)).toArray(); final int k = (iStochasticRes.firstKey() > x ? iStochasticRes.firstEntry() : iStochasticRes.floorEntry(x)).getValue(); final Object[] yk = Arrays.stream(stochasticRes).mapToDouble(p -> getY(p, k)) .mapToObj(yAxis::getValueForDisplay).map(n -> DecimalUtil.toScale(n, 0)).toArray(); final String txt = String.format("SIR(t=%.1f)\n" + "~det%s\n" + "~tau%s\n" + "~res%s", x, Arrays.toString(yi), Arrays.toString(yj), Arrays.toString(yk)); tip.setText(txt); tip.show(axes, ev.getScreenX() - ev.getSceneX() + xs, ev.getScreenY() + 15); }); try { stage.getIcons().add(new Image(FileUtil.toInputStream("icon.jpg"))); } catch (final IOException e) { LOG.error("Problem", e); } stage.setTitle("Deterministic vs. Stochastic"); stage.setScene(new Scene(layout, Color.rgb(35, 39, 50))); // stage.setOnHidden( ev -> tip.hide() ); stage.show(); }
From source file:jp.co.heppokoact.autocapture.FXMLDocumentController.java
@FXML private void areaButtonClicked(ActionEvent event) throws IOException { System.out.println("areaButtonClicked"); // ??/*from w w w.j a va 2s . c om*/ Stage transparentStage = createTransparentStage(); // ????? Scene scene = transparentStage.getScene(); scene.setOnMousePressed(e -> { // dragStartX = (int) e.getScreenX(); dragStartY = (int) e.getScreenY(); // ?? areaRect = new Rectangle(e.getX(), e.getY(), 0, 0); areaRect.setStroke(Color.RED); areaRect.setStrokeWidth(1.0); areaRect.setFill(Color.TRANSPARENT); ((Pane) scene.getRoot()).getChildren().add(areaRect); }); // ????? scene.setOnMouseDragged(e -> { // ?????? areaRect.setWidth(e.getScreenX() - dragStartX); areaRect.setHeight(e.getScreenY() - dragStartY); }); // ????? scene.setOnMouseReleased(e -> { // ? areaStartX.set(dragStartX); areaStartY.set(dragStartY); areaEndX.set((int) e.getScreenX()); areaEndY.set((int) e.getScreenY()); // ?? transparentStage.close(); }); // ?????? transparentStage.setOnCloseRequest(e -> { // ????? dragStartX = 0; dragStartY = 0; areaRect = null; }); transparentStage.show(); }
From source file:com.github.vatbub.tictactoe.view.Main.java
@FXML // This method is called by the FXMLLoader when initialization is complete void initialize() { // modify the default exception handler to show a good error message on every uncaught exception final Thread.UncaughtExceptionHandler currentUncaughtExceptionHandler = Thread .getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler((thread, exception) -> { if (currentUncaughtExceptionHandler != null) { // execute current handler as we only want to append it currentUncaughtExceptionHandler.uncaughtException(thread, exception); }/* w w w. j a va2s. c o m*/ Platform.runLater(() -> new ExceptionAlert(exception).showAndWait()); }); opponentsTurnHBox.heightProperty() .addListener((observable, oldValue, newValue) -> updateOpponentsTurnHBox(false)); aiLevelLabelClipRectangle = new Rectangle(0, 0, 0, 0); aiLevelLabelClipRectangle.setEffect(new MotionBlur(0, 10)); aiLevelLabelPane.setClip(aiLevelLabelClipRectangle); aiLevelLabelClipRectangle.heightProperty().bind(aiLevelLabelPane.heightProperty()); aiLevelLabelPane.widthProperty().addListener((observable, oldValue, newValue) -> updateAILevelLabel(true)); Rectangle menuSubBoxClipRectangle = new Rectangle(0, 0, 0, 0); menuSubBox.setClip(menuSubBoxClipRectangle); menuSubBoxClipRectangle.heightProperty().bind(menuSubBox.heightProperty()); menuSubBoxClipRectangle.widthProperty().bind(menuSubBox.widthProperty()); Rectangle playOnlineClipRectangle = new Rectangle(0, 0, 0, 0); playOnlineClipAnchorPane.setClip(playOnlineClipRectangle); playOnlineClipRectangle.heightProperty().bind(playOnlineClipAnchorPane.heightProperty()); playOnlineClipRectangle.widthProperty().bind(playOnlineClipAnchorPane.widthProperty()); player1SetSampleName(); player2SetSampleName(); gameTable.heightProperty() .addListener((observable, oldValue, newValue) -> refreshedNodes.refreshAll(gameTable.getWidth(), oldValue.doubleValue(), gameTable.getWidth(), newValue.doubleValue())); gameTable.widthProperty() .addListener((observable, oldValue, newValue) -> refreshedNodes.refreshAll(oldValue.doubleValue(), gameTable.getHeight(), newValue.doubleValue(), gameTable.getHeight())); player1AIToggle.selectedProperty().addListener((observable, oldValue, newValue) -> { showHideAILevelSlider(newValue, player2AIToggle.isSelected()); player1SetSampleName(); }); player2AIToggle.selectedProperty().addListener((observable, oldValue, newValue) -> { showHideAILevelSlider(player1AIToggle.isSelected(), newValue); player2SetSampleName(); }); gameTable.setSelectionModel(null); gameTable.heightProperty().addListener((observable, oldValue, newValue) -> { Pane header = (Pane) gameTable.lookup("TableHeaderRow"); if (header.isVisible()) { header.setMaxHeight(0); header.setMinHeight(0); header.setPrefHeight(0); header.setVisible(false); } renderRows(); }); gameTable.setRowFactory(param -> { TableRow<Row> row = new TableRow<>(); row.styleProperty().bind(style); if (rowFont == null) { rowFont = new SimpleObjectProperty<>(); rowFont.bind(row.fontProperty()); } return row; }); looseImage.fitHeightProperty().bind(looserPane.heightProperty()); looseImage.fitWidthProperty().bind(looserPane.widthProperty()); looseImage.fitHeightProperty().addListener((observable, oldValue, newValue) -> reloadImage(looseImage, getClass().getResource("loose.png").toString(), looseImage.getFitWidth(), newValue.doubleValue())); looseImage.fitWidthProperty().addListener((observable, oldValue, newValue) -> reloadImage(looseImage, getClass().getResource("loose.png").toString(), newValue.doubleValue(), looseImage.getFitWidth())); confetti.fitHeightProperty().bind(winPane.heightProperty()); confetti.fitWidthProperty().bind(winPane.widthProperty()); confetti.fitHeightProperty().addListener((observable, oldValue, newValue) -> reloadImage(confetti, getClass().getResource("confetti.png").toString(), confetti.getFitWidth(), newValue.doubleValue())); confetti.fitWidthProperty().addListener((observable, oldValue, newValue) -> reloadImage(confetti, getClass().getResource("confetti.png").toString(), newValue.doubleValue(), confetti.getFitWidth())); aiLevelSlider.valueProperty().addListener((observable, oldValue, newValue) -> updateAILevelLabel()); playOnlineHyperlink.widthProperty().addListener((observable, oldValue, newValue) -> { if (playOnlineAnchorPane.isVisible()) { setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true); } }); playOnlineHyperlink.heightProperty().addListener((observable, oldValue, newValue) -> { if (playOnlineAnchorPane.isVisible()) { setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true); } }); playOnlineHyperlink.textProperty().addListener((observable, oldValue, newValue) -> { if (!newValue.equals(oldValue)) { if (newValue.contains("ff")) { setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true, 1); } else { setLowerRightAnchorPaneDimensions(playOnlineHyperlink, currentPlayerLabel, true, -1); } } }); // Kunami code root.setOnKeyPressed(event -> { if (KunamiCode.isCompleted(event.getCode())) { if (root.getEffect() != null && root.getEffect() instanceof Blend) { BlendMode currentMode = ((Blend) root.getEffect()).getMode(); BlendMode nextMode; if (currentMode == BlendMode.values()[BlendMode.values().length - 1]) { nextMode = BlendMode.values()[0]; } else { nextMode = BlendMode.values()[Arrays.asList(BlendMode.values()).indexOf(currentMode) + 1]; } ((Blend) root.getEffect()).setMode(nextMode); } else { root.setEffect(new Blend(BlendMode.EXCLUSION)); } } }); // prompt text of the my username field in the online multiplayer menu onlineMyUsername.promptTextProperty().bind(player1Name.promptTextProperty()); onlineMyUsername.textProperty().bindBidirectional(player1Name.textProperty()); setAccessibleTextsForNodesThatDoNotChange(); updateAccessibleTexts(); initBoard(); initNewGame(); }
From source file:org.nmrfx.processor.gui.spectra.PeakListAttributes.java
Rectangle getBox(double[] ctr, double[] bou) { double x1 = xAxis.getDisplayPosition(ctr[0] + (bou[0] / 2.0)); double x2 = xAxis.getDisplayPosition(ctr[0] - (bou[0] / 2.0)); double y1 = yAxis.getDisplayPosition(ctr[1] + (bou[1] / 2.0)); double y2 = yAxis.getDisplayPosition(ctr[1] - (bou[1] / 2.0)); double xMin;// w w w . j a v a2 s . c om double xWidth; if (x1 < x2) { xMin = x1; xWidth = x2 - x1; } else { xMin = x2; xWidth = x1 - x2; } double yMin; double yHeight; if (y1 < y2) { yMin = x1; yHeight = y2 - y1; } else { yMin = y2; yHeight = y1 - y2; } return new Rectangle(xMin, yMin, xWidth, yHeight); }
From source file:org.nmrfx.processor.gui.spectra.PeakListAttributes.java
Rectangle getBox(double ctr, double bou, double height) { double x1 = xAxis.getDisplayPosition(ctr + (bou / 2.0)); double x2 = xAxis.getDisplayPosition(ctr - (bou / 2.0)); double y1 = 0.0; double y2 = height; double xMin;//from w w w . jav a 2 s .c o m double xWidth; if (x1 < x2) { xMin = x1; xWidth = x2 - x1; } else { xMin = x2; xWidth = x1 - x2; } double yMin; double yHeight; if (y1 < y2) { yMin = y1; yHeight = y2 - y1; } else { yMin = y2; yHeight = y1 - y2; } return new Rectangle(xMin, yMin, xWidth, yHeight); }