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

Print this page




 257     /***************************************************************************
 258      *                                                                         *
 259      * Public API                                                              *
 260      *                                                                         *
 261      **************************************************************************/
 262 
 263     /** {@inheritDoc} */
 264     @Override public void dispose() {
 265         super.dispose();
 266 
 267         if (behavior != null) {
 268             behavior.dispose();
 269         }
 270     }
 271 
 272     /** {@inheritDoc} */
 273     @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
 274         // The TabPane can only be as wide as it widest content width.
 275         double maxw = 0.0;
 276         for (TabContentRegion contentRegion: tabContentRegions) {
 277             maxw = Math.max(maxw, snapSize(contentRegion.prefWidth(-1)));
 278         }
 279 
 280         final boolean isHorizontal = isHorizontal();
 281         final double tabHeaderAreaSize = snapSize(isHorizontal ?
 282                 tabHeaderArea.prefWidth(-1) : tabHeaderArea.prefHeight(-1));

 283 
 284         double prefWidth = isHorizontal ?
 285                 Math.max(maxw, tabHeaderAreaSize) : maxw + tabHeaderAreaSize;
 286         return snapSize(prefWidth) + rightInset + leftInset;
 287     }
 288 
 289     /** {@inheritDoc} */
 290     @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
 291         // The TabPane can only be as high as it highest content height.
 292         double maxh = 0.0;
 293         for (TabContentRegion contentRegion: tabContentRegions) {
 294             maxh = Math.max(maxh, snapSize(contentRegion.prefHeight(-1)));
 295         }
 296 
 297         final boolean isHorizontal = isHorizontal();
 298         final double tabHeaderAreaSize = snapSize(isHorizontal ?
 299                 tabHeaderArea.prefHeight(-1) : tabHeaderArea.prefWidth(-1));

 300 
 301         double prefHeight = isHorizontal ?
 302                 maxh + snapSize(tabHeaderAreaSize) : Math.max(maxh, tabHeaderAreaSize);
 303         return snapSize(prefHeight) + topInset + bottomInset;
 304     }
 305 
 306     /** {@inheritDoc} */
 307     @Override public double computeBaselineOffset(double topInset, double rightInset, double bottomInset, double leftInset) {
 308         Side tabPosition = getSkinnable().getSide();
 309         if (tabPosition == Side.TOP) {
 310             return tabHeaderArea.getBaselineOffset() + topInset;
 311         }
 312         return 0;
 313     }
 314 
 315     /** {@inheritDoc} */
 316     @Override protected void layoutChildren(final double x, final double y,
 317                                             final double w, final double h) {
 318         TabPane tabPane = getSkinnable();
 319         Side tabPosition = tabPane.getSide();
 320 
 321         double headerHeight = snapSize(tabHeaderArea.prefHeight(-1));




 322         double tabsStartX = tabPosition.equals(Side.RIGHT)? x + w - headerHeight : x;
 323         double tabsStartY = tabPosition.equals(Side.BOTTOM)? y + h - headerHeight : y;
 324 
 325         final double leftInset = snappedLeftInset();
 326         final double topInset = snappedTopInset();
 327         final double rightInset = snappedRightInset();
 328 
 329         if (tabPosition == Side.TOP) {
 330             tabHeaderArea.resize(w, headerHeight);
 331             tabHeaderArea.relocate(tabsStartX, tabsStartY);
 332             tabHeaderArea.getTransforms().clear();
 333             tabHeaderArea.getTransforms().add(new Rotate(getRotation(Side.TOP)));
 334         } else if (tabPosition == Side.BOTTOM) {
 335             tabHeaderArea.resize(w, headerHeight);
 336             tabHeaderArea.relocate(w + leftInset, tabsStartY - headerHeight);
 337             tabHeaderArea.getTransforms().clear();
 338             tabHeaderArea.getTransforms().add(new Rotate(getRotation(Side.BOTTOM), 0, headerHeight));
 339         } else if (tabPosition == Side.LEFT) {
 340             tabHeaderArea.resize(h, headerHeight);
 341             tabHeaderArea.relocate(tabsStartX + headerHeight, h - headerHeight + topInset);




 257     /***************************************************************************
 258      *                                                                         *
 259      * Public API                                                              *
 260      *                                                                         *
 261      **************************************************************************/
 262 
 263     /** {@inheritDoc} */
 264     @Override public void dispose() {
 265         super.dispose();
 266 
 267         if (behavior != null) {
 268             behavior.dispose();
 269         }
 270     }
 271 
 272     /** {@inheritDoc} */
 273     @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
 274         // The TabPane can only be as wide as it widest content width.
 275         double maxw = 0.0;
 276         for (TabContentRegion contentRegion: tabContentRegions) {
 277             maxw = Math.max(maxw, snapSizeX(contentRegion.prefWidth(-1)));
 278         }
 279 
 280         final boolean isHorizontal = isHorizontal();
 281         final double tabHeaderAreaSize = isHorizontal
 282                 ? snapSizeX(tabHeaderArea.prefWidth(-1))
 283                 : snapSizeY(tabHeaderArea.prefHeight(-1));
 284 
 285         double prefWidth = isHorizontal ?
 286                 Math.max(maxw, tabHeaderAreaSize) : maxw + tabHeaderAreaSize;
 287         return snapSizeX(prefWidth) + rightInset + leftInset;
 288     }
 289 
 290     /** {@inheritDoc} */
 291     @Override protected double computePrefHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) {
 292         // The TabPane can only be as high as it highest content height.
 293         double maxh = 0.0;
 294         for (TabContentRegion contentRegion: tabContentRegions) {
 295             maxh = Math.max(maxh, snapSizeY(contentRegion.prefHeight(-1)));
 296         }
 297 
 298         final boolean isHorizontal = isHorizontal();
 299         final double tabHeaderAreaSize = isHorizontal
 300                 ? snapSizeY(tabHeaderArea.prefHeight(-1))
 301                 : snapSizeX(tabHeaderArea.prefWidth(-1));
 302 
 303         double prefHeight = isHorizontal ?
 304                 maxh + snapSizeY(tabHeaderAreaSize) : Math.max(maxh, tabHeaderAreaSize);
 305         return snapSizeY(prefHeight) + topInset + bottomInset;
 306     }
 307 
 308     /** {@inheritDoc} */
 309     @Override public double computeBaselineOffset(double topInset, double rightInset, double bottomInset, double leftInset) {
 310         Side tabPosition = getSkinnable().getSide();
 311         if (tabPosition == Side.TOP) {
 312             return tabHeaderArea.getBaselineOffset() + topInset;
 313         }
 314         return 0;
 315     }
 316 
 317     /** {@inheritDoc} */
 318     @Override protected void layoutChildren(final double x, final double y,
 319                                             final double w, final double h) {
 320         TabPane tabPane = getSkinnable();
 321         Side tabPosition = tabPane.getSide();
 322 
 323         // There seem to be conflicting ways in which this dimension will
 324         // be used below.  Most places use it exclusively as a "height",
 325         // but the two lines that follow, use it as either a width or a
 326         // height...?
 327         double headerHeight = snapSizeY(tabHeaderArea.prefHeight(-1));
 328         double tabsStartX = tabPosition.equals(Side.RIGHT)? x + w - headerHeight : x;
 329         double tabsStartY = tabPosition.equals(Side.BOTTOM)? y + h - headerHeight : y;
 330 
 331         final double leftInset = snappedLeftInset();
 332         final double topInset = snappedTopInset();
 333         final double rightInset = snappedRightInset();
 334 
 335         if (tabPosition == Side.TOP) {
 336             tabHeaderArea.resize(w, headerHeight);
 337             tabHeaderArea.relocate(tabsStartX, tabsStartY);
 338             tabHeaderArea.getTransforms().clear();
 339             tabHeaderArea.getTransforms().add(new Rotate(getRotation(Side.TOP)));
 340         } else if (tabPosition == Side.BOTTOM) {
 341             tabHeaderArea.resize(w, headerHeight);
 342             tabHeaderArea.relocate(w + leftInset, tabsStartY - headerHeight);
 343             tabHeaderArea.getTransforms().clear();
 344             tabHeaderArea.getTransforms().add(new Rotate(getRotation(Side.BOTTOM), 0, headerHeight));
 345         } else if (tabPosition == Side.LEFT) {
 346             tabHeaderArea.resize(h, headerHeight);
 347             tabHeaderArea.relocate(tabsStartX + headerHeight, h - headerHeight + topInset);