org.jpedal.objects.acroforms.actions.JavaFX.JavaFXFormsListener Maven / Gradle / Ivy
/*
* ===========================================
* Java Pdf Extraction Decoding Access Library
* ===========================================
*
* Project Info: http://www.idrsolutions.com
* Help section for developers at http://www.idrsolutions.com/support/
*
* (C) Copyright 1997-2017 IDRsolutions and Contributors.
*
* This file is part of JPedal/JPDF2HTML5
*
@LICENSE@
*
* ---------------
* JavaFXFormsListener.java
* ---------------
*/
package org.jpedal.objects.acroforms.actions.JavaFX;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.TouchEvent;
import org.jpedal.objects.acroforms.actions.ActionHandler;
import org.jpedal.objects.acroforms.actions.PDFListener;
import org.jpedal.objects.raw.FormObject;
/**
* Listener which listens to various actions on JavaFX Form objects and
* executes the correct method in ActionHandler
*
* @author Simon
*/
public class JavaFXFormsListener extends PDFListener {
private boolean debug;
private final EventHandler mouseHandler;
private EventHandler touchHandler;
private final ChangeListener focusHandler;
private final EventHandler keyHandler;
public JavaFXFormsListener(final FormObject form, final ActionHandler handler) {
super(form, handler);
mouseHandler = new EventHandler() {
@Override
public void handle(final MouseEvent event) {
handleMouseEvent(event);
}
};
focusHandler = new ChangeListener() {
@Override
public void changed(final ObservableValue observable, final Boolean oldValue, final Boolean newValue) {
handleFocusEvent(newValue);
}
};
keyHandler = new EventHandler() {
@Override
public void handle(final KeyEvent event) {
handleKeyEvent(event);
}
};
}
public EventHandler getMouseHandler() {
return mouseHandler;
}
public EventHandler getTouchHandler() {
return touchHandler;
}
public ChangeListener getFocusHandler() {
return focusHandler;
}
public EventHandler getKeyHandler() {
return keyHandler;
}
private void handleMouseEvent(final MouseEvent event) {
if (debug) {
System.out.println("JavaFXFormsMouseListener event: " + event.getEventType().getName());
}
if (event.getEventType() == MouseEvent.MOUSE_CLICKED) {
super.mouseClicked(event);
} else if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
super.mousePressed(event);
} else if (event.getEventType() == MouseEvent.MOUSE_RELEASED) {
super.mouseReleased(event);
} else if (event.getEventType() == MouseEvent.MOUSE_ENTERED) {
handler.A(event, formObject, ActionHandler.MOUSEENTERED);
handler.E(event, formObject);
if (formObject.getCharacteristics()[8] && formObject.getGUIComponent() != null) { //togglenoView
((Node) formObject.getGUIComponent()).setVisible(true);
}
} else if (event.getEventType() == MouseEvent.MOUSE_EXITED) {
handler.A(event, formObject, ActionHandler.MOUSEEXITED);
handler.X(event, formObject);
if (formObject.getCharacteristics()[8] && formObject.getGUIComponent() != null) { //togglenoView
((Node) formObject.getGUIComponent()).setVisible(false);
}
}
}
private void handleFocusEvent(final boolean gainedFocus) {
if (gainedFocus) {
super.focusGained(null);
} else {
super.focusLost(null);
}
}
private void handleKeyEvent(final KeyEvent event) {
if (event.getEventType().equals(KeyEvent.KEY_PRESSED)) {
// Ignored at present
} else if (event.getEventType().equals(KeyEvent.KEY_RELEASED)) {
super.keyReleased(event);
}
}
}