javafx.scene.control.DatePicker Java Examples

The following examples show how to use javafx.scene.control.DatePicker. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RFXDatePicker.java    From marathonv5 with Apache License 2.0 7 votes vote down vote up
@Override
public void focusGained(RFXComponent prev) {
    DatePicker datePicker = (DatePicker) node;
    LocalDate value = datePicker.getValue();
    if (value == null && datePicker.isEditable()) {
        prevDate = datePicker.getEditor().getText();
    } else {
        prevDate = getDatePickerText(datePicker, value);
    }
}
 
Example #2
Source File: DatePickerTableCell.java    From tornadofx-controls with Apache License 2.0 6 votes vote down vote up
private void createDatePicker() {
    datePicker = new DatePicker(getItem());
    datePicker.converterProperty().bind(converterProperty());

    datePicker.setOnAction(event -> {
        commitEdit(datePicker.getValue());
        event.consume();
    });

    datePicker.setOnKeyReleased(t -> {
        if (t.getCode() == KeyCode.ESCAPE) {
            cancelEdit();
            t.consume();
        }
    });
}
 
Example #3
Source File: RFXDatePickerTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void pickEditorDate() {
    Set<Node> datePickerNodes = getPrimaryStage().getScene().getRoot().lookupAll(".date-picker");
    List<Node> pickers = new ArrayList<>(datePickerNodes);
    DatePicker datePicker = (DatePicker) pickers.get(1);
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        RFXDatePicker rfxDatePicker = new RFXDatePicker(datePicker, null, null, lr);
        datePicker.getEditor().setText("8/8/2016");
        rfxDatePicker.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    AssertJUnit.assertEquals("8/8/2016", recording.getParameters()[0]);

}
 
Example #4
Source File: RFXDatePickerTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void getText() {
    DatePicker datePicker = (DatePicker) getPrimaryStage().getScene().getRoot().lookup(".date-picker");
    LoggingRecorder lr = new LoggingRecorder();
    List<String> text = new ArrayList<>();
    RFXDatePicker rfxDatePicker = new RFXDatePicker(datePicker, null, null, lr);
    Platform.runLater(() -> {
        datePicker.setValue(LocalDate.now());
        text.add(rfxDatePicker._getText());
    });
    new Wait("Waiting for date picker text.") {
        @Override
        public boolean until() {
            return text.size() > 0;
        }
    };
    AssertJUnit.assertEquals(datePicker.getConverter().toString(LocalDate.now()), text.get(0));
}
 
Example #5
Source File: JavaFXDatePickerElementTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void selectDate() {
    DatePicker datePickerNode = (DatePicker) getPrimaryStage().getScene().getRoot().lookup(".date-picker");
    IJavaFXElement datePicker = datePickers.get(0);
    Platform.runLater(() -> {
        datePicker.marathon_select(dateString);
    });
    List<Object> dates = new ArrayList<>();
    Platform.runLater(() -> {
        LocalDate value = datePickerNode.getValue();
        dates.add(datePickerNode.getConverter().toString(value));
    });
    new Wait("Waiting for date to be set.") {
        @Override
        public boolean until() {
            return dates.size() > 0;
        }
    };
    AssertJUnit.assertEquals(dateString, dates.get(0));
}
 
Example #6
Source File: JavaFXDatePickerElementTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void selectEdiotrDate() {
    Set<Node> datePickerNodes = getPrimaryStage().getScene().getRoot().lookupAll(".date-picker");
    List<Node> pickers = new ArrayList<>(datePickerNodes);
    DatePicker datePickerNode = (DatePicker) pickers.get(1);
    IJavaFXElement datePicker = datePickers.get(1);
    Platform.runLater(() -> {
        datePicker.marathon_select(dateString);
    });
    List<Object> dates = new ArrayList<>();
    Platform.runLater(() -> {
        LocalDate value = datePickerNode.getValue();
        dates.add(datePickerNode.getConverter().toString(value));
    });
    new Wait("Waiting for date to be set.") {
        @Override
        public boolean until() {
            return dates.size() > 0;
        }
    };
    AssertJUnit.assertEquals(dateString, dates.get(0));
}
 
