Search in sources :

Example 11 with Control

use of javafx.scene.control.Control in project honest-profiler by jvm-profiling-tools.

the class HPFXUtil method selectCtxMenu.

// Context Menu Selection
public static void selectCtxMenu(FxRobot robot, String triggerId, int itemIndex, String expectedName) {
    javafx.scene.Node node = robot.lookup(triggerId).query();
    waitUntil(() -> node.isVisible() && !node.isDisabled());
    if (isHeadless()) {
        EventHandler<? super MouseEvent> handler = ((Control) node).onMousePressedProperty().get();
        waitUntil(asyncFx(() -> handler.handle(new MouseEvent(MouseEvent.MOUSE_CLICKED, 0, 0, 0, 0, MouseButton.PRIMARY, 1, true, true, true, true, true, true, true, true, true, true, null))));
        waitUntil(() -> ((Control) node).getContextMenu() != null);
        ContextMenu menu = waitUntil(asyncFx(() -> ((Control) node).getContextMenu()));
        MenuItem item = waitUntil(asyncFx(() -> (menu.getItems().get(itemIndex))));
        assertEquals("Wrong ContextMenu MenuItem", expectedName, item.getText());
        waitUntil(asyncFx(() -> item.fire()));
    } else {
        robot.clickOn(node, SECONDARY);
        for (int i = 0; i < itemIndex + 1; i++) {
            robot.type(DOWN);
        }
        robot.type(ENTER);
    }
}
Also used : Control(javafx.scene.control.Control) MouseEvent(javafx.scene.input.MouseEvent) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem)

Example 12 with Control

use of javafx.scene.control.Control in project dolphin-platform by canoo.

the class SimpleFormRow method createEditor.

