use of javafx.scene.layout.Background in project JFoenix by jfoenixadmin.
the class PromptLinesWrapper method init.
public void init(Runnable createPromptNodeRunnable, Node... cachedNodes) {
animatedPromptTextFill = new SimpleObjectProperty<>(promptTextFill.get());
usePromptText = Bindings.createBooleanBinding(this::usePromptText, valueProperty, promptTextProperty, control.labelFloatProperty(), promptTextFill);
// draw lines
line.setManaged(false);
line.getStyleClass().add("input-line");
line.setBackground(new Background(new BackgroundFill(control.getUnFocusColor(), CornerRadii.EMPTY, Insets.EMPTY)));
// focused line
focusedLine.setManaged(false);
focusedLine.getStyleClass().add("input-focused-line");
focusedLine.setBackground(new Background(new BackgroundFill(control.getFocusColor(), CornerRadii.EMPTY, Insets.EMPTY)));
focusedLine.setOpacity(0);
focusedLine.getTransforms().add(scale);
if (usePromptText.get()) {
createPromptNodeRunnable.run();
}
usePromptText.addListener(observable -> {
createPromptNodeRunnable.run();
control.requestLayout();
});
final Supplier<WritableValue<Number>> promptTargetYSupplier = () -> promptTextSupplier.get() == null ? null : promptTextSupplier.get().translateYProperty();
final Supplier<WritableValue<Number>> promptTargetXSupplier = () -> promptTextSupplier.get() == null ? null : promptTextSupplier.get().translateXProperty();
focusTimer = new JFXAnimationTimer(new JFXKeyFrame(Duration.millis(1), JFXKeyValue.builder().setTarget(focusedLine.opacityProperty()).setEndValue(1).setInterpolator(Interpolator.EASE_BOTH).setAnimateCondition(() -> control.isFocused()).build()), new JFXKeyFrame(Duration.millis(160), JFXKeyValue.builder().setTarget(scale.xProperty()).setEndValue(1).setInterpolator(Interpolator.EASE_BOTH).setAnimateCondition(() -> control.isFocused()).build(), JFXKeyValue.builder().setTarget(animatedPromptTextFill).setEndValueSupplier(() -> control.getFocusColor()).setInterpolator(Interpolator.EASE_BOTH).setAnimateCondition(() -> control.isFocused() && control.isLabelFloat()).build(), JFXKeyValue.builder().setTargetSupplier(promptTargetXSupplier).setEndValueSupplier(() -> clip.getX()).setAnimateCondition(() -> control.isLabelFloat()).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTargetSupplier(promptTargetYSupplier).setEndValueSupplier(() -> -contentHeight).setAnimateCondition(() -> control.isLabelFloat()).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTarget(promptTextScale.xProperty()).setEndValue(0.85).setAnimateCondition(() -> control.isLabelFloat()).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTarget(promptTextScale.yProperty()).setEndValue(0.85).setAnimateCondition(() -> control.isLabelFloat()).setInterpolator(Interpolator.EASE_BOTH).build()));
unfocusTimer = new JFXAnimationTimer(new JFXKeyFrame(Duration.millis(160), JFXKeyValue.builder().setTargetSupplier(promptTargetXSupplier).setEndValue(0).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTargetSupplier(promptTargetYSupplier).setEndValue(0).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTarget(promptTextScale.xProperty()).setEndValue(1).setInterpolator(Interpolator.EASE_BOTH).build(), JFXKeyValue.builder().setTarget(promptTextScale.yProperty()).setEndValue(1).setInterpolator(Interpolator.EASE_BOTH).build()));
promptContainer.getStyleClass().add("prompt-container");
promptContainer.setManaged(false);
promptContainer.setMouseTransparent(true);
// clip prompt container
clip.setSmooth(false);
clip.setX(0);
if (control instanceof JFXTextField) {
final InvalidationListener leadingListener = obs -> {
final Node leading = ((JFXTextField) control).getLeadingGraphic();
if (leading == null) {
clip.xProperty().unbind();
clip.setX(0);
} else {
clip.xProperty().bind(((Region) leading).widthProperty().negate());
}
};
((JFXTextField) control).leadingGraphicProperty().addListener(leadingListener);
leadingListener.invalidated(null);
}
clip.widthProperty().bind(promptContainer.widthProperty().add(clip.xProperty().negate()));
promptContainer.setClip(clip);
focusTimer.setOnFinished(() -> animating = false);
unfocusTimer.setOnFinished(() -> animating = false);
focusTimer.setCacheNodes(cachedNodes);
unfocusTimer.setCacheNodes(cachedNodes);
// handle animation on focus gained/lost event
control.focusedProperty().addListener(observable -> {
if (control.isFocused()) {
focus();
} else {
unFocus();
}
});
promptTextFill.addListener(observable -> {
if (!control.isLabelFloat() || !control.isFocused()) {
animatedPromptTextFill.set(promptTextFill.get());
}
});
updateDisabled();
}
use of javafx.scene.layout.Background in project JFoenix by jfoenixadmin.
the class PromptLinesWrapper method updateDisabled.
public void updateDisabled() {
final boolean disabled = control.isDisable();
line.setBorder(!disabled ? Border.EMPTY : new Border(new BorderStroke(control.getUnFocusColor(), BorderStrokeStyle.DASHED, CornerRadii.EMPTY, new BorderWidths(1))));
line.setBackground(new Background(new BackgroundFill(disabled ? Color.TRANSPARENT : control.getUnFocusColor(), CornerRadii.EMPTY, Insets.EMPTY)));
}
use of javafx.scene.layout.Background in project JFoenix by jfoenixadmin.
the class JFXFillTransition method interpolate.
/**
* {@inheritDoc}
*/
@Override
protected void interpolate(double frac) {
if (start == null) {
starting();
}
Color newColor = start.interpolate(end, frac);
if (Color.TRANSPARENT.equals(start)) {
newColor = new Color(end.getRed(), end.getGreen(), end.getBlue(), newColor.getOpacity());
}
region.get().setBackground(new Background(new BackgroundFill(newColor, radii, insets)));
}
use of javafx.scene.layout.Background in project JFoenix by jfoenixadmin.
the class JFXToggleNodeSkin method updateSelectionBackground.
public void updateSelectionBackground() {
CornerRadii radii = getSkinnable().getBackground() == null ? CornerRadii.EMPTY : getSkinnable().getBackground().getFills().get(0).getRadii();
Insets insets = getSkinnable().getBackground() == null ? Insets.EMPTY : getSkinnable().getBackground().getFills().get(0).getInsets();
selectionOverLay.setBackground(new Background(new BackgroundFill(getSkinnable().isSelected() ? ((JFXToggleNode) getSkinnable()).getSelectedColor() : ((JFXToggleNode) getSkinnable()).getUnSelectedColor(), radii, insets)));
}
use of javafx.scene.layout.Background in project JFoenix by jfoenixadmin.
the class JFXNodeUtils method updateBackground.
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));
}
}
Aggregations