Example #7
Source File: RFXDatePickerTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Test
public void pickDate() {
    DatePicker datePicker = (DatePicker) getPrimaryStage().getScene().getRoot().lookup(".date-picker");
    LoggingRecorder lr = new LoggingRecorder();
    Platform.runLater(() -> {
        RFXDatePicker rfxDatePicker = new RFXDatePicker(datePicker, null, null, lr);
        datePicker.setValue(LocalDate.now());
        rfxDatePicker.focusLost(null);
    });
    List<Recording> recordings = lr.waitAndGetRecordings(1);
    Recording recording = recordings.get(0);
    AssertJUnit.assertEquals("recordSelect", recording.getCall());
    LocalDate date = (LocalDate) datePicker.getChronology().date(LocalDate.now());
    AssertJUnit.assertEquals(datePicker.getConverter().toString(date), recording.getParameters()[0]);
}
 
Example #8
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Tuple2<Label, DatePicker> addTopLabelDatePicker(GridPane gridPane,
                                                              int rowIndex,
                                                              String title,
                                                              double top) {
    DatePicker datePicker = new JFXDatePicker();

    final Tuple2<Label, VBox> topLabelWithVBox = addTopLabelWithVBox(gridPane, rowIndex, title, datePicker, top);

    return new Tuple2<>(topLabelWithVBox.first, datePicker);
}
 
Example #9
Source File: BattleLogController.java    From logbook-kai with MIT License 5 votes vote down vote up
@FXML
void initialize() {
    LocalDate date = LocalDate.now();
    Callback<DatePicker, DateCell> callback = d -> new DateCell() {
        @Override
        public void updateItem(LocalDate item, boolean empty) {
            super.updateItem(item, empty);
            this.getStyleClass().remove("selected");
            this.getStyleClass().remove("contains");

            LocalDate from = UnitDialog.this.from.getValue();
            LocalDate to = UnitDialog.this.to.getValue();
            if (from != null && to != null) {
                if (item.equals(from) || item.equals(to)) {
                    this.getStyleClass().add("selected");
                } else if ((from.compareTo(to) < 0 && item.compareTo(from) > 0 && item.compareTo(to) < 0)
                        || (from.compareTo(to) > 0 && item.compareTo(from) < 0 && item.compareTo(to) > 0)) {
                    this.getStyleClass().add("contains");
                }
            }
        }
    };
    this.to.setValue(date);
    this.to.setDayCellFactory(callback);
    this.from.setValue(date.minusWeeks(2));
    this.from.setDayCellFactory(callback);
}
 
Example #10
Source File: JFXDatePickerBehavior.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
/**************************************************************************
 *                                                                        *
 * Mouse Events handling (when losing focus)                              *
 *                                                                        *
 *************************************************************************/

@Override
public void onAutoHide() {
    DatePicker datePicker = (DatePicker) getControl();
    JFXDatePickerSkin cpSkin = (JFXDatePickerSkin) datePicker.getSkin();
    cpSkin.syncWithAutoUpdate();
    if (!datePicker.isShowing()) {
        super.onAutoHide();
    }
}
 
Example #11
Source File: DatePickerDemo.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Stage stage) {

    FlowPane main = new FlowPane();
    main.setVgap(20);
    main.setHgap(20);


    DatePicker datePicker = new DatePicker();

    main.getChildren().add(datePicker);
    JFXDatePicker datePickerFX = new JFXDatePicker();

    main.getChildren().add(datePickerFX);
    datePickerFX.setPromptText("pick a date");
    JFXTimePicker blueDatePicker = new JFXTimePicker();
    blueDatePicker.setDefaultColor(Color.valueOf("#3f51b5"));
    blueDatePicker.setOverLay(true);
    main.getChildren().add(blueDatePicker);


    StackPane pane = new StackPane();
    pane.getChildren().add(main);
    StackPane.setMargin(main, new Insets(100));
    pane.setStyle("-fx-background-color:WHITE");

    final Scene scene = new Scene(pane, 400, 700);
    final ObservableList<String> stylesheets = scene.getStylesheets();
    stylesheets.addAll(MainDemo.class.getResource("/css/jfoenix-fonts.css").toExternalForm(),
                       MainDemo.class.getResource("/css/jfoenix-design.css").toExternalForm());
    stage.setTitle("JFX Date Picker Demo");
    stage.setScene(scene);
    stage.show();

}
 
Example #12
Source File: RFXDatePicker.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public void focusLost(RFXComponent next) {
    DatePicker datePicker = (DatePicker) node;
    LocalDate value = datePicker.getValue();
    String currentDate;
    if (value == null && datePicker.isEditable()) {
        currentDate = datePicker.getEditor().getText();
    } else {
        currentDate = getDatePickerText(datePicker, value);
    }
    if (!currentDate.equals(prevDate))
        recorder.recordSelect(this, currentDate);
}
 
