Java Code Examples for javafx.scene.text.Text#setStroke()

The following examples show how to use javafx.scene.text.Text#setStroke() . 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: FXStockToken.java    From Rails with GNU General Public License v2.0 6 votes vote down vote up
private void populate() {
    // fill the background
    Circle circle = new Circle();

    circle.centerXProperty().bind(Bindings.divide(widthProperty(), 2));
    circle.centerYProperty().bind(Bindings.divide(heightProperty(), 2));
    circle.radiusProperty().bind(Bindings.divide(widthProperty(), 2));

    circle.setFill(backgroundColor);

    Text text = new Text(name);

    text.setStroke(foregroundColor);
    text.setBoundsType(TextBoundsType.VISUAL);

    getChildren().addAll(circle, text);
}
 
Example 2
Source File: GeoWarsApp.java    From FXGLGames with MIT License 5 votes vote down vote up
@Override
protected void initUI() {
    Text scoreText = getUIFactoryService().newText("", Color.WHITE, 28);
    scoreText.setTranslateX(60);
    scoreText.setTranslateY(70);
    scoreText.textProperty().bind(getip("score").asString());
    scoreText.setStroke(Color.GOLD);

    Text multText = getUIFactoryService().newText("", Color.WHITE, 28);
    multText.setTranslateX(60);
    multText.setTranslateY(90);
    multText.textProperty().bind(getip("multiplier").asString("x %d"));

    var livesText = getUIFactoryService().newText("", Color.WHITE, 24.0);
    livesText.setTranslateX(60);
    livesText.setTranslateY(110);
    livesText.textProperty().bind(getip("lives").asString("Lives: %d"));

    getGameScene().addUINodes(multText, scoreText, livesText);

    Text beware = getUIFactoryService().newText("Beware! Seekers get smarter every spawn!", Color.AQUA, 38);

    addUINode(beware);

    centerText(beware);

    animationBuilder()
            .duration(Duration.seconds(2))
            .autoReverse(true)
            .repeat(2)
            .fadeIn(beware)
            .buildAndPlay();
}
 
Example 3
Source File: DigitalSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    backgroundCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    backgroundCtx    = backgroundCanvas.getGraphicsContext2D();
    
    barCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    barCtx    = barCanvas.getGraphicsContext2D();

    valueBkgText = new Text();
    valueBkgText.setStroke(null);
    valueBkgText.setFill(Helper.getTranslucentColorFrom(valueColor, 0.1));

    valueText = new Text();
    valueText.setStroke(null);
    valueText.setFill(valueColor);
    Helper.enableNode(valueText, gauge.isValueVisible());

    pane = new Pane(backgroundCanvas, barCanvas, valueBkgText, valueText);
    pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), new CornerRadii(1024), Insets.EMPTY)));
    pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(gauge.getBorderWidth()))));

    getChildren().setAll(pane);
}
 
Example 4
Source File: GeoWarsApp.java    From FXGLGames with MIT License 5 votes vote down vote up
@Override
protected void initUI() {
    Text scoreText = getUIFactoryService().newText("", Color.WHITE, 28);
    scoreText.setTranslateX(60);
    scoreText.setTranslateY(70);
    scoreText.textProperty().bind(getip("score").asString());
    scoreText.setStroke(Color.GOLD);

    Text multText = getUIFactoryService().newText("", Color.WHITE, 28);
    multText.setTranslateX(60);
    multText.setTranslateY(90);
    multText.textProperty().bind(getip("multiplier").asString("x %d"));

    var livesText = getUIFactoryService().newText("", Color.WHITE, 24.0);
    livesText.setTranslateX(60);
    livesText.setTranslateY(110);
    livesText.textProperty().bind(getip("lives").asString("Lives: %d"));

    getGameScene().addUINodes(multText, scoreText, livesText);

    Text beware = getUIFactoryService().newText("Beware! Seekers get smarter every spawn!", Color.AQUA, 38);

    addUINode(beware);

    centerText(beware);

    animationBuilder()
            .duration(Duration.seconds(2))
            .autoReverse(true)
            .repeat(2)
            .fadeIn(beware)
            .buildAndPlay();
}
 
