modules/javafx.controls/src/main/java/javafx/scene/control/skin/TitledPaneSkin.java

Print this page




 215         if (behavior != null) {
 216             behavior.dispose();
 217         }
 218     }
 219 
 220     // Override LabeledSkinBase updateChildren because
 221     // it removes all the children.  The update() in TitleRegion
 222     // will replace this method.
 223     /** {@inheritDoc} */
 224     @Override protected void updateChildren() {
 225         if (titleRegion != null) {
 226             titleRegion.update();
 227         }
 228     }
 229 
 230     /** {@inheritDoc} */
 231     @Override protected void layoutChildren(final double x, double y,
 232                                             final double w, final double h) {
 233 
 234         // header
 235         double headerHeight = snapSize(titleRegion.prefHeight(-1));
 236 
 237         titleRegion.resize(w, headerHeight);
 238         positionInArea(titleRegion, x, y,
 239                 w, headerHeight, 0, HPos.LEFT, VPos.CENTER);
 240         titleRegion.requestLayout();
 241 
 242         // content
 243         double contentHeight = (h - headerHeight) * getTransition();
 244         if (isInsideAccordion()) {
 245             if (prefHeightFromAccordion != 0) {
 246                 contentHeight = (prefHeightFromAccordion - headerHeight) * getTransition();
 247             }
 248         }
 249         contentHeight = snapSize(contentHeight);
 250 
 251         y += snapSize(headerHeight);


 252         contentContainer.resize(w, contentHeight);
 253         clipRect.setHeight(contentHeight);
 254         positionInArea(contentContainer, x, y,
 255                 w, contentHeight, /*baseline ignored*/0, HPos.CENTER, VPos.CENTER);
 256     }
 257 
 258     /** {@inheritDoc} */
 259     @Override protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
 260         double titleWidth = snapSize(titleRegion.prefWidth(height));
 261         double contentWidth = snapSize(contentContainer.minWidth(height));
 262         return Math.max(titleWidth, contentWidth) + leftInset + rightInset;
 263     }
 264 
 265     /** {@inheritDoc} */
 266     @Override protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
 267         double headerHeight = snapSize(titleRegion.prefHeight(width));
 268         double contentHeight = contentContainer.minHeight(width) * getTransition();
 269         return headerHeight + snapSize(contentHeight) + topInset + bottomInset;
 270     }
 271 
 272     /** {@inheritDoc} */
 273     @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
 274         double titleWidth = snapSize(titleRegion.prefWidth(height));
 275         double contentWidth = snapSize(contentContainer.prefWidth(height));
 276         return Math.max(titleWidth, contentWidth) + leftInset + rightInset;
 277     }
 278 
 279     /** {@inheritDoc} */
 280     @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
 281         double headerHeight = snapSize(titleRegion.prefHeight(width));
 282         double contentHeight = contentContainer.prefHeight(width) * getTransition();
 283         return headerHeight + snapSize(contentHeight) + topInset + bottomInset;
 284     }
 285 
 286     /** {@inheritDoc} */
 287     @Override protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
 288         return Double.MAX_VALUE;
 289     }
 290 
 291 
 292 
 293     /***************************************************************************
 294      *                                                                         *
 295      * Private implementation                                                  *
 296      *                                                                         *
 297      **************************************************************************/
 298 
 299     private void updateClip() {
 300         clipRect.setWidth(getSkinnable().getWidth());
 301         clipRect.setHeight(contentContainer.getHeight());
 302     }
 303 


 312             transitionStartValue = getTransition();
 313             doAnimationTransition();
 314         } else {
 315             if (expanded) {
 316                 setTransition(1.0f);
 317             } else {
 318                 setTransition(0.0f);
 319             }
 320             if (content != null) {
 321                 content.setVisible(expanded);
 322              }
 323             getSkinnable().requestLayout();
 324         }
 325     }
 326 
 327     private boolean isInsideAccordion() {
 328         return getSkinnable().getParent() != null && getSkinnable().getParent() instanceof Accordion;
 329     }
 330 
 331     double getTitleRegionSize(double width) {
 332         return snapSize(titleRegion.prefHeight(width)) + snappedTopInset() + snappedBottomInset();
 333     }
 334 
 335     private double prefHeightFromAccordion = 0;
 336     void setMaxTitledPaneHeightForAccordion(double height) {
 337         this.prefHeightFromAccordion = height;
 338     }
 339 
 340     double getTitledPaneHeightForAccordion() {
 341         double headerHeight = snapSize(titleRegion.prefHeight(-1));
 342         double contentHeight = (prefHeightFromAccordion - headerHeight) * getTransition();
 343         return headerHeight + snapSize(contentHeight) + snappedTopInset() + snappedBottomInset();
 344     }
 345 
 346     private void doAnimationTransition() {
 347         if (content == null) {
 348             return;
 349         }
 350 
 351         Duration duration;
 352         if (timeline != null && (timeline.getStatus() != Status.STOPPED)) {
 353             duration = timeline.getCurrentTime();
 354             timeline.stop();
 355         } else {
 356             duration = TRANSITION_DURATION;
 357         }
 358 
 359         timeline = new Timeline();
 360         timeline.setCycleCount(1);
 361 
 362         KeyFrame k1, k2;
 363 




 215         if (behavior != null) {
 216             behavior.dispose();
 217         }
 218     }
 219 
 220     // Override LabeledSkinBase updateChildren because
 221     // it removes all the children.  The update() in TitleRegion
 222     // will replace this method.
 223     /** {@inheritDoc} */
 224     @Override protected void updateChildren() {
 225         if (titleRegion != null) {
 226             titleRegion.update();
 227         }
 228     }
 229 
 230     /** {@inheritDoc} */
 231     @Override protected void layoutChildren(final double x, double y,
 232                                             final double w, final double h) {
 233 
 234         // header
 235         double headerHeight = snapSizeY(titleRegion.prefHeight(-1));
 236 
 237         titleRegion.resize(w, headerHeight);
 238         positionInArea(titleRegion, x, y,
 239                 w, headerHeight, 0, HPos.LEFT, VPos.CENTER);
 240         titleRegion.requestLayout();
 241 
 242         // content
 243         double contentHeight = (h - headerHeight) * getTransition();
 244         if (isInsideAccordion()) {
 245             if (prefHeightFromAccordion != 0) {
 246                 contentHeight = (prefHeightFromAccordion - headerHeight) * getTransition();
 247             }
 248         }
 249         contentHeight = snapSizeY(contentHeight);
 250 
 251         // Header height was already snapped above.  Is this just in case
 252         // mods are made to the intervening code?  Or is it just redundant?
 253         y += snapSizeY(headerHeight);
 254         contentContainer.resize(w, contentHeight);
 255         clipRect.setHeight(contentHeight);
 256         positionInArea(contentContainer, x, y,
 257                 w, contentHeight, /*baseline ignored*/0, HPos.CENTER, VPos.CENTER);
 258     }
 259 
 260     /** {@inheritDoc} */
 261     @Override protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
 262         double titleWidth = snapSizeX(titleRegion.prefWidth(height));
 263         double contentWidth = snapSizeX(contentContainer.minWidth(height));
 264         return Math.max(titleWidth, contentWidth) + leftInset + rightInset;
 265     }
 266 
 267     /** {@inheritDoc} */
 268     @Override protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
 269         double headerHeight = snapSizeY(titleRegion.prefHeight(width));
 270         double contentHeight = contentContainer.minHeight(width) * getTransition();
 271         return headerHeight + snapSizeY(contentHeight) + topInset + bottomInset;
 272     }
 273 
 274     /** {@inheritDoc} */
 275     @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
 276         double titleWidth = snapSizeX(titleRegion.prefWidth(height));
 277         double contentWidth = snapSizeX(contentContainer.prefWidth(height));
 278         return Math.max(titleWidth, contentWidth) + leftInset + rightInset;
 279     }
 280 
 281     /** {@inheritDoc} */
 282     @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
 283         double headerHeight = snapSizeY(titleRegion.prefHeight(width));
 284         double contentHeight = contentContainer.prefHeight(width) * getTransition();
 285         return headerHeight + snapSizeY(contentHeight) + topInset + bottomInset;
 286     }
 287 
 288     /** {@inheritDoc} */
 289     @Override protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
 290         return Double.MAX_VALUE;
 291     }
 292 
 293 
 294 
 295     /***************************************************************************
 296      *                                                                         *
 297      * Private implementation                                                  *
 298      *                                                                         *
 299      **************************************************************************/
 300 
 301     private void updateClip() {
 302         clipRect.setWidth(getSkinnable().getWidth());
 303         clipRect.setHeight(contentContainer.getHeight());
 304     }
 305 


 314             transitionStartValue = getTransition();
 315             doAnimationTransition();
 316         } else {
 317             if (expanded) {
 318                 setTransition(1.0f);
 319             } else {
 320                 setTransition(0.0f);
 321             }
 322             if (content != null) {
 323                 content.setVisible(expanded);
 324              }
 325             getSkinnable().requestLayout();
 326         }
 327     }
 328 
 329     private boolean isInsideAccordion() {
 330         return getSkinnable().getParent() != null && getSkinnable().getParent() instanceof Accordion;
 331     }
 332 
 333     double getTitleRegionSize(double width) {
 334         return snapSizeY(titleRegion.prefHeight(width)) + snappedTopInset() + snappedBottomInset();
 335     }
 336 
 337     private double prefHeightFromAccordion = 0;
 338     void setMaxTitledPaneHeightForAccordion(double height) {
 339         this.prefHeightFromAccordion = height;
 340     }
 341 
 342     double getTitledPaneHeightForAccordion() {
 343         double headerHeight = snapSizeY(titleRegion.prefHeight(-1));
 344         double contentHeight = (prefHeightFromAccordion - headerHeight) * getTransition();
 345         return headerHeight + snapSizeY(contentHeight) + snappedTopInset() + snappedBottomInset();
 346     }
 347 
 348     private void doAnimationTransition() {
 349         if (content == null) {
 350             return;
 351         }
 352 
 353         Duration duration;
 354         if (timeline != null && (timeline.getStatus() != Status.STOPPED)) {
 355             duration = timeline.getCurrentTime();
 356             timeline.stop();
 357         } else {
 358             duration = TRANSITION_DURATION;
 359         }
 360 
 361         timeline = new Timeline();
 362         timeline.setCycleCount(1);
 363 
 364         KeyFrame k1, k2;
 365