Example #13
Source File: DatePickerSample.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public DatePickerSample() {
    HBox hBox = new HBox();
    hBox.setSpacing(15);

    DatePicker uneditableDatePicker = new DatePicker();
    uneditableDatePicker.setEditable(false);

    DatePicker editablDatePicker = new DatePicker();
    editablDatePicker.setPromptText("Edit or Pick...");
    hBox.getChildren().addAll(uneditableDatePicker, editablDatePicker);
    getChildren().add(hBox);
}
 
Example #14
Source File: JavaFXDatePickerElementTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void initializeDriver() {
    LocalDate d = LocalDate.of(2016, 3, 16);
    dateString = new DatePicker(d).getConverter().toString(d);
    driver = new JavaFXAgent();
    datePickers = driver.findElementsByTagName("date-picker");
}
 
Example #15
Source File: DateTimeRangeInputPane.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Build a single datetime picker.
 *
 * @param label
 * @param ld
 * @param h
 * @param m
 * @param s
 * @param listener
 * @return
 */
private Pane createPicker(final String label, final ChangeListener<String> changed) {
    final Label dpLabel = new Label(label);
    final DatePicker dp = new DatePicker();
    dp.setConverter(new StringConverter<LocalDate>() {
        @Override
        public String toString(final LocalDate date) {
            return date != null ? DATE_FORMATTER.format(date) : "";
        }

        @Override
        public LocalDate fromString(final String s) {
            return s != null && !s.isEmpty() ? LocalDate.parse(s, DATE_FORMATTER) : null;
        }
    });
    dpLabel.setLabelFor(dp);
    final HBox dpBox = new HBox(dpLabel, dp);
    final HBox spinnerBox = new HBox(CONTROLPANE_SPACING / 2);
    dp.maxWidthProperty().bind(spinnerBox.widthProperty().multiply(2.0 / 3.0));
    spinnerBox.getChildren().addAll(createSpinner("Hour", 0, 23, changed), createSpinner("Minute", 0, 59, changed), createSpinner("Second", 0, 59, changed));
    final VBox picker = new VBox(dpBox, spinnerBox);
    picker.setStyle("-fx-padding:4; -fx-border-radius:4; -fx-border-color: grey;");

    dp.getEditor().textProperty().addListener(changed);

    // The DatePicker has the horrible problem that you can type in the text field, but the value won't change,
    // so if you type a new date and click Go, the old date will be used, not the new date that you can see.
    // The simplest way to avoid this is to disable the text field. :-(
    dp.getEditor().setDisable(true);

    datePickers.add(dp);

    return picker;
}
 
Example #16
Source File: JavaFXDatePickerElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public boolean marathon_select(String value) {
    DatePicker datePicker = (DatePicker) getComponent();
    if (!value.equals("")) {
        try {
            LocalDate date = datePicker.getConverter().fromString(value);
            datePicker.setValue(date);
        } catch (Throwable t) {
            throw new DateTimeException("Invalid value for '" + value + "' for date-picker '");
        }
        return true;
    }
    return false;
}
 
Example #17
Source File: JavaFXElementFactory.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public static void reset() {
    add(Node.class, JavaFXElement.class);
    add(TextInputControl.class, JavaFXTextInputControlElement.class);
    add(HTMLEditor.class, JavaFXHTMLEditor.class);
    add(CheckBox.class, JavaFXCheckBoxElement.class);
    add(ToggleButton.class, JavaFXToggleButtonElement.class);
    add(Slider.class, JavaFXSliderElement.class);
    add(Spinner.class, JavaFXSpinnerElement.class);
    add(SplitPane.class, JavaFXSplitPaneElement.class);
    add(ProgressBar.class, JavaFXProgressBarElement.class);
    add(ChoiceBox.class, JavaFXChoiceBoxElement.class);
    add(ColorPicker.class, JavaFXColorPickerElement.class);
    add(ComboBox.class, JavaFXComboBoxElement.class);
    add(DatePicker.class, JavaFXDatePickerElement.class);
    add(TabPane.class, JavaFXTabPaneElement.class);
    add(ListView.class, JavaFXListViewElement.class);
    add(TreeView.class, JavaFXTreeViewElement.class);
    add(TableView.class, JavaFXTableViewElement.class);
    add(TreeTableView.class, JavaFXTreeTableViewElement.class);
    add(CheckBoxListCell.class, JavaFXCheckBoxListCellElement.class);
    add(ChoiceBoxListCell.class, JavaFXChoiceBoxCellElement.class);
    add(ComboBoxListCell.class, JavaFXComboBoxCellElement.class);
    add(CheckBoxTreeCell.class, JavaFXCheckBoxTreeCellElement.class);
    add(ChoiceBoxTreeCell.class, JavaFXChoiceBoxCellElement.class);
    add(ComboBoxTreeCell.class, JavaFXComboBoxCellElement.class);
    add(TableCell.class, JavaFXTableViewCellElement.class);
    add(CheckBoxTableCell.class, JavaFXCheckBoxTableCellElement.class);
    add(ChoiceBoxTableCell.class, JavaFXChoiceBoxCellElement.class);
    add(ComboBoxTableCell.class, JavaFXComboBoxCellElement.class);
    add(TreeTableCell.class, JavaFXTreeTableCellElement.class);
    add(CheckBoxTreeTableCell.class, JavaFXCheckBoxTreeTableCell.class);
    add(ChoiceBoxTreeTableCell.class, JavaFXChoiceBoxCellElement.class);
    add(ComboBoxTreeTableCell.class, JavaFXComboBoxCellElement.class);
    add(WebView.class, JavaFXWebViewElement.class);
    add(GenericStyledArea.GENERIC_STYLED_AREA_CLASS, RichTextFXGenericStyledAreaElement.class);
}
 
