< prev index next >

modules/controls/src/main/java/javafx/scene/control/Control.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  71  * <p>
  72  * Additionally, controls support explicit skinning to make it easy to
  73  * leverage the functionality of a control while customizing its appearance.
  74  * <p>
  75  * See specific Control subclasses for information on how to use individual
  76  * types of controls.
  77  * <p> Most controls have their focusTraversable property set to true by default, however
  78  * read-only controls such as {@link Label} and {@link ProgressIndicator}, and some
  79  * controls that are containers {@link ScrollPane} and {@link ToolBar} do not.
  80  * Consult individual control documentation for details.
  81  * @since JavaFX 2.0
  82  */
  83 public abstract class Control extends Region implements Skinnable {
  84 
  85     static {
  86         ControlHelper.setControlAccessor(new ControlHelper.ControlAccessor() {
  87             @Override
  88             public void doProcessCSS(Node node) {
  89                 ((Control) node).doProcessCSS();
  90             }




  91         });
  92 
  93         // Ensures that the default application user agent stylesheet is loaded
  94         if (Application.getUserAgentStylesheet() == null) {
  95             PlatformImpl.setDefaultPlatformUserAgentStylesheet();
  96         }
  97     }
  98 
  99     /**
 100      * Utility for loading a class in a manner that will work with multiple
 101      * class loaders, as is typically found in OSGI modular applications.
 102      * In particular, this method will attempt to just load the class
 103      * identified by className. If that fails, it attempts to load the
 104      * class using the current thread's context class loader. If that fails,
 105      * it attempts to use the class loader of the supplied "instance", and
 106      * if it still fails it walks up the class hierarchy of the instance
 107      * and attempts to use the class loader of each class in the super-type
 108      * hierarchy.
 109      *
 110      * @param className The name of the class we want to load


 638     /**
 639      * Gets the Skin's node, or returns null if there is no Skin.
 640      * Convenience method for getting the node of the skin. This is null-safe,
 641      * meaning if skin is null then it will return null instead of throwing
 642      * a NullPointerException.
 643      *
 644      * @return The Skin's node, or null.
 645      */
 646     private Node getSkinNode() {
 647         assert skinBase == null;
 648         Skin<?> skin = getSkin();
 649         return skin == null ? null : skin.getNode();
 650     }
 651 
 652     /**
 653      * Keeps a reference to the name of the class currently acting as the skin.
 654      */
 655     private String currentSkinClassName = null;
 656     private StringProperty skinClassName;
 657 
 658     /**
 659      * @treatAsPrivate
 660      * @since JavaFX 2.1
 661      */
 662     @Deprecated protected StringProperty skinClassNameProperty() {
 663         if (skinClassName == null) {
 664             skinClassName = new StyleableStringProperty() {
 665 
 666                 @Override
 667                 public void set(String v) {
 668                     // do not allow the skin to be set to null through CSS
 669                     if (v == null || v.isEmpty() || v.equals(get())) return;
 670                     super.set(v);
 671                 }
 672 
 673                 @Override
 674                 public void invalidated() {
 675 
 676                     if (get() != null) {
 677                         if (!get().equals(currentSkinClassName)) {
 678                             loadSkinClass(Control.this, skinClassName.get());
 679                         }
 680                         // Note: CSS should not set skin to null
 681                     }
 682                 }


   1 /*
   2  * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  71  * <p>
  72  * Additionally, controls support explicit skinning to make it easy to
  73  * leverage the functionality of a control while customizing its appearance.
  74  * <p>
  75  * See specific Control subclasses for information on how to use individual
  76  * types of controls.
  77  * <p> Most controls have their focusTraversable property set to true by default, however
  78  * read-only controls such as {@link Label} and {@link ProgressIndicator}, and some
  79  * controls that are containers {@link ScrollPane} and {@link ToolBar} do not.
  80  * Consult individual control documentation for details.
  81  * @since JavaFX 2.0
  82  */
  83 public abstract class Control extends Region implements Skinnable {
  84 
  85     static {
  86         ControlHelper.setControlAccessor(new ControlHelper.ControlAccessor() {
  87             @Override
  88             public void doProcessCSS(Node node) {
  89                 ((Control) node).doProcessCSS();
  90             }
  91             @Override
  92             public StringProperty skinClassNameProperty(Control control) {
  93                 return control.skinClassNameProperty();
  94             }
  95         });
  96 
  97         // Ensures that the default application user agent stylesheet is loaded
  98         if (Application.getUserAgentStylesheet() == null) {
  99             PlatformImpl.setDefaultPlatformUserAgentStylesheet();
 100         }
 101     }
 102 
 103     /**
 104      * Utility for loading a class in a manner that will work with multiple
 105      * class loaders, as is typically found in OSGI modular applications.
 106      * In particular, this method will attempt to just load the class
 107      * identified by className. If that fails, it attempts to load the
 108      * class using the current thread's context class loader. If that fails,
 109      * it attempts to use the class loader of the supplied "instance", and
 110      * if it still fails it walks up the class hierarchy of the instance
 111      * and attempts to use the class loader of each class in the super-type
 112      * hierarchy.
 113      *
 114      * @param className The name of the class we want to load


 642     /**
 643      * Gets the Skin's node, or returns null if there is no Skin.
 644      * Convenience method for getting the node of the skin. This is null-safe,
 645      * meaning if skin is null then it will return null instead of throwing
 646      * a NullPointerException.
 647      *
 648      * @return The Skin's node, or null.
 649      */
 650     private Node getSkinNode() {
 651         assert skinBase == null;
 652         Skin<?> skin = getSkin();
 653         return skin == null ? null : skin.getNode();
 654     }
 655 
 656     /**
 657      * Keeps a reference to the name of the class currently acting as the skin.
 658      */
 659     private String currentSkinClassName = null;
 660     private StringProperty skinClassName;
 661 
 662     StringProperty skinClassNameProperty() {




 663         if (skinClassName == null) {
 664             skinClassName = new StyleableStringProperty() {
 665 
 666                 @Override
 667                 public void set(String v) {
 668                     // do not allow the skin to be set to null through CSS
 669                     if (v == null || v.isEmpty() || v.equals(get())) return;
 670                     super.set(v);
 671                 }
 672 
 673                 @Override
 674                 public void invalidated() {
 675 
 676                     if (get() != null) {
 677                         if (!get().equals(currentSkinClassName)) {
 678                             loadSkinClass(Control.this, skinClassName.get());
 679                         }
 680                         // Note: CSS should not set skin to null
 681                     }
 682                 }


< prev index next >