Search in sources :

Example 1 with JFXDrawerEvent

use of com.jfoenix.controls.events.JFXDrawerEvent in project JFoenix by jfoenixadmin.

the class JFXDrawer method partialOpen.

private void partialOpen() {
    if (partialTransition != null)
        partialTransition.stop();
    partialTransition = new DrawerPartialTransitionDraw(translateProperty.get(), 0);
    partialTransition.setOnFinished((event) -> {
        translateProperty.set(0);
        onDrawerOpenedProperty.get().handle(new JFXDrawerEvent(JFXDrawerEvent.OPENED));
    });
    partialTransition.play();
}
Also used : JFXDrawerEvent(com.jfoenix.controls.events.JFXDrawerEvent)

Example 2 with JFXDrawerEvent

use of com.jfoenix.controls.events.JFXDrawerEvent in project JFoenix by jfoenixadmin.

the class JFXDrawer method initListeners.

private void initListeners() {
    updateDirection(directionProperty.get());
    initTranslate.bind(Bindings.createDoubleBinding(() -> -1 * directionProperty.get().doubleValue() * defaultSizeProperty.getValue() - initOffset * directionProperty.get().doubleValue(), defaultSizeProperty, directionProperty));
    // add listeners to update drawer properties
    overLayVisibleProperty().addListener((o, oldVal, newVal) -> {
        overlayPane.setStyle(!newVal ? "-fx-background-color : transparent;" : "");
        overlayPane.setMouseTransparent(!newVal);
        overlayPane.setPickOnBounds(newVal);
    });
    directionProperty.addListener((o, oldVal, newVal) -> updateDirection(newVal));
    initTranslate.addListener((o, oldVal, newVal) -> updateDrawerAnimation(newVal.doubleValue()));
    // content listener for mouse hold on a side
    this.content.addEventHandler(MouseEvent.MOUSE_PRESSED, (e) -> {
        if (!e.isConsumed()) {
            double size = 0;
            long valid = 0;
            for (int i = 0; i < callBacks.size(); i++) if (!callBacks.get(i).call(null))
                valid++;
            //				long valid = callBacks.stream().filter(callback->!callback.call(null)).count();
            if (directionProperty.get().equals(DrawerDirection.RIGHT))
                size = content.getWidth();
            else if (directionProperty.get().equals(DrawerDirection.BOTTOM))
                size = content.getHeight();
            double eventPoint = 0;
            if (directionProperty.get().equals(DrawerDirection.RIGHT) || directionProperty.get().equals(DrawerDirection.LEFT))
                eventPoint = e.getX();
            else
                eventPoint = e.getY();
            if (size + directionProperty.get().doubleValue() * eventPoint < activeOffset && (content.getCursor() == Cursor.DEFAULT || content.getCursor() == null) && valid == 0) {
                holdTimer.play();
                e.consume();
            }
        }
    });
    // mouse drag handler
    translateProperty.addListener((o, oldVal, newVal) -> {
        double opValue = 1 - newVal.doubleValue() / initTranslate.doubleValue();
        overlayPane.setOpacity(opValue);
    });
    // add opening/closing action listeners
    translateProperty.addListener((o, oldVal, newVal) -> {
        if (!openCalled && closeCalled && directionProperty.get().doubleValue() * newVal.doubleValue() > directionProperty.get().doubleValue() * initTranslate.doubleValue() / 2) {
            openCalled = true;
            closeCalled = false;
            onDrawerOpeningProperty.get().handle(new JFXDrawerEvent(JFXDrawerEvent.OPENING));
        }
    });
    translateProperty.addListener((o, oldVal, newVal) -> {
        if (openCalled && !closeCalled && directionProperty.get().doubleValue() * newVal.doubleValue() < directionProperty.get().doubleValue() * initTranslate.doubleValue() / 2) {
            closeCalled = true;
            openCalled = false;
            onDrawerClosingProperty.get().handle(new JFXDrawerEvent(JFXDrawerEvent.CLOSING));
        }
    });
    this.sidePane.addEventHandler(MouseEvent.MOUSE_DRAGGED, mouseDragHandler);
    this.sidePane.addEventHandler(MouseEvent.MOUSE_RELEASED, mouseReleasedHandler);
    this.sidePane.addEventHandler(MouseEvent.MOUSE_PRESSED, mousePressedHandler);
    this.content.addEventHandler(MouseEvent.MOUSE_RELEASED, (e) -> {
        holdTimer.stop();
        this.content.removeEventFilter(MouseEvent.MOUSE_DRAGGED, mouseDragHandler);
    });
    holdTimer.setOnFinished((e) -> {
        if (!this.getChildren().contains(overlayPane))
            this.getChildren().add(overlayPane);
        if (!this.getChildren().contains(sidePane))
            this.getChildren().add(sidePane);
        partialTransition = new DrawerPartialTransition(initTranslate.doubleValue(), initTranslate.doubleValue() + initOffset * directionProperty.get().doubleValue() + activeOffset * directionProperty.get().doubleValue());
        partialTransition.setOnFinished((event) -> {
            this.content.addEventFilter(MouseEvent.MOUSE_DRAGGED, mouseDragHandler);
            this.content.addEventHandler(MouseEvent.MOUSE_RELEASED, mouseReleasedHandler);
            this.content.addEventHandler(MouseEvent.MOUSE_RELEASED, new EventHandler<Event>() {

                @Override
                public void handle(Event event) {
                    JFXDrawer.this.content.removeEventHandler(MouseEvent.MOUSE_RELEASED, mouseReleasedHandler);
                    JFXDrawer.this.content.removeEventHandler(MouseEvent.MOUSE_RELEASED, this);
                }
            });
        });
        partialTransition.play();
    });
}
Also used : MouseEvent(javafx.scene.input.MouseEvent) Event(javafx.event.Event) JFXDrawerEvent(com.jfoenix.controls.events.JFXDrawerEvent) ActionEvent(javafx.event.ActionEvent) JFXDrawerEvent(com.jfoenix.controls.events.JFXDrawerEvent)

