171 /*************************************************************************** 172 * * 173 * Public API * 174 * * 175 **************************************************************************/ 176 177 /** {@inheritDoc} */ 178 @Override public void dispose() { 179 super.dispose(); 180 181 if (behavior != null) { 182 behavior.dispose(); 183 } 184 } 185 186 /** {@inheritDoc} */ 187 @Override protected void layoutChildren(final double x, final double y, 188 final double w, final double h) { 189 // calculate the available space 190 // resize thumb to preferred size 191 thumbWidth = snapSize(thumb.prefWidth(-1)); 192 thumbHeight = snapSize(thumb.prefHeight(-1)); 193 thumb.resize(thumbWidth, thumbHeight); 194 // we are assuming the is common radius's for all corners on the track 195 double trackRadius = track.getBackground() == null ? 0 : track.getBackground().getFills().size() > 0 ? 196 track.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius() : 0; 197 198 if (getSkinnable().getOrientation() == Orientation.HORIZONTAL) { 199 double tickLineHeight = (showTickMarks) ? tickLine.prefHeight(-1) : 0; 200 double trackHeight = snapSize(track.prefHeight(-1)); 201 double trackAreaHeight = Math.max(trackHeight,thumbHeight); 202 double totalHeightNeeded = trackAreaHeight + ((showTickMarks) ? trackToTickGap+tickLineHeight : 0); 203 double startY = y + ((h - totalHeightNeeded)/2); // center slider in available height vertically 204 trackLength = snapSize(w - thumbWidth); 205 trackStart = snapPosition(x + (thumbWidth/2)); 206 double trackTop = (int)(startY + ((trackAreaHeight-trackHeight)/2)); 207 thumbTop = (int)(startY + ((trackAreaHeight-thumbHeight)/2)); 208 209 positionThumb(false); 210 // layout track 211 track.resizeRelocate((int)(trackStart - trackRadius), 212 trackTop , 213 (int)(trackLength + trackRadius + trackRadius), 214 trackHeight); 215 // layout tick line 216 if (showTickMarks) { 217 tickLine.setLayoutX(trackStart); 218 tickLine.setLayoutY(trackTop+trackHeight+trackToTickGap); 219 tickLine.resize(trackLength, tickLineHeight); 220 tickLine.requestAxisLayout(); 221 } else { 222 if (tickLine != null) { 223 tickLine.resize(0,0); 224 tickLine.requestAxisLayout(); 225 } 226 tickLine = null; 227 } 228 } else { 229 double tickLineWidth = (showTickMarks) ? tickLine.prefWidth(-1) : 0; 230 double trackWidth = snapSize(track.prefWidth(-1)); 231 double trackAreaWidth = Math.max(trackWidth,thumbWidth); 232 double totalWidthNeeded = trackAreaWidth + ((showTickMarks) ? trackToTickGap+tickLineWidth : 0) ; 233 double startX = x + ((w - totalWidthNeeded)/2); // center slider in available width horizontally 234 trackLength = snapSize(h - thumbHeight); 235 trackStart = snapPosition(y + (thumbHeight/2)); 236 double trackLeft = (int)(startX + ((trackAreaWidth-trackWidth)/2)); 237 thumbLeft = (int)(startX + ((trackAreaWidth-thumbWidth)/2)); 238 239 positionThumb(false); 240 // layout track 241 track.resizeRelocate(trackLeft, 242 (int)(trackStart - trackRadius), 243 trackWidth, 244 (int)(trackLength + trackRadius + trackRadius)); 245 // layout tick line 246 if (showTickMarks) { 247 tickLine.setLayoutX(trackLeft+trackWidth+trackToTickGap); 248 tickLine.setLayoutY(trackStart); 249 tickLine.resize(tickLineWidth, trackLength); 250 tickLine.requestAxisLayout(); 251 } else { 252 if (tickLine != null) { 253 tickLine.resize(0,0); 254 tickLine.requestAxisLayout(); 255 } | 171 /*************************************************************************** 172 * * 173 * Public API * 174 * * 175 **************************************************************************/ 176 177 /** {@inheritDoc} */ 178 @Override public void dispose() { 179 super.dispose(); 180 181 if (behavior != null) { 182 behavior.dispose(); 183 } 184 } 185 186 /** {@inheritDoc} */ 187 @Override protected void layoutChildren(final double x, final double y, 188 final double w, final double h) { 189 // calculate the available space 190 // resize thumb to preferred size 191 thumbWidth = snapSizeX(thumb.prefWidth(-1)); 192 thumbHeight = snapSizeY(thumb.prefHeight(-1)); 193 thumb.resize(thumbWidth, thumbHeight); 194 // we are assuming the is common radius's for all corners on the track 195 double trackRadius = track.getBackground() == null ? 0 : track.getBackground().getFills().size() > 0 ? 196 track.getBackground().getFills().get(0).getRadii().getTopLeftHorizontalRadius() : 0; 197 198 if (getSkinnable().getOrientation() == Orientation.HORIZONTAL) { 199 double tickLineHeight = (showTickMarks) ? tickLine.prefHeight(-1) : 0; 200 double trackHeight = snapSizeY(track.prefHeight(-1)); 201 double trackAreaHeight = Math.max(trackHeight,thumbHeight); 202 double totalHeightNeeded = trackAreaHeight + ((showTickMarks) ? trackToTickGap+tickLineHeight : 0); 203 double startY = y + ((h - totalHeightNeeded)/2); // center slider in available height vertically 204 trackLength = snapSizeX(w - thumbWidth); 205 trackStart = snapPositionX(x + (thumbWidth/2)); 206 double trackTop = (int)(startY + ((trackAreaHeight-trackHeight)/2)); 207 thumbTop = (int)(startY + ((trackAreaHeight-thumbHeight)/2)); 208 209 positionThumb(false); 210 // layout track 211 track.resizeRelocate((int)(trackStart - trackRadius), 212 trackTop , 213 (int)(trackLength + trackRadius + trackRadius), 214 trackHeight); 215 // layout tick line 216 if (showTickMarks) { 217 tickLine.setLayoutX(trackStart); 218 tickLine.setLayoutY(trackTop+trackHeight+trackToTickGap); 219 tickLine.resize(trackLength, tickLineHeight); 220 tickLine.requestAxisLayout(); 221 } else { 222 if (tickLine != null) { 223 tickLine.resize(0,0); 224 tickLine.requestAxisLayout(); 225 } 226 tickLine = null; 227 } 228 } else { 229 double tickLineWidth = (showTickMarks) ? tickLine.prefWidth(-1) : 0; 230 double trackWidth = snapSizeX(track.prefWidth(-1)); 231 double trackAreaWidth = Math.max(trackWidth,thumbWidth); 232 double totalWidthNeeded = trackAreaWidth + ((showTickMarks) ? trackToTickGap+tickLineWidth : 0) ; 233 double startX = x + ((w - totalWidthNeeded)/2); // center slider in available width horizontally 234 trackLength = snapSizeY(h - thumbHeight); 235 trackStart = snapPositionY(y + (thumbHeight/2)); 236 double trackLeft = (int)(startX + ((trackAreaWidth-trackWidth)/2)); 237 thumbLeft = (int)(startX + ((trackAreaWidth-thumbWidth)/2)); 238 239 positionThumb(false); 240 // layout track 241 track.resizeRelocate(trackLeft, 242 (int)(trackStart - trackRadius), 243 trackWidth, 244 (int)(trackLength + trackRadius + trackRadius)); 245 // layout tick line 246 if (showTickMarks) { 247 tickLine.setLayoutX(trackLeft+trackWidth+trackToTickGap); 248 tickLine.setLayoutY(trackStart); 249 tickLine.resize(tickLineWidth, trackLength); 250 tickLine.requestAxisLayout(); 251 } else { 252 if (tickLine != null) { 253 tickLine.resize(0,0); 254 tickLine.requestAxisLayout(); 255 } |