< prev index next >

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

Print this page




 151 //        control.removeEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, contextMenuHandler);
 152 
 153         // unhook listeners
 154         if (lambdaChangeListenerHandler != null) {
 155             lambdaChangeListenerHandler.dispose();
 156         }
 157 
 158         this.control = null;
 159     }
 160 
 161 
 162 
 163     /***************************************************************************
 164      *                                                                         *
 165      * Public API                                                              *
 166      *                                                                         *
 167      **************************************************************************/
 168 
 169     /**
 170      * Returns the children of the skin.

 171      */
 172     public final ObservableList<Node> getChildren() {
 173         return children;
 174     }
 175 
 176     /**
 177      * Called during the layout pass of the scenegraph.




 178      */
 179     protected void layoutChildren(final double contentX, final double contentY,
 180             final double contentWidth, final double contentHeight) {
 181         // By default simply sizes all managed children to fit within the space provided
 182         for (int i=0, max=children.size(); i<max; i++) {
 183             Node child = children.get(i);
 184             if (child.isManaged()) {
 185                 layoutInArea(child, contentX, contentY, contentWidth, contentHeight, -1, HPos.CENTER, VPos.CENTER);
 186             }
 187         }
 188     }
 189 
 190     /**
 191      * Determines whether all mouse events should be automatically consumed.

 192      */
 193     protected final void consumeMouseEvents(boolean value) {
 194         if (value) {
 195             control.addEventHandler(MouseEvent.ANY, mouseEventConsumer);
 196         } else {
 197             control.removeEventHandler(MouseEvent.ANY, mouseEventConsumer);
 198         }
 199     }
 200 
 201 
 202     /**
 203      * Subclasses can invoke this method to register that they want to listen to
 204      * property change events for the given property. Registered {@link Consumer} instances
 205      * will be executed in the order in which they are registered.


 206      */
 207     protected final void registerChangeListener(ObservableValue<?> property, Consumer<ObservableValue<?>> consumer) {
 208         if (lambdaChangeListenerHandler == null) {
 209             lambdaChangeListenerHandler = new LambdaMultiplePropertyChangeListenerHandler();
 210         }
 211         lambdaChangeListenerHandler.registerChangeListener(property, consumer);
 212     }
 213 
 214     /**
 215      * Unregisters all change listeners that have been registered using {@link #registerChangeListener(ObservableValue, Consumer)}
 216      * for the given property. The end result is that the given property is no longer observed by any of the change
 217      * listeners, but it may still have additional listeners registered on it through means outside of
 218      * {@link #registerChangeListener(ObservableValue, Consumer)}.
 219      *
 220      * @param property The property for which all listeners should be removed.
 221      * @return A single chained {@link Consumer} consisting of all {@link Consumer consumers} registered through
 222      *      {@link #registerChangeListener(ObservableValue, Consumer)}. If no consumers have been registered on this
 223      *      property, null will be returned.
 224      * @since 9
 225      */


 871 
 872 
 873 
 874      /**************************************************************************
 875       *                                                                        *
 876       * Specialization of CSS handling code                                    *
 877       *                                                                        *
 878      **************************************************************************/
 879 
 880     private static class StyleableProperties {
 881         private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES;
 882 
 883         static {
 884             STYLEABLES = Collections.unmodifiableList(Control.getClassCssMetaData());
 885         }
 886     }
 887 
 888     /**
 889      * Returns the CssMetaData associated with this class, which may include the
 890      * CssMetaData of its superclasses.


 891      */
 892     public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
 893         return SkinBase.StyleableProperties.STYLEABLES;
 894     }
 895 
 896     /**
 897      * This method should delegate to {@link Node#getClassCssMetaData()} so that
 898      * a Node's CssMetaData can be accessed without the need for reflection.
 899      * @return The CssMetaData associated with this node, which may include the
 900      * CssMetaData of its superclasses.
 901      */
 902     public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
 903         return getClassCssMetaData();
 904     }
 905 
 906     /**
 907      * Used to specify that a pseudo-class of this Node has changed. If the
 908      * pseudo-class is used in a CSS selector that matches this Node, CSS will
 909      * be reapplied. Typically, this method is called from the {@code invalidated}
 910      * method of a property that is used as a pseudo-class. For example:
 911      * <code><pre>
 912      *
 913      *     private static final PseudoClass MY_PSEUDO_CLASS_STATE = PseudoClass.getPseudoClass("my-state");
 914      *
 915      *     BooleanProperty myPseudoClassState = new BooleanPropertyBase(false) {
 916      *
 917      *           {@literal @}Override public void invalidated() {
 918      *                pseudoClassStateChanged(MY_PSEUDO_CLASS_STATE, get());
 919      *           }
 920      *
 921      *           {@literal @}Override public Object getBean() {
 922      *               return MyControl.this;
 923      *           }
 924      *
 925      *           {@literal @}Override public String getName() {
 926      *               return "myPseudoClassState";
 927      *           }
 928      *       };
 929      * </pre><code>
 930      *
 931      * @see Node#pseudoClassStateChanged
 932      * @param pseudoClass the pseudo-class that has changed state
 933      * @param active whether or not the state is active
 934      * @since JavaFX 8.0
 935      */
 936     public final void pseudoClassStateChanged(PseudoClass pseudoClass, boolean active) {
 937         Control ctl = getSkinnable();
 938         if (ctl != null) {
 939             ctl.pseudoClassStateChanged(pseudoClass, active);
 940         }
 941     }
 942 
 943 
 944     /***************************************************************************
 945      *                                                                         *
 946      * Accessibility handling                                                  *
 947      *                                                                         *
 948      **************************************************************************/
 949 




 151 //        control.removeEventHandler(ContextMenuEvent.CONTEXT_MENU_REQUESTED, contextMenuHandler);
 152 
 153         // unhook listeners
 154         if (lambdaChangeListenerHandler != null) {
 155             lambdaChangeListenerHandler.dispose();
 156         }
 157 
 158         this.control = null;
 159     }
 160 
 161 
 162 
 163     /***************************************************************************
 164      *                                                                         *
 165      * Public API                                                              *
 166      *                                                                         *
 167      **************************************************************************/
 168 
 169     /**
 170      * Returns the children of the skin.
 171      * @return the children of the skin
 172      */
 173     public final ObservableList<Node> getChildren() {
 174         return children;
 175     }
 176 
 177     /**
 178      * Called during the layout pass of the scenegraph.
 179      * @param contentX the x position
 180      * @param contentY the y position
 181      * @param contentWidth the width
 182      * @param contentHeight the height
 183      */
 184     protected void layoutChildren(final double contentX, final double contentY,
 185             final double contentWidth, final double contentHeight) {
 186         // By default simply sizes all managed children to fit within the space provided
 187         for (int i=0, max=children.size(); i<max; i++) {
 188             Node child = children.get(i);
 189             if (child.isManaged()) {
 190                 layoutInArea(child, contentX, contentY, contentWidth, contentHeight, -1, HPos.CENTER, VPos.CENTER);
 191             }
 192         }
 193     }
 194 
 195     /**
 196      * Determines whether all mouse events should be automatically consumed.
 197      * @param value the consume mouse events flag
 198      */
 199     protected final void consumeMouseEvents(boolean value) {
 200         if (value) {
 201             control.addEventHandler(MouseEvent.ANY, mouseEventConsumer);
 202         } else {
 203             control.removeEventHandler(MouseEvent.ANY, mouseEventConsumer);
 204         }
 205     }
 206 
 207 
 208     /**
 209      * Subclasses can invoke this method to register that they want to listen to
 210      * property change events for the given property. Registered {@link Consumer} instances
 211      * will be executed in the order in which they are registered.
 212      * @param property the property
 213      * @param consumer the consumer
 214      */
 215     protected final void registerChangeListener(ObservableValue<?> property, Consumer<ObservableValue<?>> consumer) {
 216         if (lambdaChangeListenerHandler == null) {
 217             lambdaChangeListenerHandler = new LambdaMultiplePropertyChangeListenerHandler();
 218         }
 219         lambdaChangeListenerHandler.registerChangeListener(property, consumer);
 220     }
 221 
 222     /**
 223      * Unregisters all change listeners that have been registered using {@link #registerChangeListener(ObservableValue, Consumer)}
 224      * for the given property. The end result is that the given property is no longer observed by any of the change
 225      * listeners, but it may still have additional listeners registered on it through means outside of
 226      * {@link #registerChangeListener(ObservableValue, Consumer)}.
 227      *
 228      * @param property The property for which all listeners should be removed.
 229      * @return A single chained {@link Consumer} consisting of all {@link Consumer consumers} registered through
 230      *      {@link #registerChangeListener(ObservableValue, Consumer)}. If no consumers have been registered on this
 231      *      property, null will be returned.
 232      * @since 9
 233      */


 879 
 880 
 881 
 882      /**************************************************************************
 883       *                                                                        *
 884       * Specialization of CSS handling code                                    *
 885       *                                                                        *
 886      **************************************************************************/
 887 
 888     private static class StyleableProperties {
 889         private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES;
 890 
 891         static {
 892             STYLEABLES = Collections.unmodifiableList(Control.getClassCssMetaData());
 893         }
 894     }
 895 
 896     /**
 897      * Returns the CssMetaData associated with this class, which may include the
 898      * CssMetaData of its superclasses.
 899      * @return the CssMetaData associated with this class, which may include the
 900      * CssMetaData of its superclasses
 901      */
 902     public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData() {
 903         return SkinBase.StyleableProperties.STYLEABLES;
 904     }
 905 
 906     /**
 907      * This method should delegate to {@link Node#getClassCssMetaData()} so that
 908      * a Node's CssMetaData can be accessed without the need for reflection.
 909      * @return The CssMetaData associated with this node, which may include the
 910      * CssMetaData of its superclasses.
 911      */
 912     public List<CssMetaData<? extends Styleable, ?>> getCssMetaData() {
 913         return getClassCssMetaData();
 914     }
 915 
 916     /**
 917      * Used to specify that a pseudo-class of this Node has changed. If the
 918      * pseudo-class is used in a CSS selector that matches this Node, CSS will
 919      * be reapplied. Typically, this method is called from the {@code invalidated}
 920      * method of a property that is used as a pseudo-class. For example:
 921      * <pre><code>
 922      *
 923      *     private static final PseudoClass MY_PSEUDO_CLASS_STATE = PseudoClass.getPseudoClass("my-state");
 924      *
 925      *     BooleanProperty myPseudoClassState = new BooleanPropertyBase(false) {
 926      *
 927      *           {@literal @}Override public void invalidated() {
 928      *                pseudoClassStateChanged(MY_PSEUDO_CLASS_STATE, get());
 929      *           }
 930      *
 931      *           {@literal @}Override public Object getBean() {
 932      *               return MyControl.this;
 933      *           }
 934      *
 935      *           {@literal @}Override public String getName() {
 936      *               return "myPseudoClassState";
 937      *           }
 938      *       };
 939      * </code></pre>
 940      *
 941      * @see Node#pseudoClassStateChanged
 942      * @param pseudoClass the pseudo-class that has changed state
 943      * @param active whether or not the state is active
 944      * @since JavaFX 8.0
 945      */
 946     public final void pseudoClassStateChanged(PseudoClass pseudoClass, boolean active) {
 947         Control ctl = getSkinnable();
 948         if (ctl != null) {
 949             ctl.pseudoClassStateChanged(pseudoClass, active);
 950         }
 951     }
 952 
 953 
 954     /***************************************************************************
 955      *                                                                         *
 956      * Accessibility handling                                                  *
 957      *                                                                         *
 958      **************************************************************************/
 959 


< prev index next >