Example 3 with JFXDrawerEvent

use of com.jfoenix.controls.events.JFXDrawerEvent in project JFoenix by jfoenixadmin.

the class JFXDrawer method close.

/**
 * Starts the animation to transition this drawer to closed.
 */
public void close() {
    translateTimer.setOnFinished(() -> {
        overlayPane.setMouseTransparent(true);
        fireEvent(new JFXDrawerEvent(JFXDrawerEvent.CLOSED));
    });
    if (hasMiniSize()) {
        if (resizeTo != getMiniDrawerSize()) {
            resizeTo = getMiniDrawerSize();
            for (Map.Entry<WritableValue<?>, JFXDrawerKeyValue<?>> entry : initValues.entrySet()) {
                currentValue.put(entry.getKey(), entry.getValue().getCloseValueSupplier());
            }
        }
    } else {
        updateTempDrawerSize();
        if (translateTo != initTranslate.get()) {
            translateTo = initTranslate.get();
            for (Map.Entry<WritableValue<?>, JFXDrawerKeyValue<?>> entry : initValues.entrySet()) {
                currentValue.put(entry.getKey(), entry.getValue().getCloseValueSupplier());
            }
        }
    }
    getCachePolicy().cache(contentHolder);
    translateTimer.reverseAndContinue();
}
Also used : JFXDrawerKeyValue(com.jfoenix.transitions.JFXDrawerKeyValue) JFXDrawerEvent(com.jfoenix.controls.events.JFXDrawerEvent) HashMap(java.util.HashMap) Map(java.util.Map) WritableValue(javafx.beans.value.WritableValue)

Example 4 with JFXDrawerEvent

use of com.jfoenix.controls.events.JFXDrawerEvent in project JFoenix by jfoenixadmin.

the class JFXDrawer method partialClose.

private void partialClose() {
    for (Map.Entry<WritableValue<?>, JFXDrawerKeyValue<?>> entry : initValues.entrySet()) {
        currentValue.put(entry.getKey(), entry.getValue().getCloseValueSupplier());
    }
    translateTo = initTranslate.get();
    resizeTo = getMiniDrawerSize();
    translateTimer.setOnFinished(() -> {
        overlayPane.setMouseTransparent(true);
        fireEvent(new JFXDrawerEvent(JFXDrawerEvent.CLOSED));
    });
    getCachePolicy().cache(contentHolder);
    translateTimer.start();
}
Also used : JFXDrawerKeyValue(com.jfoenix.transitions.JFXDrawerKeyValue) HashMap(java.util.HashMap) Map(java.util.Map) WritableValue(javafx.beans.value.WritableValue) JFXDrawerEvent(com.jfoenix.controls.events.JFXDrawerEvent)

Aggregations

JFXDrawerEvent (com.jfoenix.controls.events.JFXDrawerEvent)4 JFXDrawerKeyValue (com.jfoenix.transitions.JFXDrawerKeyValue)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 WritableValue (javafx.beans.value.WritableValue)2 ActionEvent (javafx.event.ActionEvent)1 Event (javafx.event.Event)1 MouseEvent (javafx.scene.input.MouseEvent)1