Skip to content

Commit 4788cc7

Browse files
hansonrhansonr
authored andcommitted
AWT Button/Label fixes
1 parent 2c7c4af commit 4788cc7

File tree

8 files changed

+27
-12
lines changed

8 files changed

+27
-12
lines changed
219 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190205030857
1+
20190205134840
219 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190205030857
1+
20190205134840
219 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/swingjs/a2s/Button.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public Button(String text) {
1515
super(text);
1616
}
1717

18-
private static Insets awtInsets = new Insets(0, 6, 0, 6);
18+
private static Insets awtInsets = new Insets(3, 6, 3, 6);
1919
// awt.Button has an unadjustable horizontal inset of what appears to be about 6 pixels
2020
@Override
2121
public Insets getMargin() {

sources/net.sf.j2s.java.core/src/swingjs/a2s/Label.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package swingjs.a2s;
22

33
import java.awt.Color;
4+
import java.awt.Dimension;
5+
import java.awt.Insets;
46

57
import javax.swing.JLabel;
68
import javax.swing.SwingConstants;
@@ -39,6 +41,22 @@ public void setBackground(Color c) {
3941
setOpaque(c != null);
4042
}
4143

44+
private static Insets awtInsets = new Insets(3, 6, 2, 6);
45+
// awt.Label has an unadjustable horizontal inset of what appears to be about 6 pixels
46+
@Override
47+
public Insets getInsets() {
48+
return awtInsets;
49+
}
50+
51+
@Override
52+
public Insets getInsets(Insets s) {
53+
s.top = awtInsets.top;
54+
s.left = awtInsets.left;
55+
s.bottom = awtInsets.bottom;
56+
s.right = awtInsets.right;
57+
return s;
58+
}
59+
4260
public void setAlignment(int alignment) {
4361
float xAlignment = 0f;
4462
float yAlignment = 0.5f;

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,6 @@ protected void ignoreAllMouseEvents(DOMNode node) {
747747

748748
@SuppressWarnings("unused")
749749
protected static void hideAllMenus() {
750-
//System.out.println("JSCUI hideAllMenus" + JSUtil.getStackTrace(-3));
751750
JSUtil.jQuery.$(".ui-j2smenu").hide();
752751
if (/** @j2sNative javax.swing.ToolTipManager ||*/false)
753752
ToolTipManager.j2sHideToolTip();
@@ -1542,8 +1541,6 @@ protected Dimension setHTMLSize1(DOMNode node, boolean addCSS, boolean usePrefer
15421541
$(body).after(div);
15431542
Rectangle r = div.getBoundingClientRect();
15441543

1545-
//System.out.println("JSCUI " + (int) (r.width + 0.) + " " + (/** @j2sNative div.innerHTML ||*/""));
1546-
15471544
// From the DOM; Will be Rectangle2D.double, actually.
15481545
// This is preferable to $(text).width() because that is rounded
15491546
// DOWN.
@@ -1556,9 +1553,6 @@ protected Dimension setHTMLSize1(DOMNode node, boolean addCSS, boolean usePrefer
15561553
actualWidth = w;
15571554
actualHeight = h;
15581555
}
1559-
// h = preferredHeight;// (iconHeight > 0 ? iconHeight :
1560-
// centerHeight);
1561-
// TODO what if centerHeight is > prefHeight?
15621556
$(div).detach();
15631557
}
15641558
// allow a UI to slightly adjust its dimension
@@ -2307,7 +2301,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
23072301
int gap = (wText == 0 || wIcon == 0 ? 0 : b.getIconTextGap());
23082302
int w = cellComponent != null ? cellWidth : $(domNode).width();
23092303
boolean alignVCenter = (vAlign == SwingConstants.CENTER);
2310-
Insets margins = (isLabel ? insets : b.getMargin());
2304+
Insets margins = (isAWT ? b.getInsets() : isLabel ? insets : b.getMargin());
23112305
if (margins == null)
23122306
margins = zeroInsets;
23132307
int h = (dimText == null ? 0 : dimText.height);
@@ -2416,7 +2410,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
24162410
}
24172411
preferredDim = null;
24182412
// fix for button vertical alignment -- should offset just by the ascent
2419-
String yoff = (wIcon == 0 ? "-" + (jc.getFont().getFontMetrics().getAscent()>>1) + "px" : "-50%");
2413+
String yoff = "-50%";
24202414
DOMNode.setStyles(centeringNode, "position", "absolute", "top", null, "left", null, "transform", null);
24212415
if (alignHCenter && alignVCenter && wIcon == 0
24222416
|| wText == 0 && margins.left == margins.right && margins.top == margins.bottom) {
@@ -2514,6 +2508,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
25142508
switch (vTextPos) {
25152509
case SwingConstants.TOP:
25162510
top = itop = 0;
2511+
yoff = null;
25172512
break;
25182513
default:
25192514
case SwingConstants.CENTER:
@@ -2522,12 +2517,14 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
25222517
itop = 70;
25232518
iscale = "scale(0.6,0.6)";
25242519
}
2520+
yoff = (wIcon == 0 ? "-" + ((jc.getFont().getFontMetrics().getAscent()>>1)+1) + "px" : "-50%");
25252521
break;
25262522
case SwingConstants.BOTTOM:
25272523
top = itop = 100;
2524+
yoff = null;
25282525
break;
25292526
}
2530-
DOMNode.setStyles(textNode, "top", top + "%", "transform", "translateY(-" + top + "%)");
2527+
DOMNode.setStyles(textNode, "top", top + "%", "transform", "translateY(" + (yoff == null ? "-" + top + "%" : yoff + ")"));
25312528
DOMNode.setStyles(iconNode, "top", top + "%", "transform",
25322529
"translateY(-" + itop + "%)" + (iscale == null ? "" : iscale));
25332530
} else {

0 commit comments

Comments
 (0)