Example usage for javafx.scene Node addEventHandler

List of usage examples for javafx.scene Node addEventHandler

Introduction

In this page you can find the example usage for javafx.scene Node addEventHandler.

Prototype

public final <T extends Event> void addEventHandler(final EventType<T> eventType,
        final EventHandler<? super T> eventHandler) 

Source Link

Document

Registers an event handler to this node.

Usage

From source file:de.micromata.mgc.javafx.FXEvents.java

/**
 * Adds an eventhandler to the selected node.
 * /*from ww w  . j  a  v  a  2 s .co  m*/
 * @param node node to append the eventhandler to.
 * @param handler the event handler to append
 * @param type event type
 * @param controller the controller
 * @param <E> the type of the event
 */
public <E extends Event> void addEventHandler(AbstractModelController<?> controller, Node node,
        EventType<E> type, EventHandler<E> handler) {
    node.addEventHandler(type, handler);

    List<Node> eventSinks = listeners.get(controller);
    if (eventSinks == null) {
        eventSinks = new ArrayList<>();
        listeners.put(controller, eventSinks);
    }
    Optional<Node> optexist = eventSinks.stream().filter(lnode -> lnode.equals(node)).findFirst();
    if (optexist.isPresent() == false) {
        eventSinks.add(node);
    }
}

From source file:de.micromata.mgc.javafx.FXEvents.java

public void registerValMessageReceiver(AbstractModelController<?> controller, Node node, Class<?> referenceType,
        String property) {//  www.  j  a  v  a  2s .  co m
    registerListener(controller, node);
    node.addEventHandler(ValMessageEvent.MESSAGE_EVENT_TYPE, event -> {
        ValMessage msg = event.getMessage();
        if (msg.isConsumed() == true) {
            return;
        }
        if (referenceType != null && msg.getReference() != null) {
            if (referenceType.isAssignableFrom(msg.getReference().getClass()) == false) {
                return;
            }
            if (StringUtils.isNotBlank(property) && StringUtils.isNotBlank(msg.getProperty()) == true) {
                if (property.equals(msg.getProperty()) == true) {
                    controller.addToFeedback(msg);
                    FXGuiUtils.markErroneousField(controller, node, msg);

                    event.consume();

                }
            }
            controller.addToFeedback(msg);
        }

    });
}

From source file:de.micromata.mgc.javafx.FXEvents.java

public void registerValMessageReceiver(AbstractModelController<?> controller, Node node, Object model,
        String property) {/*w w w.j  a  va  2s .  c  o  m*/
    if (node == null) {
        LOG.error("Node is null on property: " + model.getClass().getSimpleName() + "." + property);
    }
    registerListener(controller, node);
    node.addEventHandler(ValMessageEvent.MESSAGE_EVENT_TYPE, event -> {
        ValMessage msg = event.getMessage();
        if (msg.isConsumed() == true) {
            return;
        }
        Object themod = model;
        String theprop = property;
        if (themod == msg.getReference()) {
            if (StringUtils.isNotBlank(property) && StringUtils.isNotBlank(msg.getProperty()) == true
                    && property.equals(msg.getProperty()) == true) {

                controller.addToFeedback(msg);
                FXGuiUtils.markErroneousField(controller, node, msg);
                event.consume();
            }

        } else if (msg.isConsumed() == false && themod == msg.getReference()) {
            controller.addToFeedback(msg);
        }

    });
}