Example #18
Source File: LocalDateTimeEditorFactory.java    From constellation with Apache License 2.0 4 votes vote down vote up
private HBox createTimeSpinners() {
    datePicker = new DatePicker();
    datePicker.setConverter(new LocalDateStringConverter(
            TemporalFormatting.DATE_FORMATTER, TemporalFormatting.DATE_FORMATTER));
    datePicker.getEditor().textProperty().addListener((v, o, n) -> {
        update();
    });
    datePicker.setValue(LocalDate.now());
    datePicker.valueProperty().addListener((v, o, n) -> {
        update();
    });

    hourSpinner = new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 23));
    minSpinner = new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 59));
    secSpinner = new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 59));
    milliSpinner = new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 999));
    hourSpinner.getValueFactory().setValue(LocalTime.now(ZoneOffset.UTC).getHour());
    minSpinner.getValueFactory().setValue(LocalTime.now(ZoneOffset.UTC).getMinute());
    secSpinner.getValueFactory().setValue(LocalTime.now(ZoneOffset.UTC).getSecond());
    milliSpinner.getValueFactory().setValue(0);

    final HBox timeSpinnerContainer = new HBox(CONTROLS_DEFAULT_VERTICAL_SPACING);

    final Label dateLabel = new Label("Date:");
    dateLabel.setId(LABEL_ID);
    dateLabel.setLabelFor(datePicker);

    final Label hourSpinnerLabel = new Label("Hour:");
    hourSpinnerLabel.setId(LABEL_ID);
    hourSpinnerLabel.setLabelFor(hourSpinner);

    final Label minSpinnerLabel = new Label("Minute:");
    minSpinnerLabel.setId(LABEL_ID);
    minSpinnerLabel.setLabelFor(minSpinner);

    final Label secSpinnerLabel = new Label("Second:");
    secSpinnerLabel.setId(LABEL_ID);
    secSpinnerLabel.setLabelFor(secSpinner);

    final Label milliSpinnerLabel = new Label("Millis:");
    milliSpinnerLabel.setId(LABEL_ID);
    milliSpinnerLabel.setLabelFor(milliSpinner);

    hourSpinner.setPrefWidth(NUMBER_SPINNER_WIDTH);
    minSpinner.setPrefWidth(NUMBER_SPINNER_WIDTH);
    secSpinner.setPrefWidth(NUMBER_SPINNER_WIDTH);
    milliSpinner.setPrefWidth(MILLIS_SPINNER_WIDTH);

    hourSpinner.setEditable(true);
    minSpinner.setEditable(true);
    secSpinner.setEditable(true);
    milliSpinner.setEditable(true);

    hourSpinner.valueProperty().addListener((o, n, v) -> {
        update();
    });
    minSpinner.valueProperty().addListener((o, n, v) -> {
        update();
    });
    secSpinner.valueProperty().addListener((o, n, v) -> {
        update();
    });
    milliSpinner.valueProperty().addListener((o, n, v) -> {
        update();
    });

    final VBox dateLabelNode = new VBox(5);
    dateLabelNode.getChildren().addAll(dateLabel, datePicker);
    final VBox hourLabelNode = new VBox(5);
    hourLabelNode.getChildren().addAll(hourSpinnerLabel, hourSpinner);
    final VBox minLabelNode = new VBox(5);
    minLabelNode.getChildren().addAll(minSpinnerLabel, minSpinner);
    final VBox secLabelNode = new VBox(5);
    secLabelNode.getChildren().addAll(secSpinnerLabel, secSpinner);
    final VBox milliLabelNode = new VBox(5);
    milliLabelNode.getChildren().addAll(milliSpinnerLabel, milliSpinner);

    timeSpinnerContainer.getChildren().addAll(dateLabelNode, hourLabelNode, minLabelNode, secLabelNode, milliLabelNode);

    return timeSpinnerContainer;
}
 
