6736649: test/closed/javax/swing/JMenuItem/6458123/ManualBug6458123.java fails on Linux
Now text bearings are taken into account when labelRect width is calculated Reviewed-by: alexp
This commit is contained in:
parent
189c383d48
commit
b6db0aad85
@ -136,7 +136,7 @@ class SynthMenuItemLayoutHelper extends MenuItemLayoutHelper {
|
|||||||
|
|
||||||
// accRect
|
// accRect
|
||||||
if (!getAccText().equals("")) {
|
if (!getAccText().equals("")) {
|
||||||
getAccSize().setWidth(accGu.computeStringWidth(getAccContext(),
|
getAccSize().setWidth(accGu.computeStringWidth(getAccContext(),
|
||||||
getAccFontMetrics().getFont(), getAccFontMetrics(),
|
getAccFontMetrics().getFont(), getAccFontMetrics(),
|
||||||
getAccText()));
|
getAccText()));
|
||||||
getAccSize().setHeight(getAccFontMetrics().getHeight());
|
getAccSize().setHeight(getAccFontMetrics().getHeight());
|
||||||
@ -195,6 +195,7 @@ class SynthMenuItemLayoutHelper extends MenuItemLayoutHelper {
|
|||||||
getHorizontalAlignment(), getVerticalAlignment(),
|
getHorizontalAlignment(), getVerticalAlignment(),
|
||||||
getHorizontalTextPosition(), getVerticalTextPosition(),
|
getHorizontalTextPosition(), getVerticalTextPosition(),
|
||||||
getViewRect(), iconRect, textRect, getGap());
|
getViewRect(), iconRect, textRect, getGap());
|
||||||
|
textRect.width += getLeftTextExtraWidth() + getRightTextExtraWidth();
|
||||||
Rectangle labelRect = iconRect.union(textRect);
|
Rectangle labelRect = iconRect.union(textRect);
|
||||||
getLabelSize().setHeight(labelRect.height);
|
getLabelSize().setHeight(labelRect.height);
|
||||||
getLabelSize().setWidth(labelRect.width);
|
getLabelSize().setWidth(labelRect.width);
|
||||||
|
@ -83,6 +83,9 @@ public class MenuItemLayoutHelper {
|
|||||||
private int afterCheckIconGap;
|
private int afterCheckIconGap;
|
||||||
private int minTextOffset;
|
private int minTextOffset;
|
||||||
|
|
||||||
|
private int leftTextExtraWidth;
|
||||||
|
private int rightTextExtraWidth;
|
||||||
|
|
||||||
private Rectangle viewRect;
|
private Rectangle viewRect;
|
||||||
|
|
||||||
private RectSize iconSize;
|
private RectSize iconSize;
|
||||||
@ -143,6 +146,7 @@ public class MenuItemLayoutHelper {
|
|||||||
this.checkSize = new RectSize();
|
this.checkSize = new RectSize();
|
||||||
this.arrowSize = new RectSize();
|
this.arrowSize = new RectSize();
|
||||||
this.labelSize = new RectSize();
|
this.labelSize = new RectSize();
|
||||||
|
calcExtraWidths();
|
||||||
calcWidthsAndHeights();
|
calcWidthsAndHeights();
|
||||||
setOriginalWidths();
|
setOriginalWidths();
|
||||||
calcMaxWidths();
|
calcMaxWidths();
|
||||||
@ -151,6 +155,29 @@ public class MenuItemLayoutHelper {
|
|||||||
calcMaxTextOffset(viewRect);
|
calcMaxTextOffset(viewRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void calcExtraWidths() {
|
||||||
|
leftTextExtraWidth = getLeftExtraWidth(text);
|
||||||
|
rightTextExtraWidth = getRightExtraWidth(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getLeftExtraWidth(String str) {
|
||||||
|
int lsb = SwingUtilities2.getLeftSideBearing(mi, fm, str);
|
||||||
|
if (lsb < 0) {
|
||||||
|
return -lsb;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getRightExtraWidth(String str) {
|
||||||
|
int rsb = SwingUtilities2.getRightSideBearing(mi, fm, str);
|
||||||
|
if (rsb > 0) {
|
||||||
|
return rsb;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void setOriginalWidths() {
|
private void setOriginalWidths() {
|
||||||
iconSize.origWidth = iconSize.width;
|
iconSize.origWidth = iconSize.width;
|
||||||
textSize.origWidth = textSize.width;
|
textSize.origWidth = textSize.width;
|
||||||
@ -286,6 +313,7 @@ public class MenuItemLayoutHelper {
|
|||||||
verticalAlignment, horizontalAlignment,
|
verticalAlignment, horizontalAlignment,
|
||||||
verticalTextPosition, horizontalTextPosition,
|
verticalTextPosition, horizontalTextPosition,
|
||||||
viewRect, iconRect, textRect, gap);
|
viewRect, iconRect, textRect, gap);
|
||||||
|
textRect.width += leftTextExtraWidth + rightTextExtraWidth;
|
||||||
Rectangle labelRect = iconRect.union(textRect);
|
Rectangle labelRect = iconRect.union(textRect);
|
||||||
labelSize.height = labelRect.height;
|
labelSize.height = labelRect.height;
|
||||||
labelSize.width = labelRect.width;
|
labelSize.width = labelRect.width;
|
||||||
@ -727,7 +755,7 @@ public class MenuItemLayoutHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets Y coordinates of text and icon
|
* Sets Y coordinates of text and icon
|
||||||
* taking into account the vertical alignment
|
* taking into account the vertical alignment
|
||||||
*/
|
*/
|
||||||
@ -1089,6 +1117,14 @@ public class MenuItemLayoutHelper {
|
|||||||
this.labelSize = labelSize;
|
this.labelSize = labelSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getLeftTextExtraWidth() {
|
||||||
|
return leftTextExtraWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getRightTextExtraWidth() {
|
||||||
|
return rightTextExtraWidth;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns false if the component is a JMenu and it is a top
|
* Returns false if the component is a JMenu and it is a top
|
||||||
* level menu (on the menubar).
|
* level menu (on the menubar).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user