import javafx.animation.Timeline; //导入方法依赖的package包/类
private EventHandler buildEvent() {
return new EventHandler() {
@Override
public void handle(Event e) {
if (turned)
return;
if (e.getEventType() == MouseEvent.MOUSE_ENTERED || e.getEventType() == GazeEvent.GAZE_ENTERED) {
progressIndicator.setOpacity(1);
progressIndicator.setProgress(0);
Timeline timelineCard = new Timeline();
timelineCard.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.xProperty(), card.getX() - (initWidth * zoom_factor - initWidth) / 2)));
timelineCard.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.yProperty(), card.getY() - (initHeight * zoom_factor - initHeight) / 2)));
timelineCard.getKeyFrames().add(
new KeyFrame(new Duration(1), new KeyValue(card.widthProperty(), initWidth * zoom_factor)));
timelineCard.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.heightProperty(), initHeight * zoom_factor)));
timelineProgressBar = new Timeline();
timelineProgressBar.getKeyFrames().add(new KeyFrame(new Duration(fixationlength),
new KeyValue(progressIndicator.progressProperty(), 1)));
timelineCard.play();
timelineProgressBar.play();
timelineProgressBar.setOnFinished(new EventHandler() {
@Override
public void handle(ActionEvent actionEvent) {
turned = true;
card.setFill(new ImagePattern(image, 0, 0, 1, 1, true));
card.removeEventFilter(MouseEvent.ANY, enterEvent);
card.removeEventFilter(GazeEvent.ANY, enterEvent);
if (winner) {
onCorrectCardSelected();
} else {// bad card
onWrongCardSelected();
}
}
});
} else if (e.getEventType() == MouseEvent.MOUSE_EXITED || e.getEventType() == GazeEvent.GAZE_EXITED) {
Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.xProperty(), card.getX() + (initWidth * zoom_factor - initWidth) / 2)));
timeline.getKeyFrames().add(new KeyFrame(new Duration(1),
new KeyValue(card.yProperty(), card.getY() + (initHeight * zoom_factor - initHeight) / 2)));
timeline.getKeyFrames()
.add(new KeyFrame(new Duration(1), new KeyValue(card.widthProperty(), initWidth)));
timeline.getKeyFrames()
.add(new KeyFrame(new Duration(1), new KeyValue(card.heightProperty(), initHeight)));
timeline.play();
timelineProgressBar.stop();
progressIndicator.setOpacity(0);
progressIndicator.setProgress(0);
}
}
};
}