Example #19
Source File: DatePickerSample.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void initUI() {
    VBox vbox = new VBox(20);
    vbox.setStyle("-fx-padding: 10;");
    Scene scene = new Scene(vbox, 400, 400);
    stage.setScene(scene);

    checkInDatePicker = new DatePicker();
    checkOutDatePicker = new DatePicker();
    checkInDatePicker.setValue(LocalDate.now());

    final Callback<DatePicker, DateCell> dayCellFactory = new Callback<DatePicker, DateCell>() {
        @Override
        public DateCell call(final DatePicker datePicker) {
            return new DateCell() {
                @Override
                public void updateItem(LocalDate item, boolean empty) {
                    super.updateItem(item, empty);

                    if (item.isBefore(checkInDatePicker.getValue().plusDays(1))) {
                        setDisable(true);
                        setStyle("-fx-background-color: #ffc0cb;");
                    }
                    long p = ChronoUnit.DAYS.between(checkInDatePicker.getValue(), item);
                    setTooltip(new Tooltip("You're about to stay for " + p + " days"));
                }
            };
        }
    };

    checkOutDatePicker.setDayCellFactory(dayCellFactory);
    checkOutDatePicker.setValue(checkInDatePicker.getValue().plusDays(1));
    checkInDatePicker.setChronology(ThaiBuddhistChronology.INSTANCE);
    checkOutDatePicker.setChronology(HijrahChronology.INSTANCE);

    GridPane gridPane = new GridPane();
    gridPane.setHgap(10);
    gridPane.setVgap(10);

    Label checkInlabel = new Label("Check-In Date:");
    gridPane.add(checkInlabel, 0, 0);
    GridPane.setHalignment(checkInlabel, HPos.LEFT);

    gridPane.add(checkInDatePicker, 0, 1);

    Label checkOutlabel = new Label("Check-Out Date:");
    gridPane.add(checkOutlabel, 0, 2);
    GridPane.setHalignment(checkOutlabel, HPos.LEFT);

    gridPane.add(checkOutDatePicker, 0, 3);

    vbox.getChildren().add(gridPane);

}
 
Example #20
Source File: WalletPasswordWindow.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
private void showRestoreScreen() {
    Label headLine2Label = new AutoTooltipLabel(Res.get("seed.restore.title"));
    headLine2Label.getStyleClass().add("popup-headline");
    headLine2Label.setMouseTransparent(true);
    GridPane.setHalignment(headLine2Label, HPos.LEFT);
    GridPane.setRowIndex(headLine2Label, ++rowIndex);
    GridPane.setMargin(headLine2Label, new Insets(30, 0, 0, 0));
    gridPane.getChildren().add(headLine2Label);

    seedWordsTextArea = addTextArea(gridPane, ++rowIndex, Res.get("seed.enterSeedWords"), 5);
    ;
    seedWordsTextArea.setPrefHeight(60);

    Tuple2<Label, DatePicker> labelDatePickerTuple2 = addTopLabelDatePicker(gridPane, ++rowIndex,
            Res.get("seed.creationDate"), 10);
    datePicker = labelDatePickerTuple2.second;
    restoreButton = addPrimaryActionButton(gridPane, ++rowIndex, Res.get("seed.restore"), 0);
    restoreButton.setDefaultButton(true);
    stage.setHeight(570);


    // wallet creation date is not encrypted
    LocalDate walletCreationDate = Instant.ofEpochSecond(walletsManager.getChainSeedCreationTimeSeconds()).atZone(ZoneId.systemDefault()).toLocalDate();
    log.info("walletCreationDate " + walletCreationDate);
    datePicker.setValue(walletCreationDate);
    restoreButton.disableProperty().bind(createBooleanBinding(() -> !seedWordsValid.get() || !seedWordsEdited.get(),
            seedWordsValid, seedWordsEdited));

    seedWordsValidChangeListener = (observable, oldValue, newValue) -> {
        if (newValue) {
            seedWordsTextArea.getStyleClass().remove("validation-error");
        } else {
            seedWordsTextArea.getStyleClass().add("validation-error");
        }
    };

    wordsTextAreaChangeListener = (observable, oldValue, newValue) -> {
        seedWordsEdited.set(true);
        try {
            MnemonicCode codec = new MnemonicCode();
            codec.check(Splitter.on(" ").splitToList(newValue));
            seedWordsValid.set(true);
        } catch (IOException | MnemonicException e) {
            seedWordsValid.set(false);
        }
    };

    seedWordsValid.addListener(seedWordsValidChangeListener);
    seedWordsTextArea.textProperty().addListener(wordsTextAreaChangeListener);
    restoreButton.disableProperty().bind(createBooleanBinding(() -> !seedWordsValid.get() || !seedWordsEdited.get(),
            seedWordsValid, seedWordsEdited));

    restoreButton.setOnAction(e -> onRestore());

    seedWordsTextArea.getStyleClass().remove("validation-error");
    datePicker.getStyleClass().remove("validation-error");

    layout();
}
 
