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

Print this page
rev 9240 : 8076423: JEP 253: Prepare JavaFX UI Controls & CSS APIs for Modularization

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.  Oracle designates this

@@ -23,18 +23,12 @@
  * questions.
  */
 
 package com.sun.javafx.scene.control.behavior;
 
-import static javafx.scene.input.KeyCode.*;
-import static javafx.scene.input.KeyEvent.*;
-
-
-import java.util.ArrayList;
-import java.util.List;
 import javafx.scene.control.ColorPicker;
-import com.sun.javafx.scene.control.skin.ColorPickerSkin;
+import javafx.scene.control.PopupControl;
 
 import javafx.scene.paint.Color;
 
 public class ColorPickerBehavior extends ComboBoxBaseBehavior<Color> {
 

@@ -46,61 +40,30 @@
     
     /**
      * 
      */
     public ColorPickerBehavior(final ColorPicker colorPicker) {
-        super(colorPicker, COLOR_PICKER_BINDINGS);
-    }
-
-    /***************************************************************************
-     *                                                                         *
-     * Key event handling                                                      *
-     *                                                                         *
-     **************************************************************************/
-    
-    /**
-     * Opens the Color Picker Palette.
-     */
-    protected static final String OPEN_ACTION = "Open";
-
-    /**
-     * Closes the Color Picker Palette.
-     */
-    protected static final String CLOSE_ACTION = "Close";
-    
-
-    protected static final List<KeyBinding> COLOR_PICKER_BINDINGS = new ArrayList<KeyBinding>();
-    static {
-//        COLOR_PICKER_BINDINGS.addAll(COMBO_BOX_BASE_BINDINGS);
-        COLOR_PICKER_BINDINGS.add(new KeyBinding(ESCAPE, KEY_PRESSED, CLOSE_ACTION));
-        COLOR_PICKER_BINDINGS.add(new KeyBinding(SPACE, KEY_PRESSED, OPEN_ACTION));
-        COLOR_PICKER_BINDINGS.add(new KeyBinding(ENTER, KEY_PRESSED, OPEN_ACTION));
-        
-    }
-
-    @Override protected void callAction(String name) {
-        if (OPEN_ACTION.equals(name)) {
-            show();
-        } else if(CLOSE_ACTION.equals(name)) {
-            hide();
-        }
-        else super.callAction(name);
+        super(colorPicker);
     }
     
      /**************************************************************************
      *                                                                        *
      * Mouse Events                                                           *
      *                                                                        *
      *************************************************************************/
 
-    @Override public void onAutoHide() {
+    @Override public void onAutoHide(PopupControl popup) {
         // when we click on some non  interactive part of the 
         // Color Palette - we do not want to hide.
-        ColorPicker colorPicker = (ColorPicker)getControl();
-        ColorPickerSkin cpSkin = (ColorPickerSkin)colorPicker.getSkin();
-        cpSkin.syncWithAutoUpdate();
+        if (!popup.isShowing() && getNode().isShowing()) {
+            // Popup was dismissed. Maybe user clicked outside or typed ESCAPE.
+            // Make sure DatePicker button is in sync.
+            getNode().hide();
+        }
         // if the ColorPicker is no longer showing, then invoke the super method
         // to keep its show/hide state in sync.
-        if (!colorPicker.isShowing()) super.onAutoHide();
+        if (!getNode().isShowing()) {
+            super.onAutoHide(popup);
+        }
     }
 
 }