modules/controls/src/main/java/com/sun/javafx/scene/control/DatePickerContent.java

Print this page




 126         {
 127             LocalDate date = datePicker.getValue();
 128             displayedYearMonth.set((date != null) ? YearMonth.from(date) : YearMonth.now());
 129         }
 130 
 131         displayedYearMonth.addListener((observable, oldValue, newValue) -> {
 132             updateValues();
 133         });
 134 
 135 
 136         getChildren().add(createMonthYearPane());
 137 
 138         gridPane = new GridPane() {
 139             @Override protected double computePrefWidth(double height) {
 140                 final double width = super.computePrefWidth(height);
 141 
 142                 // RT-30903: Make sure width snaps to pixel when divided by
 143                 // number of columns. GridPane doesn't do this with percentage
 144                 // width constraints. See GridPane.adjustColumnWidths().
 145                 final int nCols = daysPerWeek + (datePicker.isShowWeekNumbers() ? 1 : 0);
 146                 final double snaphgap = snapSpace(getHgap());
 147                 final double left = snapSpace(getInsets().getLeft());
 148                 final double right = snapSpace(getInsets().getRight());
 149                 final double hgaps = snaphgap * (nCols - 1);
 150                 final double contentWidth = width - left - right - hgaps;
 151                 return ((snapSize(contentWidth / nCols)) * nCols) + left + right + hgaps;
 152             }
 153 
 154             @Override protected void layoutChildren() {
 155                 // Prevent AssertionError in GridPane
 156                 if (getWidth() > 0 && getHeight() > 0) {
 157                     super.layoutChildren();
 158                 }
 159             }
 160         };
 161         gridPane.setFocusTraversable(true);
 162         gridPane.getStyleClass().add("calendar-grid");
 163         gridPane.setVgap(-1);
 164         gridPane.setHgap(-1);
 165 
 166         // Add a focus owner listener to Scene when it becomes available.
 167         final WeakChangeListener<Node> weakFocusOwnerListener =
 168             new WeakChangeListener<Node>((ov2, oldFocusOwner, newFocusOwner) -> {
 169                 if (newFocusOwner == gridPane) {
 170                     if (oldFocusOwner instanceof DateCell) {
 171                         // Backwards traversal, skip gridPane.




 126         {
 127             LocalDate date = datePicker.getValue();
 128             displayedYearMonth.set((date != null) ? YearMonth.from(date) : YearMonth.now());
 129         }
 130 
 131         displayedYearMonth.addListener((observable, oldValue, newValue) -> {
 132             updateValues();
 133         });
 134 
 135 
 136         getChildren().add(createMonthYearPane());
 137 
 138         gridPane = new GridPane() {
 139             @Override protected double computePrefWidth(double height) {
 140                 final double width = super.computePrefWidth(height);
 141 
 142                 // RT-30903: Make sure width snaps to pixel when divided by
 143                 // number of columns. GridPane doesn't do this with percentage
 144                 // width constraints. See GridPane.adjustColumnWidths().
 145                 final int nCols = daysPerWeek + (datePicker.isShowWeekNumbers() ? 1 : 0);
 146                 final double snaphgap = snapSpaceX(getHgap());
 147                 final double left = snapSpaceX(getInsets().getLeft());
 148                 final double right = snapSpaceX(getInsets().getRight());
 149                 final double hgaps = snaphgap * (nCols - 1);
 150                 final double contentWidth = width - left - right - hgaps;
 151                 return ((snapSizeX(contentWidth / nCols)) * nCols) + left + right + hgaps;
 152             }
 153 
 154             @Override protected void layoutChildren() {
 155                 // Prevent AssertionError in GridPane
 156                 if (getWidth() > 0 && getHeight() > 0) {
 157                     super.layoutChildren();
 158                 }
 159             }
 160         };
 161         gridPane.setFocusTraversable(true);
 162         gridPane.getStyleClass().add("calendar-grid");
 163         gridPane.setVgap(-1);
 164         gridPane.setHgap(-1);
 165 
 166         // Add a focus owner listener to Scene when it becomes available.
 167         final WeakChangeListener<Node> weakFocusOwnerListener =
 168             new WeakChangeListener<Node>((ov2, oldFocusOwner, newFocusOwner) -> {
 169                 if (newFocusOwner == gridPane) {
 170                     if (oldFocusOwner instanceof DateCell) {
 171                         // Backwards traversal, skip gridPane.