modules/controls/src/main/java/com/sun/javafx/scene/control/ContextMenuContent.java
Print this page
*** 175,214 ****
double alt = -1;
Node n = menuItemContainer.left;
if (n != null) {
if (n.getContentBias() == Orientation.VERTICAL) { // width depends on height
! alt = snapSize(n.prefHeight(-1));
} else alt = -1;
! maxLeftWidth = Math.max(maxLeftWidth, snapSize(n.prefWidth(alt)));
maxRowHeight = Math.max(maxRowHeight, n.prefHeight(-1));
}
n = menuItemContainer.graphic;
if (n != null) {
if (n.getContentBias() == Orientation.VERTICAL) { // width depends on height
! alt = snapSize(n.prefHeight(-1));
} else alt = -1;
! maxGraphicWidth = Math.max(maxGraphicWidth, snapSize(n.prefWidth(alt)));
maxRowHeight = Math.max(maxRowHeight, n.prefHeight(-1));
}
n = menuItemContainer.label;
if (n != null) {
if (n.getContentBias() == Orientation.VERTICAL) {
! alt = snapSize(n.prefHeight(-1));
} else alt = -1;
! maxLabelWidth = Math.max(maxLabelWidth, snapSize(n.prefWidth(alt)));
maxRowHeight = Math.max(maxRowHeight, n.prefHeight(-1));
}
n = menuItemContainer.right;
if (n != null) {
if (n.getContentBias() == Orientation.VERTICAL) { // width depends on height
! alt = snapSize(n.prefHeight(-1));
} else alt = -1;
! maxRightWidth = Math.max(maxRightWidth, snapSize(n.prefWidth(alt)));
maxRowHeight = Math.max(maxRowHeight, n.prefHeight(-1));
}
}
}
--- 175,214 ----
double alt = -1;
Node n = menuItemContainer.left;
if (n != null) {
if (n.getContentBias() == Orientation.VERTICAL) { // width depends on height
! alt = snapSizeY(n.prefHeight(-1));
} else alt = -1;
! maxLeftWidth = Math.max(maxLeftWidth, snapSizeX(n.prefWidth(alt)));
maxRowHeight = Math.max(maxRowHeight, n.prefHeight(-1));
}
n = menuItemContainer.graphic;
if (n != null) {
if (n.getContentBias() == Orientation.VERTICAL) { // width depends on height
! alt = snapSizeY(n.prefHeight(-1));
} else alt = -1;
! maxGraphicWidth = Math.max(maxGraphicWidth, snapSizeX(n.prefWidth(alt)));
maxRowHeight = Math.max(maxRowHeight, n.prefHeight(-1));
}
n = menuItemContainer.label;
if (n != null) {
if (n.getContentBias() == Orientation.VERTICAL) {
! alt = snapSizeY(n.prefHeight(-1));
} else alt = -1;
! maxLabelWidth = Math.max(maxLabelWidth, snapSizeX(n.prefWidth(alt)));
maxRowHeight = Math.max(maxRowHeight, n.prefHeight(-1));
}
n = menuItemContainer.right;
if (n != null) {
if (n.getContentBias() == Orientation.VERTICAL) { // width depends on height
! alt = snapSizeY(n.prefHeight(-1));
} else alt = -1;
! maxRightWidth = Math.max(maxRightWidth, snapSizeX(n.prefWidth(alt)));
maxRowHeight = Math.max(maxRowHeight, n.prefHeight(-1));
}
}
}
*** 331,341 ****
if (itemsContainer.getChildren().size() == 0) return;
final double x = snappedLeftInset();
final double y = snappedTopInset();
final double w = getWidth() - x - snappedRightInset();
final double h = getHeight() - y - snappedBottomInset();
! final double contentHeight = snapSize(getContentHeight()); // itemsContainer.prefHeight(-1);
itemsContainer.resize(w,contentHeight);
itemsContainer.relocate(x, y);
if (isFirstShow && ty == 0) {
--- 331,341 ----
if (itemsContainer.getChildren().size() == 0) return;
final double x = snappedLeftInset();
final double y = snappedTopInset();
final double w = getWidth() - x - snappedRightInset();
final double h = getHeight() - y - snappedBottomInset();
! final double contentHeight = snapSizeY(getContentHeight()); // itemsContainer.prefHeight(-1);
itemsContainer.resize(w,contentHeight);
itemsContainer.relocate(x, y);
if (isFirstShow && ty == 0) {
*** 350,371 ****
clipRect.setY(0);
clipRect.setWidth(w);
clipRect.setHeight(h);
if (upArrow.isVisible()) {
! final double prefHeight = snapSize(upArrow.prefHeight(-1));
! clipRect.setHeight(snapSize(clipRect.getHeight() - prefHeight));
! clipRect.setY(snapSize(clipRect.getY()) + prefHeight);
! upArrow.resize(snapSize(upArrow.prefWidth(-1)), prefHeight);
positionInArea(upArrow, x, y, w, prefHeight, /*baseline ignored*/0,
HPos.CENTER, VPos.CENTER);
}
if (downArrow.isVisible()) {
! final double prefHeight = snapSize(downArrow.prefHeight(-1));
! clipRect.setHeight(snapSize(clipRect.getHeight()) - prefHeight);
! downArrow.resize(snapSize(downArrow.prefWidth(-1)), prefHeight);
positionInArea(downArrow, x, (y + h - prefHeight), w, prefHeight, /*baseline ignored*/0,
HPos.CENTER, VPos.CENTER);
}
}
--- 350,371 ----
clipRect.setY(0);
clipRect.setWidth(w);
clipRect.setHeight(h);
if (upArrow.isVisible()) {
! final double prefHeight = snapSizeY(upArrow.prefHeight(-1));
! clipRect.setHeight(snapSizeY(clipRect.getHeight() - prefHeight));
! clipRect.setY(snapSizeY(clipRect.getY()) + prefHeight);
! upArrow.resize(snapSizeX(upArrow.prefWidth(-1)), prefHeight);
positionInArea(upArrow, x, y, w, prefHeight, /*baseline ignored*/0,
HPos.CENTER, VPos.CENTER);
}
if (downArrow.isVisible()) {
! final double prefHeight = snapSizeY(downArrow.prefHeight(-1));
! clipRect.setHeight(snapSizeY(clipRect.getHeight()) - prefHeight);
! downArrow.resize(snapSizeX(downArrow.prefWidth(-1)), prefHeight);
positionInArea(downArrow, x, (y + h - prefHeight), w, prefHeight, /*baseline ignored*/0,
HPos.CENTER, VPos.CENTER);
}
}
*** 373,392 ****
computeVisualMetrics();
double prefWidth = 0;
if (itemsContainer.getChildren().size() == 0) return 0;
for (Node n : itemsContainer.getChildren()) {
if (! n.isVisible()) continue;
! prefWidth = Math.max(prefWidth, snapSize(n.prefWidth(-1)));
}
! return snappedLeftInset() + snapSize(prefWidth) + snappedRightInset();
}
@Override protected double computePrefHeight(double width) {
if (itemsContainer.getChildren().size() == 0) return 0;
final double screenHeight = getScreenHeight();
final double contentHeight = getContentHeight(); // itemsContainer.prefHeight(width);
! double totalHeight = snappedTopInset() + snapSize(contentHeight) + snappedBottomInset();
// the pref height of this menu is the smaller value of the
// actual pref height and the height of the screens _visual_ bounds.
double prefHeight = (screenHeight <= 0) ? (totalHeight) : (Math.min(totalHeight, screenHeight));
return prefHeight;
}
--- 373,392 ----
computeVisualMetrics();
double prefWidth = 0;
if (itemsContainer.getChildren().size() == 0) return 0;
for (Node n : itemsContainer.getChildren()) {
if (! n.isVisible()) continue;
! prefWidth = Math.max(prefWidth, snapSizeX(n.prefWidth(-1)));
}
! return snappedLeftInset() + snapSizeX(prefWidth) + snappedRightInset();
}
@Override protected double computePrefHeight(double width) {
if (itemsContainer.getChildren().size() == 0) return 0;
final double screenHeight = getScreenHeight();
final double contentHeight = getContentHeight(); // itemsContainer.prefHeight(width);
! double totalHeight = snappedTopInset() + snapSizeY(contentHeight) + snappedBottomInset();
// the pref height of this menu is the smaller value of the
// actual pref height and the height of the screens _visual_ bounds.
double prefHeight = (screenHeight <= 0) ? (totalHeight) : (Math.min(totalHeight, screenHeight));
return prefHeight;
}
*** 402,421 ****
private double getScreenHeight() {
if (contextMenu == null || contextMenu.getOwnerWindow() == null ||
contextMenu.getOwnerWindow().getScene() == null) {
return -1;
}
! return snapSize(com.sun.javafx.util.Utils.getScreen(
contextMenu.getOwnerWindow().getScene().getRoot()).getVisualBounds().getHeight());
}
private double getContentHeight() {
double h = 0.0d;
for (Node i : itemsContainer.getChildren()) {
if (i.isVisible()) {
! h += snapSize(i.prefHeight(-1));
}
}
return h;
}
--- 402,421 ----
private double getScreenHeight() {
if (contextMenu == null || contextMenu.getOwnerWindow() == null ||
contextMenu.getOwnerWindow().getScene() == null) {
return -1;
}
! return snapSizeY(com.sun.javafx.util.Utils.getScreen(
contextMenu.getOwnerWindow().getScene().getRoot()).getVisualBounds().getHeight());
}
private double getContentHeight() {
double h = 0.0d;
for (Node i : itemsContainer.getChildren()) {
if (i.isVisible()) {
! h += snapSizeY(i.prefHeight(-1));
}
}
return h;
}
*** 1004,1015 ****
@Override protected void layoutChildren() {
double yOffset = ty;
for (Node n : getChildren()) {
if (n.isVisible()) {
! final double prefHeight = snapSize(n.prefHeight(-1));
! n.resize(snapSize(getWidth()), prefHeight);
n.relocate(snappedLeftInset(), yOffset);
yOffset += prefHeight;
}
}
}
--- 1004,1015 ----
@Override protected void layoutChildren() {
double yOffset = ty;
for (Node n : getChildren()) {
if (n.isVisible()) {
! final double prefHeight = snapSizeY(n.prefHeight(-1));
! n.resize(snapSizeX(getWidth()), prefHeight);
n.relocate(snappedLeftInset(), yOffset);
yOffset += prefHeight;
}
}
}
*** 1067,1078 ****
@Override protected double computePrefHeight(double width) {
return snappedTopInset() + upDownArrow.prefHeight(-1) + snappedBottomInset();
}
@Override protected void layoutChildren() {
! double w = snapSize(upDownArrow.prefWidth(-1));
! double h = snapSize(upDownArrow.prefHeight(-1));
upDownArrow.resize(w, h);
positionInArea(upDownArrow, 0, 0, getWidth(), getHeight(),
/*baseline ignored*/0, HPos.CENTER, VPos.CENTER);
}
--- 1067,1078 ----
@Override protected double computePrefHeight(double width) {
return snappedTopInset() + upDownArrow.prefHeight(-1) + snappedBottomInset();
}
@Override protected void layoutChildren() {
! double w = snapSizeX(upDownArrow.prefWidth(-1));
! double h = snapSizeY(upDownArrow.prefHeight(-1));
upDownArrow.resize(w, h);
positionInArea(upDownArrow, 0, 0, getWidth(), getHeight(),
/*baseline ignored*/0, HPos.CENTER, VPos.CENTER);
}