modules/controls/src/main/java/com/sun/javafx/scene/control/DatePickerContent.java
Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization
*** 21,31 ****
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! package com.sun.javafx.scene.control.skin;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DecimalStyle;
--- 21,31 ----
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
! package com.sun.javafx.scene.control;
import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DecimalStyle;
*** 40,49 ****
--- 40,50 ----
import java.util.Locale;
import static java.time.temporal.ChronoField.*;
import static java.time.temporal.ChronoUnit.*;
+ import com.sun.javafx.scene.control.skin.*;
import javafx.application.Platform;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.WeakChangeListener;
import javafx.event.EventHandler;
*** 113,123 ****
static String getString(String key) {
return ControlResources.getString("DatePicker."+key);
}
! DatePickerContent(final DatePicker datePicker) {
this.datePicker = datePicker;
getStyleClass().add("date-picker-popup");
daysPerWeek = getDaysPerWeek();
--- 114,124 ----
static String getString(String key) {
return ControlResources.getString("DatePicker."+key);
}
! public DatePickerContent(final DatePicker datePicker) {
this.datePicker = datePicker;
getStyleClass().add("date-picker-popup");
daysPerWeek = getDaysPerWeek();
*** 184,194 ****
--- 185,197 ----
gridPane.sceneProperty().addListener(new WeakChangeListener<Scene>((ov, oldScene, newScene) -> {
if (oldScene != null) {
oldScene.focusOwnerProperty().removeListener(weakFocusOwnerListener);
}
if (newScene != null) {
+ Platform.runLater(() -> {
newScene.focusOwnerProperty().addListener(weakFocusOwnerListener);
+ });
}
}));
if (gridPane.getScene() != null) {
gridPane.getScene().focusOwnerProperty().addListener(weakFocusOwnerListener);
}
*** 287,297 ****
}
private ObjectProperty<YearMonth> displayedYearMonth =
new SimpleObjectProperty<YearMonth>(this, "displayedYearMonth");
! ObjectProperty<YearMonth> displayedYearMonthProperty() {
return displayedYearMonth;
}
protected BorderPane createMonthYearPane() {
--- 290,300 ----
}
private ObjectProperty<YearMonth> displayedYearMonth =
new SimpleObjectProperty<YearMonth>(this, "displayedYearMonth");
! public ObjectProperty<YearMonth> displayedYearMonthProperty() {
return displayedYearMonth;
}
protected BorderPane createMonthYearPane() {
*** 366,376 ****
forwardYearButton.setOnAction(t -> {
forward(1, YEARS, false);
});
yearSpinner.getChildren().addAll(backYearButton, yearLabel, forwardYearButton);
! yearSpinner.setFillHeight(false);
monthYearPane.setRight(yearSpinner);
return monthYearPane;
}
--- 369,379 ----
forwardYearButton.setOnAction(t -> {
forward(1, YEARS, false);
});
yearSpinner.getChildren().addAll(backYearButton, yearLabel, forwardYearButton);
! yearSpinner.setFillHeight(false);
monthYearPane.setRight(yearSpinner);
return monthYearPane;
}
*** 378,396 ****
updateMonthLabelWidth();
updateDayNameCells();
updateValues();
}
! void updateValues() {
// Note: Preserve this order, as DatePickerHijrahContent needs
// updateDayCells before updateMonthYearPane().
updateWeeknumberDateCells();
updateDayCells();
updateMonthYearPane();
}
! void updateGrid() {
gridPane.getColumnConstraints().clear();
gridPane.getChildren().clear();
int nCols = daysPerWeek + (datePicker.isShowWeekNumbers() ? 1 : 0);
--- 381,399 ----
updateMonthLabelWidth();
updateDayNameCells();
updateValues();
}
! public void updateValues() {
// Note: Preserve this order, as DatePickerHijrahContent needs
// updateDayCells before updateMonthYearPane().
updateWeeknumberDateCells();
updateDayCells();
updateMonthYearPane();
}
! public void updateGrid() {
gridPane.getColumnConstraints().clear();
gridPane.getChildren().clear();
int nCols = daysPerWeek + (datePicker.isShowWeekNumbers() ? 1 : 0);
*** 417,427 ****
gridPane.add(dayCells.get(row*daysPerWeek+col), col + nCols - daysPerWeek, row + 2);
}
}
}
! void updateDayNameCells() {
// first day of week, 1 = monday, 7 = sunday
int firstDayOfWeek = WeekFields.of(getLocale()).getFirstDayOfWeek().getValue();
// july 13th 2009 is a Monday, so a firstDayOfWeek=1 must come out of the 13th
LocalDate date = LocalDate.of(2009, 7, 12 + firstDayOfWeek);
--- 420,430 ----
gridPane.add(dayCells.get(row*daysPerWeek+col), col + nCols - daysPerWeek, row + 2);
}
}
}
! public void updateDayNameCells() {
// first day of week, 1 = monday, 7 = sunday
int firstDayOfWeek = WeekFields.of(getLocale()).getFirstDayOfWeek().getValue();
// july 13th 2009 is a Monday, so a firstDayOfWeek=1 must come out of the 13th
LocalDate date = LocalDate.of(2009, 7, 12 + firstDayOfWeek);
*** 429,439 ****
String name = weekDayNameFormatter.withLocale(getLocale()).format(date.plus(i, DAYS));
dayNameCells.get(i).setText(titleCaseWord(name));
}
}
! void updateWeeknumberDateCells() {
if (datePicker.isShowWeekNumbers()) {
final Locale locale = getLocale();
final int maxWeeksPerMonth = 6; // TODO: Get this from chronology?
LocalDate firstOfMonth = displayedYearMonth.get().atDay(1);
--- 432,442 ----
String name = weekDayNameFormatter.withLocale(getLocale()).format(date.plus(i, DAYS));
dayNameCells.get(i).setText(titleCaseWord(name));
}
}
! public void updateWeeknumberDateCells() {
if (datePicker.isShowWeekNumbers()) {
final Locale locale = getLocale();
final int maxWeeksPerMonth = 6; // TODO: Get this from chronology?
LocalDate firstOfMonth = displayedYearMonth.get().atDay(1);
*** 448,458 ****
weekNumberCells.get(i).setText(cellText);
}
}
}
! void updateDayCells() {
Locale locale = getLocale();
Chronology chrono = getPrimaryChronology();
int firstOfMonthIdx = determineFirstOfMonthDayOfWeek();
YearMonth curMonth = displayedYearMonth.get();
--- 451,461 ----
weekNumberCells.get(i).setText(cellText);
}
}
}
! public void updateDayCells() {
Locale locale = getLocale();
Chronology chrono = getPrimaryChronology();
int firstOfMonthIdx = determineFirstOfMonthDayOfWeek();
YearMonth curMonth = displayedYearMonth.get();
*** 697,707 ****
}
}
return dayCells.get(dayCells.size()/2+1);
}
! void clearFocus() {
LocalDate focusDate = datePicker.getValue();
if (focusDate == null) {
focusDate = LocalDate.now();
}
if (YearMonth.from(focusDate).equals(displayedYearMonth.get())) {
--- 700,710 ----
}
}
return dayCells.get(dayCells.size()/2+1);
}
! public void clearFocus() {
LocalDate focusDate = datePicker.getValue();
if (focusDate == null) {
focusDate = LocalDate.now();
}
if (YearMonth.from(focusDate).equals(displayedYearMonth.get())) {