Search in sources :

Example 26 with JFXTextField

use of com.jfoenix.controls.JFXTextField in project JFoenix by jfoenixadmin.

the class JFXTextFieldSkinAndroid method layoutChildren.

@Override
protected void layoutChildren(final double x, final double y, final double w, final double h) {
    final double height = getSkinnable().getHeight();
    final Node leadingGraphic = ((JFXTextField) getSkinnable()).getLeadingGraphic();
    final Node trailingGraphic = ((JFXTextField) getSkinnable()).getTrailingGraphic();
    final double leadingW = leadingGraphic == null ? 0.0 : snapSize(leadingGraphic.prefWidth(height));
    final double trailingW = trailingGraphic == null ? 0.0 : snapSize(trailingGraphic.prefWidth(height));
    final double textX = snapPosition(x) + leadingW;
    final double textW = w - snapSize(leadingW) - snapSize(trailingW);
    super.layoutChildren(textX, y, textW, h);
    linesWrapper.layoutLines(x, y, w, h, height, Math.floor(h));
    linesWrapper.layoutPrompt(textX, y, textW, h);
    errorContainer.layoutPane(x, height + linesWrapper.focusedLine.getHeight(), w, h);
    // draw leading/trailing graphics
    if (leadingGraphic != null) {
        leadingGraphic.resizeRelocate(snappedLeftInset(), 0, leadingW, height);
    }
    if (trailingGraphic != null) {
        trailingGraphic.resizeRelocate(w - trailingW + snappedLeftInset(), 0, trailingW, height);
    }
    if (getSkinnable().getWidth() > 0) {
        updateTextPos();
    }
    linesWrapper.updateLabelFloatLayout();
    if (invalid) {
        invalid = false;
        // update validation container
        errorContainer.invalid(w);
        // focus
        linesWrapper.invalid();
    }
}
Also used : Node(javafx.scene.Node) JFXTextField(com.jfoenix.controls.JFXTextField)

Example 27 with JFXTextField

use of com.jfoenix.controls.JFXTextField in project JFoenix by jfoenixadmin.

the class JFXTextFieldSkinAndroid method computeMinHeight.

@Override
protected double computeMinHeight(double w, double topInset, double rightInset, double bottomInset, double leftInset) {
    final double h = super.computeMinHeight(w, topInset, rightInset, bottomInset, leftInset);
    Node leadingGraphic = ((JFXTextField) getSkinnable()).getTrailingGraphic();
    Node trailingGraphic = ((JFXTextField) getSkinnable()).getTrailingGraphic();
    final double leadingH = leadingGraphic == null ? 0.0 : snapSize(leadingGraphic.minHeight(w));
    final double trailingH = trailingGraphic == null ? 0.0 : snapSize(trailingGraphic.minHeight(w));
    return Math.max(Math.max(h, leadingH), trailingH);
}
Also used : Node(javafx.scene.Node) JFXTextField(com.jfoenix.controls.JFXTextField)

Example 28 with JFXTextField

use of com.jfoenix.controls.JFXTextField 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();
}
Also used : BooleanBinding(javafx.beans.binding.BooleanBinding) Control(javafx.scene.control.Control) StackPane(javafx.scene.layout.StackPane) Bindings(javafx.beans.binding.Bindings) Supplier(java.util.function.Supplier) JFXKeyFrame(com.jfoenix.transitions.JFXKeyFrame) InvalidationListener(javafx.beans.InvalidationListener) JFXKeyValue(com.jfoenix.transitions.JFXKeyValue) Insets(javafx.geometry.Insets) ComboBox(javafx.scene.control.ComboBox) BorderWidths(javafx.scene.layout.BorderWidths) BackgroundFill(javafx.scene.layout.BackgroundFill) Color(javafx.scene.paint.Color) ObjectProperty(javafx.beans.property.ObjectProperty) Node(javafx.scene.Node) Border(javafx.scene.layout.Border) Rectangle(javafx.scene.shape.Rectangle) JFXAnimationTimer(com.jfoenix.transitions.JFXAnimationTimer) Background(javafx.scene.layout.Background) BorderStrokeStyle(javafx.scene.layout.BorderStrokeStyle) BorderStroke(javafx.scene.layout.BorderStroke) Text(javafx.scene.text.Text) Duration(javafx.util.Duration) Region(javafx.scene.layout.Region) Interpolator(javafx.animation.Interpolator) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Paint(javafx.scene.paint.Paint) IFXLabelFloatControl(com.jfoenix.controls.base.IFXLabelFloatControl) Scale(javafx.scene.transform.Scale) ObservableValue(javafx.beans.value.ObservableValue) WritableValue(javafx.beans.value.WritableValue) JFXTextField(com.jfoenix.controls.JFXTextField) CornerRadii(javafx.scene.layout.CornerRadii) JFXAnimationTimer(com.jfoenix.transitions.JFXAnimationTimer) Background(javafx.scene.layout.Background) JFXKeyFrame(com.jfoenix.transitions.JFXKeyFrame) BackgroundFill(javafx.scene.layout.BackgroundFill) JFXTextField(com.jfoenix.controls.JFXTextField) Node(javafx.scene.Node) InvalidationListener(javafx.beans.InvalidationListener) WritableValue(javafx.beans.value.WritableValue)

