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

Print this page

        

*** 256,273 **** * * * Properties * * * **************************************************************************/ // --- spacing private DoubleProperty spacing; private final void setSpacing(double value) { ! spacingProperty().set(snapSpace(value)); } private final double getSpacing() { ! return spacing == null ? 0.0 : snapSpace(spacing.get()); } private final DoubleProperty spacingProperty() { if (spacing == null) { spacing = new StyleableDoubleProperty() { --- 256,281 ---- * * * Properties * * * **************************************************************************/ + private double snapSpacing(double value) { + if (getSkinnable().getOrientation() == Orientation.VERTICAL) { + return snapSpaceY(value); + } else { + return snapSpaceX(value); + } + } + // --- spacing private DoubleProperty spacing; private final void setSpacing(double value) { ! spacingProperty().set(snapSpacing(value)); } private final double getSpacing() { ! return spacing == null ? 0.0 : snapSpacing(spacing.get()); } private final DoubleProperty spacingProperty() { if (spacing == null) { spacing = new StyleableDoubleProperty() {
*** 364,381 **** /** {@inheritDoc} */ @Override protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { final ToolBar toolbar = getSkinnable(); return toolbar.getOrientation() == Orientation.VERTICAL ? computePrefWidth(-1, topInset, rightInset, bottomInset, leftInset) : ! snapSize(overflowMenu.prefWidth(-1)) + leftInset + rightInset; } /** {@inheritDoc} */ @Override protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { final ToolBar toolbar = getSkinnable(); return toolbar.getOrientation() == Orientation.VERTICAL? ! snapSize(overflowMenu.prefHeight(-1)) + topInset + bottomInset : computePrefHeight(-1, topInset, rightInset, bottomInset, leftInset); } /** {@inheritDoc} */ @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { --- 372,389 ---- /** {@inheritDoc} */ @Override protected double computeMinWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { final ToolBar toolbar = getSkinnable(); return toolbar.getOrientation() == Orientation.VERTICAL ? computePrefWidth(-1, topInset, rightInset, bottomInset, leftInset) : ! snapSizeX(overflowMenu.prefWidth(-1)) + leftInset + rightInset; } /** {@inheritDoc} */ @Override protected double computeMinHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { final ToolBar toolbar = getSkinnable(); return toolbar.getOrientation() == Orientation.VERTICAL? ! snapSizeY(overflowMenu.prefHeight(-1)) + topInset + bottomInset : computePrefHeight(-1, topInset, rightInset, bottomInset, leftInset); } /** {@inheritDoc} */ @Override protected double computePrefWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) {
*** 383,399 **** final ToolBar toolbar = getSkinnable(); if (toolbar.getOrientation() == Orientation.HORIZONTAL) { for (Node node : toolbar.getItems()) { if (!node.isManaged()) continue; ! prefWidth += snapSize(node.prefWidth(-1)) + getSpacing(); } prefWidth -= getSpacing(); } else { for (Node node : toolbar.getItems()) { if (!node.isManaged()) continue; ! prefWidth = Math.max(prefWidth, snapSize(node.prefWidth(-1))); } if (toolbar.getItems().size() > 0) { savedPrefWidth = prefWidth; } else { prefWidth = savedPrefWidth; --- 391,407 ---- final ToolBar toolbar = getSkinnable(); if (toolbar.getOrientation() == Orientation.HORIZONTAL) { for (Node node : toolbar.getItems()) { if (!node.isManaged()) continue; ! prefWidth += snapSizeX(node.prefWidth(-1)) + getSpacing(); } prefWidth -= getSpacing(); } else { for (Node node : toolbar.getItems()) { if (!node.isManaged()) continue; ! prefWidth = Math.max(prefWidth, snapSizeX(node.prefWidth(-1))); } if (toolbar.getItems().size() > 0) { savedPrefWidth = prefWidth; } else { prefWidth = savedPrefWidth;
*** 408,424 **** final ToolBar toolbar = getSkinnable(); if(toolbar.getOrientation() == Orientation.VERTICAL) { for (Node node: toolbar.getItems()) { if (!node.isManaged()) continue; ! prefHeight += snapSize(node.prefHeight(-1)) + getSpacing(); } prefHeight -= getSpacing(); } else { for (Node node : toolbar.getItems()) { if (!node.isManaged()) continue; ! prefHeight = Math.max(prefHeight, snapSize(node.prefHeight(-1))); } if (toolbar.getItems().size() > 0) { savedPrefHeight = prefHeight; } else { prefHeight = savedPrefHeight; --- 416,432 ---- final ToolBar toolbar = getSkinnable(); if(toolbar.getOrientation() == Orientation.VERTICAL) { for (Node node: toolbar.getItems()) { if (!node.isManaged()) continue; ! prefHeight += snapSizeY(node.prefHeight(-1)) + getSpacing(); } prefHeight -= getSpacing(); } else { for (Node node : toolbar.getItems()) { if (!node.isManaged()) continue; ! prefHeight = Math.max(prefHeight, snapSizeY(node.prefHeight(-1))); } if (toolbar.getItems().size() > 0) { savedPrefHeight = prefHeight; } else { prefHeight = savedPrefHeight;
*** 428,486 **** } /** {@inheritDoc} */ @Override protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { return getSkinnable().getOrientation() == Orientation.VERTICAL ? ! snapSize(getSkinnable().prefWidth(-1)) : Double.MAX_VALUE; } /** {@inheritDoc} */ @Override protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { return getSkinnable().getOrientation() == Orientation.VERTICAL ? ! Double.MAX_VALUE : snapSize(getSkinnable().prefHeight(-1)); } /** {@inheritDoc} */ @Override protected void layoutChildren(final double x,final double y, final double w, final double h) { // super.layoutChildren(); final ToolBar toolbar = getSkinnable(); if (toolbar.getOrientation() == Orientation.VERTICAL) { ! if (snapSize(toolbar.getHeight()) != previousHeight || needsUpdate) { ((VBox)box).setSpacing(getSpacing()); ((VBox)box).setAlignment(getBoxAlignment()); ! previousHeight = snapSize(toolbar.getHeight()); addNodesToToolBar(); } } else { ! if (snapSize(toolbar.getWidth()) != previousWidth || needsUpdate) { ((HBox)box).setSpacing(getSpacing()); ((HBox)box).setAlignment(getBoxAlignment()); ! previousWidth = snapSize(toolbar.getWidth()); addNodesToToolBar(); } } needsUpdate = false; double toolbarWidth = w; double toolbarHeight = h; if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! toolbarHeight -= (overflow ? snapSize(overflowMenu.prefHeight(-1)) : 0); } else { ! toolbarWidth -= (overflow ? snapSize(overflowMenu.prefWidth(-1)) : 0); } box.resize(toolbarWidth, toolbarHeight); positionInArea(box, x, y, toolbarWidth, toolbarHeight, /*baseline ignored*/0, HPos.CENTER, VPos.CENTER); // If popup menu is not null show the overflowControl if (overflow) { ! double overflowMenuWidth = snapSize(overflowMenu.prefWidth(-1)); ! double overflowMenuHeight = snapSize(overflowMenu.prefHeight(-1)); double overflowX = x; double overflowY = x; if (getSkinnable().getOrientation() == Orientation.VERTICAL) { // This is to prevent the overflow menu from moving when there // are no items in the toolbar. --- 436,494 ---- } /** {@inheritDoc} */ @Override protected double computeMaxWidth(double height, double topInset, double rightInset, double bottomInset, double leftInset) { return getSkinnable().getOrientation() == Orientation.VERTICAL ? ! snapSizeX(getSkinnable().prefWidth(-1)) : Double.MAX_VALUE; } /** {@inheritDoc} */ @Override protected double computeMaxHeight(double width, double topInset, double rightInset, double bottomInset, double leftInset) { return getSkinnable().getOrientation() == Orientation.VERTICAL ? ! Double.MAX_VALUE : snapSizeY(getSkinnable().prefHeight(-1)); } /** {@inheritDoc} */ @Override protected void layoutChildren(final double x,final double y, final double w, final double h) { // super.layoutChildren(); final ToolBar toolbar = getSkinnable(); if (toolbar.getOrientation() == Orientation.VERTICAL) { ! if (snapSizeY(toolbar.getHeight()) != previousHeight || needsUpdate) { ((VBox)box).setSpacing(getSpacing()); ((VBox)box).setAlignment(getBoxAlignment()); ! previousHeight = snapSizeY(toolbar.getHeight()); addNodesToToolBar(); } } else { ! if (snapSizeX(toolbar.getWidth()) != previousWidth || needsUpdate) { ((HBox)box).setSpacing(getSpacing()); ((HBox)box).setAlignment(getBoxAlignment()); ! previousWidth = snapSizeX(toolbar.getWidth()); addNodesToToolBar(); } } needsUpdate = false; double toolbarWidth = w; double toolbarHeight = h; if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! toolbarHeight -= (overflow ? snapSizeY(overflowMenu.prefHeight(-1)) : 0); } else { ! toolbarWidth -= (overflow ? snapSizeX(overflowMenu.prefWidth(-1)) : 0); } box.resize(toolbarWidth, toolbarHeight); positionInArea(box, x, y, toolbarWidth, toolbarHeight, /*baseline ignored*/0, HPos.CENTER, VPos.CENTER); // If popup menu is not null show the overflowControl if (overflow) { ! double overflowMenuWidth = snapSizeX(overflowMenu.prefWidth(-1)); ! double overflowMenuHeight = snapSizeY(overflowMenu.prefHeight(-1)); double overflowX = x; double overflowY = x; if (getSkinnable().getOrientation() == Orientation.VERTICAL) { // This is to prevent the overflow menu from moving when there // are no items in the toolbar.
*** 489,506 **** } HPos pos = ((VBox)box).getAlignment().getHpos(); if (HPos.LEFT.equals(pos)) { overflowX = x + Math.abs((toolbarWidth - overflowMenuWidth)/2); } else if (HPos.RIGHT.equals(pos)) { ! overflowX = (snapSize(toolbar.getWidth()) - snappedRightInset() - toolbarWidth) + Math.abs((toolbarWidth - overflowMenuWidth)/2); } else { overflowX = x + ! Math.abs((snapSize(toolbar.getWidth()) - (x) + snappedRightInset() - overflowMenuWidth)/2); } ! overflowY = snapSize(toolbar.getHeight()) - overflowMenuHeight - y; } else { // This is to prevent the overflow menu from moving when there // are no items in the toolbar. if (toolbarHeight == 0) { toolbarHeight = savedPrefHeight; --- 497,514 ---- } HPos pos = ((VBox)box).getAlignment().getHpos(); if (HPos.LEFT.equals(pos)) { overflowX = x + Math.abs((toolbarWidth - overflowMenuWidth)/2); } else if (HPos.RIGHT.equals(pos)) { ! overflowX = (snapSizeX(toolbar.getWidth()) - snappedRightInset() - toolbarWidth) + Math.abs((toolbarWidth - overflowMenuWidth)/2); } else { overflowX = x + ! Math.abs((snapSizeX(toolbar.getWidth()) - (x) + snappedRightInset() - overflowMenuWidth)/2); } ! overflowY = snapSizeY(toolbar.getHeight()) - overflowMenuHeight - y; } else { // This is to prevent the overflow menu from moving when there // are no items in the toolbar. if (toolbarHeight == 0) { toolbarHeight = savedPrefHeight;
*** 508,523 **** VPos pos = ((HBox)box).getAlignment().getVpos(); if (VPos.TOP.equals(pos)) { overflowY = y + Math.abs((toolbarHeight - overflowMenuHeight)/2); } else if (VPos.BOTTOM.equals(pos)) { ! overflowY = (snapSize(toolbar.getHeight()) - snappedBottomInset() - toolbarHeight) + Math.abs((toolbarHeight - overflowMenuHeight)/2); } else { overflowY = y + Math.abs((toolbarHeight - overflowMenuHeight)/2); } ! overflowX = snapSize(toolbar.getWidth()) - overflowMenuWidth - snappedRightInset(); } overflowMenu.resize(overflowMenuWidth, overflowMenuHeight); positionInArea(overflowMenu, overflowX, overflowY, overflowMenuWidth, overflowMenuHeight, /*baseline ignored*/0, HPos.CENTER, VPos.CENTER); } --- 516,531 ---- VPos pos = ((HBox)box).getAlignment().getVpos(); if (VPos.TOP.equals(pos)) { overflowY = y + Math.abs((toolbarHeight - overflowMenuHeight)/2); } else if (VPos.BOTTOM.equals(pos)) { ! overflowY = (snapSizeY(toolbar.getHeight()) - snappedBottomInset() - toolbarHeight) + Math.abs((toolbarHeight - overflowMenuHeight)/2); } else { overflowY = y + Math.abs((toolbarHeight - overflowMenuHeight)/2); } ! overflowX = snapSizeX(toolbar.getWidth()) - overflowMenuWidth - snappedRightInset(); } overflowMenu.resize(overflowMenuWidth, overflowMenuHeight); positionInArea(overflowMenu, overflowX, overflowY, overflowMenuWidth, overflowMenuHeight, /*baseline ignored*/0, HPos.CENTER, VPos.CENTER); }
*** 557,593 **** private void addNodesToToolBar() { final ToolBar toolbar = getSkinnable(); double length = 0; if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! length = snapSize(toolbar.getHeight()) - snappedTopInset() - snappedBottomInset() + getSpacing(); } else { ! length = snapSize(toolbar.getWidth()) - snappedLeftInset() - snappedRightInset() + getSpacing(); } // Is there overflow ? double x = 0; boolean hasOverflow = false; for (Node node : getSkinnable().getItems()) { if (!node.isManaged()) continue; if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! x += snapSize(node.prefHeight(-1)) + getSpacing(); } else { ! x += snapSize(node.prefWidth(-1)) + getSpacing(); } if (x > length) { hasOverflow = true; break; } } if (hasOverflow) { if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! length -= snapSize(overflowMenu.prefHeight(-1)); } else { ! length -= snapSize(overflowMenu.prefWidth(-1)); } length -= getSpacing(); } // Determine which node goes to the toolbar and which goes to the overflow. --- 565,601 ---- private void addNodesToToolBar() { final ToolBar toolbar = getSkinnable(); double length = 0; if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! length = snapSizeY(toolbar.getHeight()) - snappedTopInset() - snappedBottomInset() + getSpacing(); } else { ! length = snapSizeX(toolbar.getWidth()) - snappedLeftInset() - snappedRightInset() + getSpacing(); } // Is there overflow ? double x = 0; boolean hasOverflow = false; for (Node node : getSkinnable().getItems()) { if (!node.isManaged()) continue; if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! x += snapSizeY(node.prefHeight(-1)) + getSpacing(); } else { ! x += snapSizeX(node.prefWidth(-1)) + getSpacing(); } if (x > length) { hasOverflow = true; break; } } if (hasOverflow) { if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! length -= snapSizeY(overflowMenu.prefHeight(-1)); } else { ! length -= snapSizeX(overflowMenu.prefWidth(-1)); } length -= getSpacing(); } // Determine which node goes to the toolbar and which goes to the overflow.
*** 598,610 **** node.getStyleClass().remove("menu-item"); node.getStyleClass().remove("custom-menu-item"); if (node.isManaged()) { if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! x += snapSize(node.prefHeight(-1)) + getSpacing(); } else { ! x += snapSize(node.prefWidth(-1)) + getSpacing(); } } if (x <= length) { box.getChildren().add(node); --- 606,618 ---- node.getStyleClass().remove("menu-item"); node.getStyleClass().remove("custom-menu-item"); if (node.isManaged()) { if (getSkinnable().getOrientation() == Orientation.VERTICAL) { ! x += snapSizeY(node.prefHeight(-1)) + getSpacing(); } else { ! x += snapSizeX(node.prefWidth(-1)) + getSpacing(); } } if (x <= length) { box.getChildren().add(node);