changeset 1114:ae1d114a26e3

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/2.2/scrum/controls/jfx/rt
author jgiles
date Tue, 22 May 2012 12:09:26 +1200
parents 862bbb9698c8 8d71632fa551
children afd4133eb2f6 0093b277b701
files
diffstat 3 files changed, 130 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TableCellBehavior.java	Mon May 21 14:09:46 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TableCellBehavior.java	Tue May 22 12:09:26 2012 +1200
@@ -24,6 +24,7 @@
  */
 package com.sun.javafx.scene.control.behavior;
 
+import com.sun.javafx.PlatformUtil;
 import java.util.List;
 import java.util.WeakHashMap;
 
@@ -34,6 +35,13 @@
 /**
  */
 public class TableCellBehavior extends CellBehaviorBase<TableCell> {
+    
+    /***************************************************************************
+     *                                                                         *
+     * Private static implementation                                           *
+     *                                                                         *
+     **************************************************************************/
+    
     // global map used to store the focus cell for a table view when it is first
     // shift-clicked. This allows for proper keyboard interactions, in particular
     // resolving RT-11446
@@ -58,26 +66,59 @@
         return map.containsKey(table) && map.get(table) != null;
     }
     
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Private fields                                                          *
+     *                                                                         *
+     **************************************************************************/      
+    
     // For RT-17456: have selection occur as fast as possible with mouse input.
     // The idea is (consistently with some native applications we've tested) to 
     // do the action as soon as you can. It takes a bit more coding but provides
     // the best feel:
     //  - when you click on a not-selected item, you can select immediately on press
     //  - when you click on a selected item, you need to wait whether DragDetected or Release comes first 
-    private boolean selected = false;
+    // To support touch devices, we have to slightly modify this behavior, such
+    // that selection only happens on mouse release, if only minimal dragging
+    // has occurred.
     private boolean latePress = false;
+    private final boolean isEmbedded = PlatformUtil.isEmbedded();
+    private boolean wasSelected = false;
+    
+    
+
+    /***************************************************************************
+     *                                                                         *
+     * Constructors                                                            *
+     *                                                                         *
+     **************************************************************************/    
 
     public TableCellBehavior(TableCell control) {
         super(control);
     }
     
+    
+    /***************************************************************************
+     *                                                                         *
+     * Public API                                                              *
+     *                                                                         *
+     **************************************************************************/    
+    
     @Override public void mousePressed(MouseEvent event) {
-        if (selected) {
+        boolean selectedBefore = getControl().isSelected();
+        
+        if (getControl().isSelected()) {
             latePress = true;
             return;
         }
+
+        doSelect(event);
         
-        doSelect(event);
+        if (isEmbedded && selectedBefore) {
+            wasSelected = getControl().isSelected();
+        }
     }
     
     @Override public void mouseReleased(MouseEvent event) {
@@ -85,11 +126,28 @@
             latePress = false;
             doSelect(event);
         }
+        
+        wasSelected = false;
     }
     
     @Override public void mouseDragged(MouseEvent event) {
         latePress = false;
+        
+        // the mouse has now been dragged on a touch device, we should
+        // remove the selection if we just added it in the last mouse press
+        // event
+        if (isEmbedded && ! wasSelected && getControl().isSelected()) {
+            getControl().getTableView().getSelectionModel().clearSelection(getControl().getIndex());
+        }
     }
