下面列出了怎么用javafx.scene.effect.BlurType的API类实例代码及写法,或者点击链接到github查看源代码。
protected void initGraphics() {
// Set initial size
if (Double.compare(tile.getPrefWidth(), 0.0) <= 0 || Double.compare(tile.getPrefHeight(), 0.0) <= 0 ||
Double.compare(tile.getWidth(), 0.0) <= 0 || Double.compare(tile.getHeight(), 0.0) <= 0) {
if (tile.getPrefWidth() > 0 && tile.getPrefHeight() > 0) {
tile.setPrefSize(tile.getPrefWidth(), tile.getPrefHeight());
} else {
tile.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
shadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 3, 0, 0, 0);
notifyRegion = new NotifyRegion();
enableNode(notifyRegion, false);
pane = new Pane(notifyRegion);
pane.setBorder(new Border(new BorderStroke(tile.getBorderColor(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(tile.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(tile.getBackgroundColor(), new CornerRadii(PREFERRED_WIDTH * 0.025), Insets.EMPTY)));
getChildren().setAll(pane);
}
/**
* Prepare Stage for dock feedback display
*/
void buildDockFeedbackStage() {
dockFeedbackPopup = new Stage(StageStyle.TRANSPARENT);
dockFeedback = new Rectangle(0, 0, 100, 100);
dockFeedback.setArcHeight(10);
dockFeedback.setArcWidth(10);
dockFeedback.setFill(Color.TRANSPARENT);
dockFeedback.setStroke(Color.BLACK);
dockFeedback.setStrokeWidth(2);
dockFeedback.setCache(true);
dockFeedback.setCacheHint(CacheHint.SPEED);
dockFeedback.setEffect(new DropShadow(BlurType.TWO_PASS_BOX, Color.BLACK, 10, 0.2, 3, 3));
dockFeedback.setMouseTransparent(true);
BorderPane borderpane = new BorderPane();
borderpane.setStyle("-fx-background-color:transparent"); //J8
borderpane.setCenter(dockFeedback);
Scene scene = new Scene(borderpane);
scene.setFill(Color.TRANSPARENT);
dockFeedbackPopup.setScene(scene);
dockFeedbackPopup.sizeToScene();
}
private static void animate(Node node, long millis, int r, int g, int b) {
DoubleProperty dblProp = new SimpleDoubleProperty(1);
dblProp.addListener((ob, o, n) -> {
InnerShadow innerShadow = new InnerShadow();
innerShadow.setBlurType(BlurType.ONE_PASS_BOX);
innerShadow.setChoke(1);
innerShadow.setRadius(5);
innerShadow.setColor(Color.rgb(r, g, b, n.doubleValue()));
node.setEffect(innerShadow);
});
Timeline timeline = new Timeline();
KeyValue kv = new KeyValue(dblProp, 0);
KeyFrame kf = new KeyFrame(Duration.millis(millis), kv);
timeline.getKeyFrames().add(kf);
timeline.play();
}
@Override protected void initGraphics() {
super.initGraphics();
titleText = new Text();
titleText.setFill(tile.getTitleColor());
Helper.enableNode(titleText, !tile.getTitle().isEmpty());
text = new Text(tile.getText());
text.setFill(tile.getUnitColor());
Helper.enableNode(text, tile.isTextVisible());
description = new Label(tile.getDescription());
description.setAlignment(tile.getDescriptionAlignment());
description.setWrapText(true);
description.setTextFill(tile.getTextColor());
Helper.enableNode(description, !tile.getDescription().isEmpty());
ledBorder = new Circle();
led = new Circle();
hightlight = new Circle();
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * size, 0, 0, 0);
led.setEffect(innerShadow);
getPane().getChildren().addAll(titleText, text, description, ledBorder, led, hightlight);
}
public Toast(final String msg) {
label = new Label(msg);
String style = "-fx-background-color:black;" +
"-fx-background-radius:10;" +
"-fx-font: 16px \"Microsoft YaHei\";" +
"-fx-text-fill:white;-fx-padding:10;";
label.setStyle(style);
DropShadow dropShadow = new DropShadow();
dropShadow.setBlurType(BlurType.THREE_PASS_BOX);
dropShadow.setWidth(40);
dropShadow.setHeight(40);
dropShadow.setRadius(19.5);
dropShadow.setOffsetX(0);
dropShadow.setOffsetY(00);
dropShadow.setColor(Color.color(0, 0, 0));
label.setEffect(dropShadow);
}
private void initGraphics() {
backgroundCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
backgroundCtx = backgroundCanvas.getGraphicsContext2D();
foregroundCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
foregroundCtx = foregroundCanvas.getGraphicsContext2D();
ledInnerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.BLACK, 0.2 * PREFERRED_WIDTH, 0, 0, 0);
ledDropShadow = new DropShadow(BlurType.TWO_PASS_BOX, getSkinnable().getBarColor(), 0.3 * PREFERRED_WIDTH, 0, 0, 0);
pane = new Pane(backgroundCanvas, foregroundCanvas);
pane.setBorder(new Border(new BorderStroke(getSkinnable().getBorderPaint(), BorderStrokeStyle.SOLID, CornerRadii.EMPTY, new BorderWidths(1))));
pane.setBackground(new Background(new BackgroundFill(getSkinnable().getBackgroundPaint(), CornerRadii.EMPTY, Insets.EMPTY)));
getChildren().setAll(pane);
}
public LcdSkin(Gauge gauge) {
super(gauge);
width = PREFERRED_WIDTH;
height = PREFERRED_HEIGHT;
valueOffsetLeft = 0.0;
valueOffsetRight = 0.0;
digitalFontSizeFactor = 1.0;
backgroundTextBuilder = new StringBuilder();
valueFormatString = new StringBuilder("%.").append(gauge.getDecimals()).append("f").toString();
otherFormatString = new StringBuilder("%.").append(gauge.getTickLabelDecimals()).append("f").toString();
locale = gauge.getLocale();
sections = gauge.getSections();
sectionColorMap = new HashMap<>(sections.size());
currentValueListener = o -> handleEvents("REDRAW");
updateSectionColors();
FOREGROUND_SHADOW.setOffsetX(0);
FOREGROUND_SHADOW.setOffsetY(1);
FOREGROUND_SHADOW.setColor(Color.rgb(0, 0, 0, 0.5));
FOREGROUND_SHADOW.setBlurType(BlurType.TWO_PASS_BOX);
FOREGROUND_SHADOW.setRadius(2);
initGraphics();
registerListeners();
}
@Override
public Node buildIcon(StringFormat format, byte[] value) {
Text t = new Text(format.format(format.value(value)));
t.setFont(Font.font(ExternalFonts.SOURCESANSPRO_BLACK, FontWeight.BOLD, 32.0));
t.setFill(Color.WHITE);
DropShadow dropShadow = new DropShadow();
dropShadow.setRadius(4.0);
dropShadow.setColor(Color.BLACK /* valueOf("#4b5157")*/);
dropShadow.setBlurType(BlurType.ONE_PASS_BOX);
t.setEffect(dropShadow);
return t;
}
private void initGraphics() {
frame = new Region();
frame.setOpacity(getSkinnable().isFrameVisible() ? 1 : 0);
led = new Region();
led.setStyle("-led-color: " + Util.colorToCss((Color) getSkinnable().getLedColor()) + ";");
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 8, 0d, 0d, 0d);
glow = new DropShadow(BlurType.TWO_PASS_BOX, (Color) getSkinnable().getLedColor(), 20, 0d, 0d, 0d);
glow.setInput(innerShadow);
highlight = new Region();
// Set the appropriate style classes
changeStyle();
// Add all nodes
getChildren().setAll(frame, led, highlight);
}
public LcdSkin(final Lcd CONTROL) {
super(CONTROL);
valueOffsetLeft = 0.0;
valueOffsetRight = 0.0;
digitalFontSizeFactor = 1.0;
backgroundTextBuilder = new StringBuilder();
decBuffer = new StringBuilder(16);
FOREGROUND_SHADOW.setOffsetX(0);
FOREGROUND_SHADOW.setOffsetY(1);
FOREGROUND_SHADOW.setColor(Color.rgb(0, 0, 0, 0.5));
FOREGROUND_SHADOW.setBlurType(BlurType.TWO_PASS_BOX);
FOREGROUND_SHADOW.setRadius(2);
init();
initGraphics();
registerListeners();
}
public LcdClockSkin(final LcdClock CONTROL) {
super(CONTROL);
aspectRatio = PREFERRED_HEIGHT / PREFERRED_WIDTH;
valueOffsetRight = 0.0;
digitalFontSizeFactor = 1.0;
backgroundTextBuilder = new StringBuilder();
FOREGROUND_SHADOW.setOffsetX(0);
FOREGROUND_SHADOW.setOffsetY(1);
FOREGROUND_SHADOW.setColor(Color.rgb(0, 0, 0, 0.5));
FOREGROUND_SHADOW.setBlurType(BlurType.TWO_PASS_BOX);
FOREGROUND_SHADOW.setRadius(2);
adjustDateFormat();
init();
initGraphics();
registerListeners();
}
private void initGraphics() {
frame = new Region();
frame.getStyleClass().setAll("frame");
frame.setOpacity(getSkinnable().isFrameVisible() ? 1 : 0);
led = new Region();
led.getStyleClass().setAll("main");
led.setStyle("-led-color: " + (getSkinnable().getLedColor()).toString().replace("0x", "#") + ";");
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 8, 0d, 0d, 0d);
glow = new DropShadow(BlurType.TWO_PASS_BOX, (Color) getSkinnable().getLedColor(), 20, 0d, 0d, 0d);
glow.setInput(innerShadow);
highlight = new Region();
highlight.getStyleClass().setAll("highlight");
getChildren().addAll(frame, led, highlight);
}
private void initGraphics() {
frame = new Region();
frame.getStyleClass().setAll("frame");
frame.setOpacity(isFrameVisible() ? 1 : 0);
led = new Region();
led.getStyleClass().setAll("main");
led.setStyle("-led-color: " + (getLedColor()).toString().replace("0x", "#") + ";");
innerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 8, 0d, 0d, 0d);
glow = new DropShadow(BlurType.TWO_PASS_BOX, getLedColor(), 20, 0d, 0d, 0d);
glow.setInput(innerShadow);
highlight = new Region();
highlight.getStyleClass().setAll("highlight");
// Add all nodes
getChildren().addAll(frame, led, highlight);
}
/**
* Updates the selected state of this timeline, and if <code>true</code>,
* visually updates the transaction with a 'glow'.
*
* @param selected Whether the transaction is currently selected.
*/
public void setSelected(final boolean selected) {
isSelected = selected;
if (isSelected) {
this.setEffect(new DropShadow(BlurType.GAUSSIAN, Color.RED, 15.0, 0.45, 0.0, 0.0));
} else {
// Remove the selection effect:
this.setEffect(null);
}
}
private void updateSelectedVisualIndication() {
if (isSelected) {
Color highlightColor = selectedWithTransaction ? Color.RED : Color.YELLOW;
triangle.setEffect(new DropShadow(BlurType.GAUSSIAN, highlightColor, 15.0, 0.45, 0.0, 0.0));
} else {
// Remove the selection effect:
triangle.setEffect(null);
}
}
/**
* Update the current selection on the ScatterChart within this
* ScatterChartPane. This allows a primary selection (which will highlight
* in red) as well as a secondary selection (which will highlight in
* yellow).
*
* @param primarySelection the set of data objects representing the primary
* selection.
* @param secondarySelection the set of data objects representing the
* secondary selection.
*/
protected void selectElementsOnChart(final Set<ScatterData> primarySelection, final Set<ScatterData> secondarySelection) {
final DropShadow primarySelectionShadow = new DropShadow(BlurType.THREE_PASS_BOX, Color.RED, 20.0, 0.85, 0.0, 0.0);
final DropShadow secondarySelectionShadow = new DropShadow(BlurType.THREE_PASS_BOX, Color.YELLOW, 20.0, 0.85, 0.0, 0.0);
Platform.runLater(() -> {
synchronized (currentData) {
for (final ScatterData data : currentData) {
if (secondarySelection != null && secondarySelection.contains(data)) {
data.getData().getNode().setEffect(secondarySelectionShadow);
continue;
}
if (primarySelection != null && primarySelection.contains(data)) {
data.getData().getNode().setEffect(primarySelectionShadow);
continue;
}
@SuppressWarnings("unchecked") // getData will return data of type number and number
Data<Number, Number> data2 = (Data<Number, Number>) data.getData();
Node dataNode = data2.getNode();
dataNode.setEffect(null);
}
}
});
if (primarySelection != null && !currentSelectedData.equals(primarySelection)) {
currentSelectedData.clear();
currentSelectedData.addAll(primarySelection);
}
}
public DropShadow getDropShadow() {
DropShadow shadow = new DropShadow();
if (use) {
shadow.setColor(getColor());
} else {
shadow.setColor(Color.TRANSPARENT);
}
shadow.setOffsetX(getOffsetX());
shadow.setOffsetY(getOffsetY());
shadow.setSpread(getSpread());
shadow.setRadius(getRadius());
shadow.setBlurType(BlurType.GAUSSIAN);
return shadow;
}
protected void initGraphics() {
// Set initial size
if (Double.compare(tile.getPrefWidth(), 0.0) <= 0 || Double.compare(tile.getPrefHeight(), 0.0) <= 0 ||
Double.compare(tile.getWidth(), 0.0) <= 0 || Double.compare(tile.getHeight(), 0.0) <= 0) {
if (tile.getPrefWidth() > 0 && tile.getPrefHeight() > 0) {
tile.setPrefSize(tile.getPrefWidth(), tile.getPrefHeight());
} else {
tile.setPrefSize(PREFERRED_WIDTH, PREFERRED_HEIGHT);
}
}
shadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 3, 0, 0, 0);
backgroundImageView = new ImageView();
backgroundImageView.setPreserveRatio(true);
backgroundImageView.setMouseTransparent(true);
if (null == tile.getBackgroundImage()) {
enableNode(backgroundImageView, false);
} else {
backgroundImageView.setImage(tile.getBackgroundImage());
enableNode(backgroundImageView, true);
}
notifyRegion = new NotifyRegion();
enableNode(notifyRegion, false);
infoRegion = new InfoRegion();
infoRegion.setPickOnBounds(false);
enableNode(infoRegion, false);
lowerRightRegion = new LowerRightRegion();
enableNode(lowerRightRegion, false);
pane = new Pane(backgroundImageView, notifyRegion, infoRegion, lowerRightRegion);
pane.getStyleClass().add("tile");
pane.setBorder(new Border(new BorderStroke(tile.getBorderColor(), BorderStrokeStyle.SOLID, new CornerRadii(PREFERRED_WIDTH * 0.025), new BorderWidths(tile.getBorderWidth()))));
pane.setBackground(new Background(new BackgroundFill(tile.getBackgroundColor(), new CornerRadii(PREFERRED_WIDTH * 0.025), Insets.EMPTY)));
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);
}
}
getStyleClass().add("switch");
shadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 3, 0, 0, 0);
switchBorder = new Rectangle();
switchBorder.setFill(getForegroundColor());
switchBackground = new Rectangle();
switchBackground.setMouseTransparent(true);
switchBackground.setFill(isActive() ? getActiveColor() : getBackgroundColor());
thumb = new Circle();
thumb.setMouseTransparent(true);
thumb.setFill(getForegroundColor());
thumb.setEffect(shadow);
pane = new Pane(switchBorder, switchBackground, thumb);
getChildren().setAll(pane);
}
public LcdClockSkin(Clock clock) {
super(clock);
digitalFontSizeFactor = 1.0;
backgroundTextBuilder = new StringBuilder();
FOREGROUND_SHADOW.setOffsetX(0);
FOREGROUND_SHADOW.setOffsetY(1);
FOREGROUND_SHADOW.setColor(Color.rgb(0, 0, 0, 0.5));
FOREGROUND_SHADOW.setBlurType(BlurType.TWO_PASS_BOX);
FOREGROUND_SHADOW.setRadius(2);
adjustDateFormat();
initGraphics();
registerListeners();
}
/**
* this method is used to add shadow effect to the node,
* however the shadow is not real ( gets affected with node transformations)
* <p>
* use {@link #createMaterialNode(Node, int)} instead to generate a real shadow
*/
public static void setDepth(Node control, int level) {
level = level < 0 ? 0 : level;
level = level > 5 ? 5 : level;
control.setEffect(new DropShadow(BlurType.GAUSSIAN,
depth[level].getColor(),
depth[level].getRadius(),
depth[level].getSpread(),
depth[level].getOffsetX(),
depth[level].getOffsetY()));
}
private void initGraphics() {
green = new Region();
green.getStyleClass().setAll("green");
yellow = new Region();
yellow.getStyleClass().setAll("yellow");
red = new Region();
red.getStyleClass().setAll("red");
rack = new Region();
rack.getStyleClass().setAll("rack");
bodyDropShadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.web("0x000000a6"), 0.0133333333 * PREFERRED_WIDTH, 1.0, 0d, 2d);
bodyInnerShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.web("0x000000a6"), 0.0133333333 * PREFERRED_WIDTH, 1.0, 1.4142135623730951, 1.4142135623730951);
bodyInnerShadow.setInput(bodyDropShadow);
body = new Region();
body.getStyleClass().setAll("body");
body.setEffect(bodyInnerShadow);
roof = new Region();
roof.getStyleClass().setAll("roof");
pane = new Pane();
pane.getChildren().setAll(green,
yellow,
red,
rack,
body,
roof);
getChildren().setAll(pane);
resize();
}
private void initGraphics() {
size = getSkinnable().getPrefWidth() < getSkinnable().getPrefHeight() ? getSkinnable().getPrefWidth() : getSkinnable().getPrefHeight();
frame = new Circle(0.5 * size, 0.5 * size, 0.5 * size);
frame.setStroke(null);
frame.setVisible(getSkinnable().isFrameVisible());
main = new Circle(0.5 * size, 0.5 * size, 0.36 * size);
main.setStroke(null);
innerShadow = new InnerShadow();
innerShadow.setRadius(0.090 * main.getLayoutBounds().getWidth());
innerShadow.setColor(Color.BLACK);
innerShadow.setBlurType(BlurType.GAUSSIAN);
innerShadow.setInput(null);
glow = new DropShadow();
glow.setRadius(0.45 * main.getLayoutBounds().getWidth());
glow.setColor((Color) getSkinnable().getLedColor());
glow.setBlurType(BlurType.GAUSSIAN);
glow.setInput(innerShadow);
highlight = new Circle(0.5 * size, 0.5 * size, 0.29 * size);
highlight.setStroke(null);
getChildren().setAll(frame, main, highlight);
}
private void recalc() {
double size = getWidth() < getHeight() ? getWidth() : getHeight();
ledOffShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * size, 0, 0, 0);
ledOnShadow = new InnerShadow(BlurType.TWO_PASS_BOX, Color.rgb(0, 0, 0, 0.65), 0.07 * size, 0, 0, 0);
ledOnShadow.setInput(new DropShadow(BlurType.TWO_PASS_BOX, ledColor.get(), 0.36 * size, 0, 0, 0));
frameGradient = new LinearGradient(0.14 * size, 0.14 * size,
0.84 * size, 0.84 * size,
false, CycleMethod.NO_CYCLE,
new Stop(0.0, Color.rgb(20, 20, 20, 0.65)),
new Stop(0.15, Color.rgb(20, 20, 20, 0.65)),
new Stop(0.26, Color.rgb(41, 41, 41, 0.65)),
new Stop(0.26, Color.rgb(41, 41, 41, 0.64)),
new Stop(0.85, Color.rgb(200, 200, 200, 0.41)),
new Stop(1.0, Color.rgb(200, 200, 200, 0.35)));
ledOnGradient = new LinearGradient(0.25 * size, 0.25 * size,
0.74 * size, 0.74 * size,
false, CycleMethod.NO_CYCLE,
new Stop(0.0, ledColor.get().deriveColor(0d, 1d, 0.77, 1d)),
new Stop(0.49, ledColor.get().deriveColor(0d, 1d, 0.5, 1d)),
new Stop(1.0, ledColor.get()));
ledOffGradient = new LinearGradient(0.25 * size, 0.25 * size,
0.74 * size, 0.74 * size,
false, CycleMethod.NO_CYCLE,
new Stop(0.0, ledColor.get().deriveColor(0d, 1d, 0.20, 1d)),
new Stop(0.49, ledColor.get().deriveColor(0d, 1d, 0.13, 1d)),
new Stop(1.0, ledColor.get().deriveColor(0d, 1d, 0.2, 1d)));
highlightGradient = new RadialGradient(0, 0,
0.3 * size, 0.3 * size,
0.29 * size,
false, CycleMethod.NO_CYCLE,
new Stop(0.0, Color.WHITE),
new Stop(1.0, Color.TRANSPARENT));
draw();
}
@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() {
stops = new ArrayList<>(16);
for (Stop stop : getGradientStops()) {
if (Double.compare(stop.getOffset(), 0.0) == 0) stops.add(new Stop(0, stop.getColor()));
stops.add(new Stop(stop.getOffset() * 0.69924 + 0.285, stop.getColor()));
}
chartCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
chartCtx = chartCanvas.getGraphicsContext2D();
overlayCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
overlayCtx = overlayCanvas.getGraphicsContext2D();
unitText = new Text(getUnit());
unitText.setTextAlignment(TextAlignment.CENTER);
unitText.setTextOrigin(VPos.CENTER);
unitText.setFont(Fonts.latoLight(0.045 * PREFERRED_WIDTH));
legendStep = (getMaxValue() - getMinValue()) / 5d;
dropShadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.BLACK, 5, 0, 0, 0);
minValueText = new Text(String.format(Locale.US, formatString, getMinValue()));
minValueText.setTextAlignment(TextAlignment.CENTER);
minValueText.setTextOrigin(VPos.CENTER);
minValueText.setVisible(isLegendVisible());
minValueText.setEffect(dropShadow);
legend1Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep));
legend1Text.setTextAlignment(TextAlignment.CENTER);
legend1Text.setTextOrigin(VPos.CENTER);
legend1Text.setVisible(isLegendVisible());
legend1Text.setEffect(dropShadow);
legend2Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep * 2));
legend2Text.setTextAlignment(TextAlignment.CENTER);
legend2Text.setTextOrigin(VPos.CENTER);
legend2Text.setVisible(isLegendVisible());
legend2Text.setEffect(dropShadow);
legend3Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep * 3));
legend3Text.setTextAlignment(TextAlignment.CENTER);
legend3Text.setTextOrigin(VPos.CENTER);
legend3Text.setVisible(isLegendVisible());
legend3Text.setEffect(dropShadow);
legend4Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep * 3));
legend4Text.setTextAlignment(TextAlignment.CENTER);
legend4Text.setTextOrigin(VPos.CENTER);
legend4Text.setVisible(isLegendVisible());
legend4Text.setEffect(dropShadow);
maxValueText = new Text(String.format(Locale.US, formatString, getMaxValue()));
maxValueText.setTextAlignment(TextAlignment.CENTER);
maxValueText.setTextOrigin(VPos.CENTER);
maxValueText.setVisible(isLegendVisible());
maxValueText.setEffect(dropShadow);
// Add all nodes
pane = new Pane(chartCanvas, overlayCanvas, unitText, minValueText, legend1Text, legend2Text, legend3Text, legend4Text, maxValueText);
pane.setBackground(new Background(new BackgroundFill(getChartBackgroundColor(), new CornerRadii(1024), Insets.EMPTY)));
getChildren().setAll(pane);
}
public RaceTrack() {
ImageView carImageView = new ImageView(new Image(
DataAppPreloader.class.getResourceAsStream("images/car.png")));
road = SVGPathBuilder.create()
.content(trackPath).fill(null).stroke(Color.gray(0.4))
.strokeWidth(50)
.effect(DropShadowBuilder.create().radius(20).blurType(BlurType.ONE_PASS_BOX).build())
.build();
SVGPath trackLine = SVGPathBuilder.create()
.content(trackPath).fill(null).stroke(Color.WHITE)
.strokeDashArray(8d,6d).build();
Line startLine = LineBuilder.create()
.startX(610.312).startY(401.055).endX(610.312).endY(450.838)
.stroke(Color.WHITE).strokeDashArray(2d,2d).build();
Text startFinish = TextBuilder.create().text("START/FINISH").fill(Color.WHITE)
.x(570).y(475).build();
percentage = TextBuilder.create().text("0%")
.x(390).y(170).font(Font.font("System", 60))
.fill(Color.web("#ddf3ff"))
.stroke(Color.web("#73c0f7"))
.effect(DropShadowBuilder.create().radius(15).color(Color.web("#3382ba")).blurType(BlurType.ONE_PASS_BOX).build())
.build();
ImageView raceCarImg = new ImageView(new Image(
DataAppPreloader.class.getResourceAsStream("images/Mini-red-and-white.png")));
raceCarImg.setX(raceCarImg.getImage().getWidth()/2);
raceCarImg.setY(raceCarImg.getImage().getHeight()/2);
raceCarImg.setRotate(90);
raceCar = new Group(raceCarImg);
track = new Group(road, trackLine, startLine, startFinish);
track.setCache(true);
// add children
getChildren().addAll(track, raceCar, percentage);
// Create path animation that we will use to drive the car along the track
race = new PathTransition(Duration.seconds(1), road, raceCar);
race.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
race.play();
race.pause();
// center our content and set our size
setTranslateX(-road.getBoundsInLocal().getMinX());
setTranslateY(-road.getBoundsInLocal().getMinY());
setPrefSize(road.getBoundsInLocal().getWidth(), road.getBoundsInLocal().getHeight());
setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);
}
public RaceTrack() {
ImageView carImageView = new ImageView(new Image(
DataAppPreloader.class.getResourceAsStream("images/car.png")));
road = SVGPathBuilder.create()
.content(trackPath).fill(null).stroke(Color.gray(0.4))
.strokeWidth(50)
.effect(DropShadowBuilder.create().radius(20).blurType(BlurType.ONE_PASS_BOX).build())
.build();
SVGPath trackLine = SVGPathBuilder.create()
.content(trackPath).fill(null).stroke(Color.WHITE)
.strokeDashArray(8d,6d).build();
Line startLine = LineBuilder.create()
.startX(610.312).startY(401.055).endX(610.312).endY(450.838)
.stroke(Color.WHITE).strokeDashArray(2d,2d).build();
Text startFinish = TextBuilder.create().text("START/FINISH").fill(Color.WHITE)
.x(570).y(475).build();
percentage = TextBuilder.create().text("0%")
.x(390).y(170).font(Font.font("System", 60))
.fill(Color.web("#ddf3ff"))
.stroke(Color.web("#73c0f7"))
.effect(DropShadowBuilder.create().radius(15).color(Color.web("#3382ba")).blurType(BlurType.ONE_PASS_BOX).build())
.build();
ImageView raceCarImg = new ImageView(new Image(
DataAppPreloader.class.getResourceAsStream("images/Mini-red-and-white.png")));
raceCarImg.setX(raceCarImg.getImage().getWidth()/2);
raceCarImg.setY(raceCarImg.getImage().getHeight()/2);
raceCarImg.setRotate(90);
raceCar = new Group(raceCarImg);
track = new Group(road, trackLine, startLine, startFinish);
track.setCache(true);
// add children
getChildren().addAll(track, raceCar, percentage);
// Create path animation that we will use to drive the car along the track
race = new PathTransition(Duration.seconds(1), road, raceCar);
race.setOrientation(PathTransition.OrientationType.ORTHOGONAL_TO_TANGENT);
race.play();
race.pause();
// center our content and set our size
setTranslateX(-road.getBoundsInLocal().getMinX());
setTranslateY(-road.getBoundsInLocal().getMinY());
setPrefSize(road.getBoundsInLocal().getWidth(), road.getBoundsInLocal().getHeight());
setMaxSize(USE_PREF_SIZE, USE_PREF_SIZE);
}
@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() {
stops = new ArrayList<>(16);
for (Stop stop : getGradientStops()) {
if (Double.compare(stop.getOffset(), 0.0) == 0) stops.add(new Stop(0, stop.getColor()));
stops.add(new Stop(stop.getOffset() * 0.69924 + 0.285, stop.getColor()));
}
chartCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
chartCtx = chartCanvas.getGraphicsContext2D();
overlayCanvas = new Canvas(PREFERRED_WIDTH, PREFERRED_HEIGHT);
overlayCtx = overlayCanvas.getGraphicsContext2D();
unitText = new Text(getUnit());
unitText.setTextAlignment(TextAlignment.CENTER);
unitText.setTextOrigin(VPos.CENTER);
unitText.setFont(Fonts.latoLight(0.045 * PREFERRED_WIDTH));
legendStep = (getMaxValue() - getMinValue()) / 5d;
dropShadow = new DropShadow(BlurType.TWO_PASS_BOX, Color.BLACK, 5, 0, 0, 0);
minValueText = new Text(String.format(Locale.US, formatString, getMinValue()));
minValueText.setTextAlignment(TextAlignment.CENTER);
minValueText.setTextOrigin(VPos.CENTER);
minValueText.setVisible(isLegendVisible());
minValueText.setEffect(dropShadow);
legend1Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep));
legend1Text.setTextAlignment(TextAlignment.CENTER);
legend1Text.setTextOrigin(VPos.CENTER);
legend1Text.setVisible(isLegendVisible());
legend1Text.setEffect(dropShadow);
legend2Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep * 2));
legend2Text.setTextAlignment(TextAlignment.CENTER);
legend2Text.setTextOrigin(VPos.CENTER);
legend2Text.setVisible(isLegendVisible());
legend2Text.setEffect(dropShadow);
legend3Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep * 3));
legend3Text.setTextAlignment(TextAlignment.CENTER);
legend3Text.setTextOrigin(VPos.CENTER);
legend3Text.setVisible(isLegendVisible());
legend3Text.setEffect(dropShadow);
legend4Text = new Text(String.format(Locale.US, formatString, getMinValue() + legendStep * 3));
legend4Text.setTextAlignment(TextAlignment.CENTER);
legend4Text.setTextOrigin(VPos.CENTER);
legend4Text.setVisible(isLegendVisible());
legend4Text.setEffect(dropShadow);
maxValueText = new Text(String.format(Locale.US, formatString, getMaxValue()));
maxValueText.setTextAlignment(TextAlignment.CENTER);
maxValueText.setTextOrigin(VPos.CENTER);
maxValueText.setVisible(isLegendVisible());
maxValueText.setEffect(dropShadow);
// Add all nodes
pane = new Pane(chartCanvas, overlayCanvas, unitText, minValueText, legend1Text, legend2Text, legend3Text, legend4Text, maxValueText);
pane.setBackground(new Background(new BackgroundFill(getChartBackgroundColor(), new CornerRadii(1024), Insets.EMPTY)));
getChildren().setAll(pane);
}