*
*/
private void showPopup(MouseEvent evt)
{
// create a picker
CalendarPicker calendarPicker = new CalendarPicker();
calendarPicker.setMode(CalendarPicker.Mode.SINGLE);
calendarPicker.localeProperty().set(getSkinnable().localeProperty().get());
calendarPicker.allowNullProperty().set(getSkinnable().allowNullProperty().get());
calendarPicker.calendarProperty().set(getSkinnable().calendarProperty().get());
calendarPicker.disabledCalendars().addAll(getSkinnable().disabledCalendars());
calendarPicker.highlightedCalendars().addAll(getSkinnable().highlightedCalendars());
calendarPicker.setCalendarRangeCallback(new Callback<CalendarRange,Void>() {
@Override
public Void call(CalendarRange calendarRange) {
Callback<CalendarRange, Void> lCallback = getSkinnable().getCalendarRangeCallback();
if (lCallback == null) {
return null;
}
return lCallback.call(calendarRange);
}
});
// TODO: replace with PopupControl because that is styleable (see C:/Users/user/Documents/openjfx/8.0rt/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxPopupControl.java)
// popup = new PopupControl() {
//
// @Override public Styleable getStyleableParent() {
// return CalendarTextFieldSkin.this.getSkinnable();
// }
// {
// setSkin(new Skin<Skinnable>() {
// @Override public Skinnable getSkinnable() { return CalendarTextFieldSkin.this.getSkinnable(); }
// @Override public Node getNode() { return lBorderPane; }
// @Override public void dispose() { }
// });
// getScene().getRoot().impl_processCSS(true);
// }
// };
Popup lPopup = new Popup();
lPopup.setAutoFix(true);
lPopup.setAutoHide(true);
lPopup.setHideOnEscape(true);
BorderPane lBorderPane = new BorderPane();
lBorderPane.getStyleClass().add(this.getClass().getSimpleName() + "_popup");
lBorderPane.setCenter(calendarPicker);
calendarPicker.showTimeProperty().set( getSkinnable().getShowTime() );
// because the Java 8 DateTime classes use the CalendarPicker, we need to add some specific CSS classes here to support seamless CSS
if (getSkinnable().getStyleClass().contains(LocalDateTextField.class.getSimpleName())) {
calendarPicker.getStyleClass().addAll(LocalDatePicker.class.getSimpleName());
}
if (getSkinnable().getStyleClass().contains(LocalDateTimeTextField.class.getSimpleName())) {
calendarPicker.getStyleClass().addAll(LocalDateTimePicker.class.getSimpleName());
}
// add a close and accept button if we're showing time
if ( getSkinnable().getShowTime())
{
VBox lVBox = new VBox();
lBorderPane.rightProperty().set(lVBox);
ImageView lAcceptIconImageView = new ImageViewButton();
lAcceptIconImageView.getStyleClass().addAll("accept-icon");
lAcceptIconImageView.setPickOnBounds(true);
lAcceptIconImageView.setOnMouseClicked( (mouseEvent) -> {
getSkinnable().calendarProperty().set(calendarPicker.calendarProperty().get());
lPopup.hide();
});
lVBox.add(lAcceptIconImageView);
ImageView lCloseIconImageView = new ImageViewButton();
lCloseIconImageView.getStyleClass().addAll("close-icon");
lCloseIconImageView.setPickOnBounds(true);
lCloseIconImageView.setOnMouseClicked( (mouseEvent) -> {
lPopup.hide();
});
lVBox.add(lCloseIconImageView);
}
// if a value is selected in date mode, immediately close the popup
calendarPicker.calendarProperty().addListener( (observable) -> {
if (lPopup != null && getSkinnable().getShowTime() == false && lPopup.isShowing()) {
lPopup.hide();
}
});
// when the popup is hidden
lPopup.setOnHiding( (windowEvent) -> {
// and time is not shown, the value must be set into the textfield
if ( getSkinnable().getShowTime() == false) {
getSkinnable().calendarProperty().set(calendarPicker.calendarProperty().get());
}
// but at least the textfield must be enabled again
textField.setDisable(false);
});
// add to popup
lPopup.getContent().add(lBorderPane);
// show it just below the textfield
textField.setDisable(true);
lPopup.show(textField, NodeUtil.screenX(getSkinnable()), NodeUtil.screenY(getSkinnable()) + textField.getHeight());
// move the focus over
calendarPicker.requestFocus(); // TODO: not working
}