javafx.scene.shape.Rectangle Java Examples
The following examples show how to use
javafx.scene.shape.Rectangle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MenuBox.java From FXTutorials with MIT License | 14 votes |
public MenuBox(int width, int height) { Rectangle bg = new Rectangle(width, height); bg.setFill(Colors.MENU_BG); Rectangle lineTop = new Rectangle(width, 2); lineTop.setFill(Colors.MENU_BORDER); lineTop.setStroke(Color.BLACK); Rectangle lineBot = new Rectangle(width, 2); lineBot.setTranslateY(height - 2); lineBot.setFill(Colors.MENU_BORDER); lineBot.setStroke(Color.BLACK); box = new VBox(5); box.setTranslateX(25); box.setTranslateY(25); getChildren().addAll(bg, lineTop, lineBot, box); }
Example #2
Source File: RectangleSample.java From marathonv5 with Apache License 2.0 | 7 votes |
public RectangleSample() { super(180,90); // Simple red filled rectangle Rectangle rect1 = new Rectangle(25,25,40,40); rect1.setFill(Color.RED); // Blue stroked rectangle Rectangle rect2 = new Rectangle(135,25,40,40); rect2.setStroke(Color.DODGERBLUE); rect2.setFill(null); // Create a group to show all the rectangles); getChildren().add(new Group(rect1,rect2)); // REMOVE ME setControls( new SimplePropertySheet.PropDesc("Rectangle 1 Fill", rect1.fillProperty()), new SimplePropertySheet.PropDesc("Rectangle 1 Width", rect1.widthProperty(), 10d, 50d), new SimplePropertySheet.PropDesc("Rectangle 1 Height", rect1.heightProperty(), 10d, 50d), new SimplePropertySheet.PropDesc("Rectangle 1 Arc Width", rect1.arcWidthProperty(), 0d, 50d), new SimplePropertySheet.PropDesc("Rectangle 1 Arc Height", rect1.arcHeightProperty(), 0d, 50d), new SimplePropertySheet.PropDesc("Rectangle 2 Stroke", rect2.strokeProperty()), new SimplePropertySheet.PropDesc("Rectangle 2 Stroke Width", rect2.strokeWidthProperty(), 1d, 5d), new SimplePropertySheet.PropDesc("Rectangle 2 Width", rect2.widthProperty(), 10d, 50d), new SimplePropertySheet.PropDesc("Rectangle 2 Height", rect2.heightProperty(), 10d, 50d), new SimplePropertySheet.PropDesc("Rectangle 2 Arc Width", rect2.arcWidthProperty(), 0d, 50d), new SimplePropertySheet.PropDesc("Rectangle 2 Arc Height", rect2.arcHeightProperty(), 0d, 50d) ); // END REMOVE ME }
Example #3
Source File: FillTransitionSample.java From marathonv5 with Apache License 2.0 | 6 votes |
public FillTransitionSample() { super(100,100); Rectangle rect = new Rectangle(0, 0, 100, 100); rect.setArcHeight(20); rect.setArcWidth(20); rect.setFill(Color.DODGERBLUE); getChildren().add(rect); fillTransition = FillTransitionBuilder.create() .duration(Duration.seconds(3)) .shape(rect) .fromValue(Color.RED) .toValue(Color.DODGERBLUE) .cycleCount(Timeline.INDEFINITE) .autoReverse(true) .build(); }
Example #4
Source File: CellGestures.java From fxgraph with Do What The F*ck You Want To Public License | 6 votes |
@Override public Node apply(Region region, Wrapper<Point2D> mouseLocation) { final DoubleProperty xProperty = region.layoutXProperty(); final DoubleProperty yProperty = region.layoutYProperty(); final Rectangle resizeHandleNW = new Rectangle(handleRadius, handleRadius, Color.BLACK); resizeHandleNW.xProperty().bind(xProperty.subtract(handleRadius / 2)); resizeHandleNW.yProperty().bind(yProperty.subtract(handleRadius / 2)); setUpDragging(resizeHandleNW, mouseLocation, Cursor.NW_RESIZE); resizeHandleNW.setOnMouseDragged(event -> { if(mouseLocation.value != null) { dragNorth(event, mouseLocation, region, handleRadius); dragWest(event, mouseLocation, region, handleRadius); mouseLocation.value = new Point2D(event.getSceneX(), event.getSceneY()); } }); return resizeHandleNW; }
Example #5
Source File: TowerDefenseFactory.java From FXGLGames with MIT License | 6 votes |
@Spawns("Tower") public Entity spawnTower(SpawnData data) { TowerDataComponent towerComponent = new TowerDataComponent(); // try { // towerComponent = getAssetLoader() // .loadKV("Tower" + data.get("index") + ".kv") // .to(TowerDataComponent.class); // // } catch (Exception e) { // throw new RuntimeException("Failed to parse KV file: " + e); // } return entityBuilder() .type(TowerDefenseType.TOWER) .from(data) .view(new Rectangle(40, 40, data.get("color"))) .with(new CollidableComponent(true), towerComponent) .with(new TowerComponent()) .build(); }
Example #6
Source File: RotateTransitionSample.java From marathonv5 with Apache License 2.0 | 6 votes |
public RotateTransitionSample() { super(140,140); Rectangle rect = new Rectangle(20, 20, 100, 100); rect.setArcHeight(20); rect.setArcWidth(20); rect.setFill(Color.ORANGE); getChildren().add(rect); rotateTransition = RotateTransitionBuilder.create() .node(rect) .duration(Duration.seconds(4)) .fromAngle(0) .toAngle(720) .cycleCount(Timeline.INDEFINITE) .autoReverse(true) .build(); }
Example #7
Source File: BarChartItem.java From OEE-Designer with MIT License | 6 votes |
private void initGraphics() { if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) { if (getPrefWidth() > 0 && getPrefHeight() > 0) { setPrefSize(getPrefWidth(), getPrefHeight()); } else { setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } } nameText = new Text(getName()); nameText.setTextOrigin(VPos.TOP); valueText = new Text(String.format(locale, formatString, getValue())); valueText.setTextOrigin(VPos.TOP); barBackground = new Rectangle(); bar = new Rectangle(); pane = new Pane(nameText, valueText, barBackground, bar); pane.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY))); getChildren().setAll(pane); }
Example #8
Source File: ClusterMonitorTileSkin.java From tilesfx with Apache License 2.0 | 6 votes |
public ChartItem(final ChartData CHART_DATA, final CtxBounds CONTENT_BOUNDS, final String FORMAT_STRING) { chartData = CHART_DATA; contentBounds = CONTENT_BOUNDS; title = new Label(chartData.getName()); value = new Label(String.format(Locale.US, FORMAT_STRING, chartData.getValue())); scale = new Rectangle(0, 0); bar = new Rectangle(0, 0); formatString = FORMAT_STRING; step = PREF_WIDTH / (CHART_DATA.getMaxValue() - CHART_DATA.getMinValue()); compressed = false; chartDataListener = e -> { switch(e.getType()) { case UPDATE : update(); break; case FINISHED: update(); break; } }; initGraphics(); registerListeners(); }
Example #9
Source File: DragResizerUtil.java From chart-fx with Apache License 2.0 | 6 votes |
protected void setNodeSize(final Node node, final double x, final double y, final double width, final double height) { node.setLayoutX(x); node.setLayoutY(y); // TODO find generic way to set width and height of any node // here we cannot set height and width to node directly. if (node instanceof Canvas) { ((Canvas) node).setWidth(width); ((Canvas) node).setHeight(height); } else if (node instanceof Rectangle) { ((Rectangle) node).setWidth(width); ((Rectangle) node).setHeight(height); } else if (node instanceof Region) { ((Region) node).setPrefWidth(width); ((Region) node).setPrefHeight(height); } }
Example #10
Source File: ScaleTransitionSample.java From marathonv5 with Apache License 2.0 | 6 votes |
public ScaleTransitionSample() { super(150,150); Rectangle rect = new Rectangle(50, 50, 50, 50); rect.setArcHeight(15); rect.setArcWidth(15); rect.setFill(Color.ORANGE); getChildren().add(rect); scaleTransition = ScaleTransitionBuilder.create() .node(rect) .duration(Duration.seconds(4)) .toX(3) .toY(3) .cycleCount(Timeline.INDEFINITE) .autoReverse(true) .build(); }
Example #11
Source File: IOSApp.java From mars-sim with GNU General Public License v3.0 | 6 votes |
private Parent createContent() { Pane root = new Pane(); root.setPrefSize(300, 300); Rectangle bg = new Rectangle(300, 300); ToggleSwitch toggle = new ToggleSwitch(); toggle.setTranslateX(100); toggle.setTranslateY(100); Text text = new Text(); text.setFont(Font.font(18)); text.setFill(Color.WHITE); text.setTranslateX(100); text.setTranslateY(200); text.textProperty().bind(Bindings.when(toggle.switchedOnProperty()).then("ON").otherwise("OFF")); root.getChildren().addAll(toggle, text); return root; }
Example #12
Source File: SeaBattle.java From games_oop_javafx with Apache License 2.0 | 6 votes |
private void buildShip(Group board, int desk, int startX, int startY) { Rectangle rect = new Rectangle(); rect.setX(startX); rect.setY(startY); rect.setHeight(25); rect.setWidth(desk * 25); rect.setFill(Color.BLACK); rect.setOnMouseDragged( event -> { rect.setX(event.getX()); rect.setY(event.getY()); } ); rect.setOnMouseReleased( event -> { rect.setX((((int) event.getX() / 25) * 25)); rect.setY(((int) event.getY() / 25) * 25); } ); rect.setOnMouseClicked( event -> { if (event.getButton() != MouseButton.PRIMARY) { Rectangle momento = new Rectangle(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight()); rect.setWidth(momento.getHeight()); rect.setHeight(momento.getWidth()); } } ); board.getChildren().add(rect); }
Example #13
Source File: StrokeTransitionSample.java From marathonv5 with Apache License 2.0 | 6 votes |
public StrokeTransitionSample() { super(150,150); Rectangle rect = new Rectangle(0, 0, 150, 150); rect.setArcHeight(20); rect.setArcWidth(20); rect.setFill(null); rect.setStroke(Color.DODGERBLUE); rect.setStrokeWidth(10); getChildren().add(rect); strokeTransition = StrokeTransitionBuilder.create() .duration(Duration.seconds(3)) .shape(rect) .fromValue(Color.RED) .toValue(Color.DODGERBLUE) .cycleCount(Timeline.INDEFINITE) .autoReverse(true) .build(); }
Example #14
Source File: BarChartItem.java From tilesfx with Apache License 2.0 | 6 votes |
private void initGraphics() { if (Double.compare(getPrefWidth(), 0.0) <= 0 || Double.compare(getPrefHeight(), 0.0) <= 0 || Double.compare(getWidth(), 0.0) <= 0 || Double.compare(getHeight(), 0.0) <= 0) { if (getPrefWidth() > 0 && getPrefHeight() > 0) { setPrefSize(getPrefWidth(), getPrefHeight()); } else { setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT); } } nameText = new Text(getName()); nameText.setTextOrigin(VPos.TOP); valueText = new Text(String.format(locale, formatString, getValue())); valueText.setTextOrigin(VPos.TOP); barBackground = new Rectangle(); bar = new Rectangle(); pane = new Pane(nameText, valueText, barBackground, bar); pane.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY))); getChildren().setAll(pane); }
Example #15
Source File: SpaceRangerFactory.java From FXGLGames with MIT License | 6 votes |
@Spawns("projectile") public Entity newProjectile(SpawnData data) { var view = new Rectangle(30, 3, Color.LIGHTBLUE); view.setStroke(Color.WHITE); view.setArcWidth(15); view.setArcHeight(10); return entityBuilder() .type(EntityType.PROJECTILE) .from(data) .viewWithBBox(view) .collidable() .zIndex(-5) .with(new ProjectileComponent(new Point2D(1, 0), 760)) .build(); }
Example #16
Source File: MicroscopeView.java From narjillos with MIT License | 6 votes |
public Node toNode() { Vector screenSize = viewport.getSizeSC(); if (screenSize.equals(currentScreenSize)) return microscope; currentScreenSize = screenSize; double minScreenSize = Math.min(screenSize.x, screenSize.y); double maxScreenSize = Math.max(screenSize.x, screenSize.y); // Leave an ample left/bottom black margin - otherwise, the background // will be visible for a moment while enlarging the window. Rectangle black = new Rectangle(-10, -10, maxScreenSize + 1000, maxScreenSize + 1000); Circle hole = new Circle(screenSize.x / 2, screenSize.y / 2, minScreenSize / 2.03); microscope = Shape.subtract(black, hole); microscope.setEffect(new BoxBlur(5, 5, 1)); return microscope; }
Example #17
Source File: Minimal.java From JavaFX with MIT License | 6 votes |
private Node createLoadPane() { loadPane = new TilePane(5, 5); loadPane.setPrefColumns(3); loadPane.setPadding(new Insets(5)); for (int i = 0; i < 9; i++) { StackPane waitingPane = new StackPane(); Rectangle background = new Rectangle((380) / 3, (380) / 3, Color.WHITE); indicators[i] = new ProgressIndicator(); indicators[i].setPrefSize(50, 50); indicators[i].setMaxSize(50, 50); indicators[i].setTranslateY(-25); indicators[i].setTranslateX(-10); loading[i] = new Label(); loading[i].setTranslateY(25); waitingPane.getChildren().addAll(background, indicators[i], loading[i]); loadPane.getChildren().add(waitingPane); } return loadPane; }
Example #18
Source File: Exercise_16_08.java From Intro-to-Java-Programming with MIT License | 5 votes |
/** Return a rectangle */ private Rectangle getRectangle() { Rectangle r = new Rectangle(0, 0, 250, 110); r.setStroke(Color.WHITE); r.setFill(Color.WHITE); return r; }
Example #19
Source File: RectangleCell.java From fxgraph with Do What The F*ck You Want To Public License | 5 votes |
@Override public Region getGraphic(Graph graph) { final Rectangle view = new Rectangle(50, 50); view.setStroke(Color.DODGERBLUE); view.setFill(Color.DODGERBLUE); final Pane pane = new Pane(view); pane.setPrefSize(50, 50); view.widthProperty().bind(pane.prefWidthProperty()); view.heightProperty().bind(pane.prefHeightProperty()); CellGestures.makeResizable(pane); return pane; }
Example #20
Source File: BreakoutApp.java From FXGLGames with MIT License | 5 votes |
@Override protected void initUI() { debugText = new Text(); debugText.setFill(Color.WHITE); var textScore = getUIFactoryService().newText(getip("score").asString()); addUINode(textScore, 220, getAppHeight() - 20); addUINode(debugText, 50, 50); var regionLeft = new Rectangle(getAppWidth() / 2, getAppHeight() - 200); regionLeft.setOpacity(0); regionLeft.setOnMousePressed(e -> getInput().mockKeyPress(KeyCode.A)); regionLeft.setOnMouseReleased(e -> getInput().mockKeyRelease(KeyCode.A)); var regionRight = new Rectangle(getAppWidth() / 2, getAppHeight() - 200); regionRight.setOpacity(0); regionRight.setOnMousePressed(e -> getInput().mockKeyPress(KeyCode.D)); regionRight.setOnMouseReleased(e -> getInput().mockKeyRelease(KeyCode.D)); addUINode(regionLeft); addUINode(regionRight, getAppWidth() / 2, 0); runOnce(() -> { //getSceneService().pushSubScene(new TutorialSubScene()); runOnce(() -> getBallControl().changeColorToNext(), Duration.seconds(0.016)); }, Duration.seconds(0.5)); }
Example #21
Source File: StopWatchSample.java From marathonv5 with Apache License 2.0 | 5 votes |
private Rectangle createTic(double angle, double width, double height) { Rectangle rectangle = new Rectangle(-width / 2, -height / 2, width, height); rectangle.setFill(Color.rgb(10, 10, 10)); rectangle.setRotate(angle); rectangle.setLayoutX(radius * Math.cos(Math.toRadians(angle))); rectangle.setLayoutY(radius * Math.sin(Math.toRadians(angle))); return rectangle; }
Example #22
Source File: Callout.java From mars-sim with GNU General Public License v3.0 | 5 votes |
protected void buildAnimation(Node head, Line beginLeaderLine, Line endLeaderLine, HBox mainTitle, Rectangle subTitleRect, HBox subTitle) { // generate a sequence animation calloutAnimation = new SequentialTransition(); // Allow animation to go in reverse calloutAnimation.setCycleCount(2); calloutAnimation.setAutoReverse(true); // Animation of head calloutAnimation.getChildren().add(buildHeadAnim(head)); // Animation of the beginning leader line. calloutAnimation.getChildren().add(buildBeginLeaderLineAnim(beginLeaderLine)); // Animation of the ending leader line. calloutAnimation.getChildren().add(buildEndLeaderLineAnim(endLeaderLine)); // Animation of the main title calloutAnimation.getChildren().add(buildMainTitleAnim(mainTitle)); // Animation of the subtitle rectangle calloutAnimation.getChildren().add(buildSubtitleRectAnim(mainTitle, subTitleRect)); // Animation of the subtitle calloutAnimation.getChildren().add(buildSubTitleAnim(mainTitle, subTitle)); Timeline pause = new Timeline(new KeyFrame(Duration.millis(getPauseTime()/2))); calloutAnimation.getChildren().add(pause); }
Example #23
Source File: Piece.java From DevToolBox with GNU Lesser General Public License v2.1 | 5 votes |
private Shape createPieceTab(double eclipseCenterX, double eclipseCenterY, double eclipseRadiusX, double eclipseRadiusY, double rectangleX, double rectangleY, double rectangleWidth, double rectangleHeight, double circle1CenterX, double circle1CenterY, double circle1Radius, double circle2CenterX, double circle2CenterY, double circle2Radius) { Ellipse e = new Ellipse(eclipseCenterX, eclipseCenterY, eclipseRadiusX, eclipseRadiusY); Rectangle r = new Rectangle(rectangleX, rectangleY, rectangleWidth, rectangleHeight); Shape tab = Shape.union(e, r); Circle c1 = new Circle(circle1CenterX, circle1CenterY, circle1Radius); tab = Shape.subtract(tab, c1); Circle c2 = new Circle(circle2CenterX, circle2CenterY, circle2Radius); tab = Shape.subtract(tab, c2); return tab; }
Example #24
Source File: DockingDemo.java From phoebus with Eclipse Public License 1.0 | 5 votes |
@Override public void start(final Stage stage) { // Add dock items to the original stage final DockItem tab1 = new DockItem("Tab 1"); final BorderPane layout = new BorderPane(); layout.setTop(new Label("Top")); layout.setCenter(new Label("Tab that indicates resize behavior")); layout.setBottom(new Label("Bottom")); tab1.setContent(layout); final DockItem tab2 = new DockItem("Tab 2"); tab2.setContent(new Rectangle(500, 500, Color.RED)); // The DockPane is added to a stage by 'configuring' it. // Initial tabs can be provided right away DockPane tabs = DockStage.configureStage(stage, tab1, tab2); stage.setX(100); // .. or tabs are added later final DockItem tab3 = new DockItem("Tab 3"); tab3.setContent(new Rectangle(500, 500, Color.GRAY)); tabs.addTab(tab3); // Create another stage with more dock items final DockItem tab4 = new DockItem("Tab 4"); tab4.setContent(new Rectangle(500, 500, Color.YELLOW)); final DockItem tab5 = new DockItem("Tab 5"); tab5.setContent(new Rectangle(500, 500, Color.BISQUE)); final Stage other = new Stage(); DockStage.configureStage(other, tab4, tab5); other.setX(600); stage.show(); other.show(); }
Example #25
Source File: PageView.java From latexdraw with GNU General Public License v3.0 | 5 votes |
/** * Creates a view of a page. * @param origin The origin point where the page has to be placed. Cannot be null. */ public PageView(final @NotNull PreferencesService prefs, final Point origin) { super(); recPage = new Rectangle(); recShadowBottom = new Rectangle(); recShadowRight = new Rectangle(); recPage.setStrokeWidth(1d); recPage.setStroke(Color.BLACK); recPage.setFill(null); recPage.setX(origin.getX()); recPage.setY(origin.getY()); recShadowRight.setStroke(null); recShadowBottom.setStroke(null); recShadowRight.setFill(Color.GRAY); recShadowBottom.setFill(Color.GRAY); getChildren().add(recShadowBottom); getChildren().add(recShadowRight); getChildren().add(recPage); recPage.toFront(); setMouseTransparent(true); setFocusTraversable(false); update(prefs.getPage()); prefs.pageProperty().addListener((observable, oldValue, newValue) -> update(newValue)); }
Example #26
Source File: SpaceLevel.java From FXGLGames with MIT License | 5 votes |
public SpaceLevel() { Rectangle bg = new Rectangle(getAppWidth() - 20, 200, Color.color(0, 0, 0, 0.6)); bg.setArcWidth(25); bg.setArcHeight(25); bg.setStroke(Color.color(0.1, 0.2, 0.86, 0.76)); bg.setStrokeWidth(3); storyPane.setTranslateX(10); storyPane.setTranslateY(25); rootPane = new Pane(bg, storyPane); rootPane.setTranslateX(10); rootPane.setTranslateY(getAppHeight() - 200); }
Example #27
Source File: BombermanFactory.java From FXGLGames with MIT License | 5 votes |
@Spawns("w") public Entity newWall(SpawnData data) { return FXGL.entityBuilder() .type(BombermanType.WALL) .from(data) .view(new Rectangle(40, 40, Color.GRAY.saturate())) .build(); }
Example #28
Source File: Exercise_15_13.java From Intro-to-Java-Programming with MIT License | 5 votes |
@Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane Pane pane = new Pane(); // Create a rectangle Rectangle rectangle = new Rectangle(100, 60, 100, 40); rectangle.setFill(Color.WHITE); rectangle.setStroke(Color.BLACK); // Place the rectangle in the pane pane.getChildren().add(rectangle); // Create and register the handle pane.setOnMouseMoved(e -> { pane.getChildren().clear(); Text text = new Text(e.getX(), e.getY(), "Mouse point is " + (rectangle.contains(e.getX(), e.getY()) ? "inside " : "outside ") + "the rectangle"); pane.getChildren().addAll(rectangle, text); }); // Create a scene and place it in the stage Scene scene = new Scene(pane, 400, 200); primaryStage.setTitle("Exercise_15_13"); // Set the stage title primaryStage.setScene(scene); // Place the scene in the stage primaryStage.show(); // Display the stage }
Example #29
Source File: StackPaneSample.java From marathonv5 with Apache License 2.0 | 5 votes |
public StackPaneSample() { StackPane stackPane = new StackPane(); Rectangle rectangle = new Rectangle(280, 70, Color.BISQUE); rectangle.setStroke(Color.BLACK); ImageView imageView = new ImageView(ICON_48); Label label = new Label("Your name could be here.", imageView); label.setContentDisplay(ContentDisplay.RIGHT); stackPane.getChildren().addAll(rectangle, label); getChildren().add(stackPane); }
Example #30
Source File: TicTacToeApp.java From FXTutorials with MIT License | 5 votes |
public Tile() { Rectangle border = new Rectangle(200, 200); border.setFill(null); border.setStroke(Color.BLACK); text.setFont(Font.font(72)); setAlignment(Pos.CENTER); getChildren().addAll(border, text); setOnMouseClicked(event -> { if (!playable) return; if (event.getButton() == MouseButton.PRIMARY) { if (!turnX) return; drawX(); turnX = false; checkState(); } else if (event.getButton() == MouseButton.SECONDARY) { if (turnX) return; drawO(); turnX = true; checkState(); } }); }