Example 29 with JFXTextField

use of com.jfoenix.controls.JFXTextField in project JFoenix by jfoenixadmin.

the class JFXTextFieldSkin method computeMinHeight.

@Override
protected double computeMinHeight(double w, double topInset, double rightInset, double bottomInset, double leftInset) {
    final double h = super.computeMinHeight(w, topInset, rightInset, bottomInset, leftInset);
    Node leadingGraphic = ((JFXTextField) getSkinnable()).getTrailingGraphic();
    Node trailingGraphic = ((JFXTextField) getSkinnable()).getTrailingGraphic();
    final double leadingH = leadingGraphic == null ? 0.0 : snapSize(leadingGraphic.minHeight(w));
    final double trailingH = trailingGraphic == null ? 0.0 : snapSize(trailingGraphic.minHeight(w));
    return Math.max(Math.max(h, leadingH), trailingH);
}
Also used : Node(javafx.scene.Node) JFXTextField(com.jfoenix.controls.JFXTextField)

Example 30 with JFXTextField

use of com.jfoenix.controls.JFXTextField in project JFoenix by jfoenixadmin.

the class JFXTimePickerSkin method handleControlPropertyChanged.

@Override
protected void handleControlPropertyChanged(String p) {
    if ("DEFAULT_COLOR".equals(p)) {
        ((JFXTextField) getEditor()).setFocusColor(jfxTimePicker.getDefaultColor());
    } else if ("CONVERTER".equals(p)) {
        updateDisplayNode();
    } else if ("EDITOR".equals(p)) {
        getEditableInputNode();
    } else if ("SHOWING".equals(p)) {
        if (jfxTimePicker.isShowing()) {
            show();
        } else {
            hide();
        }
    } else if ("VALUE".equals(p)) {
        updateDisplayNode();
        jfxTimePicker.fireEvent(new ActionEvent());
    } else {
        super.handleControlPropertyChanged(p);
    }
}
Also used : ActionEvent(javafx.event.ActionEvent) JFXTextField(com.jfoenix.controls.JFXTextField)

Aggregations

JFXTextField (com.jfoenix.controls.JFXTextField)30 Node (javafx.scene.Node)11 Field (java.lang.reflect.Field)5 StackPane (javafx.scene.layout.StackPane)5 Insets (javafx.geometry.Insets)4 TextField (javafx.scene.control.TextField)4 VBox (javafx.scene.layout.VBox)4 Text (javafx.scene.text.Text)4 JFXButton (com.jfoenix.controls.JFXButton)3 JFXTreeView (com.jfoenix.controls.JFXTreeView)3 CachedTransition (com.jfoenix.transitions.CachedTransition)3 TextFieldSkin (com.sun.javafx.scene.control.skin.TextFieldSkin)3 Bindings (javafx.beans.binding.Bindings)3 ObjectProperty (javafx.beans.property.ObjectProperty)3 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)3 Scene (javafx.scene.Scene)3 Color (javafx.scene.paint.Color)3 JFXTreeViewPath (com.jfoenix.controls.JFXTreeViewPath)2 Arrays.asList (java.util.Arrays.asList)2 List (java.util.List)2