modules/controls/src/main/java/javafx/scene/control/skin/CheckBoxSkin.java

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

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2010, 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

@@ -21,62 +21,119 @@
  * 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;
+package javafx.scene.control.skin;
 
+import com.sun.javafx.scene.control.behavior.BehaviorBase;
+import com.sun.javafx.scene.control.skin.Utils;
+import javafx.scene.Node;
+import javafx.scene.control.Button;
 import javafx.scene.control.CheckBox;
+import com.sun.javafx.scene.control.behavior.ButtonBehavior;
+import javafx.scene.control.Control;
 import javafx.scene.layout.StackPane;
 
-import com.sun.javafx.scene.control.behavior.ButtonBehavior;
 import javafx.geometry.NodeOrientation;
 
 /**
- * Skin for tri state selection Control.
+ * Default skin implementation for the tri-state {@link CheckBox} control.
+ *
+ * @see CheckBox
+ * @since 9
  */
-public class CheckBoxSkin extends LabeledSkinBase<CheckBox, ButtonBehavior<CheckBox>> {
+public class CheckBoxSkin extends LabeledSkinBase<CheckBox> {
+
+    /***************************************************************************
+     *                                                                         *
+     * Private fields                                                          *
+     *                                                                         *
+     **************************************************************************/
 
     private final StackPane box = new StackPane();
     private StackPane innerbox;
+    private final BehaviorBase<CheckBox> behavior;
+
 
-    public CheckBoxSkin(CheckBox checkbox) {
-        super(checkbox, new ButtonBehavior<CheckBox>(checkbox));
+
+    /***************************************************************************
+     *                                                                         *
+     * Constructors                                                            *
+     *                                                                         *
+     **************************************************************************/
+
+    /**
+     * Creates a new CheckBoxSkin instance, installing the necessary child
+     * nodes into the Control {@link Control#getChildren() children} list, as
+     * well as the necessary input mappings for handling key, mouse, etc events.
+     *
+     * @param control The control that this skin should be installed onto.
+     */
+    public CheckBoxSkin(CheckBox control) {
+        super(control);
+
+        // install default input map for the CheckBox control
+        behavior = new ButtonBehavior<>(control);
+//        control.setInputMap(behavior.getInputMap());
 
         box.getStyleClass().setAll("box");
         innerbox = new StackPane();
         innerbox.getStyleClass().setAll("mark");
         innerbox.setNodeOrientation(NodeOrientation.LEFT_TO_RIGHT);
         box.getChildren().add(innerbox);
         updateChildren();
     }
 
+
+
+    /***************************************************************************
+     *                                                                         *
+     * Public API                                                              *
+     *                                                                         *
+     **************************************************************************/
+
+    /** {@inheritDoc} */
+    @Override public void dispose() {
+        super.dispose();
+
+        if (behavior != null) {
+            behavior.dispose();
+        }
+    }
+
+    /** {@inheritDoc} */
     @Override protected void updateChildren() {
         super.updateChildren();
         if (box != null) {
             getChildren().add(box);
         }
     }
     
+    /** {@inheritDoc} */
     @Override protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
         return super.computeMinWidth(height, topInset, rightInset, bottomInset, leftInset) + snapSize(box.minWidth(-1));
     }
     
+    /** {@inheritDoc} */
     @Override protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
         return Math.max(super.computeMinHeight(width - box.minWidth(-1), topInset, rightInset, bottomInset, leftInset),
                 topInset + box.minHeight(-1) + bottomInset);
     }
 
+    /** {@inheritDoc} */
     @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
         return super.computePrefWidth(height, topInset, rightInset, bottomInset, leftInset) + snapSize(box.prefWidth(-1));
     }
 
+    /** {@inheritDoc} */
     @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
         return Math.max(super.computePrefHeight(width - box.prefWidth(-1), topInset, rightInset, bottomInset, leftInset),
                         topInset + box.prefHeight(-1) + bottomInset);
     }
 
+    /** {@inheritDoc} */
     @Override protected void layoutChildren(final double x, final double y,
             final double w, final double h) {
         final CheckBox checkBox = getSkinnable(); 
         final double boxWidth = snapSize(box.prefWidth(-1));
         final double boxHeight = snapSize(box.prefHeight(-1));