+    
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Private implementation                                                  *
+     *                                                                         *
+     **************************************************************************/      
 
     private void doSelect(MouseEvent e) {
         // Note that table.select will reset selection
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TreeCellBehavior.java	Mon May 21 14:09:46 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/behavior/TreeCellBehavior.java	Tue May 22 12:09:26 2012 +1200
@@ -25,6 +25,7 @@
 
 package com.sun.javafx.scene.control.behavior;
 
+import com.sun.javafx.PlatformUtil;
 import com.sun.javafx.logging.PlatformLogger;
 import com.sun.javafx.scene.control.Logging;
 import java.util.WeakHashMap;
@@ -36,6 +37,13 @@
 /**
  */
 public class TreeCellBehavior extends CellBehaviorBase<TreeCell<?>> {
+    
+    /***************************************************************************
+     *                                                                         *
+     * Private static implementation                                           *
+     *                                                                         *
+     **************************************************************************/
+    
     // global map used to store the focus index for a tree view when it is first
     // shift-clicked. This allows for proper keyboard interactions, in particular
     // resolving RT-11446
@@ -60,26 +68,61 @@
         return map.containsKey(tree) && map.get(tree) != -1;
     }
     
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Private fields                                                          *
+     *                                                                         *
+     **************************************************************************/    
+    
     // For RT-17456: have selection occur as fast as possible with mouse input.
     // The idea is (consistently with some native applications we've tested) to 
     // do the action as soon as you can. It takes a bit more coding but provides
     // the best feel:
     //  - when you click on a not-selected item, you can select immediately on press
     //  - when you click on a selected item, you need to wait whether DragDetected or Release comes first 
-    private boolean selected = false;
+    // To support touch devices, we have to slightly modify this behavior, such
+    // that selection only happens on mouse release, if only minimal dragging
+    // has occurred.
     private boolean latePress = false;
+    private final boolean isEmbedded = PlatformUtil.isEmbedded();
+    private boolean wasSelected = false;
+
+    
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Constructors                                                            *
+     *                                                                         *
+     **************************************************************************/
     
     public TreeCellBehavior(final TreeCell control) {
         super(control);
     }
+    
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Public API                                                              *
+     *                                                                         *
+     **************************************************************************/    
 
     @Override public void mousePressed(MouseEvent event) {
-        if (selected) {
+        boolean selectedBefore = getControl().isSelected();
+        
+        if (getControl().isSelected()) {
             latePress = true;
             return;
         }
+
+        doSelect(event);
         
-        doSelect(event);
+        if (isEmbedded && selectedBefore) {
+            wasSelected = getControl().isSelected();
+        }
     }
     
     @Override public void mouseReleased(MouseEvent event) {
@@ -87,12 +130,29 @@
             latePress = false;
             doSelect(event);
         }
+        
+        wasSelected = false;
     }
     
     @Override public void mouseDragged(MouseEvent event) {
         latePress = false;
+        
+        // the mouse has now been dragged on a touch device, we should
+        // remove the selection if we just added it in the last mouse press
+        // event
+        if (isEmbedded && ! wasSelected && getControl().isSelected()) {
+            getControl().getTreeView().getSelectionModel().clearSelection(getControl().getIndex());
+        }
     }
     
+    
+    
+    /***************************************************************************
+     *                                                                         *
+     * Private implementation                                                  *
+     *                                                                         *
+     **************************************************************************/      
+    
     private void doSelect(MouseEvent event) {
         // we update the cell to point to the new tree node
         TreeCell<?> treeCell = getControl();
--- a/javafx-ui-controls/src/javafx/scene/control/ComboBox.java	Mon May 21 14:09:46 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/ComboBox.java	Tue May 22 12:09:26 2012 +1200
@@ -64,11 +64,12 @@
  * exceedingly long.
  * 
  * <p>As with ListView, it is possible to modify the 
- * {@link javafx.scene.control.SelectionModel SelectionModel} that is used, 
- * although this is likely to be rarely changed. The default
- * SelectionModel used in ComboBox is a {@link SingleSelectionModel}, but this
- * can be switched out by developers to instead allow for multiple selection to 
- * occur, or to alter the behavior of the various methods provided in these APIs.
+ * {@link javafx.scene.control.SelectionModel selection model} that is used, 
+ * although this is likely to be rarely changed. This is because the ComboBox
+ * enforces the need for a {@link javafx.scene.control.SingleSelectionModel} 
+ * instance, and it is not likely that there is much need for alternate 
+ * implementations. Nonetheless, the option is there should use cases be found 
+ * for switching the selection model.
  * 
  * <p>As the ComboBox internally renders content with a ListView, API exists in
  * the ComboBox class to allow for a custom cell factory to be set. For more