下面列出了javafx.scene.shape.Path#setFillRule ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static Path processPath(final List<String> PATH_LIST, final PathReader READER) {
final Path PATH = new Path();
PATH.setFillRule(FillRule.EVEN_ODD);
while (!PATH_LIST.isEmpty()) {
if ("M".equals(READER.read())) {
PATH.getElements().add(new MoveTo(READER.nextX(), READER.nextY()));
} else if ("L".equals(READER.read())) {
PATH.getElements().add(new LineTo(READER.nextX(), READER.nextY()));
} else if ("C".equals(READER.read())) {
PATH.getElements().add(new CubicCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY()));
} else if ("Q".equals(READER.read())) {
PATH.getElements().add(new QuadCurveTo(READER.nextX(), READER.nextY(), READER.nextX(), READER.nextY()));
} else if ("H".equals(READER.read())) {
PATH.getElements().add(new HLineTo(READER.nextX()));
} else if ("L".equals(READER.read())) {
PATH.getElements().add(new VLineTo(READER.nextY()));
} else if ("A".equals(READER.read())) {
PATH.getElements().add(new ArcTo(READER.nextX(), READER.nextY(), 0, READER.nextX(), READER.nextY(), false, false));
} else if ("Z".equals(READER.read())) {
PATH.getElements().add(new ClosePath());
}
}
return PATH;
}
protected Path createPath()
{
Path p = new Path();
applyNodeProperties(p);
applyShapeProperties(p);
p.setFillRule(fillRule);
return p;
}
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);
}
@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);
}
private void initGraphics() {
Font.loadFont(getClass().getResourceAsStream("/eu/hansolo/enzo/fonts/opensans-semibold.ttf"), (0.06 * PREFERRED_HEIGHT)); // "OpenSans"
sectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
sectionsCtx = sectionsCanvas.getGraphicsContext2D();
measuredRangeCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
measuredRangeCanvas.setManaged(getSkinnable().isMeasuredRangeVisible());
measuredRangeCanvas.setVisible(getSkinnable().isMeasuredRangeVisible());
measuredRangeCtx = measuredRangeCanvas.getGraphicsContext2D();
if (getSkinnable().getValue() < getSkinnable().getMinValue()) getSkinnable().setValue(getSkinnable().getMinValue());
if (getSkinnable().getValue() > getSkinnable().getMaxValue()) getSkinnable().setValue(getSkinnable().getMaxValue());
needleRotate = new Rotate(180 - getSkinnable().getStartAngle());
if (getSkinnable().getMinValue() < 0) {
needleRotate.setAngle(needleRotate.getAngle() + (getSkinnable().getValue() - getSkinnable().getOldValue() - getSkinnable().getMinValue()) * angleStep);
} else {
//needleRotate.setAngle(needleRotate.getAngle() + (getSkinnable().getValue() - getSkinnable().getOldValue() + getSkinnable().getMinValue()) * angleStep);
}
angleStep = getSkinnable().getAngleRange() / (getSkinnable().getMaxValue() - getSkinnable().getMinValue());
needleRotate.setAngle(needleRotate.getAngle() + (getSkinnable().getValue() - getSkinnable().getOldValue()) * angleStep);
needle = new Path();
needle.setFillRule(FillRule.EVEN_ODD);
needle.getStyleClass().setAll("needle");
needle.getTransforms().setAll(needleRotate);
value = new Text(String.format(Locale.US, "%." + getSkinnable().getDecimals() + "f", getSkinnable().getMinValue()) + getSkinnable().getUnit());
value.setMouseTransparent(true);
value.setTextOrigin(VPos.CENTER);
value.getStyleClass().setAll("value");
title = new Text(getSkinnable().getTitle());
title.setTextOrigin(VPos.CENTER);
title.getStyleClass().setAll("title");
// Add all nodes
pane = new Pane();
pane.getStyleClass().add("simple-gauge");
pane.getChildren().setAll(sectionsCanvas,
measuredRangeCanvas,
needle,
value,
title);
getChildren().setAll(pane);
resize();
}
@Override protected void initGraphics() {
super.initGraphics();
angleRange = tile.getAngleRange();
angleStep = tile.getAngleStep();
if (tile.isAutoScale()) tile.calcAutoScale();
oldValue = tile.getValue();
barBackgroundColor = tile.getBarBackgroundColor();
gradientLookup = new GradientLookup(tile.getGradientStops());
knob = new Circle();
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(barBackgroundColor);
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
barBackground.setStrokeLineCap(StrokeLineCap.ROUND);
barBackground.setFill(null);
bar = new Arc(PREFERRED_WIDTH * 0.5, PREFERRED_HEIGHT * 0.696, PREFERRED_WIDTH * 0.275, PREFERRED_WIDTH * 0.275, angleRange * 0.5 + 90, 0);
bar.setType(ArcType.OPEN);
bar.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
bar.setStrokeLineCap(StrokeLineCap.ROUND);
bar.setFill(null);
barBounds = new Rectangle();
createConicalGradient();
needleRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
needleRectRotate = new Rotate((tile.getValue() - oldValue - minValue) * angleStep);
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());
Helper.enableNode(valueText, tile.isValueVisible() && !tile.isAlert());
unitText = new Text(tile.getUnit());
unitText.setFill(tile.getUnitColor());
Helper.enableNode(unitText, !tile.getUnit().isEmpty());
valueUnitFlow = new TextFlow(valueText, unitText);
valueUnitFlow.setTextAlignment(TextAlignment.CENTER);
minValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMinValue()));
minValueText.setFill(tile.getTitleColor());
minValueText.setTextOrigin(VPos.CENTER);
maxValueText = new Text(String.format(locale, "%." + tile.getTickLabelDecimals() + "f", tile.getMaxValue()));
maxValueText.setFill(tile.getTitleColor());
maxValueText.setTextOrigin(VPos.CENTER);
text = new Text(tile.getText());
text.setTextOrigin(VPos.TOP);
text.setFill(tile.getTextColor());
getPane().getChildren().addAll(knob, barBackground, bar, needle, titleText, valueUnitFlow, minValueText, maxValueText, text);
}
@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);
}
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);
}
}
ticksAndSectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ticksAndSections = ticksAndSectionsCanvas.getGraphicsContext2D();
ledCanvas = new Canvas();
led = ledCanvas.getGraphicsContext2D();
thresholdTooltip = new Tooltip("Threshold\n(" + String.format(locale, formatString, gauge.getThreshold()) + ")");
thresholdTooltip.setTextAlignment(TextAlignment.CENTER);
threshold = new Path();
Helper.enableNode(threshold, gauge.isThresholdVisible());
Tooltip.install(threshold, thresholdTooltip);
average = new Path();
Helper.enableNode(average, gauge.isAverageVisible());
markerPane = new Pane();
needleRotate = new Rotate(180 - START_ANGLE);
needleRotate.setAngle(needleRotate.getAngle() + (gauge.getValue() - oldValue - gauge.getMinValue()) * angleStep);
needleMoveTo1 = new MoveTo();
needleCubicCurveTo2 = new CubicCurveTo();
needleCubicCurveTo3 = new CubicCurveTo();
needleCubicCurveTo4 = new CubicCurveTo();
needleLineTo5 = new LineTo();
needleCubicCurveTo6 = new CubicCurveTo();
needleClosePath7 = new ClosePath();
needle = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleLineTo5, needleCubicCurveTo6, needleClosePath7);
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
needle.getStyleClass().add("needle");
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(needle);
shadowGroup.setEffect(gauge.isShadowsEnabled() ? dropShadow : null);
shadowGroup.getStyleClass().add("shadow-group");
unitText = new Text(gauge.getUnit());
unitText.setMouseTransparent(true);
unitText.setTextOrigin(VPos.CENTER);
unitText.getStyleClass().add("unit");
lcd = new Rectangle(0.3 * PREFERRED_WIDTH, 0.1 * PREFERRED_HEIGHT);
lcd.setArcWidth(0.0125 * PREFERRED_HEIGHT);
lcd.setArcHeight(0.0125 * PREFERRED_HEIGHT);
lcd.relocate((PREFERRED_WIDTH - lcd.getWidth()) * 0.5, 0.66 * PREFERRED_HEIGHT);
lcd.getStyleClass().add("lcd");
Helper.enableNode(lcd, gauge.isLcdVisible() && gauge.isValueVisible());
lcdText = new Label(String.format(locale, "%." + gauge.getDecimals() + "f", gauge.getValue()));
lcdText.setAlignment(Pos.CENTER_RIGHT);
lcdText.setVisible(gauge.isValueVisible());
lcdText.getStyleClass().add("lcd-foreground");
// Set initial value
angleStep = ANGLE_RANGE / gauge.getRange();
double targetAngle = 180 - START_ANGLE + (gauge.getValue() - gauge.getMinValue()) * angleStep;
targetAngle = clamp(180 - START_ANGLE, 180 - START_ANGLE + ANGLE_RANGE, targetAngle);
needleRotate.setAngle(targetAngle);
// Add all nodes
pane = new Pane();
pane.getChildren().setAll(ticksAndSectionsCanvas,
markerPane,
ledCanvas,
unitText,
lcd,
lcdText,
shadowGroup);
pane.getStyleClass().add("background-pane");
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);
}
}
ticksAndSectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ticksAndSections = ticksAndSectionsCanvas.getGraphicsContext2D();
ledCanvas = new Canvas();
led = ledCanvas.getGraphicsContext2D();
thresholdTooltip = new Tooltip("Threshold\n(" + String.format(locale, formatString, gauge.getThreshold()) + ")");
thresholdTooltip.setTextAlignment(TextAlignment.CENTER);
threshold = new Path();
Helper.enableNode(threshold, gauge.isThresholdVisible());
Tooltip.install(threshold, thresholdTooltip);
average = new Path();
Helper.enableNode(average, gauge.isAverageVisible());
markerPane = new Pane();
needleRotate = new Rotate(180 - START_ANGLE);
needleRotate.setAngle(needleRotate.getAngle() + (gauge.getValue() - oldValue - gauge.getMinValue()) * angleStep);
needleMoveTo1 = new MoveTo();
needleCubicCurveTo2 = new CubicCurveTo();
needleCubicCurveTo3 = new CubicCurveTo();
needleCubicCurveTo4 = new CubicCurveTo();
needleLineTo5 = new LineTo();
needleCubicCurveTo6 = new CubicCurveTo();
needleClosePath7 = new ClosePath();
needle = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleLineTo5, needleCubicCurveTo6, needleClosePath7);
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
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(needle);
shadowGroup.setEffect(gauge.isShadowsEnabled() ? dropShadow : null);
unitText = new Text(gauge.getUnit());
unitText.setMouseTransparent(true);
unitText.setTextOrigin(VPos.CENTER);
lcd = new Rectangle(0.3 * PREFERRED_WIDTH, 0.1 * PREFERRED_HEIGHT);
lcd.setArcWidth(0.0125 * PREFERRED_HEIGHT);
lcd.setArcHeight(0.0125 * PREFERRED_HEIGHT);
lcd.relocate((PREFERRED_WIDTH - lcd.getWidth()) * 0.5, 0.66 * PREFERRED_HEIGHT);
Helper.enableNode(lcd, gauge.isLcdVisible() && gauge.isValueVisible());
lcdText = new Label(String.format(locale, "%." + gauge.getDecimals() + "f", gauge.getValue()));
lcdText.setAlignment(Pos.CENTER_RIGHT);
lcdText.setVisible(gauge.isValueVisible());
// Set initial value
angleStep = ANGLE_RANGE / gauge.getRange();
double targetAngle = 180 - START_ANGLE + (gauge.getValue() - gauge.getMinValue()) * angleStep;
targetAngle = clamp(180 - START_ANGLE, 180 - START_ANGLE + ANGLE_RANGE, targetAngle);
needleRotate.setAngle(targetAngle);
// Add all nodes
pane = new Pane();
pane.getChildren().setAll(ticksAndSectionsCanvas,
markerPane,
ledCanvas,
unitText,
lcd,
lcdText,
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 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() {
// 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);
}
}
minuteTickMarks = new Path();
minuteTickMarks.setFillRule(FillRule.EVEN_ODD);
minuteTickMarks.setFill(null);
minuteTickMarks.setStroke(clock.getMinuteColor());
minuteTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);
hourTickMarks = new Path();
hourTickMarks.setFillRule(FillRule.EVEN_ODD);
hourTickMarks.setFill(null);
hourTickMarks.setStroke(clock.getHourColor());
hourTickMarks.setStrokeLineCap(StrokeLineCap.ROUND);
hour = new Rectangle(3, 60);
hour.setArcHeight(3);
hour.setArcWidth(3);
hour.setStroke(clock.getHourColor());
hour.getTransforms().setAll(hourRotate);
minute = new Rectangle(3, 96);
minute.setArcHeight(3);
minute.setArcWidth(3);
minute.setStroke(clock.getMinuteColor());
minute.getTransforms().setAll(minuteRotate);
second = new Rectangle(1, 96);
second.setArcHeight(1);
second.setArcWidth(1);
second.setStroke(clock.getSecondColor());
second.getTransforms().setAll(secondRotate);
second.setVisible(clock.isSecondsVisible());
second.setManaged(clock.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(clock.getShadowsEnabled() ? dropShadow : null);
shadowGroupMinute.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
shadowGroupSecond.setEffect(clock.getShadowsEnabled() ? dropShadow : null);
title = new Text("");
title.setTextOrigin(VPos.TOP);
Helper.enableNode(title, clock.isTitleVisible());
amPmText = new Text(clock.getTime().get(ChronoField.AMPM_OF_DAY) == 0 ? "AM" : "PM");
dateText = new Text("");
Helper.enableNode(dateText, clock.isDateVisible());
text = new Text("");
Helper.enableNode(text, clock.isTextVisible());
pane = new Pane(hourTickMarks, minuteTickMarks, title, amPmText, dateText, text, shadowGroupHour, shadowGroupMinute, shadowGroupSecond);
pane.setBorder(new Border(new BorderStroke(clock.getBorderPaint(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(clock.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(clock.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);
}
}
ticksAndSectionsCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
ticksAndSections = ticksAndSectionsCanvas.getGraphicsContext2D();
ledCanvas = new Canvas();
led = ledCanvas.getGraphicsContext2D();
thresholdTooltip = new Tooltip("Threshold\n(" + String.format(locale, formatString, gauge.getThreshold()) + ")");
thresholdTooltip.setTextAlignment(TextAlignment.CENTER);
threshold = new Path();
Helper.enableNode(threshold, gauge.isThresholdVisible());
Tooltip.install(threshold, thresholdTooltip);
average = new Path();
Helper.enableNode(average, gauge.isAverageVisible());
markerPane = new Pane();
needleRotate = new Rotate(180 - START_ANGLE);
needleRotate.setAngle(needleRotate.getAngle() + (gauge.getValue() - oldValue - gauge.getMinValue()) * angleStep);
needleMoveTo1 = new MoveTo();
needleCubicCurveTo2 = new CubicCurveTo();
needleCubicCurveTo3 = new CubicCurveTo();
needleCubicCurveTo4 = new CubicCurveTo();
needleLineTo5 = new LineTo();
needleCubicCurveTo6 = new CubicCurveTo();
needleClosePath7 = new ClosePath();
needle = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleLineTo5, needleCubicCurveTo6, needleClosePath7);
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
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(needle);
shadowGroup.setEffect(gauge.isShadowsEnabled() ? dropShadow : null);
titleText = new Text(gauge.getTitle());
titleText.setTextOrigin(VPos.CENTER);
titleText.setFill(gauge.getTitleColor());
Helper.enableNode(titleText, !gauge.getTitle().isEmpty());
unitText = new Text(gauge.getUnit());
unitText.setMouseTransparent(true);
unitText.setTextOrigin(VPos.CENTER);
lcd = new Rectangle(0.3 * PREFERRED_WIDTH, 0.1 * PREFERRED_HEIGHT);
lcd.setArcWidth(0.0125 * PREFERRED_HEIGHT);
lcd.setArcHeight(0.0125 * PREFERRED_HEIGHT);
lcd.relocate((PREFERRED_WIDTH - lcd.getWidth()) * 0.5, 0.44 * PREFERRED_HEIGHT);
Helper.enableNode(lcd, gauge.isLcdVisible() && gauge.isValueVisible());
lcdText = new Label(String.format(locale, "%." + gauge.getDecimals() + "f", gauge.getValue()));
lcdText.setAlignment(Pos.CENTER_RIGHT);
lcdText.setVisible(gauge.isValueVisible());
// Set initial value
angleStep = ANGLE_RANGE / gauge.getRange();
double targetAngle = 180 - START_ANGLE + (gauge.getValue() - gauge.getMinValue()) * angleStep;
targetAngle = clamp(180 - START_ANGLE, 180 - START_ANGLE + ANGLE_RANGE, targetAngle);
needleRotate.setAngle(targetAngle);
lightEffect = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(255, 255, 255, 0.65), 2, 0.0, 0.0, 2.0);
foreground = new SVGPath();
foreground.setContent("M 26 26.5 C 26 20.2432 26.2432 20 32.5 20 L 277.5 20 C 283.7568 20 284 20.2432 284 26.5 L 284 143.5 C 284 149.7568 283.7568 150 277.5 150 L 32.5 150 C 26.2432 150 26 149.7568 26 143.5 L 26 26.5 ZM 0 6.7241 L 0 253.2758 C 0 260 0 260 6.75 260 L 303.25 260 C 310 260 310 260 310 253.2758 L 310 6.7241 C 310 0 310 0 303.25 0 L 6.75 0 C 0 0 0 0 0 6.7241 Z");
foreground.setEffect(lightEffect);
// Add all nodes
pane = new Pane();
pane.getChildren().setAll(ticksAndSectionsCanvas,
markerPane,
ledCanvas,
unitText,
lcd,
lcdText,
shadowGroup,
foreground,
titleText);
getChildren().setAll(pane);
}
private void resize() {
width = getSkinnable().getWidth();
height = getSkinnable().getHeight();
if (getSkinnable().isKeepAspect()) {
if (aspectRatio * width > height) {
width = 1 / (aspectRatio / height);
} else if (1 / (aspectRatio / height) > width) {
height = aspectRatio * width;
}
}
if (width > 0 && height > 0) {
// Autocenter the control
//getSkinnable().setTranslateX((getSkinnable().getWidth() - width) * 0.5);
//getSkinnable().setTranslateY((getSkinnable().getHeight() - height) * 0.5);
flapHeight = 0.49206349206349204 * height;
fixtureRight.setPrefSize(0.0476190476 * height, 0.164021164021164 * height);
fixtureRight.setTranslateX(width - 0.0476190476 * height);
fixtureRight.setTranslateY(0.41798941798941797 * height);
fixtureLeft.setPrefSize(0.0476190476 * height, 0.164021164021164 * height);
fixtureLeft.setTranslateY(0.41798941798941797 * height);
if (width > height && width > 0 && height > 0) {
final Path UPPER = new Path();
UPPER.setFillRule(FillRule.EVEN_ODD);
UPPER.getElements().add(new MoveTo(width, 0.0));
UPPER.getElements().add(new LineTo(width, 0.4074074074074074 * height));
UPPER.getElements().add(new LineTo(width - 0.0582010582 * height, 0.4074074074074074 * height));
UPPER.getElements().add(new LineTo(width - 0.0582010582 * height, 0.49206349206349204 * height));
UPPER.getElements().add(new LineTo(0.0582010582 * height, 0.49206349206349204 * height));
UPPER.getElements().add(new LineTo(0.0582010582 * height, 0.4074074074074074 * height));
UPPER.getElements().add(new LineTo(0.0, 0.4074074074074074 * height));
UPPER.getElements().add(new LineTo(0.0, 0.0));
UPPER.getElements().add(new LineTo(width, 0.0));
UPPER.getElements().add(new ClosePath());
final String UPPER_SVG = ShapeConverter.shapeToSvgString(UPPER);
final Path LOWER = new Path();
LOWER.setFillRule(FillRule.EVEN_ODD);
LOWER.getElements().add(new MoveTo(width, height));
LOWER.getElements().add(new LineTo(width, 0.5925925925925926 * height));
LOWER.getElements().add(new LineTo(width - 0.0582010582 * height, 0.5925925925925926 * height));
LOWER.getElements().add(new LineTo(width - 0.0582010582 * height, 0.5079365079365079 * height));
LOWER.getElements().add(new LineTo(0.0582010582 * height, 0.5079365079365079 * height));
LOWER.getElements().add(new LineTo(0.0582010582 * height, 0.5925925925925926 * height));
LOWER.getElements().add(new LineTo(0.0, 0.5925925925925926 * height));
LOWER.getElements().add(new LineTo(0.0, height));
LOWER.getElements().add(new LineTo(width, height));
LOWER.getElements().add(new ClosePath());
final String LOWER_SVG = ShapeConverter.shapeToSvgString(LOWER);
upperBackground.setStyle(new StringBuilder("-fx-shape:").append("\"").append(UPPER_SVG).append("\";").toString());
lowerBackground.setStyle(new StringBuilder("-fx-shape:").append("\"").append(LOWER_SVG).append("\";").toString());
flap.setStyle(new StringBuilder("-fx-shape:").append("\"").append(UPPER_SVG).append("\";").toString());
}
upperBackground.setPrefSize(width, flapHeight);
lowerBackground.setPrefSize(width, flapHeight);
lowerBackground.setTranslateY(0.5079365079365079 * height);
//font = Font.font("Bebas Neue", height * 0.9);
font = Font.font("Droid Sans Mono", height * 0.75);
upperBackgroundText.setWidth(width);
upperBackgroundText.setHeight(flapHeight);
lowerBackgroundText.setWidth(width);
lowerBackgroundText.setHeight(flapHeight);
lowerBackgroundText.setTranslateY(0.5079365079365079 * height);
flap.setPrefSize(width, flapHeight);
rotateFlap.setPivotY(height * 0.5);
flapTextFront.setWidth(width);
flapTextFront.setHeight(flapHeight);
flapTextBack.setWidth(width);
flapTextBack.setHeight(flapHeight);
ctxUpperBackgroundText.setFont(font);
ctxLowerBackgroundText.setFont(font);
ctxTextFront.setFont(font);
ctxTextBack.setFont(font);
refreshTextCtx();
innerShadow.setOffsetY(-0.01 * flapHeight);
innerShadow.setRadius(0.01 * flapHeight);
innerHighlight.setOffsetY(0.01 * flapHeight);
innerHighlight.setRadius(0.01 * flapHeight);
reversedInnerShadow.setOffsetY(-0.01 * 0.4920634921 * height);
reversedInnerShadow.setRadius(0.01 * 0.4920634921 * height);
reversedInnerHighlight.setOffsetY(0.01 * 0.4920634921 * height);
reversedInnerHighlight.setRadius(0.01 * 0.4920634921 * height);
}
}
@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);
}
}
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);
}
@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);
}
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);
}
}
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);
}
@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);
}
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, ANGLE_RANGE * 0.5 + 90, -ANGLE_RANGE);
barBackground.setType(ArcType.OPEN);
barBackground.setStroke(gauge.getBarBackgroundColor());
barBackground.setStrokeWidth(PREFERRED_WIDTH * 0.02819549 * 2);
barBackground.setStrokeLineCap(StrokeLineCap.BUTT);
barBackground.setFill(null);
sectionCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
sectionCtx = sectionCanvas.getGraphicsContext2D();
needleRotate = new Rotate((gauge.getValue() - oldValue - minValue) * angleStep);
needleMoveTo1 = new MoveTo();
needleCubicCurveTo2 = new CubicCurveTo();
needleCubicCurveTo3 = new CubicCurveTo();
needleCubicCurveTo4 = new CubicCurveTo();
needleCubicCurveTo5 = new CubicCurveTo();
needleClosePath6 = new ClosePath();
needleMoveTo7 = new MoveTo();
needleCubicCurveTo8 = new CubicCurveTo();
needleCubicCurveTo9 = new CubicCurveTo();
needleCubicCurveTo10 = new CubicCurveTo();
needleCubicCurveTo11 = new CubicCurveTo();
needleClosePath12 = new ClosePath();
needle = new Path(needleMoveTo1, needleCubicCurveTo2, needleCubicCurveTo3, needleCubicCurveTo4, needleCubicCurveTo5, needleClosePath6,
needleMoveTo7, needleCubicCurveTo8, needleCubicCurveTo9, needleCubicCurveTo10, needleCubicCurveTo11, needleClosePath12);
needle.setFillRule(FillRule.EVEN_ODD);
needle.getTransforms().setAll(needleRotate);
needle.setFill(gauge.getNeedleColor());
needle.setStrokeType(StrokeType.INSIDE);
needle.setStrokeWidth(1);
needle.setStroke(gauge.getBackgroundPaint());
needleTooltip = new Tooltip(String.format(locale, formatString, gauge.getValue()));
needleTooltip.setTextAlignment(TextAlignment.CENTER);
Tooltip.install(needle, needleTooltip);
pane = new Pane(barBackground, sectionCanvas, needle);
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);
}