Example #21
Source File: LocalDateInputPane.java    From constellation with Apache License 2.0 4 votes vote down vote up
public LocalDateInputPane(final PluginParameter<LocalDateParameterValue> parameter) {
    field = new DatePicker();
    final LocalDateParameterValue pv = parameter.getParameterValue();

    field.setPromptText(PATTERN);
    field.setConverter(new StringConverter<LocalDate>() {
        @Override
        public String toString(final LocalDate date) {
            return date != null ? DATE_FORMATTER.format(date) : "";
        }

        @Override
        public LocalDate fromString(final String s) {
            return s != null && !s.isEmpty() ? LocalDate.parse(s, DATE_FORMATTER) : null;
        }
    });

    field.setValue(pv.get());

    if (parameter.getParameterValue().getGuiInit() != null) {
        parameter.getParameterValue().getGuiInit().init(field);
    }

    field.setDisable(!parameter.isEnabled());
    field.setVisible(parameter.isVisible());
    field.setManaged(parameter.isVisible());
    this.setManaged(parameter.isVisible());
    this.setVisible(parameter.isVisible());

    field.setOnAction(event -> {
        parameter.setLocalDateValue(field.getValue());
    });

    parameter.addListener((PluginParameter<?> pluginParameter, ParameterChange change) -> {
        Platform.runLater(() -> {
            switch (change) {
                case VALUE:
                    // Don't change the value if it isn't necessary.
                    //                    final LocalDate param = LocalDate.parse(pluginParameter.getStringValue(), DATE_FORMATTER);
                    final LocalDate param = pluginParameter.getLocalDateValue();
                    if (!param.equals(field.getValue())) {
                        field.setValue(param);
                    }
                    break;
                case ENABLED:
                    field.setDisable(!pluginParameter.isEnabled());
                    break;
                case VISIBLE:
                    field.setManaged(parameter.isVisible());
                    field.setVisible(parameter.isVisible());
                    this.setVisible(parameter.isVisible());
                    this.setManaged(parameter.isVisible());
                    break;
                default:
                    LOGGER.log(Level.FINE, "ignoring parameter change type {0}.", change);
                    break;
            }
        });
    });

    getChildren().add(field);
}
 
Example #22
Source File: JFXDatePickerSkin.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
protected StringConverter<LocalDate> getConverter() {
    return ((DatePicker) getSkinnable()).getConverter();
}
 
Example #23
Source File: JFXDatePickerSkin.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
protected TextField getEditor() {
    return ((DatePicker) getSkinnable()).getEditor();
}
 