Example 5
Source File: MenuItem.java    From FXTutorials with MIT License 5 votes vote down vote up
public MenuItem(String name, int width) {
    setAlignment(Pos.CENTER_LEFT);

    text = new Text(name);
    text.setTranslateX(5);
    text.setFont(font);
    text.setFill(Colors.MENU_TEXT);
    text.setStroke(Color.BLACK);

    shadow = new DropShadow(5, Color.BLACK);
    text.setEffect(shadow);

    selection = new Rectangle(width - 45, 30);
    selection.setFill(Colors.MENU_ITEM_SELECTION);
    selection.setStroke(Color.BLACK);
    selection.setVisible(false);

    GaussianBlur blur = new GaussianBlur(8);
    selection.setEffect(blur);

    getChildren().addAll(selection, text);

    setOnMouseEntered(e -> {
        onSelect();
    });

    setOnMouseExited(e -> {
        onDeselect();
    });

    setOnMousePressed(e -> {
        text.setFill(Color.YELLOW);
    });
}
 
Example 6
Source File: TimelineEventsSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public TimelineEventsSample() {
    super(70,70);
    //create a circle with effect
    final Circle circle = new Circle(20,  Color.rgb(156,216,255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text (i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    //create a timeline for moving the circle

    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //one can add a specific action when each frame is started. There are one or more frames during
    // executing one KeyFrame depending on set Interpolator.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }

    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.seconds(2);
    //one can add a specific action when the keyframe is reached
    EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
             stack.setTranslateX(java.lang.Math.random()*200-100);
             //reset counter
             i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    getChildren().add(stack);
}
 
Example 7
Source File: TimelineEventsSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public TimelineEventsSample() {
    super(70,70);
    //create a circle with effect
    final Circle circle = new Circle(20,  Color.rgb(156,216,255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text (i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    //create a timeline for moving the circle

    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //one can add a specific action when each frame is started. There are one or more frames during
    // executing one KeyFrame depending on set Interpolator.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }

    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.seconds(2);
    //one can add a specific action when the keyframe is reached
    EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
             stack.setTranslateX(java.lang.Math.random()*200-100);
             //reset counter
             i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    getChildren().add(stack);
}
 
Example 8
Source File: TimelineEvents.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void init(Stage primaryStage) {
    Group root = new Group();
    primaryStage.setResizable(false);
    primaryStage.setScene(new Scene(root, 260,100));
    //create a circle with effect
    final Circle circle = new Circle(20,  Color.rgb(156,216,255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text (i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    //create a timeline for moving the circle

    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //one can add a specific action when each frame is started. There are one or more frames during
    // executing one KeyFrame depending on set Interpolator.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }

    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.seconds(2);
    //one can add a specific action when the keyframe is reached
    EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
             stack.setTranslateX(java.lang.Math.random()*200);
             //reset counter
             i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    root.getChildren().add(stack);
}
 
Example 9
Source File: GeoWarsApp.java    From FXGLGames with MIT License 4 votes vote down vote up
private void addScoreKill(Point2D enemyPosition) {
    inc("kills", +1);

    if (geti("kills") == 15) {
        set("kills", 0);
        inc("multiplier", +1);
    }

    final int multiplier = geti("multiplier");

    inc("score", +100*multiplier);

    var shadow = new DropShadow(25, Color.WHITE);

    Text bonusText = getUIFactoryService().newText("+100" + (multiplier == 1 ? "" : "x" + multiplier), Color.color(1, 1, 1, 0.8), 24);
    bonusText.setStroke(Color.GOLD);
    bonusText.setEffect(shadow);

    var e = entityBuilder()
            .at(enemyPosition)
            .view(bonusText)
            .buildAndAttach();

    animationBuilder()
            .onFinished(() -> e.removeFromWorld())
            .interpolator(Interpolators.EXPONENTIAL.EASE_OUT())
            .translate(e)
            .from(enemyPosition)
            .to(enemyPosition.subtract(0, 65))
            .buildAndPlay();

    animationBuilder()
            .duration(Duration.seconds(0.35))
            .autoReverse(true)
            .repeat(2)
            .interpolator(Interpolators.BOUNCE.EASE_IN())
            .scale(e)
            .from(new Point2D(1, 1))
            .to(new Point2D(1.2, 0.85))
            .buildAndPlay();
}
 
Example 10
Source File: SimpleDigitalSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    arcExtend = gauge.getArcExtend();

    backgroundCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    backgroundCtx    = backgroundCanvas.getGraphicsContext2D();

    barCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    barCtx    = barCanvas.getGraphicsContext2D();

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

    valueBkgText = new Text();
    valueBkgText.setStroke(null);
    valueBkgText.setFill(Helper.getTranslucentColorFrom(valueColor, 0.1));
    Helper.enableNode(valueBkgText, gauge.isValueVisible());

    valueText = new Text();
    valueText.setStroke(null);
    valueText.setFill(valueColor);
    Helper.enableNode(valueText, gauge.isValueVisible());

    if (gauge.isGradientBarEnabled()) { setupGradient(); }

    pane = new Pane(backgroundCanvas, barCanvas, titleText, valueBkgText, valueText);
    pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(gauge.getBorderWidth()))));
    pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), new CornerRadii(1024), Insets.EMPTY)));

    getChildren().setAll(pane);
}
 
Example 11
Source File: SimpleSectionSkin.java    From Medusa with Apache License 2.0 4 votes vote down vote up
private void initGraphics() {
    // Set initial size
    if (Double.compare(gauge.getPrefWidth(), 0.0) <= 0 || Double.compare(gauge.getPrefHeight(), 0.0) <= 0 ||
        Double.compare(gauge.getWidth(), 0.0) <= 0 || Double.compare(gauge.getHeight(), 0.0) <= 0) {
        if (gauge.getPrefWidth() > 0 && gauge.getPrefHeight() > 0) {
            gauge.setPrefSize(gauge.getPrefWidth(), gauge.getPrefHeight());
        } else {
            gauge.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
        }
    }

    sectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
    sectionCtx    = sectionCanvas.getGraphicsContext2D();

    barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, gauge.getStartAngle() + 90, -ANGLE_RANGE);
    barBackground.setType(ArcType.OPEN);
    barBackground.setStroke(gauge.getBarBackgroundColor());
    barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.125);
    barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
    barBackground.setFill(null);

    bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, gauge.getStartAngle() + 90, 0);
    bar.setType(ArcType.OPEN);
    bar.setStroke(gauge.getBarColor());
    bar.setStrokeWidth(PREFERRED_WIDTH * 0.125);
    bar.setStrokeLineCap(StrokeLineCap.BUTT);
    bar.setFill(null);

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

    valueText = new Text();
    valueText.setStroke(null);
    valueText.setFill(gauge.getValueColor());
    Helper.enableNode(valueText, gauge.isValueVisible());

    unitText = new Text();
    unitText.setStroke(null);
    unitText.setFill(gauge.getUnitColor());
    Helper.enableNode(unitText, gauge.isValueVisible() && !gauge.getUnit().isEmpty());

    pane = new Pane(barBackground, sectionCanvas, titleText, valueText, unitText, bar);

    getChildren().setAll(pane);
}
 
