2626package javafx .scene .control .skin ;
2727
2828import com .sun .javafx .scene .control .behavior .BehaviorBase ;
29- import javafx .beans . InvalidationListener ;
30- import javafx . beans . Observable ;
29+ import com . sun . javafx .scene . control . behavior . ListCellBehavior ;
30+
3131import javafx .geometry .Orientation ;
32- import javafx .scene .Node ;
33- import javafx .scene .control .Accordion ;
34- import javafx .scene .control .Button ;
3532import javafx .scene .control .Control ;
3633import javafx .scene .control .ListCell ;
3734import javafx .scene .control .ListView ;
38-
39- import com .sun .javafx .scene .control .behavior .ListCellBehavior ;
35+ import javafx .scene .layout .Region ;
4036
4137/**
4238 * Default skin implementation for the {@link ListCell} control.
@@ -52,12 +48,8 @@ public class ListCellSkin<T> extends CellSkinBase<ListCell<T>> {
5248 * *
5349 **************************************************************************/
5450
55- private double fixedCellSize ;
56- private boolean fixedCellSizeEnabled ;
5751 private final BehaviorBase <ListCell <T >> behavior ;
5852
59-
60-
6153 /***************************************************************************
6254 * *
6355 * Constructors *
@@ -77,31 +69,8 @@ public ListCellSkin(ListCell<T> control) {
7769 // install default input map for the ListCell control
7870 behavior = new ListCellBehavior <>(control );
7971// control.setInputMap(behavior.getInputMap());
80-
81- setupListeners ();
8272 }
8373
84- private void setupListeners () {
85- ListView listView = getSkinnable ().getListView ();
86- if (listView == null ) {
87- getSkinnable ().listViewProperty ().addListener (new InvalidationListener () {
88- @ Override public void invalidated (Observable observable ) {
89- getSkinnable ().listViewProperty ().removeListener (this );
90- setupListeners ();
91- }
92- });
93- } else {
94- this .fixedCellSize = listView .getFixedCellSize ();
95- this .fixedCellSizeEnabled = fixedCellSize > 0 ;
96- registerChangeListener (listView .fixedCellSizeProperty (), e -> {
97- this .fixedCellSize = getSkinnable ().getListView ().getFixedCellSize ();
98- this .fixedCellSizeEnabled = fixedCellSize > 0 ;
99- });
100- }
101- }
102-
103-
104-
10574 /***************************************************************************
10675 * *
10776 * Public API *
@@ -127,7 +96,8 @@ private void setupListeners() {
12796
12897 /** {@inheritDoc} */
12998 @ Override protected double computePrefHeight (double width , double topInset , double rightInset , double bottomInset , double leftInset ) {
130- if (fixedCellSizeEnabled ) {
99+ double fixedCellSize = getFixedCellSize ();
100+ if (fixedCellSize > 0 ) {
131101 return fixedCellSize ;
132102 }
133103
@@ -140,7 +110,8 @@ private void setupListeners() {
140110
141111 /** {@inheritDoc} */
142112 @ Override protected double computeMinHeight (double width , double topInset , double rightInset , double bottomInset , double leftInset ) {
143- if (fixedCellSizeEnabled ) {
113+ double fixedCellSize = getFixedCellSize ();
114+ if (fixedCellSize > 0 ) {
144115 return fixedCellSize ;
145116 }
146117
@@ -149,10 +120,15 @@ private void setupListeners() {
149120
150121 /** {@inheritDoc} */
151122 @ Override protected double computeMaxHeight (double width , double topInset , double rightInset , double bottomInset , double leftInset ) {
152- if (fixedCellSizeEnabled ) {
123+ double fixedCellSize = getFixedCellSize ();
124+ if (fixedCellSize > 0 ) {
153125 return fixedCellSize ;
154126 }
155-
156127 return super .computeMaxHeight (width , topInset , rightInset , bottomInset , leftInset );
157128 }
129+
130+ private double getFixedCellSize () {
131+ ListView <?> listView = getSkinnable ().getListView ();
132+ return listView != null ? listView .getFixedCellSize () : Region .USE_COMPUTED_SIZE ;
133+ }
158134}
0 commit comments