Example #24
Source File: PikaRFIDDirectReader.java    From pikatimer with GNU General Public License v3.0 4 votes vote down vote up
private void setClockDialog(){
    Integer localTZ = TimeZone.getDefault().getOffset(System.currentTimeMillis())/3600000;
    Integer ultraTZ = Integer.parseInt(ultraSettings.get("23"));

    // open a dialog box 
    Dialog<Boolean> dialog = new Dialog();
    dialog.setTitle("Set Ultra Clock");
    dialog.setHeaderText("Set the clock for " + ultraIP);
    ButtonType setButtonType = new ButtonType("Set", ButtonBar.ButtonData.OK_DONE);
    dialog.getDialogPane().getButtonTypes().addAll(setButtonType, ButtonType.CANCEL);
    
    VBox clockVBox = new VBox();
    clockVBox.setStyle("-fx-font-size: 16px;");
    
    CheckBox useComputer = new CheckBox("Sync with the local computer");
    VBox manualVBox = new VBox();
    manualVBox.setSpacing(5.0);
    manualVBox.disableProperty().bind(useComputer.selectedProperty());
    
    HBox dateHBox = new HBox();
    dateHBox.setSpacing(5.0);
    Label dateLabel = new Label("Date:");
    dateLabel.setMinWidth(40);
    DatePicker ultraDate = new DatePicker();
    dateHBox.getChildren().addAll(dateLabel,ultraDate);
    
    HBox timeHBox = new HBox();
    timeHBox.setSpacing(5.0);
    Label timeLabel = new Label("Time:");
    timeLabel.setMinWidth(40);
    TextField ultraTime = new TextField();
    timeHBox.getChildren().addAll(timeLabel,ultraTime);
    
    HBox tzHBox = new HBox();
    tzHBox.setSpacing(5.0);
    Label tzLabel = new Label("TimeZone:");
    tzLabel.setMinWidth(40);
    Spinner<Integer> tzSpinner = new Spinner<>(-23, 23, localTZ);    
    tzHBox.getChildren().addAll(tzLabel,tzSpinner);

    manualVBox.getChildren().addAll(dateHBox,timeHBox,tzHBox);
    
    CheckBox autoGPS = new CheckBox("Use GPS to auto-set the clock");
    autoGPS.setSelected(true);

    
    clockVBox.getChildren().addAll(useComputer,manualVBox,autoGPS);
    dialog.getDialogPane().setContent(clockVBox);
    
    BooleanProperty timeOK = new SimpleBooleanProperty(false);

    ultraTime.textProperty().addListener((observable, oldValue, newValue) -> {
        timeOK.setValue(false);
        if (DurationParser.parsable(newValue)) timeOK.setValue(Boolean.TRUE);
        if ( newValue.isEmpty() || newValue.matches("^[0-9]*(:?([0-5]?([0-9]?(:([0-5]?([0-9]?)?)?)?)?)?)?") ){
            System.out.println("Possiblely good start Time (newValue: " + newValue + ")");
        } else {
            Platform.runLater(() -> {
                int c = ultraTime.getCaretPosition();
                if (oldValue.length() > newValue.length()) c++;
                else c--;
                ultraTime.setText(oldValue);
                ultraTime.positionCaret(c);
            });
            System.out.println("Bad clock time (newValue: " + newValue + ")");
        }
    });
    
    
    ultraDate.setValue(LocalDate.now());
    ultraTime.setText(LocalTime.ofSecondOfDay(LocalTime.now().toSecondOfDay()).toString());

    Node createButton = dialog.getDialogPane().lookupButton(setButtonType);
    createButton.disableProperty().bind(timeOK.not());
    
    dialog.setResultConverter(dialogButton -> {
        if (dialogButton == setButtonType) {
            return Boolean.TRUE;
        }
        return null;
    });

    Optional<Boolean> result = dialog.showAndWait();

    if (result.isPresent()) {
        if (useComputer.selectedProperty().get()) {
            System.out.println("Timezone check: Local :" + localTZ + " ultra: " + ultraTZ);
            if (localTZ.equals(ultraTZ)) setClock(LocalDateTime.now(),null,autoGPS.selectedProperty().get());
            else setClock(LocalDateTime.now(),localTZ,autoGPS.selectedProperty().get());
        } else {
            LocalTime time = LocalTime.MIDNIGHT.plusSeconds(DurationParser.parse(ultraTime.getText()).getSeconds());
            Integer newTZ = tzSpinner.getValue();
            if (newTZ.equals(ultraTZ)) setClock(LocalDateTime.of(ultraDate.getValue(), time),null,autoGPS.selectedProperty().get());
            else {
                setClock(LocalDateTime.of(ultraDate.getValue(), time),newTZ,autoGPS.selectedProperty().get());
            }
        }
        
    }
}
 
Example #25
Source File: DatePickerTableCell.java    From tornadofx-controls with Apache License 2.0 4 votes vote down vote up
public void setDatePicker(DatePicker datePicker) {
    this.datePicker = datePicker;
}
 
Example #26
Source File: DatePickerTableCell.java    From tornadofx-controls with Apache License 2.0 4 votes vote down vote up
public DatePicker getDatePicker() {
    return datePicker;
}
 
Example #27
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public String getDatePickerText(DatePicker datePicker, LocalDate value) {
    return datePicker.getConverter().toString(value);
}
 
Example #28
Source File: GetNewSecret.java    From strongbox with Apache License 2.0 4 votes vote down vote up
private Optional<ZonedDateTime> getDate(DatePicker datePicker) {
    return datePicker.getValue() != null
            ? Optional.of(ZonedDateTime.of(datePicker.getValue().atTime(0, 0), ZoneId.of("UTC")))
            : Optional.empty();
}
 
