下面列出了javafx.scene.layout.BackgroundFill#getRadii ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Constructs the animation
*
* @param node the node to animate
* @param colorA the color to start with
* @param colorB the other color
* @param colorSteps how many interpolations between the two colors
*/
public GlowBackground(Region node, Color colorA, Color colorB, int colorSteps) {
super(node);
this.originalBackground = getNode().backgroundProperty().get();
if (originalBackground != null && !originalBackground.getFills().isEmpty()) {
BackgroundFill lastFill = originalBackground.getFills().get(originalBackground.getFills().size() - 1);
originalRadii = lastFill.getRadii();
originalInsets = lastFill.getInsets();
} else {
originalRadii = CornerRadii.EMPTY;
originalInsets = Insets.EMPTY;
}
int totalFrames = colorSteps * 2;
double millisPerFrame = 1000 / totalFrames;
for (int i = 0; i < totalFrames; i++) {
Color color;
double frac = i * 2.0 / totalFrames;
Duration dur = Duration.millis(i * millisPerFrame);
if (i <= colorSteps) {
color = colorA.interpolate(colorB, frac);
} else {
color = colorB.interpolate(colorA, frac - 1);
}
getTimeline().getKeyFrames().add(
new KeyFrame(dur,
new KeyValue(getNode().backgroundProperty(),
// new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY)))));
new Background(new BackgroundFill(color, originalRadii, originalInsets)))));
}
}
public static void updateBackground(Background newBackground, Region nodeToUpdate, Paint fill) {
if (newBackground != null && !newBackground.getFills().isEmpty()) {
final BackgroundFill[] fills = new BackgroundFill[newBackground.getFills().size()];
for (int i = 0; i < newBackground.getFills().size(); i++) {
BackgroundFill bf = newBackground.getFills().get(i);
fills[i] = new BackgroundFill(fill, bf.getRadii(), bf.getInsets());
}
nodeToUpdate.setBackground(new Background(fills));
}
}
private static String backgroundFillToString(BackgroundFill backgroundFill) {
return "paint=" + backgroundFill.getFill()
+ " insets=" + backgroundFill.getInsets()
+ " radii=" + backgroundFill.getRadii();
}