Class GemsSkinBase<C extends javafx.scene.control.Control>

java.lang.Object
javafx.scene.control.SkinBase<C>
com.dlsc.gemsfx.skins.GemsSkinBase<C>
Type Parameters:
C - the type of control rendered by this skin
All Implemented Interfaces:
javafx.scene.control.Skin<C>
Direct Known Subclasses:
ArcProgressIndicatorSkin, AvatarViewSkin, BeforeAfterViewSkin, CalendarViewSkin, ChipViewSkin, CustomComboBoxSkinBase, DateRangeViewSkin, EmailFieldSkin, FilterViewSkin, GridTableViewSkin, InfoCenterViewSkin, MaskedViewSkin, MultiColumnListViewSkin, PagingControlsSkin, PagingGridTableViewSkin, PagingListViewSkin, PhotoViewSkin, ScreensViewSkin, SearchFieldSkin, SearchFieldSkinBase, SegmentedBarSkin, SelectionBoxSkin, SkeletonSkin, StripViewSkin, SVGImageViewSkin, TagsFieldSkin, TextViewSkin, YearMonthViewSkin, YearViewSkin

public abstract class GemsSkinBase<C extends javafx.scene.control.Control> extends javafx.scene.control.SkinBase<C>
A base class for GemsFX skins that automatically tracks listener registrations and removes them all in dispose(), preventing memory leaks caused by skins holding strong references on the skinnable control's observable properties.

Usage: instead of manually calling obs.addListener(l) in the constructor and obs.removeListener(l) in dispose(), call register(obs, l). The listener will be added immediately and removed automatically on disposal.

  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    GemsSkinBase(C control)
    Creates a skin for the given control.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Removes all registered listeners, event handlers, and event filters, then delegates to SkinBase.dispose().
    protected javafx.beans.InvalidationListener
    register(javafx.beans.Observable obs, javafx.beans.InvalidationListener listener)
    Adds an InvalidationListener to the given Observable and tracks it for automatic removal when this skin is disposed.
    protected <T> javafx.beans.value.ChangeListener<T>
    register(javafx.beans.value.ObservableValue<T> obs, javafx.beans.value.ChangeListener<T> listener)
    Adds a ChangeListener to the given ObservableValue and tracks it for automatic removal when this skin is disposed.
    protected <T> javafx.collections.ListChangeListener<T>
    register(javafx.collections.ObservableList<T> list, javafx.collections.ListChangeListener<T> listener)
    Adds a ListChangeListener to the given ObservableList and tracks it for automatic removal when this skin is disposed.
    protected <K,V> javafx.collections.MapChangeListener<K,V>
    register(javafx.collections.ObservableMap<K,V> map, javafx.collections.MapChangeListener<K,V> listener)
    Adds a MapChangeListener to the given ObservableMap and tracks it for automatic removal when this skin is disposed.
    protected <E extends javafx.event.Event>
    javafx.event.EventHandler<E>
    registerFilter(javafx.scene.Node target, javafx.event.EventType<E> type, javafx.event.EventHandler<E> filter)
    Adds an event filter to the given Node and tracks it for automatic removal when this skin is disposed.
    protected <E extends javafx.event.Event>
    javafx.event.EventHandler<E>
    registerHandler(javafx.scene.Node target, javafx.event.EventType<E> type, javafx.event.EventHandler<E> handler)
    Adds an event handler to the given Node and tracks it for automatic removal when this skin is disposed.

    Methods inherited from class javafx.scene.control.SkinBase

    computeBaselineOffset, computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, consumeMouseEvents, executeAccessibleAction, getChildren, getClassCssMetaData, getCssMetaData, getNode, getSkinnable, layoutChildren, layoutInArea, layoutInArea, layoutInArea, positionInArea, positionInArea, pseudoClassStateChanged, queryAccessibleAttribute, registerChangeListener, registerInvalidationListener, registerListChangeListener, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, unregisterChangeListeners, unregisterInvalidationListeners, unregisterListChangeListeners

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • GemsSkinBase

      protected GemsSkinBase(C control)
      Creates a skin for the given control.
      Parameters:
      control - the control rendered by this skin
  • Method Details

    • register

      protected javafx.beans.InvalidationListener register(javafx.beans.Observable obs, javafx.beans.InvalidationListener listener)
      Adds an InvalidationListener to the given Observable and tracks it for automatic removal when this skin is disposed.
      Parameters:
      obs - the observable to listen to
      listener - the listener to add and later remove
      Returns:
      the listener, for use as a field initializer
    • register

      protected <T> javafx.beans.value.ChangeListener<T> register(javafx.beans.value.ObservableValue<T> obs, javafx.beans.value.ChangeListener<T> listener)
      Adds a ChangeListener to the given ObservableValue and tracks it for automatic removal when this skin is disposed.
      Type Parameters:
      T - the value type observed by the listener
      Parameters:
      obs - the observable value to listen to
      listener - the listener to add and later remove
      Returns:
      the listener, for use as a field initializer
    • register

      protected <T> javafx.collections.ListChangeListener<T> register(javafx.collections.ObservableList<T> list, javafx.collections.ListChangeListener<T> listener)
      Adds a ListChangeListener to the given ObservableList and tracks it for automatic removal when this skin is disposed.
      Type Parameters:
      T - the list element type observed by the listener
      Parameters:
      list - the observable list to listen to
      listener - the listener to add and later remove
      Returns:
      the listener, for use as a field initializer
    • register

      protected <K,V> javafx.collections.MapChangeListener<K,V> register(javafx.collections.ObservableMap<K,V> map, javafx.collections.MapChangeListener<K,V> listener)
      Adds a MapChangeListener to the given ObservableMap and tracks it for automatic removal when this skin is disposed.
      Type Parameters:
      K - the key type observed by the listener
      V - the value type observed by the listener
      Parameters:
      map - the observable map to listen to
      listener - the listener to add and later remove
      Returns:
      the listener, for use as a field initializer
    • registerHandler

      protected <E extends javafx.event.Event> javafx.event.EventHandler<E> registerHandler(javafx.scene.Node target, javafx.event.EventType<E> type, javafx.event.EventHandler<E> handler)
      Adds an event handler to the given Node and tracks it for automatic removal when this skin is disposed.
      Type Parameters:
      E - the event type handled by the handler
      Parameters:
      target - the node receiving the handler
      type - the event type to handle
      handler - the handler to add and later remove
      Returns:
      the handler, for use as a field initializer
    • registerFilter

      protected <E extends javafx.event.Event> javafx.event.EventHandler<E> registerFilter(javafx.scene.Node target, javafx.event.EventType<E> type, javafx.event.EventHandler<E> filter)
      Adds an event filter to the given Node and tracks it for automatic removal when this skin is disposed.
      Type Parameters:
      E - the event type filtered by the filter
      Parameters:
      target - the node receiving the filter
      type - the event type to filter
      filter - the filter to add and later remove
      Returns:
      the filter, for use as a field initializer
    • dispose

      public void dispose()
      Removes all registered listeners, event handlers, and event filters, then delegates to SkinBase.dispose().
      Specified by:
      dispose in interface javafx.scene.control.Skin<C extends javafx.scene.control.Control>
      Overrides:
      dispose in class javafx.scene.control.SkinBase<C extends javafx.scene.control.Control>