Example #29
Source File: DateTimePane.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
/** @param self This cell's picker
 *  @param other Other date picker who's date to highlight
 */
public HighlightingDateCell(final DatePicker self, final DatePicker other)
{
    this.self = self;
    this.other = other;
}
 
Example #30
Source File: DateTimeEditorFactory.java    From constellation with Apache License 2.0 4 votes vote down vote up
private HBox createTimeSpinners() {
    datePicker = new DatePicker();
    datePicker.setConverter(new LocalDateStringConverter(
            TemporalFormatting.DATE_FORMATTER, TemporalFormatting.DATE_FORMATTER));
    datePicker.getEditor().textProperty().addListener((v, o, n) -> {
        update();
        updateTimeZoneList();
    });
    datePicker.setValue(LocalDate.now());
    datePicker.valueProperty().addListener((v, o, n) -> {
        update();
        updateTimeZoneList();
    });

    hourSpinner = new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 23));
    minSpinner = new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 59));
    secSpinner = new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 59));
    milliSpinner = new Spinner<>(new SpinnerValueFactory.IntegerSpinnerValueFactory(0, 999));
    hourSpinner.getValueFactory().setValue(LocalTime.now(ZoneOffset.UTC).getHour());
    minSpinner.getValueFactory().setValue(LocalTime.now(ZoneOffset.UTC).getMinute());
    secSpinner.getValueFactory().setValue(LocalTime.now(ZoneOffset.UTC).getSecond());
    milliSpinner.getValueFactory().setValue(0);

    final HBox timeSpinnerContainer = new HBox(CONTROLS_DEFAULT_VERTICAL_SPACING);

    final Label dateLabel = new Label("Date:");
    dateLabel.setId(LABEL_ID);
    dateLabel.setLabelFor(datePicker);

    final Label hourSpinnerLabel = new Label("Hour:");
    hourSpinnerLabel.setId(LABEL_ID);
    hourSpinnerLabel.setLabelFor(hourSpinner);

    final Label minSpinnerLabel = new Label("Minute:");
    minSpinnerLabel.setId(LABEL_ID);
    minSpinnerLabel.setLabelFor(minSpinner);

    final Label secSpinnerLabel = new Label("Second:");
    secSpinnerLabel.setId(LABEL_ID);
    secSpinnerLabel.setLabelFor(secSpinner);

    final Label milliSpinnerLabel = new Label("Millis:");
    milliSpinnerLabel.setId(LABEL_ID);
    milliSpinnerLabel.setLabelFor(milliSpinner);

    hourSpinner.setPrefWidth(NUMBER_SPINNER_WIDTH);
    minSpinner.setPrefWidth(NUMBER_SPINNER_WIDTH);
    secSpinner.setPrefWidth(NUMBER_SPINNER_WIDTH);
    milliSpinner.setPrefWidth(MILLIS_SPINNER_WIDTH);

    hourSpinner.setEditable(true);
    minSpinner.setEditable(true);
    secSpinner.setEditable(true);
    milliSpinner.setEditable(true);

    hourSpinner.valueProperty().addListener((o, n, v) -> {
        update();
        updateTimeZoneList();
    });
    minSpinner.valueProperty().addListener((o, n, v) -> {
        update();
        updateTimeZoneList();
    });
    secSpinner.valueProperty().addListener((o, n, v) -> {
        update();
        updateTimeZoneList();
    });
    milliSpinner.valueProperty().addListener((o, n, v) -> {
        update();
        updateTimeZoneList();
    });

    final VBox dateLabelNode = new VBox(5);
    dateLabelNode.getChildren().addAll(dateLabel, datePicker);
    final VBox hourLabelNode = new VBox(5);
    hourLabelNode.getChildren().addAll(hourSpinnerLabel, hourSpinner);
    final VBox minLabelNode = new VBox(5);
    minLabelNode.getChildren().addAll(minSpinnerLabel, minSpinner);
    final VBox secLabelNode = new VBox(5);
    secLabelNode.getChildren().addAll(secSpinnerLabel, secSpinner);
    final VBox milliLabelNode = new VBox(5);
    milliLabelNode.getChildren().addAll(milliSpinnerLabel, milliSpinner);

    timeSpinnerContainer.getChildren().addAll(dateLabelNode, hourLabelNode, minLabelNode, secLabelNode, milliLabelNode);

    return timeSpinnerContainer;
}