Example 12
Source File: GeoWarsApp.java    From FXGLGames with MIT License 4 votes vote down vote up
private void addScoreKill(Point2D enemyPosition) {
    inc("kills", +1);

    if (geti("kills") == 15) {
        set("kills", 0);
        inc("multiplier", +1);
    }

    final int multiplier = geti("multiplier");

    inc("score", +100*multiplier);

    var shadow = new DropShadow(25, Color.WHITE);

    Text bonusText = getUIFactoryService().newText("+100" + (multiplier == 1 ? "" : "x" + multiplier), Color.color(1, 1, 1, 0.8), 24);
    bonusText.setStroke(Color.GOLD);
    bonusText.setEffect(shadow);

    var e = entityBuilder()
            .at(enemyPosition)
            .view(bonusText)
            .buildAndAttach();

    animationBuilder()
            .onFinished(() -> e.removeFromWorld())
            .interpolator(Interpolators.EXPONENTIAL.EASE_OUT())
            .translate(e)
            .from(enemyPosition)
            .to(enemyPosition.subtract(0, 65))
            .buildAndPlay();

    animationBuilder()
            .duration(Duration.seconds(0.35))
            .autoReverse(true)
            .repeat(2)
            .interpolator(Interpolators.BOUNCE.EASE_IN())
            .scale(e)
            .from(new Point2D(1, 1))
            .to(new Point2D(1.2, 0.85))
            .buildAndPlay();
}