下面列出了javafx.scene.shape.Path#setStroke ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
}
path = new Path();
path.setStroke(Color.TRANSPARENT);
icon = new Path();
icon.setStroke(Color.TRANSPARENT);
tooltip = new Tooltip("");
getChildren().setAll(path, icon);
}
public static Node createIconContent() {
Path path = new Path();
path.getElements().addAll(
new MoveTo(25, 25),
new HLineTo(45),
new ArcTo(20, 20, 0, 80, 25, true, true)
);
path.setStroke(Color.web("#b9c0c5"));
path.setStrokeWidth(5);
path.getStrokeDashArray().addAll(15d,15d);
path.setFill(null);
javafx.scene.effect.InnerShadow effect = new javafx.scene.effect.InnerShadow();
effect.setOffsetX(1);
effect.setOffsetY(1);
effect.setRadius(3);
effect.setColor(Color.rgb(0,0,0,0.6));
path.setEffect(effect);
return path;
}
private Path createSegment(final double START_ANGLE, final double END_ANGLE, final double INNER_RADIUS, final double OUTER_RADIUS, final Color FILL, final Color STROKE, final TreeNode NODE) {
double startAngleRad = Math.toRadians(START_ANGLE + 90);
double endAngleRad = Math.toRadians(END_ANGLE + 90);
boolean largeAngle = Math.abs(END_ANGLE - START_ANGLE) > 180.0;
double x1 = centerX + INNER_RADIUS * Math.sin(startAngleRad);
double y1 = centerY - INNER_RADIUS * Math.cos(startAngleRad);
double x2 = centerX + OUTER_RADIUS * Math.sin(startAngleRad);
double y2 = centerY - OUTER_RADIUS * Math.cos(startAngleRad);
double x3 = centerX + OUTER_RADIUS * Math.sin(endAngleRad);
double y3 = centerY - OUTER_RADIUS * Math.cos(endAngleRad);
double x4 = centerX + INNER_RADIUS * Math.sin(endAngleRad);
double y4 = centerY - INNER_RADIUS * Math.cos(endAngleRad);
MoveTo moveTo1 = new MoveTo(x1, y1);
LineTo lineTo2 = new LineTo(x2, y2);
ArcTo arcTo3 = new ArcTo(OUTER_RADIUS, OUTER_RADIUS, 0, x3, y3, largeAngle, true);
LineTo lineTo4 = new LineTo(x4, y4);
ArcTo arcTo1 = new ArcTo(INNER_RADIUS, INNER_RADIUS, 0, x1, y1, largeAngle, false);
Path path = new Path(moveTo1, lineTo2, arcTo3, lineTo4, arcTo1);
path.setFill(FILL);
path.setStroke(STROKE);
String tooltipText = new StringBuilder(NODE.getData().getName()).append("\n").append(String.format(Locale.US, formatString, NODE.getData().getValue())).toString();
Tooltip.install(path, new Tooltip(tooltipText));
path.setOnMousePressed(new WeakEventHandler<>(e -> NODE.getTreeRoot().fireTreeNodeEvent(new TreeNodeEvent(NODE, EventType.NODE_SELECTED))));
return path;
}
/**
* Node that represents the playing area/desktop where the puzzle pieces sit
*/
Desk(int numOfColumns, int numOfRows) {
setStyle("-fx-background-color: #cccccc; "
+ "-fx-border-color: #464646; "
+ "-fx-effect: innershadow( two-pass-box , rgba(0,0,0,0.8) , 15, 0.0 , 0 , 4 );");
double DESK_WIDTH = Piece.SIZE * numOfColumns;
double DESK_HEIGHT = Piece.SIZE * numOfRows;
setPrefSize(DESK_WIDTH, DESK_HEIGHT);
setMaxSize(DESK_WIDTH, DESK_HEIGHT);
autosize();
// create path for lines
Path grid = new Path();
grid.setStroke(Color.rgb(70, 70, 70));
getChildren().add(grid);
// create vertical lines
for (int col = 0; col < numOfColumns - 1; col++) {
grid.getElements().addAll(
new MoveTo(Piece.SIZE + Piece.SIZE * col, 5),
new LineTo(Piece.SIZE + Piece.SIZE * col, Piece.SIZE * numOfRows - 5));
}
// create horizontal lines
for (int row = 0; row < numOfRows - 1; row++) {
grid.getElements().addAll(
new MoveTo(5, Piece.SIZE + Piece.SIZE * row),
new LineTo(Piece.SIZE * numOfColumns - 5, Piece.SIZE + Piece.SIZE * row));
}
}
/**
* The constructor by default.
* @param border The selection border.
*/
public RotationHandler(final @NotNull Rectangle border) {
super();
final Arc arc = new Arc();
arc.setCenterX(DEFAULT_SIZE / 2d);
arc.setRadiusX(DEFAULT_SIZE / 2d);
arc.setRadiusY(DEFAULT_SIZE / 2d);
arc.setType(ArcType.OPEN);
arc.setLength(270d);
arc.setStroke(DEFAULT_COLOR);
arc.setStrokeWidth(2.5d);
arc.setStrokeLineCap(StrokeLineCap.BUTT);
arc.setFill(new Color(1d, 1d, 1d, 0d));
getChildren().add(arc);
final Path arrows = new Path();
arrows.setStroke(null);
arrows.setFill(new Color(0d, 0d, 0d, 0.4));
arrows.getElements().add(new MoveTo(DEFAULT_SIZE + DEFAULT_SIZE / 4d, 0d));
arrows.getElements().add(new LineTo(DEFAULT_SIZE, DEFAULT_SIZE / 2d));
arrows.getElements().add(new LineTo(DEFAULT_SIZE - DEFAULT_SIZE / 4d, 0d));
arrows.getElements().add(new ClosePath());
getChildren().add(arrows);
translateXProperty().bind(Bindings.createDoubleBinding(() -> border.getLayoutX() + border.getWidth(), border.xProperty(),
border.widthProperty(), border.layoutXProperty()));
translateYProperty().bind(Bindings.createDoubleBinding(() -> border.getLayoutY() + DEFAULT_SIZE, border.yProperty(),
border.heightProperty(), border.layoutYProperty()));
}
public PathSample() {
super(180,90);
// Create path shape - square
Path path1 = new Path();
path1.getElements().addAll(
new MoveTo(25, 25),
new HLineTo(65),
new VLineTo(65),
new LineTo(25, 65),
new ClosePath()
);
path1.setFill(null);
path1.setStroke(Color.RED);
path1.setStrokeWidth(2);
// Create path shape - curves
Path path2 = new Path();
path2.getElements().addAll(
new MoveTo(100, 45),
new CubicCurveTo(120, 20, 130, 80, 140, 45),
new QuadCurveTo(150, 0, 160, 45),
new ArcTo(20, 40, 0, 180, 45, true, true)
);
path2.setFill(null);
path2.setStroke(Color.DODGERBLUE);
path2.setStrokeWidth(2);
// show the path shapes;
getChildren().add(new Group(path1, path2));
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Path 1 Stroke", path1.strokeProperty()),
new SimplePropertySheet.PropDesc("Path 2 Stroke", path2.strokeProperty())
);
// END REMOVE ME
}
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);
}
}
batteryBackground = new Path();
batteryBackground.setFillRule(FillRule.EVEN_ODD);
batteryBackground.setStroke(null);
battery = new Path();
battery.setFillRule(FillRule.EVEN_ODD);
battery.setStroke(null);
valueText = new Text(String.format(locale, "%.0f%%", gauge.getCurrentValue()));
valueText.setVisible(gauge.isValueVisible());
valueText.setManaged(gauge.isValueVisible());
// Add all nodes
pane = new Pane();
pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1))));
pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));
pane.getChildren().setAll(batteryBackground, battery, valueText);
getChildren().setAll(pane);
}
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); // 11x7
}
}
state = State.CONSTANT;
triangle = new Path();
triangle.setStroke(null);
triangle.setFill(state.color);
triangle.setRotate(state.angle);
nameText = new Text(getName());
nameText.setTextOrigin(VPos.TOP);
valueText = new Text();
valueText.setTextOrigin(VPos.TOP);
updateValueText();
separator = new Line();
pane = new Pane(triangle, nameText, valueText, separator);
pane.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, CornerRadii.EMPTY, Insets.EMPTY)));
getChildren().setAll(pane);
}
@Override protected void initGraphics() {
super.initGraphics();
if (tile.isAutoScale()) tile.calcAutoScale();
oldValue = tile.getValue();
sectionMap = new HashMap<>(sections.size());
for(Section section : sections) { sectionMap.put(section, new Arc()); }
barColor = tile.getBarColor();
thresholdColor = tile.getThresholdColor();
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(barColor);
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(tile.getThresholdColor());
thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
thresholdBar.setFill(null);
Helper.enableNode(thresholdBar, !tile.getSectionsVisible());
sectionPane = new Pane();
Helper.enableNode(sectionPane, tile.getSectionsVisible());
if (sectionsVisible) { drawSections(); }
alertIcon = new Path();
alertIcon.setFillRule(FillRule.EVEN_ODD);
alertIcon.setFill(Color.YELLOW);
alertIcon.setStroke(null);
Helper.enableNode(alertIcon, tile.isAlert());
alertTooltip = new Tooltip(tile.getAlertMessage());
Tooltip.install(alertIcon, alertTooltip);
needleRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
needleRectRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
needleRect = new Rectangle();
needleRect.setFill(tile.getBackgroundColor());
needleRect.getTransforms().setAll(needleRectRotate);
needle = new Path();
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
needle.setFill(tile.getNeedleColor());
needle.setStrokeWidth(0);
needle.setStroke(Color.TRANSPARENT);
titleText = new Text(tile.getTitle());
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
valueText.setFill(tile.getValueColor());
valueText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());
unitText = new Text(tile.getUnit());
unitText.setFill(tile.getUnitColor());
unitText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(unitText, tile.isValueVisible() && !tile.isAlert());
valueUnitFlow = new TextFlow(valueText, unitText);
valueUnitFlow.setTextAlignment(TextAlignment.CENTER);
minValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMinValue()));
minValueText.setFill(tile.getTitleColor());
maxValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMaxValue()));
maxValueText.setFill(tile.getTitleColor());
thresholdRect = new Rectangle();
thresholdRect.setFill(sectionsVisible ? Color.TRANSPARENT : tile.getValue() > tile.getThreshold() ? tile.getThresholdColor() : Tile.GRAY);
Helper.enableNode(thresholdRect, tile.isThresholdVisible());
thresholdText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getThreshold()));
thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : Tile.GRAY);
Helper.enableNode(thresholdText, tile.isThresholdVisible());
getPane().getChildren().addAll(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueUnitFlow, minValueText, maxValueText, thresholdRect, thresholdText);
}
@Override protected void initGraphics() {
// Set initial size
if (Double.compare(clock.getPrefWidth(), 0.0) <= 0 || Double.compare(clock.getPrefHeight(), 0.0) <= 0 ||
Double.compare(clock.getWidth(), 0.0) <= 0 || Double.compare(clock.getHeight(), 0.0) <= 0) {
if (clock.getPrefWidth() > 0 && clock.getPrefHeight() > 0) {
clock.setPrefSize(clock.getPrefWidth(), clock.getPrefHeight());
} else {
clock.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
sectionsAndAreasCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
sectionsAndAreasCtx = sectionsAndAreasCanvas.getGraphicsContext2D();
tickCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
tickCtx = tickCanvas.getGraphicsContext2D();
alarmPane = new Pane();
hour = new Path();
hour.setFillRule(FillRule.EVEN_ODD);
hour.setStroke(null);
hour.getTransforms().setAll(hourRotate);
minute = new Path();
minute.setFillRule(FillRule.EVEN_ODD);
minute.setStroke(null);
minute.getTransforms().setAll(minuteRotate);
second = new Path();
second.setFillRule(FillRule.EVEN_ODD);
second.setStroke(null);
second.getTransforms().setAll(secondRotate);
second.setVisible(clock.isSecondsVisible());
second.setManaged(clock.isSecondsVisible());
knob = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.0148448);
knob.setStroke(null);
dropShadow = new DropShadow();
dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);
shadowGroupHour = new Group(hour);
shadowGroupMinute = new Group(minute);
shadowGroupSecond = new Group(second, knob);
shadowGroupHour.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
shadowGroupMinute.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
shadowGroupSecond.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
title = new Text("");
title.setVisible(clock.isTitleVisible());
title.setManaged(clock.isTitleVisible());
dateNumber = new Text("");
dateNumber.setVisible(clock.isDateVisible());
dateNumber.setManaged(clock.isDateVisible());
text = new Text("");
text.setVisible(clock.isTextVisible());
text.setManaged(clock.isTextVisible());
pane = new Pane(sectionsAndAreasCanvas, tickCanvas, alarmPane, title, dateNumber, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond);
pane.setBorder(new Border(new BorderStroke(clock.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(clock.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(clock.getBackgroundPaint(), new CornerRadii(1024), Insets.EMPTY)));
getChildren().setAll(pane);
}
@Override protected void initGraphics() {
// Set initial size
if (Double.compare(clock.getPrefWidth(), 0.0) <= 0 || Double.compare(clock.getPrefHeight(), 0.0) <= 0 ||
Double.compare(clock.getWidth(), 0.0) <= 0 || Double.compare(clock.getHeight(), 0.0) <= 0) {
if (clock.getPrefWidth() > 0 && clock.getPrefHeight() > 0) {
clock.setPrefSize(clock.getPrefWidth(), clock.getPrefHeight());
} else {
clock.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
mainInnerShadow0 = new InnerShadow();
mainInnerShadow0.setOffsetX(0.0);
mainInnerShadow0.setOffsetY(0.0);
mainInnerShadow0.setRadius(3.0 / 132.0 * PREFERRED_WIDTH);
mainInnerShadow0.setColor(Color.rgb(255, 255, 255, 0.5));
mainInnerShadow0.setBlurType(BlurType.TWO_PASS_BOX);
mainInnerShadow1 = new InnerShadow();
mainInnerShadow1.setOffsetX(0.0);
mainInnerShadow1.setOffsetY(1.0);
mainInnerShadow1.setRadius(2.0 / 132.0 * PREFERRED_WIDTH);
mainInnerShadow1.setColor(Color.rgb(0, 0, 0, 0.65));
mainInnerShadow1.setBlurType(BlurType.TWO_PASS_BOX);
mainInnerShadow1.setInput(mainInnerShadow0);
crystalClip = new Rectangle(0, 0, PREFERRED_WIDTH, PREFERRED_HEIGHT);
crystalClip.setArcWidth(5);
crystalClip.setArcHeight(5);
crystalImage = Helper.createNoiseImage(PREFERRED_WIDTH, PREFERRED_HEIGHT, DARK_NOISE_COLOR, BRIGHT_NOISE_COLOR, 8);
crystalOverlay = new ImageView(crystalImage);
crystalOverlay.setClip(crystalClip);
boolean crystalEnabled = clock.isLcdCrystalEnabled();
crystalOverlay.setManaged(crystalEnabled);
crystalOverlay.setVisible(crystalEnabled);
boolean secondsVisible = clock.isSecondsVisible();
backgroundTimeText = new Text("");
backgroundTimeText.setFill(clock.getLcdDesign().lcdBackgroundColor);
backgroundTimeText.setOpacity((LcdFont.LCD == clock.getLcdFont() || LcdFont.ELEKTRA == clock.getLcdFont()) ? 1 : 0);
backgroundSecondText = new Text("");
backgroundSecondText.setFill(clock.getLcdDesign().lcdBackgroundColor);
backgroundSecondText.setOpacity((LcdFont.LCD == clock.getLcdFont() || LcdFont.ELEKTRA == clock.getLcdFont()) ? 1 : 0);
backgroundSecondText.setManaged(secondsVisible);
backgroundSecondText.setVisible(secondsVisible);
timeText = new Text("");
timeText.setFill(clock.getLcdDesign().lcdForegroundColor);
secondText = new Text("");
secondText.setFill(clock.getLcdDesign().lcdForegroundColor);
secondText.setManaged(secondsVisible);
secondText.setVisible(secondsVisible);
title = new Text(clock.getTitle());
title.setFill(clock.getLcdDesign().lcdForegroundColor);
boolean titleVisible = clock.isTitleVisible();
title.setManaged(titleVisible);
title.setVisible(titleVisible);
dateText = new Text(dateFormat.format(clock.getTime()));
dateText.setFill(clock.getLcdDesign().lcdForegroundColor);
boolean dateVisible = clock.isDateVisible();
dateText.setManaged(dateVisible);
dateText.setVisible(dateVisible);
dayOfWeekText = new Text("");
dayOfWeekText.setFill(clock.getLcdDesign().lcdForegroundColor);
dayOfWeekText.setManaged(dateVisible);
dayOfWeekText.setVisible(dateVisible);
alarm = new Path();
alarm.setFillRule(FillRule.EVEN_ODD);
alarm.setStroke(null);
boolean alarmVisible = clock.getAlarms().size() > 0;
alarm.setManaged(alarmVisible);
alarm.setVisible(alarmVisible);
shadowGroup = new Group();
shadowGroup.setEffect(clock.getShadowsEnabled() ? FOREGROUND_SHADOW : null);
shadowGroup.getChildren().setAll(timeText,
secondText,
title,
dateText,
dayOfWeekText,
alarm);
pane = new Pane();
pane.setEffect(clock.getShadowsEnabled() ? mainInnerShadow1 : null);
pane.getChildren().setAll(crystalOverlay,
backgroundTimeText,
backgroundSecondText,
shadowGroup);
getChildren().setAll(pane);
}
@Override protected void initGraphics() {
// Set initial size
if (Double.compare(clock.getPrefWidth(), 0.0) <= 0 || Double.compare(clock.getPrefHeight(), 0.0) <= 0 ||
Double.compare(clock.getWidth(), 0.0) <= 0 || Double.compare(clock.getHeight(), 0.0) <= 0) {
if (clock.getPrefWidth() > 0 && clock.getPrefHeight() > 0) {
clock.setPrefSize(clock.getPrefWidth(), clock.getPrefHeight());
} else {
clock.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
sectionsAndAreasCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
sectionsAndAreasCtx = sectionsAndAreasCanvas.getGraphicsContext2D();
tickCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
tickCtx = tickCanvas.getGraphicsContext2D();
alarmPane = new Pane();
hour = new Path();
hour.setFillRule(FillRule.EVEN_ODD);
hour.setStroke(null);
hour.setFill(clock.getHourColor());
hour.getTransforms().setAll(hourRotate);
minute = new Path();
minute.setFillRule(FillRule.EVEN_ODD);
minute.setStroke(null);
minute.setFill(clock.getMinuteColor());
minute.getTransforms().setAll(minuteRotate);
dropShadow = new DropShadow();
dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);
shadowGroup = new Group(hour, minute);
shadowGroup.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
title = new Text("");
title.setVisible(clock.isTitleVisible());
title.setManaged(clock.isTitleVisible());
dateText = new Text("");
dateText.setVisible(clock.isDateVisible());
dateText.setManaged(clock.isDateVisible());
text = new Text("");
text.setVisible(clock.isTextVisible());
text.setManaged(clock.isTextVisible());
pane = new Pane(sectionsAndAreasCanvas, tickCanvas, alarmPane, title, dateText, text, shadowGroup);
pane.setBorder(new Border(new BorderStroke(clock.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(clock.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(clock.getBackgroundPaint(), new CornerRadii(1024), 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);
}
}
tube = new Path();
tube.setFillRule(FillRule.EVEN_ODD);
tube.setStroke(null);
Tooltip.install(tube, barTooltip);
tubeTop = new Ellipse();
tubeTop.setStroke(Color.rgb(255, 255, 255, 0.5));
tubeTop.setStrokeType(StrokeType.INSIDE);
tubeTop.setStrokeWidth(1);
tubeBottom = new Ellipse();
tubeBottom.setStroke(null);
fluidUpperLeft = new CubicCurveTo(0.21794871794871795 * PREFERRED_WIDTH, 0.24444444444444444 * PREFERRED_HEIGHT,
0.0, 0.18888888888888888 * PREFERRED_HEIGHT,
0.0, 0.12222222222222222 * PREFERRED_HEIGHT);
fluidUpperCenter = new CubicCurveTo(PREFERRED_WIDTH, 0.18888888888888888 * PREFERRED_HEIGHT,
0.782051282051282 * PREFERRED_WIDTH, 0.24444444444444444 * PREFERRED_HEIGHT,
0.5 * PREFERRED_WIDTH, 0.24444444444444444 * PREFERRED_HEIGHT);
fluidUpperRight = new CubicCurveTo(PREFERRED_WIDTH, 0.7111111111111111 * PREFERRED_HEIGHT,
PREFERRED_WIDTH, 0.12222222222222222 * PREFERRED_HEIGHT,
PREFERRED_WIDTH, 0.12222222222222222 * PREFERRED_HEIGHT);
fluidBody = new Path();
fluidBody.getElements().add(new MoveTo(0.0, 0.7111111111111111 * PREFERRED_HEIGHT));
fluidBody.getElements().add(new CubicCurveTo(0.0, 0.7777777777777778 * PREFERRED_HEIGHT,
0.21794871794871795 * PREFERRED_WIDTH, 0.8333333333333334 * PREFERRED_HEIGHT,
0.5 * PREFERRED_WIDTH, 0.8333333333333334 * PREFERRED_HEIGHT));
fluidBody.getElements().add(new CubicCurveTo(0.782051282051282 * PREFERRED_WIDTH, 0.8333333333333334 * PREFERRED_HEIGHT,
PREFERRED_WIDTH, 0.7777777777777778 * PREFERRED_HEIGHT,
PREFERRED_WIDTH, 0.7111111111111111 * PREFERRED_HEIGHT));
fluidBody.getElements().add(fluidUpperRight);
fluidBody.getElements().add(fluidUpperCenter);
fluidBody.getElements().add(fluidUpperLeft);
fluidBody.getElements().add(new CubicCurveTo(0.0, 0.12222222222222222 * PREFERRED_HEIGHT,
0.0, 0.7111111111111111 * PREFERRED_HEIGHT,
0.0, 0.7111111111111111 * PREFERRED_HEIGHT));
fluidBody.getElements().add(new ClosePath());
fluidBody.setFillRule(FillRule.EVEN_ODD);
fluidBody.setStroke(null);
fluidTop = new Ellipse();
fluidTop.setStroke(null);
valueText = new Text(String.format(locale, formatString, gauge.getCurrentValue()));
valueText.setMouseTransparent(true);
Helper.enableNode(valueText, gauge.isValueVisible());
titleText = new Text(gauge.getTitle());
// Add all nodes
pane = new Pane(tubeBottom, fluidBody, fluidTop, tube, tubeTop, valueText, titleText);
pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(gauge.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), CornerRadii.EMPTY, 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);
}
}
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);
needleRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);
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());
Helper.enableNode(titleText, !gauge.getTitle().isEmpty());
valueText = new Text(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getCurrentValue()));
valueText.setFill(gauge.getValueColor());
Helper.enableNode(valueText, gauge.isValueVisible());
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());
thresholdText = new Text(String.format(locale, "%." + gauge.getTickLabelDecimals() + "f", gauge.getThreshold()));
thresholdText.setFill(gauge.getTitleColor());
Helper.enableNode(thresholdText, Double.compare(gauge.getThreshold(), gauge.getMinValue()) != 0 && Double.compare(gauge.getThreshold(), gauge.getMaxValue()) != 0);
pane = new Pane(barBackground, thresholdBar, needle, titleText, valueText, minValueText, maxValueText, thresholdText);
pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(gauge.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), CornerRadii.EMPTY, 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);
}
}
unitText = new Text(gauge.getUnit());
unitText.setTextOrigin(VPos.CENTER);
unitText.setFill(gauge.getUnitColor());
Helper.enableNode(unitText, !gauge.getUnit().isEmpty());
titleText = new Text(gauge.getTitle());
titleText.setTextOrigin(VPos.CENTER);
titleText.setFill(gauge.getTitleColor());
Helper.enableNode(titleText, !gauge.getTitle().isEmpty());
valueText = new Text(formatNumber(gauge.getLocale(), gauge.getFormatString(), gauge.getDecimals(), gauge.getCurrentValue()));
valueText.setTextOrigin(VPos.CENTER);
valueText.setFill(gauge.getValueColor());
Helper.enableNode(valueText, gauge.isValueVisible());
minValue = gauge.getMinValue();
minText = new Text(String.format(locale, otherFormatString, minValue));
minText.setTextOrigin(VPos.CENTER);
minText.setFill(gauge.getValueColor());
maxText = new Text(String.format(locale, otherFormatString, gauge.getMaxValue()));
maxText.setTextOrigin(VPos.CENTER);
maxText.setFill(gauge.getValueColor());
boolean tickLabelsVisible = gauge.getTickLabelsVisible();
Helper.enableNode(minText, tickLabelsVisible);
Helper.enableNode(maxText, tickLabelsVisible);
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.3), 30.0, 0.0, 0.0, 10.0);
barBackgroundStart = new MoveTo(0, 0.675 * PREFERRED_HEIGHT);
barBackgroundOuterArc = new ArcTo(0.675 * PREFERRED_HEIGHT, 0.675 * PREFERRED_HEIGHT, 0, PREFERRED_WIDTH, 0.675 * PREFERRED_HEIGHT, true, true);
barBackgroundLineToInnerArc = new LineTo(0.72222 * PREFERRED_WIDTH, 0.675 * PREFERRED_HEIGHT);
barBackgroundInnerArc = new ArcTo(0.3 * PREFERRED_HEIGHT, 0.3 * PREFERRED_HEIGHT, 0, 0.27778 * PREFERRED_WIDTH, 0.675 * PREFERRED_HEIGHT, false, false);
barBackground = new Path();
barBackground.setFillRule(FillRule.EVEN_ODD);
barBackground.getElements().add(barBackgroundStart);
barBackground.getElements().add(barBackgroundOuterArc);
barBackground.getElements().add(barBackgroundLineToInnerArc);
barBackground.getElements().add(barBackgroundInnerArc);
barBackground.getElements().add(new ClosePath());
barBackground.setFill(gauge.getBarBackgroundColor());
barBackground.setStroke(gauge.getBorderPaint());
barBackground.setEffect(gauge.isShadowsEnabled() ? innerShadow : null);
dataBarStart = new MoveTo(0, 0.675 * PREFERRED_HEIGHT);
dataBarOuterArc = new ArcTo(0.675 * PREFERRED_HEIGHT, 0.675 * PREFERRED_HEIGHT, 0, 0, 0, false, true);
dataBarLineToInnerArc = new LineTo(0.27778 * PREFERRED_WIDTH, 0.675 * PREFERRED_HEIGHT);
dataBarInnerArc = new ArcTo(0.3 * PREFERRED_HEIGHT, 0.3 * PREFERRED_HEIGHT, 0, 0, 0, false, false);
dataBar = new Path();
dataBar.setFillRule(FillRule.EVEN_ODD);
dataBar.getElements().add(dataBarStart);
dataBar.getElements().add(dataBarOuterArc);
dataBar.getElements().add(dataBarLineToInnerArc);
dataBar.getElements().add(dataBarInnerArc);
dataBar.getElements().add(new ClosePath());
dataBar.setFill(gauge.getBarColor());
dataBar.setStroke(gauge.getBorderPaint());
dataBar.setEffect(gauge.isShadowsEnabled() ? innerShadow : null);
threshold = new Line();
threshold.setStrokeLineCap(StrokeLineCap.BUTT);
Helper.enableNode(threshold, gauge.isThresholdVisible());
thresholdText = new Text(String.format(locale, formatString, gauge.getThreshold()));
Helper.enableNode(thresholdText, gauge.isThresholdVisible());
pane = new Pane(unitText, titleText, valueText, minText, maxText, barBackground, dataBar, threshold, thresholdText);
pane.setBorder(new Border(new BorderStroke(gauge.getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(gauge.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(gauge.getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));
getChildren().setAll(pane);
}
@Override protected void initGraphics() {
super.initGraphics();
if (tile.isAutoScale()) tile.calcAutoScale();
oldValue = tile.getValue();
sectionMap = new HashMap<>(sections.size());
for(Section section : sections) { sectionMap.put(section, new Arc()); }
barColor = tile.getBarColor();
thresholdColor = tile.getThresholdColor();
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(barColor);
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(tile.getThresholdColor());
thresholdBar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
thresholdBar.setStrokeLineCap(StrokeLineCap.BUTT);
thresholdBar.setFill(null);
Helper.enableNode(thresholdBar, !tile.getSectionsVisible());
sectionPane = new Pane();
Helper.enableNode(sectionPane, tile.getSectionsVisible());
if (sectionsVisible) { drawSections(); }
alertIcon = new Path();
alertIcon.setFillRule(FillRule.EVEN_ODD);
alertIcon.setFill(Color.YELLOW);
alertIcon.setStroke(null);
Helper.enableNode(alertIcon, tile.isAlert());
alertTooltip = new Tooltip(tile.getAlertMessage());
Tooltip.install(alertIcon, alertTooltip);
needleRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
needleRectRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
needleRect = new Rectangle();
needleRect.setFill(tile.getBackgroundColor());
needleRect.getTransforms().setAll(needleRectRotate);
needle = new Path();
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
needle.setFill(tile.getNeedleColor());
needle.setStrokeWidth(0);
needle.setStroke(Color.TRANSPARENT);
titleText = new Text(tile.getTitle());
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, tile.getCurrentValue()));
valueText.setFill(tile.getValueColor());
valueText.setTextOrigin(VPos.BASELINE);
Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());
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);
minValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMinValue()));
minValueText.setFill(tile.getTitleColor());
maxValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMaxValue()));
maxValueText.setFill(tile.getTitleColor());
thresholdRect = new Rectangle();
thresholdRect.setFill(sectionsVisible ? Color.TRANSPARENT : tile.getValue() > tile.getThreshold() ? tile.getThresholdColor() : Tile.GRAY);
Helper.enableNode(thresholdRect, tile.isThresholdVisible());
thresholdText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getThreshold()));
thresholdText.setFill(sectionsVisible ? Color.TRANSPARENT : Tile.GRAY);
Helper.enableNode(thresholdText, tile.isThresholdVisible());
getPane().getChildren().addAll(barBackground, thresholdBar, sectionPane, alertIcon, needleRect, needle, titleText, valueUnitFlow, fractionLine, minValueText, maxValueText, thresholdRect, thresholdText);
}
@Override protected void initGraphics() {
// Set initial size
if (Double.compare(clock.getPrefWidth(), 0.0) <= 0 || Double.compare(clock.getPrefHeight(), 0.0) <= 0 ||
Double.compare(clock.getWidth(), 0.0) <= 0 || Double.compare(clock.getHeight(), 0.0) <= 0) {
if (clock.getPrefWidth() > 0 && clock.getPrefHeight() > 0) {
clock.setPrefSize(clock.getPrefWidth(), clock.getPrefHeight());
} else {
clock.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
sectionsAndAreasCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
sectionsAndAreasCtx = sectionsAndAreasCanvas.getGraphicsContext2D();
tickCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
tickCtx = tickCanvas.getGraphicsContext2D();
alarmPane = new Pane();
hour = new Rectangle(3, 60);
hour.setArcHeight(3);
hour.setArcWidth(3);
hour.setStroke(null);
hour.setFill(clock.getHourColor());
hour.getTransforms().setAll(hourRotate);
minute = new Rectangle(3, 96);
minute.setArcHeight(3);
minute.setArcWidth(3);
minute.setStroke(null);
minute.setFill(clock.getMinuteColor());
minute.getTransforms().setAll(minuteRotate);
second = new Path();
second.setFillRule(FillRule.EVEN_ODD);
second.setStroke(null);
second.setFill(clock.getSecondColor());
second.getTransforms().setAll(secondRotate);
enableNode(second, clock.isSecondsVisible());
dropShadow = new DropShadow();
dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);
knob = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, 4.5);
knob.setStroke(null);
knob.setFill(clock.getKnobColor());
knob.setEffect(dropShadow);
shadowGroupHour = new Group(hour);
shadowGroupMinute = new Group(minute);
shadowGroupSecond = new Group(second);
shadowGroupHour.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
shadowGroupMinute.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
shadowGroupSecond.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
title = new Text("");
title.setVisible(clock.isTitleVisible());
title.setManaged(clock.isTitleVisible());
text = new Text("");
text.setVisible(clock.isTextVisible());
text.setManaged(clock.isTextVisible());
pane = new Pane(sectionsAndAreasCanvas, tickCanvas, alarmPane, title, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond, knob);
pane.setBorder(new Border(new BorderStroke(clock.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(clock.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(clock.getBackgroundPaint(), new CornerRadii(1024), Insets.EMPTY)));
getChildren().setAll(pane);
}
@Override protected void initGraphics() {
super.initGraphics();
currentValueListener = o -> {
if (tile.isRunning()) { return; } // Update time only if clock is not already running
updateTime(ZonedDateTime.ofInstant(Instant.ofEpochSecond(tile.getCurrentTime()), ZoneId.of(ZoneId.systemDefault().getId())));
};
timeListener = o -> updateTime(tile.getTime());
dateFormatter = DateTimeFormatter.ofPattern("EE d", tile.getLocale());
sectionMap = new HashMap<>(tile.getTimeSections().size());
for (TimeSection section : tile.getTimeSections()) { sectionMap.put(section, new Arc()); }
minuteRotate = new Rotate();
hourRotate = new Rotate();
secondRotate = new Rotate();
sectionsPane = new Pane();
sectionsPane.getChildren().addAll(sectionMap.values());
Helper.enableNode(sectionsPane, tile.getSectionsVisible());
minuteTickMarks = new Path();
minuteTickMarks.setFillRule(FillRule.EVEN_ODD);
minuteTickMarks.setFill(null);
minuteTickMarks.setStroke(tile.getMinuteColor());
minuteTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);
hourTickMarks = new Path();
hourTickMarks.setFillRule(FillRule.EVEN_ODD);
hourTickMarks.setFill(null);
hourTickMarks.setStroke(tile.getHourColor());
hourTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);
hour = new Rectangle(3, 60);
hour.setArcHeight(3);
hour.setArcWidth(3);
hour.setStroke(tile.getHourColor());
hour.getTransforms().setAll(hourRotate);
minute = new Rectangle(3, 96);
minute.setArcHeight(3);
minute.setArcWidth(3);
minute.setStroke(tile.getMinuteColor());
minute.getTransforms().setAll(minuteRotate);
second = new Rectangle(1, 96);
second.setArcHeight(1);
second.setArcWidth(1);
second.setStroke(tile.getSecondColor());
second.getTransforms().setAll(secondRotate);
second.setVisible(tile.isSecondsVisible());
second.setManaged(tile.isSecondsVisible());
knob = new Circle(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.5, 4.5);
knob.setStroke(Color.web("#282a3280"));
dropShadow = new DropShadow();
dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);
shadowGroupHour = new Group(hour);
shadowGroupMinute = new Group(minute);
shadowGroupSecond = new Group(second, knob);
shadowGroupHour.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
shadowGroupMinute.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
shadowGroupSecond.setEffect(tile.isShadowsEnabled() ? dropShadow : null);
titleText = new Text("");
titleText.setTextOrigin(VPos.TOP);
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
amPmText = new Text(tile.getTime().get(ChronoField.AMPM_OF_DAY) == 0 ? "AM" : "PM");
dateText = new Text("");
Helper.enableNode(dateText, tile.isDateVisible());
text = new Text("");
Helper.enableNode(text, tile.isTextVisible());
getPane().getChildren().addAll(sectionsPane, hourTickMarks, minuteTickMarks, titleText, amPmText, dateText, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond);
}
@Override protected void initGraphics() {
// Set initial size
if (Double.compare(clock.getPrefWidth(), 0.0) <= 0 || Double.compare(clock.getPrefHeight(), 0.0) <= 0 ||
Double.compare(clock.getWidth(), 0.0) <= 0 || Double.compare(clock.getHeight(), 0.0) <= 0) {
if (clock.getPrefWidth() > 0 && clock.getPrefHeight() > 0) {
clock.setPrefSize(clock.getPrefWidth(), clock.getPrefHeight());
} else {
clock.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
sectionsAndAreasCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
sectionsAndAreasCtx = sectionsAndAreasCanvas.getGraphicsContext2D();
tickCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
tickCtx = tickCanvas.getGraphicsContext2D();
alarmPane = new Pane();
hour = new Path();
hour.setFillRule(FillRule.EVEN_ODD);
hour.setStroke(null);
hour.getTransforms().setAll(hourRotate);
minute = new Path();
minute.setFillRule(FillRule.EVEN_ODD);
minute.setStroke(null);
minute.getTransforms().setAll(minuteRotate);
second = new Path();
second.setFillRule(FillRule.EVEN_ODD);
second.setStroke(null);
second.getTransforms().setAll(secondRotate);
second.setVisible(clock.isSecondsVisible());
second.setManaged(clock.isSecondsVisible());
centerDot = new Circle();
centerDot.setFill(Color.WHITE);
dropShadow = new DropShadow();
dropShadow.setColor(Color.rgb(0, 0, 0, 0.25));
dropShadow.setBlurType(BlurType.TWO_PASS_BOX);
dropShadow.setRadius(0.015 * PREFERRED_WIDTH);
dropShadow.setOffsetY(0.015 * PREFERRED_WIDTH);
shadowGroupHour = new Group(hour);
shadowGroupMinute = new Group(minute);
shadowGroupSecond = new Group(second);
shadowGroupHour.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
shadowGroupMinute.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
shadowGroupSecond.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
title = new Text("");
title.setVisible(clock.isTitleVisible());
title.setManaged(clock.isTitleVisible());
dateText = new Text("");
dateText.setVisible(clock.isDateVisible());
dateText.setManaged(clock.isDateVisible());
dateNumber = new Text("");
dateNumber.setVisible(clock.isDateVisible());
dateNumber.setManaged(clock.isDateVisible());
text = new Text("");
text.setVisible(clock.isTextVisible());
text.setManaged(clock.isTextVisible());
pane = new Pane(sectionsAndAreasCanvas, tickCanvas, alarmPane, title, dateText, dateNumber, text, shadowGroupMinute, shadowGroupHour, shadowGroupSecond, centerDot);
pane.setBorder(new Border(new BorderStroke(clock.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(1024), new BorderWidths(clock.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(clock.getBackgroundPaint(), new CornerRadii(1024), 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);
}
}
graphBounds = new Rectangle(PREFERRED_WIDTH * 0.05, PREFERRED_HEIGHT * 0.5, PREFERRED_WIDTH * 0.9, PREFERRED_HEIGHT * 0.45);
titleText = new Text(gauge.getTitle());
titleText.setFill(gauge.getTitleColor());
Helper.enableNode(titleText, !gauge.getTitle().isEmpty());
valueText = new Text(String.format(locale, formatString, gauge.getValue()));
valueText.setFill(gauge.getValueColor());
Helper.enableNode(valueText, gauge.isValueVisible());
unitText = new Text(gauge.getUnit());
unitText.setFill(gauge.getUnitColor());
Helper.enableNode(unitText, !gauge.getUnit().isEmpty());
averageText = new Text(String.format(locale, formatString, gauge.getAverage()));
averageText.setFill(gauge.getAverageColor());
Helper.enableNode(averageText, gauge.isAverageVisible());
highText = new Text();
highText.setTextOrigin(VPos.BOTTOM);
highText.setFill(gauge.getValueColor());
lowText = new Text();
lowText.setTextOrigin(VPos.TOP);
lowText.setFill(gauge.getValueColor());
subTitleText = new Text(gauge.getSubTitle());
subTitleText.setTextOrigin(VPos.TOP);
subTitleText.setFill(gauge.getSubTitleColor());
stdDeviationArea = new Rectangle();
Helper.enableNode(stdDeviationArea, gauge.isAverageVisible());
averageLine = new Line();
averageLine.setStroke(gauge.getAverageColor());
averageLine.getStrokeDashArray().addAll(PREFERRED_WIDTH * 0.005, PREFERRED_WIDTH * 0.005);
Helper.enableNode(averageLine, gauge.isAverageVisible());
pathElements = new ArrayList<>(noOfDatapoints);
pathElements.add(0, new MoveTo());
for (int i = 1 ; i < noOfDatapoints ; i++) { pathElements.add(i, new LineTo()); }
sparkLine = new Path();
sparkLine.getElements().addAll(pathElements);
sparkLine.setFill(null);
sparkLine.setStroke(gauge.getBarColor());
sparkLine.setStrokeWidth(PREFERRED_WIDTH * 0.0075);
sparkLine.setStrokeLineCap(StrokeLineCap.ROUND);
sparkLine.setStrokeLineJoin(StrokeLineJoin.ROUND);
dot = new Circle();
dot.setFill(gauge.getBarColor());
pane = new Pane(titleText, valueText, unitText, stdDeviationArea, averageLine, sparkLine, dot, averageText, highText, lowText, subTitleText);
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);
}