protected Control createEditor(FormField bean) {
    try {
        Control editor = null;
        if (bean.getContentType().equals(String.class)) {
            // if (((StringFormFieldBean) bean).isMultiline()) {
            // editor = new TextArea();
            // ((TextArea) editor).setWrapText(true);
            // } else {
            editor = new TextField();
            // }
            FXBinder.bind(((TextInputControl) editor).textProperty()).bidirectionalTo(bean.valueProperty());
        } else if (bean.getContentType().equals(Boolean.class)) {
            editor = new CheckBox();
            FXBinder.bind(((CheckBox) editor).textProperty()).bidirectionalTo(bean.titleProperty());
            FXBinder.bind(((CheckBox) editor).selectedProperty()).bidirectionalTo(bean.valueProperty());
        } else if (bean.getContentType().equals(Date.class)) {
            editor = new DatePicker();
            FXBinder.bind(((DatePicker) editor).valueProperty()).bidirectionalTo(bean.valueProperty(), new BidirectionalConverter<Date, LocalDate>() {

                @Override
                public LocalDate convert(Date value) {
                    return LocalDate.from(value.toInstant());
                }

                @Override
                public Date convertBack(LocalDate value) {
                    return Date.from(Instant.from(value));
                }
            });
        }
        FXBinder.bind(editor.disableProperty()).to(bean.disabledProperty());
        Utils.registerTooltip(editor, bean);
        editor.setMaxWidth(Double.MAX_VALUE);
        editor.getStyleClass().add("simple-form-editor");
        return editor;
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : TextInputControl(javafx.scene.control.TextInputControl) TextInputControl(javafx.scene.control.TextInputControl) Control(javafx.scene.control.Control) CheckBox(javafx.scene.control.CheckBox) TextField(javafx.scene.control.TextField) DatePicker(javafx.scene.control.DatePicker) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 13 with Control

use of javafx.scene.control.Control 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 14 with Control

use of javafx.scene.control.Control in project JFoenix by jfoenixadmin.

the class JFXResponsiveHandler method scanAllNodes.

/**
 * scans all nodes in the scene and apply the css pseduoClass to them.
 *
 * @param parent      stage parent node
 * @param pseudoClass css class for certain device
 */
private void scanAllNodes(Parent parent, PseudoClass pseudoClass) {
    parent.getChildrenUnmodifiable().addListener(new ListChangeListener<Node>() {

        @Override
        public void onChanged(javafx.collections.ListChangeListener.Change<? extends Node> c) {
            while (c.next()) {
                if (!c.wasPermutated() && !c.wasUpdated()) {
                    for (Node addedNode : c.getAddedSubList()) {
                        if (addedNode instanceof Parent) {
                            scanAllNodes((Parent) addedNode, pseudoClass);
                        }
                    }
                }
            }
        }
    });
    for (Node component : parent.getChildrenUnmodifiable()) {
        if (component instanceof Pane) {
            ((Pane) component).getChildren().addListener(new ListChangeListener<Node>() {

                @Override
                public void onChanged(javafx.collections.ListChangeListener.Change<? extends Node> c) {
                    while (c.next()) {
                        if (!c.wasPermutated() && !c.wasUpdated()) {
                            for (Node addedNode : c.getAddedSubList()) {
                                if (addedNode instanceof Parent) {
                                    scanAllNodes((Parent) addedNode, pseudoClass);
                                }
                            }
                        }
                    }
                }
            });
            // if the component is a container, scan its children
            scanAllNodes((Pane) component, pseudoClass);
        } else if (component instanceof ScrollPane) {
            ((ScrollPane) component).contentProperty().addListener((o, oldVal, newVal) -> {
                scanAllNodes((Parent) newVal, pseudoClass);
            });
            // if the component is a container, scan its children
            if (((ScrollPane) component).getContent() instanceof Parent) {
                scanAllNodes((Parent) ((ScrollPane) component).getContent(), pseudoClass);
            }
        } else if (component instanceof Control) {
            // if the component is an instance of IInputControl, add to list
            component.pseudoClassStateChanged(PSEUDO_CLASS_EX_SMALL, pseudoClass == PSEUDO_CLASS_EX_SMALL);
            component.pseudoClassStateChanged(PSEUDO_CLASS_SMALL, pseudoClass == PSEUDO_CLASS_SMALL);
            component.pseudoClassStateChanged(PSEUDO_CLASS_MEDIUM, pseudoClass == PSEUDO_CLASS_MEDIUM);
            component.pseudoClassStateChanged(PSEUDO_CLASS_LARGE, pseudoClass == PSEUDO_CLASS_LARGE);
        }
    }
}
Also used : Parent(javafx.scene.Parent) ScrollPane(javafx.scene.control.ScrollPane) ListChangeListener(javafx.collections.ListChangeListener) Stage(javafx.stage.Stage) PseudoClass(javafx.css.PseudoClass) Node(javafx.scene.Node) Control(javafx.scene.control.Control) Pane(javafx.scene.layout.Pane) Control(javafx.scene.control.Control) Parent(javafx.scene.Parent) ScrollPane(javafx.scene.control.ScrollPane) Node(javafx.scene.Node) ScrollPane(javafx.scene.control.ScrollPane) Pane(javafx.scene.layout.Pane) ListChangeListener(javafx.collections.ListChangeListener)

Aggregations

Control (javafx.scene.control.Control)14 Node (javafx.scene.Node)12 Parent (javafx.scene.Parent)6 Scene (javafx.scene.Scene)4 IFXLabelFloatControl (com.jfoenix.controls.base.IFXLabelFloatControl)3 Method (java.lang.reflect.Method)3 List (java.util.List)3 Application (javafx.application.Application)3 ObservableList (javafx.collections.ObservableList)3 FXMLLoader (javafx.fxml.FXMLLoader)3 Parameter (com.scythe.instrumenter.InstrumentationProperties.Parameter)2 PropertyChangeListener (java.beans.PropertyChangeListener)2 File (java.io.File)2 Field (java.lang.reflect.Field)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Modifier (java.lang.reflect.Modifier)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashSet (java.util.HashSet)2