changeset 4840:7f98f57fecd2

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/8.0/MASTER/jfx/rt
author David Grieve<david.grieve@oracle.com>
date Wed, 28 Aug 2013 07:36:05 -0400
parents 903908477a58 2285e786059a
children bf88b13087fd
files
diffstat 2 files changed, 48 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/DateCellBehavior.java	Tue Aug 27 11:46:26 2013 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/DateCellBehavior.java	Wed Aug 28 07:36:05 2013 -0400
@@ -61,8 +61,6 @@
         DATE_CELL_BINDINGS.add(new KeyBinding(LEFT, "TraverseLeft"));
         DATE_CELL_BINDINGS.add(new KeyBinding(RIGHT, "TraverseRight"));
         DATE_CELL_BINDINGS.add(new KeyBinding(HOME, "Today"));
-        DATE_CELL_BINDINGS.add(new KeyBinding(PAGE_UP, "PreviousMonth"));
-        DATE_CELL_BINDINGS.add(new KeyBinding(PAGE_DOWN, "NextMonth"));
         DATE_CELL_BINDINGS.add(new KeyBinding(ENTER, "SelectDate"));
         DATE_CELL_BINDINGS.add(new KeyBinding(SPACE, "SelectDate"));
     }
@@ -79,8 +77,6 @@
         if (dpc != null) {
             switch (name) {
               case "Today":         dpc.goToDate(LocalDate.now()); break;
-              case "PreviousMonth": dpc.goToDayCell(cell, -1, MONTHS); break;
-              case "NextMonth":     dpc.goToDayCell(cell, +1, MONTHS); break;
               case "SelectDate":    dpc.selectDayCell(cell); break;
               default: super.callAction(name);
             }
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/DatePickerContent.java	Tue Aug 27 11:46:26 2013 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/DatePickerContent.java	Wed Aug 28 07:36:05 2013 -0400
@@ -72,6 +72,8 @@
 import com.sun.javafx.scene.control.skin.resources.ControlResources;
 import com.sun.javafx.scene.traversal.Direction;
 
+import static com.sun.javafx.PlatformUtil.*;
+
 /**
  * The full content for the DatePicker popup. This class could
  * probably be used more or less as-is with an embeddable type of date
@@ -228,6 +230,10 @@
         addEventHandler(KeyEvent.ANY, new EventHandler<KeyEvent>() {
             @Override public void handle(KeyEvent e) {
                 Node node = getScene().getFocusOwner();
+                if (node instanceof DateCell) {
+                    lastFocusedDayCell = (DateCell)node;
+                }
+
                 if (e.getEventType() == KeyEvent.KEY_PRESSED) {
                     switch (e.getCode()) {
                       case TAB:
@@ -258,8 +264,36 @@
                           node.impl_traverse(Direction.RIGHT);
                           e.consume();
                           break;
+
+                      case PAGE_UP:
+                          if ((isMac() && e.isMetaDown()) || (!isMac() && e.isControlDown())) {
+                              if (!backYearButton.isDisabled()) {
+                                  forward(-1, YEARS);
+                              }
+                          } else {
+                              if (!backMonthButton.isDisabled()) {
+                                  forward(-1, MONTHS);
+                              }
+                          }
+                          e.consume();
+                          break;
+
+                      case PAGE_DOWN:
+                          if ((isMac() && e.isMetaDown()) || (!isMac() && e.isControlDown())) {
+                              if (!forwardYearButton.isDisabled()) {
+                                  forward(1, YEARS);
+                              }
+                          } else {
+                              if (!forwardMonthButton.isDisabled()) {
+                                  forward(1, MONTHS);
+                              }
+                          }
+                          e.consume();
+                          break;
                     }
-                    if (e.isConsumed() && node instanceof DateCell) {
+
+                    node = getScene().getFocusOwner();
+                    if (node instanceof DateCell) {
                         lastFocusedDayCell = (DateCell)node;
                     }
                 }
@@ -317,7 +351,7 @@
 
         backMonthButton.setOnAction(new EventHandler<ActionEvent>() {
             @Override public void handle(ActionEvent t) {
-                displayedYearMonth.set(displayedYearMonth.get().minusMonths(1));
+                forward(-1, MONTHS);
             }
         });
 
@@ -326,7 +360,7 @@
 
         forwardMonthButton.setOnAction(new EventHandler<ActionEvent>() {
             @Override public void handle(ActionEvent t) {
-                displayedYearMonth.set(displayedYearMonth.get().plusMonths(1));
+                forward(1, MONTHS);
             }
         });
 
@@ -357,7 +391,7 @@
 
         backYearButton.setOnAction(new EventHandler<ActionEvent>() {
             @Override public void handle(ActionEvent t) {
-                displayedYearMonth.set(displayedYearMonth.get().minusYears(1));
+                forward(-1, YEARS);
             }
         });
 
@@ -366,7 +400,7 @@
 
         forwardYearButton.setOnAction(new EventHandler<ActionEvent>() {
             @Override public void handle(ActionEvent t) {
-                displayedYearMonth.set(displayedYearMonth.get().plusYears(1));
+                forward(1, YEARS);
             }
         });
 
@@ -660,6 +694,15 @@
         goToDate(dayCellDate(dateCell).plus(offset, unit));
     }
 
+    protected void forward(int offset, ChronoUnit unit) {
+        YearMonth yearMonth = displayedYearMonth.get();
+        DateCell dateCell = lastFocusedDayCell;
+        if (dateCell == null || !dayCellDate(dateCell).getMonth().equals(yearMonth.getMonth())) {
+            dateCell = findDayCellForDate(yearMonth.atDay(1));
+        }
+        goToDayCell(dateCell, offset, unit);
+    }
+
     // public for behavior class
     public void goToDate(LocalDate date) {
         if (isValidDate(datePicker.getChronology(), date)) {