Java Code Examples for javafx.scene.shape.Rectangle#setFill()

The following examples show how to use javafx.scene.shape.Rectangle#setFill() . 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 vote down vote up
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: PackMan.java    From games_oop_javafx with Apache License 2.0 6 votes vote down vote up
private Rectangle buildFigure(int x, int y, int size, String image) {
    Rectangle rect = new Rectangle();
    rect.setX(x);
    rect.setY(y);
    rect.setHeight(size);
    rect.setWidth(size);
    Image img = new Image(this.getClass().getClassLoader().getResource(image).toString());
    rect.setFill(new ImagePattern(img));
    return rect;
}
 
Example 3
Source File: RotateSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (0, 0, 64, 64);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00"));

    Polygon polygon = createArrow();
    polygon.setLayoutX(65);
    polygon.setLayoutY(5);
    polygon.setRotate(165);
    

    Rectangle r2 = new Rectangle (0, 0, 64, 64);
    r2.setArcHeight(15);
    r2.setArcWidth(15);
    r2.setFill(Color.web("#ed4b00"));
    r2.setRotate(60);
    r2.setOpacity(0.5);
    javafx.scene.Group g = new javafx.scene.Group(r2,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example 4
Source File: StrokeTransitionSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
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 5
Source File: ScaleSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public static Node createIconContent() {
    final Rectangle r1 = new Rectangle (50, 50, 14, 14);
    r1.setArcHeight(4);
    r1.setArcWidth(4);
    r1.setFill(Color.web("#ed4b00"));

    Polygon polygon = createArrow();
    polygon.setLayoutX(68);
    polygon.setLayoutY(25);
    polygon.setRotate(45);

    Rectangle r3 = new Rectangle (25, 25, 64, 64);
    r3.setArcHeight(15);
    r3.setArcWidth(15);
    r3.setFill(Color.web("#f49b00"));
    javafx.scene.Group g = new javafx.scene.Group(r3,r1, polygon);
    return new javafx.scene.Group(g);
}
 
Example 6
Source File: FadeTransitionSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public FadeTransitionSample() {
    super(100,100);
    Rectangle rect = new Rectangle(0, 0, 100, 100);
    rect.setArcHeight(20);
    rect.setArcWidth(20);
    rect.setFill(Color.DODGERBLUE);
    getChildren().add(rect);
    
    fadeTransition = FadeTransitionBuilder.create()
        .duration(Duration.seconds(4))
        .node(rect)
        .fromValue(1)
        .toValue(0.2)
        .cycleCount(Timeline.INDEFINITE)
        .autoReverse(true)
        .build();
}
 
Example 7
Source File: FadeTransitionSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public FadeTransitionSample() {
    super(100,100);
    Rectangle rect = new Rectangle(0, 0, 100, 100);
    rect.setArcHeight(20);
    rect.setArcWidth(20);
    rect.setFill(Color.DODGERBLUE);
    getChildren().add(rect);
    
    fadeTransition = FadeTransitionBuilder.create()
        .duration(Duration.seconds(4))
        .node(rect)
        .fromValue(1)
        .toValue(0.2)
        .cycleCount(Timeline.INDEFINITE)
        .autoReverse(true)
        .build();
}
 
Example 8
Source File: Exercise_16_08.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
/** 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 9
Source File: PauseTransitionSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public PauseTransitionSample() {
    super(400,150);
    // create rectangle
    Rectangle rect = new Rectangle(-25,-25,50, 50);
    rect.setArcHeight(15);
    rect.setArcWidth(15);
    rect.setFill(Color.CRIMSON);
    rect.setTranslateX(50);
    rect.setTranslateY(75);
    getChildren().add(rect);
    
    animation = SequentialTransitionBuilder.create()
        .node(rect)
        .children(
            TranslateTransitionBuilder.create()
                .duration(Duration.seconds(2))
                .fromX(50)
                .toX(200)
                .build(),
            PauseTransitionBuilder.create()
                .duration(Duration.seconds(2))
                .build(),
            TranslateTransitionBuilder.create()
                .duration(Duration.seconds(2))
                .fromX(200)
                .toX(350)
                .build()
        )
        .cycleCount(Timeline.INDEFINITE)
        .autoReverse(true)
        .build();                
}
 
Example 10
Source File: Exercise_15_13.java    From Intro-to-Java-Programming with MIT License 5 votes vote down vote up
@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 11
Source File: Board.java    From util4j with Apache License 2.0 5 votes vote down vote up
private Rectangle createCell(int i, int j){
    final double arcSize = CELL_SIZE / 6d;
    Rectangle cell = new Rectangle(i * CELL_SIZE, j * CELL_SIZE, CELL_SIZE, CELL_SIZE);
    // provide default style in case css are not loaded
    cell.setFill(Color.WHITE);
    cell.setStroke(Color.GREY);
    cell.setArcHeight(arcSize);
    cell.setArcWidth(arcSize);
    cell.getStyleClass().add("game-grid-cell");
    return cell;
}
 
Example 12
Source File: AreaShareChart.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
public AreaShareChart(@Nonnull ModularFeatureListRow row, AtomicDouble progress) {
  Float sum = row.streamFeatures().map(ModularFeature::getArea).filter(p -> p.getValue() != null)
      .map(Property<Float>::getValue).reduce(0f, Float::sum);

  List<Rectangle> all = new ArrayList<>();
  int i = 0;
  int size = row.getFeatures().size();
  for (Entry<RawDataFile, ModularFeature> entry : row.getFeatures().entrySet()) {
    Property<Float> areaProperty = entry.getValue().get(AreaType.class);
    if (areaProperty.getValue() != null) {
      // color from sample
      Color color = entry.getValue().get(RawColorType.class).getValue();
      if (color == null)
        color = Color.DARKORANGE;

      float ratio = areaProperty.getValue() / sum;
      Rectangle rect = new Rectangle();
      rect.setFill(color);
      // bind width
      rect.widthProperty().bind(this.widthProperty().multiply(ratio));
      rect.setHeight(i % 2 == 0 ? 20 : 25);
      all.add(rect);
      i++;
      if (progress != null)
        progress.addAndGet(1.0 / size);
    }
  }
  HBox box = new HBox(0, all.toArray(Rectangle[]::new));
  box.setPrefWidth(100);
  box.setAlignment(Pos.CENTER_LEFT);

  this.getChildren().add(box);
}
 
Example 13
Source File: SpecklesView.java    From narjillos with MIT License 5 votes vote down vote up
public SpecklesView(Viewport viewport, long ecosystemSize) {
	this.viewport = viewport;

	createBackgroundTextures();

	background = new Rectangle(0, 0, ecosystemSize, ecosystemSize);
	background.setFill(new ImagePattern(backgroundTexture, 0, 0, viewport.getSizeSC().x, viewport.getSizeSC().y, false));

	infraredBackground = new Rectangle(0, 0, ecosystemSize, ecosystemSize);
	infraredBackground
			.setFill(new ImagePattern(infraredBackgroundTexture, 0, 0, viewport.getSizeSC().x, viewport.getSizeSC().y, false));
}
 
Example 14
Source File: AudioClipSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static Group createRectangle(Color color, double tx, double ty, double sx, double sy) {
    Group squareGroup = new Group();
    Rectangle squareShape = new Rectangle(1.0, 1.0);
    squareShape.setFill(color);
    squareShape.setTranslateX(-0.5);
    squareShape.setTranslateY(-0.5);
    squareGroup.getChildren().add(squareShape);
    squareGroup.setTranslateX(tx);
    squareGroup.setTranslateY(ty);
    squareGroup.setScaleX(sx);
    squareGroup.setScaleY(sy);
    return squareGroup;
}
 
Example 15
Source File: StopWatchSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
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 16
Source File: ColorTileSkin.java    From tilesfx with Apache License 2.0 4 votes vote down vote up
@Override protected void initGraphics() {
    super.initGraphics();

    gradientLookup = new GradientLookup();

    if (tile.getSections().isEmpty()) {
        tile.setSections(new Section(0.00, 0.25, ColorSkin.GREEN),
                         new Section(0.25, 0.50, ColorSkin.YELLOW),
                         new Section(0.50, 0.75, ColorSkin.ORANGE),
                         new Section(0.75, 1.00, ColorSkin.RED));
    }
    tile.setBackgroundColor(tile.getSections().get(0).getColor());

    titleText = new Text();
    titleText.setFill(tile.getTitleColor());
    Helper.enableNode(titleText, !tile.getTitle().isEmpty());

    valueText = new Text(String.format(locale, formatString, ((tile.getValue() - minValue) / range * 100)));
    valueText.setFill(tile.getValueColor());
    valueText.setTextOrigin(VPos.BASELINE);
    Helper.enableNode(valueText, tile.isValueVisible());

    upperUnitText = new Text("");
    upperUnitText.setFill(tile.getUnitColor());
    Helper.enableNode(upperUnitText, !tile.getUnit().isEmpty());

    fractionLine = new Line();

    unitText = new Text(tile.getUnit());
    unitText.setFill(tile.getUnitColor());
    Helper.enableNode(unitText, !tile.getUnit().isEmpty());

    unitFlow = new VBox(upperUnitText, unitText);
    unitFlow.setAlignment(Pos.CENTER_RIGHT);

    valueUnitFlow = new HBox(valueText, unitFlow);
    valueUnitFlow.setAlignment(Pos.CENTER);
    valueUnitFlow.setMouseTransparent(true);

    barBackground = new Rectangle();
    barBackground.setFill(tile.getBarBackgroundColor());

    bar = new Rectangle();
    bar.setFill(tile.getForegroundColor());

    getPane().getChildren().addAll(titleText, valueUnitFlow, fractionLine, barBackground, bar);
}
 
Example 17
Source File: ScaleSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public ScaleSample() {
    super(180,180);
    // simple rectangle
    Rectangle rect1 = new Rectangle(0, 25, 25, 25);
    rect1.setArcHeight(15);
    rect1.setArcWidth(15);
    rect1.setFill(Color.WHITE);
    rect1.setStroke(Color.DODGERBLUE);
    rect1.setStrokeWidth(3);
    
    Polygon arrow = createArrow();
    arrow.setLayoutX(46);
    arrow.setLayoutY(22);
    arrow.setRotate(90);
    
    // simple rectangle with scale 2 in X axis and 0.5 in Y
    Rectangle rect2 = new Rectangle(95, 25, 25, 25);
    rect2.setArcHeight(15);
    rect2.setArcWidth(15);
    rect2.setFill(Color.WHITE);
    rect2.setStroke(Color.DODGERBLUE);
    rect2.setStrokeWidth(3);
    rect2.setScaleX(2);
    rect2.setScaleY(0.5);
    // rectangle with adjustable scale
    Rectangle rect3 = new Rectangle(40, 130, 25, 25);
    rect3.setArcHeight(15);
    rect3.setArcWidth(15);
    rect3.setFill(Color.WHITE);
    rect3.setStroke(Color.DODGERBLUE);
    rect3.setStrokeWidth(3);
    rect3.setScaleX(6);
    rect3.setScaleY(0.5);
    rect3.setTranslateX(rect3.getTranslateX()+30);
    //getChildren().addAll(rect1, rect2, rect3);
    getChildren().addAll(rect1, arrow, rect2, rect3);
    
    // REMOVE ME
    setControls(
            new SimplePropertySheet.PropDesc("Scale X", rect3.scaleXProperty(), 0.1d, 16d),
            new SimplePropertySheet.PropDesc("Scale Y", rect3.scaleYProperty(), 0.1d, 4d)
    );
    // END REMOVE ME
}
 
Example 18
Source File: DynamicAnchorConnectionSnippet.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public Scene createScene() {
	BorderPane root = new BorderPane();
	Scene scene = new Scene(root, 640, 480);

	nodeA = new Rectangle(50, 50);
	nodeA.setFill(Color.RED);

	nodeB = new Rectangle(50, 50);
	nodeB.setFill(Color.BLUE);

	nodeC = new Rectangle(50, 50);
	nodeC.setFill(Color.GREEN);

	Button btnA = new Button("move A");
	btnA.setOnAction(createMoveHandler("A", nodeA, 100, 100, 200));
	btnA.relocate(0, 0);

	Button btnB = new Button("move B");
	btnB.setOnAction(createMoveHandler("B", nodeB, 300, 100, 200));
	btnB.relocate(70, 0);

	Button btnC = new Button("move C");
	btnC.setOnAction(createMoveHandler("C", nodeC, 200, 200, 300));
	btnC.relocate(140, 0);

	Connection connectionAB = new Connection();
	Connection connectionBC = new Connection();

	Group group = new Group(nodeA, nodeB, nodeC, connectionAB, connectionBC,
			btnA, btnB, btnC);
	root.getChildren().add(group);

	anchorA = new DynamicAnchor(nodeA);
	anchorB = new DynamicAnchor(nodeB);
	anchorC = new DynamicAnchor(nodeC);
	connectionAB.setStartAnchor(anchorA);
	connectionAB.setEndAnchor(anchorB);
	connectionBC.setStartAnchor(anchorB);
	connectionBC.setEndAnchor(anchorC);

	nodeA.relocate(100, 100);
	nodeB.relocate(300, 100);
	nodeC.relocate(200, 200);

	return scene;
}
 
Example 19
Source File: SwitchTileSkin.java    From OEE-Designer with MIT License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override protected void initGraphics() {
       super.initGraphics();

       mouseEventHandler = e -> {
           final EventType TYPE = e.getEventType();
           if (MouseEvent.MOUSE_PRESSED == TYPE) {
               tile.setActive(!tile.isActive());
               tile.fireEvent(SWITCH_PRESSED);
           } else if(MouseEvent.MOUSE_RELEASED == TYPE) {
               tile.fireEvent(SWITCH_RELEASED);
           }
       };
       selectedListener = o -> moveThumb();

       timeline = new Timeline();

       titleText = new Text();
       titleText.setFill(tile.getTitleColor());
       Helper.enableNode(titleText, !tile.getTitle().isEmpty());

       text = new Text(tile.getText());
       text.setFill(tile.getUnitColor());
       Helper.enableNode(text, tile.isTextVisible());

       description = new Label(tile.getDescription());
       description.setAlignment(tile.getDescriptionAlignment());
       description.setWrapText(true);
       description.setTextFill(tile.getTextColor());
       Helper.enableNode(description, !tile.getDescription().isEmpty());

       switchBorder = new Rectangle();

       switchBackground = new Rectangle();
       switchBackground.setMouseTransparent(true);
       switchBackground.setFill(tile.isActive() ? tile.getActiveColor() : tile.getBackgroundColor());

       thumb = new Circle();
       thumb.setMouseTransparent(true);
       thumb.setEffect(shadow);

       getPane().getChildren().addAll(titleText, text, description, switchBorder, switchBackground, thumb);
   }
 
Example 20
Source File: JFXSpinnerSkin.java    From JFoenix with Apache License 2.0 3 votes vote down vote up
public JFXSpinnerSkin(JFXSpinner control) {
    super(control, new BehaviorBase<JFXSpinner>(control, Collections.emptyList()));

    this.control = control;

    blueColor = Color.valueOf("#4285f4");
    redColor = Color.valueOf("#db4437");
    yellowColor = Color.valueOf("#f4b400");
    greenColor = Color.valueOf("#0F9D58");

    arc = new Arc();
    arc.setManaged(false);
    arc.setStartAngle(0);
    arc.setLength(180);
    arc.getStyleClass().setAll("arc");
    arc.setFill(Color.TRANSPARENT);
    arc.setStrokeWidth(3);

    track = new Arc();
    track.setManaged(false);
    track.setStartAngle(0);
    track.setLength(360);
    track.setStrokeWidth(3);
    track.getStyleClass().setAll("track");
    track.setFill(Color.TRANSPARENT);

    fillRect = new Rectangle();
    fillRect.setFill(Color.TRANSPARENT);
    text = new Text();
    text.getStyleClass().setAll("text", "percentage");
    final Group group = new Group(fillRect, track, arc, text);
    group.setManaged(false);
    arcPane = new StackPane(group);
    arcPane.setPrefSize(50, 50);
    getChildren().setAll(arcPane);

    // register listeners
    registerChangeListener(control.indeterminateProperty(), "INDETERMINATE");
    registerChangeListener(control.progressProperty(), "PROGRESS");
    registerChangeListener(control.visibleProperty(), "VISIBLE");
    registerChangeListener(control.parentProperty(), "PARENT");
    registerChangeListener(control.sceneProperty(), "SCENE");
}