下面列出了javafx.scene.text.Text#setFill ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public Node buildIcon(StringFormat format, byte[] value) {
Text t = new Text(format.format(format.value(value)));
t.setFont(Font.font(ExternalFonts.SOURCESANSPRO_BLACK, FontWeight.BOLD, 32.0));
t.setFill(Color.WHITE);
DropShadow dropShadow = new DropShadow();
dropShadow.setRadius(4.0);
dropShadow.setColor(Color.BLACK /* valueOf("#4b5157")*/);
dropShadow.setBlurType(BlurType.ONE_PASS_BOX);
t.setEffect(dropShadow);
return t;
}
private void drawText() {
final double CENTER_X = 0.5 * width;
final double CENTER_Y = 0.5 * height;
final int NO_OF_SECTORS = getNoOfSectors();
Font font = Fonts.latoRegular(0.035 * size);
double radAngle = RadarChartMode.SECTOR == getMode() ? Math.toRadians(180 + angleStep * 0.5) : Math.toRadians(180);
double radAngleStep = Math.toRadians(angleStep);
textGroup.getChildren().clear();
for (int i = 0 ; i < NO_OF_SECTORS ; i++) {
double r = size * 0.48;
double x = CENTER_X - size * 0.015 + (-Math.sin(radAngle) * r);
double y = CENTER_Y + (+Math.cos(radAngle) * r);
Text text = new Text(data.get(i).getName());
text.setFont(font);
text.setFill(data.get(i).getTextColor());
text.setTextOrigin(VPos.CENTER);
text.setTextAlignment(TextAlignment.CENTER);
text.setRotate(Math.toDegrees(radAngle) - 180);
text.setX(x);
text.setY(y);
textGroup.getChildren().add(text);
radAngle += radAngleStep;
}
}
@Override
public void updateItem(TemplateInfo item, boolean empty) {
super.updateItem(item, empty);
if (item == null) {
setGraphic(null);
setText(null);
} else {
Text t = IconBuilder.create(IconFontGlyph.valueOf(item.icon), 18.0).build();
t.setFill(Color.WHITE);
TextFlow tf = new TextFlow(t);
tf.setTextAlignment(TextAlignment.CENTER);
tf.setPadding(new Insets(5, 5, 5, 5));
tf.setStyle("-fx-background-color: #505050; -fx-background-radius: 5px;");
tf.setPrefWidth(30.0);
setGraphic(tf);
setText(item.name);
}
}
private void createLetter(String c) {
final Text letter = new Text(c);
letter.setFill(Color.BLACK);
letter.setFont(FONT_DEFAULT);
letter.setTextOrigin(VPos.TOP);
letter.setTranslateX((getWidth() - letter.getBoundsInLocal().getWidth()) / 2);
letter.setTranslateY((getHeight() - letter.getBoundsInLocal().getHeight()) / 2);
getChildren().add(letter);
// over 3 seconds move letter to random position and fade it out
final Timeline timeline = new Timeline();
timeline.getKeyFrames().add(
new KeyFrame(Duration.seconds(3), new EventHandler<ActionEvent>() {
@Override public void handle(ActionEvent event) {
// we are done remove us from scene
getChildren().remove(letter);
}
},
new KeyValue(letter.translateXProperty(), getRandom(0.0f, getWidth() - letter.getBoundsInLocal().getWidth()),INTERPOLATOR),
new KeyValue(letter.translateYProperty(), getRandom(0.0f, getHeight() - letter.getBoundsInLocal().getHeight()),INTERPOLATOR),
new KeyValue(letter.opacityProperty(), 0f)
));
timeline.play();
}
@Override protected void initGraphics() {
super.initGraphics();
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());
ledBorder = new Circle();
led = new Circle();
hightlight = new Circle();
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * size, 0, 0, 0);
led.setEffect(innerShadow);
getPane().getChildren().addAll(titleText, text, description, ledBorder, led, hightlight);
}
@Override protected void initGraphics() {
super.initGraphics();
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());
LocalTime duration = tile.getDuration();
leftText = new Text(Integer.toString(duration.getHour() > 0 ? duration.getHour() : duration.getMinute()));
leftText.setFill(tile.getValueColor());
leftUnit = new Text(duration.getHour() > 0 ? "h" : "m");
leftUnit.setFill(tile.getValueColor());
rightText = new Text(Integer.toString(duration.getHour() > 0 ? duration.getMinute() : duration.getSecond()));
rightText.setFill(tile.getValueColor());
rightUnit = new Text(duration.getHour() > 0 ? "m" : "s");
rightUnit.setFill(tile.getValueColor());
timeText = new TextFlow(leftText, leftUnit, rightText, rightUnit);
timeText.setTextAlignment(TextAlignment.RIGHT);
timeText.setPrefWidth(PREFERRED_WIDTH * 0.9);
description = new Label(tile.getDescription());
description.setAlignment(Pos.TOP_RIGHT);
description.setWrapText(true);
description.setTextFill(tile.getDescriptionColor());
Helper.enableNode(description, !tile.getDescription().isEmpty());
getPane().getChildren().addAll(titleText, text, timeText, description);
}
private void initGraphics() {
regularFont = Fonts.latoRegular(10);
lightFont = Fonts.latoLight(10);
itemText = new Text("NAME");
itemText.setFill(_textColor);
itemText.setFont(regularFont);
itemNameText = new Text("-");
itemNameText.setFill(_textColor);
itemNameText.setFont(regularFont);
line = new Line(0, 0, 0, 56);
line.setStroke(_textColor);
vBoxTitles = new VBox(2, itemText);
vBoxTitles.setAlignment(Pos.CENTER_LEFT);
VBox.setMargin(itemText, new Insets(3, 0, 0, 0));
vBoxValues = new VBox(2, itemNameText);
vBoxValues.setAlignment(Pos.CENTER_RIGHT);
VBox.setMargin(itemNameText, new Insets(3, 0, 0, 0));
HBox.setHgrow(vBoxValues, Priority.ALWAYS);
hBox = new HBox(5, vBoxTitles, line, vBoxValues);
hBox.setPrefSize(120, 69);
hBox.setPadding(new Insets(5));
hBox.setBackground(new Background(new BackgroundFill(_backgroundColor, new CornerRadii(3), Insets.EMPTY)));
hBox.setMouseTransparent(true);
getContent().addAll(hBox);
}
@Override protected void initGraphics() {
super.initGraphics();
updateHandler = e -> {
final EventType TYPE = e.getType();
switch (TYPE) {
case UPDATE : updateChart(); break;
case FINISHED: sortItems(); break;
}
};
paneSizeListener = o -> resizeItems();
handlerMap = new HashMap<>();
registerItemListeners();
tile.getLeaderBoardItems().forEach(item -> item.setItemSortingTopic(tile.getItemSortingTopic()));
leaderBoardPane = new Pane();
leaderBoardPane.getChildren().addAll(tile.getLeaderBoardItems());
sortItems();
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());
getPane().getChildren().addAll(titleText, text, leaderBoardPane);
}
public static Node createIconContent() {
Text sample = new Text("FX");
sample.setFont(Font.font(Font.getDefault().getFamily(), FontWeight.BOLD,80));
sample.setStyle("-fx-font-size: 80px;");
sample.setFill(Color.web("#aaaaaa"));
final InnerShadow innerShadow = new InnerShadow();
innerShadow.setRadius(4);
innerShadow.setOffsetX(1);
innerShadow.setOffsetY(1);
innerShadow.setColor(Color.web("#333333"));
sample.setEffect(innerShadow);
return sample;
}
@Override protected void initGraphics() {
super.initGraphics();
sunburstChart = tile.getSunburstChart();
titleText = new Text();
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
text = new Text(tile.getText());
text.setFill(tile.getTextColor());
Helper.enableNode(text, tile.isTextVisible());
getPane().getChildren().addAll(titleText, sunburstChart, text);
}
public Node toNode(int ticksInLastSecond, String environmentStatistics, String performanceStatistics, Speed speed, Effects effects,
String trackingStatus, boolean isBusy) {
String message = "FPS: " + ticksInLastSecond + " / " + performanceStatistics + "\n" +
environmentStatistics + "\n" +
getSpeedMessage(speed, effects) + "\n" +
"Mode: " + trackingStatus + "\n" +
getBusyMessage(isBusy);
Text result = new Text(message);
result.setFont(Font.font("HelveticaNeue-Bold", 14));
result.setFill(speed.getViewColor());
result.setTranslateX(5);
result.setTranslateY(15);
return result;
}
@Override protected void initGraphics() {
super.initGraphics();
final ZonedDateTime TIME = tile.getTime();
titleText = new Text(MONTH_YEAR_FORMATTER.format(TIME));
titleText.setFill(tile.getTitleColor());
clickHandler = e -> checkClick(e);
labels = new ArrayList<>(56);
for (int i = 0 ; i < 56 ; i++) {
Label label = new Label();
label.setManaged(false);
label.setVisible(false);
label.setAlignment(Pos.CENTER);
label.addEventHandler(MouseEvent.MOUSE_PRESSED, clickHandler);
labels.add(label);
}
weekBorder = new Border(new BorderStroke(Color.TRANSPARENT,
Tile.GRAY,
Color.TRANSPARENT,
Color.TRANSPARENT,
BorderStrokeStyle.NONE,
BorderStrokeStyle.SOLID,
BorderStrokeStyle.NONE,
BorderStrokeStyle.NONE,
CornerRadii.EMPTY, BorderWidths.DEFAULT,
Insets.EMPTY));
text = new Text(DAY_FORMATTER.format(TIME));
text.setFill(tile.getTextColor());
getPane().getChildren().addAll(titleText, text);
getPane().getChildren().addAll(labels);
}
@Override protected void initGraphics() {
super.initGraphics();
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());
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());
unitText = new Text(" " + tile.getUnit());
unitText.setFill(tile.getUnitColor());
unitText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(unitText, !tile.getUnit().isEmpty());
valueUnitFlow = new TextFlow(valueText, unitText);
valueUnitFlow.setTextAlignment(TextAlignment.RIGHT);
description = new Label(tile.getText());
description.setAlignment(tile.getDescriptionAlignment());
description.setWrapText(true);
description.setTextFill(tile.getTextColor());
Helper.enableNode(description, tile.isTextVisible());
getPane().getChildren().addAll(titleText, text, valueUnitFlow, description);
}
@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));
}
public Node toNode(String message) {
Text result = new Text(" " + message + getSlowMotionMessage());
result.setFont(Font.font("HelveticaNeue-Bold", fontSize));
result.setFill(Color.LIGHTGREEN);
result.setTranslateY(fontSize);
return result;
}
private void initializeContainers(Node node, boolean fullScreen, boolean max, boolean min) {
buttonsContainer = new HBox();
buttonsContainer.getStyleClass().add("jfx-decorator-buttons-container");
buttonsContainer.setBackground(new Background(new BackgroundFill(Color.BLACK,
CornerRadii.EMPTY,
Insets.EMPTY)));
// BINDING
buttonsContainer.setPadding(new Insets(4));
buttonsContainer.setAlignment(Pos.CENTER_RIGHT);
// customize decorator buttons
List<JFXButton> btns = new ArrayList<>();
if (fullScreen) {
btns.add(btnFull);
}
if (min) {
btns.add(btnMin);
}
if (max) {
btns.add(btnMax);
// maximize/restore the window on header double click
buttonsContainer.addEventHandler(MouseEvent.MOUSE_CLICKED, (mouseEvent) -> {
if (mouseEvent.getClickCount() == 2) {
btnMax.fire();
}
});
}
btns.add(btnClose);
text = new Text();
text.getStyleClass().addAll("jfx-decorator-text", "title", "jfx-decorator-title");
text.setFill(Color.WHITE);
text.textProperty().bind(title); //binds the Text's text to title
title.bind(primaryStage.titleProperty()); //binds title to the primaryStage's title
graphicContainer = new HBox();
graphicContainer.setPickOnBounds(false);
graphicContainer.setAlignment(Pos.CENTER_LEFT);
graphicContainer.getChildren().setAll(text);
HBox graphicTextContainer = new HBox(graphicContainer, text);
graphicTextContainer.getStyleClass().add("jfx-decorator-title-container");
graphicTextContainer.setAlignment(Pos.CENTER_LEFT);
graphicTextContainer.setPickOnBounds(false);
HBox.setHgrow(graphicTextContainer, Priority.ALWAYS);
HBox.setMargin(graphicContainer, new Insets(0, 8, 0, 8));
buttonsContainer.getChildren().setAll(graphicTextContainer);
buttonsContainer.getChildren().addAll(btns);
buttonsContainer.addEventHandler(MouseEvent.MOUSE_ENTERED, (enter) -> allowMove = true);
buttonsContainer.addEventHandler(MouseEvent.MOUSE_EXITED, (enter) -> {
if (!isDragging) {
allowMove = false;
}
});
buttonsContainer.setMinWidth(180);
contentPlaceHolder.getStyleClass().add("jfx-decorator-content-container");
contentPlaceHolder.setMinSize(0, 0);
StackPane clippedContainer = new StackPane(node);
contentPlaceHolder.getChildren().add(clippedContainer);
((Region) node).setMinSize(0, 0);
VBox.setVgrow(contentPlaceHolder, Priority.ALWAYS);
contentPlaceHolder.getStyleClass().add("resize-border");
contentPlaceHolder.setBorder(new Border(new BorderStroke(Color.BLACK,
BorderStrokeStyle.SOLID,
CornerRadii.EMPTY,
new BorderWidths(0, 4, 4, 4))));
// BINDING
Rectangle clip = new Rectangle();
clip.widthProperty().bind(clippedContainer.widthProperty());
clip.heightProperty().bind(clippedContainer.heightProperty());
clippedContainer.setClip(clip);
this.getChildren().addAll(buttonsContainer, contentPlaceHolder);
}
@Override protected void initGraphics() {
super.initGraphics();
if (tile.isAutoScale()) tile.calcAutoScale();
gradientLookup = new GradientLookup(tile.getGradientStops());
noOfGradientStops = tile.getGradientStops().size();
sectionsVisible = tile.getSectionsVisible();
colorGradientEnabled = tile.isStrokeWithGradient();
titleText = new Text(tile.getTitle());
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, tile.getValue()));
valueText.setFill(tile.getValueColor());
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);
text = new Text(tile.getText());
text.setTextOrigin(VPos.TOP);
text.setFill(tile.getTextColor());
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.4, PREFERRED_HEIGHT * 0.4, 0, ANGLE_RANGE);
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(tile.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, 270, 0);
bar.setType(ArcType.OPEN);
bar.setStroke(tile.getBarColor());
bar.setStrokeWidth(PREFERRED_WIDTH * 0.125);
bar.setStrokeLineCap(StrokeLineCap.BUTT);
bar.setFill(null);
lowerThreshold = new Line();
lowerThreshold.setStroke(tile.getLowerThresholdColor());
lowerThreshold.setStrokeLineCap(StrokeLineCap.BUTT);
Helper.enableNode(lowerThreshold, tile.isLowerThresholdVisible());
lowerThresholdText = new Text(String.format(locale, formatString, tile.getLowerThreshold()));
Helper.enableNode(lowerThresholdText, tile.isLowerThresholdVisible());
threshold = new Line();
threshold.setStroke(tile.getThresholdColor());
threshold.setStrokeLineCap(StrokeLineCap.BUTT);
Helper.enableNode(threshold, tile.isThresholdVisible());
thresholdText = new Text(String.format(locale, formatString, tile.getThreshold()));
Helper.enableNode(thresholdText, tile.isThresholdVisible());
minValueText = new Text();
maxValueText = new Text();
getPane().getChildren().addAll(barBackground, bar, lowerThreshold, lowerThresholdText, threshold, thresholdText, minValueText, maxValueText, titleText, valueUnitFlow, fractionLine, text);
}
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);
}
}
colorRing = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.5);
colorRing.setFill(Color.TRANSPARENT);
colorRing.setStrokeWidth(PREFERRED_WIDTH * 0.0075);
colorRing.setStroke(gauge.getBarColor());
bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.468, PREFERRED_HEIGHT * 0.468, 90, 0);
bar.setType(ArcType.OPEN);
bar.setStroke(gauge.getBarColor());
bar.setStrokeWidth(PREFERRED_WIDTH * 0.15);
bar.setStrokeLineCap(StrokeLineCap.BUTT);
bar.setFill(null);
separator = new Line(PREFERRED_WIDTH * 0.5, 1, PREFERRED_WIDTH * 0.5, 0.16667 * PREFERRED_HEIGHT);
separator.setStroke(gauge.getBorderPaint());
separator.setFill(Color.TRANSPARENT);
titleText = new Text(gauge.getTitle());
titleText.setFont(Fonts.robotoLight(PREFERRED_WIDTH * 0.08));
titleText.setFill(gauge.getTitleColor());
Helper.enableNode(titleText, !gauge.getTitle().isEmpty());
valueText = new Text(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getCurrentValue()));
valueText.setFont(Fonts.robotoRegular(PREFERRED_WIDTH * 0.27333));
valueText.setFill(gauge.getValueColor());
Helper.enableNode(valueText, gauge.isValueVisible());
unitText = new Text(gauge.getUnit());
unitText.setFont(Fonts.robotoLight(PREFERRED_WIDTH * 0.08));
unitText.setFill(gauge.getUnitColor());
Helper.enableNode(unitText, !gauge.getUnit().isEmpty());
pane = new Pane(colorRing, bar, separator, titleText, valueText, unitText);
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);
}
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);
}
}
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, -angleRange);
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(gauge.getBarColor());
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setFill(null);
thresholdBar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, -angleRange * 0.5 + 90, 0);
thresholdBar.setType(ArcType.OPEN);
thresholdBar.setStroke(gauge.getThresholdColor());
thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
thresholdBar.setFill(null);
enableNode(thresholdBar, !gauge.getSectionsVisible());
sectionPane = new Pane();
enableNode(sectionPane, gauge.getSectionsVisible());
if (sectionsVisible) { drawSections(); }
alertIcon = new Path();
alertIcon.setFillRule(FillRule.EVEN_ODD);
alertIcon.setFill(Color.YELLOW);
alertIcon.setStroke(null);
enableNode(alertIcon, gauge.isAlert());
alertTooltip = new Tooltip(gauge.getAlertMessage());
Tooltip.install(alertIcon, alertTooltip);
needleRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);
needleRectRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);
needleRect = new Rectangle();
needleRect.setFill(gauge.getBackgroundPaint());
needleRect.getTransforms().setAll(needleRectRotate);
needle = new Path();
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
needle.setFill(gauge.getNeedleColor());
needle.setStrokeWidth(0);
needle.setStroke(Color.TRANSPARENT);
titleText = new Text(gauge.getTitle());
titleText.setFill(gauge.getTitleColor());
enableNode(titleText, !gauge.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, gauge.getCurrentValue()));
valueText.setFill(gauge.getValueColor());
enableNode(valueText, gauge.isValueVisible() && !gauge.isAlert());
unitText = new Text(gauge.getUnit());
unitText.setFill(gauge.getUnitColor());
enableNode(unitText, gauge.isValueVisible() && !gauge.isAlert());
minValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMinValue()));
minValueText.setFill(gauge.getTitleColor());
maxValueText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getMaxValue()));
maxValueText.setFill(gauge.getTitleColor());
thresholdRect = new Rectangle();
thresholdRect.setFill(sectionsVisible ? GRAY : gauge.getThresholdColor());
enableNode(thresholdRect, gauge.isThresholdVisible());
thresholdText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getThreshold()));
thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : gauge.getBackgroundPaint());
enableNode(thresholdText, gauge.isThresholdVisible());
pane = new Pane(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueText, unitText, minValueText, maxValueText, thresholdRect, thresholdText);
pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(gauge.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), new CornerRadii(PREFERRED_WIDTH * 0.025), Insets.EMPTY)));
getChildren().setAll(pane);
}
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);
}
}
shadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 12, 0, 3, 3);
textShadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 4, 0, 2, 2);
valueText = new Text(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getCurrentValue()));
valueText.setFill(Color.WHITE);
valueText.setFont(Fonts.robotoBold(PREFERRED_WIDTH * 0.20625));
valueText.setTextOrigin(VPos.CENTER);
valueText.relocate(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.46875);
valueText.setEffect(textShadow);
Helper.enableNode(valueText, gauge.isValueVisible());
unitText = new Text(gauge.getUnit());
unitText.setFill(Color.WHITE);
unitText.setFont(Fonts.robotoBold(PREFERRED_WIDTH * 0.0875));
unitText.setTextOrigin(VPos.CENTER);
unitText.relocate(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.65625);
unitText.setEffect(textShadow);
Helper.enableNode(unitText, !gauge.getUnit().isEmpty());
backgroundRing = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5,
PREFERRED_WIDTH * 0.43125, PREFERRED_HEIGHT * 0.43125,
0, 360);
backgroundRing.setFill(null);
backgroundRing.setStroke(Color.rgb(255, 255, 255, 0.9));
backgroundRing.setStrokeLineCap(StrokeLineCap.BUTT);
backgroundRing.setStrokeWidth(PREFERRED_WIDTH * 0.1375);
backgroundRing.setEffect(shadow);
barBackground = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5,
PREFERRED_WIDTH * 0.43125, PREFERRED_HEIGHT * 0.43125,
0, 360);
barBackground.setFill(null);
barBackground.setStroke(Color.rgb(255, 255, 255, 0.4));
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.1375);
bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5,
PREFERRED_WIDTH * 0.43125, PREFERRED_HEIGHT * 0.43125,
90, -gauge.getAngleStep() * gauge.getValue());
bar.setFill(null);
bar.setStroke(Color.WHITE);
bar.setStrokeWidth(PREFERRED_WIDTH * 0.1375);
bar.setStrokeLineCap(StrokeLineCap.BUTT);
pane = new Pane(valueText, unitText, backgroundRing, barBackground, bar);
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);
}