Skip to content

Commit d247028

Browse files
hansonrhansonr
authored andcommitted
fix for Button borders lost
1 parent 4f5a9bd commit d247028

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
import javax.swing.UIManager;
4141
import javax.swing.border.AbstractBorder;
4242
import javax.swing.border.Border;
43+
import javax.swing.plaf.BorderUIResource;
4344
import javax.swing.plaf.ComponentUI;
4445
import javax.swing.plaf.FontUIResource;
4546
import javax.swing.plaf.UIResource;
@@ -598,7 +599,7 @@ public void removeKeyListener(KeyListener l) {
598599
|| JSUtil.isOverridden(this, "paintComponent$java_awt_Graphics", JComponent.class)
599600
|| JSUtil.isOverridden(this, "paintContainer$java_awt_Graphics", Container.class)
600601
|| JSUtil.isOverridden(this, "update$java_awt_Graphics", JComponent.class)
601-
|| JSUtil.isOverridden(秘border, "paintBorder$java_awt_Component$java_awt_Graphics$I$I$I$I",
602+
|| 秘paintsBorder() && JSUtil.isOverridden(秘border, "paintBorder$java_awt_Component$java_awt_Graphics$I$I$I$I",
602603
AbstractBorder.class)
603604
? PAINTS_SELF_YES : PAINTS_SELF_NO);
604605
}
@@ -608,6 +609,12 @@ public void removeKeyListener(KeyListener l) {
608609
return (秘iPaintMyself != PAINTS_SELF_NO);
609610
}
610611

612+
protected boolean 秘paintsBorder() {
613+
// default ButtonBorders are not painted by default; this happens to also include internal frames
614+
return (秘border != null
615+
&& !(秘border instanceof BorderUIResource.CompoundBorderUIResource));
616+
}
617+
611618
/**
612619
* JScrollBar needs to know if we need to paint this component when it is scrolled
613620
*

sources/net.sf.j2s.java.core/src/javax/swing/AbstractButton.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,7 @@ protected void actionPropertyChanged(AbstractButton button,
13801380
* @see #setBorderPainted
13811381
*/
13821382
public boolean isBorderPainted() {
1383-
return paintBorder;
1383+
return paintBorder && 秘paintsBorder();
13841384
}
13851385

13861386
/**

sources/net.sf.j2s.java.core/src/javax/swing/plaf/basic/BasicBorders.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ public static class ButtonBorder extends EmptyBorder implements UIResource {
249249
protected Color darkShadow;
250250
protected Color highlight;
251251
protected Color lightHighlight;
252+
protected void noPaint(){};
252253

253254
public ButtonBorder(Color shadow, Color darkShadow,
254255
Color highlight, Color lightHighlight) {

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

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,11 @@ protected int getDefaultIconTextGap() {
22902290

22912291
protected Dimension preferredDim;
22922292

2293+
/**
2294+
* particularly for buttons
2295+
*/
2296+
private boolean isFullyCentered;
2297+
22932298
protected static Insets zeroInsets = new Insets(0, 0, 0, 0);
22942299

22952300
protected void getJSInsets() {
@@ -2358,19 +2363,18 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
23582363
int wText = (dimText == null ? 0 : dimText.width);
23592364
int gap = (wText == 0 || wIcon == 0 ? 0 : b.getIconTextGap());
23602365
int w0 = cellComponent != null ? cellWidth : $(domNode).width();
2361-
int w = w0;
2362-
if (w < wIcon + wText) {
2363-
// jQuery method can fail that may not have worked.
2364-
w = wIcon + wText;
2366+
int w = w0;
2367+
if (w < wIcon + wText) {
2368+
// jQuery method can fail that may not have worked.
2369+
w = wIcon + wText;
23652370
}
23662371
boolean alignVCenter = (vAlign == SwingConstants.CENTER);
2367-
Insets margins = (isLabel ? (isAWT ? b.getInsets() : insets) :
2368-
getButtonMargins(b, justGetPreferred));
2372+
Insets margins = (isLabel ? (isAWT ? b.getInsets() : insets) : getButtonMargins(b, justGetPreferred));
23692373
if (margins == null)
23702374
margins = zeroInsets;
2371-
Insets insets = (isLabel || !isSimpleButton || justGetPreferred ? zeroInsets :
2372-
getButtonOuterInsets(b));
2373-
//System.out.println("JSCUI margins " + justGetPreferred + " " + b.getText() + " " + margins + " " + insets);
2375+
Insets insets = (isLabel || !isSimpleButton || justGetPreferred ? zeroInsets : getButtonOuterInsets(b));
2376+
// System.out.println("JSCUI margins " + justGetPreferred + " " + b.getText() +
2377+
// " " + margins + " " + insets);
23742378
int h = (dimText == null ? 0 : dimText.height);
23752379
int ih = (dimIcon == null ? 0 : dimIcon.height);
23762380
int hCtr = Math.max(h, ih);
@@ -2469,7 +2473,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
24692473
w = w0;
24702474
break;
24712475
}
2472-
}
2476+
}
24732477
if (justGetPreferred) {
24742478
if (preferredDim == null)
24752479
preferredDim = new Dimension();
@@ -2481,17 +2485,19 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
24812485
DOMNode.setStyles(centeringNode, "position", "absolute", "top", null, "left", null, "transform", null);
24822486
DOMNode.setStyles(centeringNode, "width", wCtr + "px", "height", hCtr + "px");
24832487

2484-
if (alignHCenter && alignVCenter && wIcon == 0
2485-
|| wText == 0 && margins.left == margins.right && margins.top == margins.bottom
2486-
&& insets.left == insets.right && insets.top == insets.bottom) {
2488+
if (alignHCenter && alignVCenter && wIcon == 0 || wText == 0 && margins.left == margins.right
2489+
&& margins.top == margins.bottom && insets.left == insets.right && insets.top == insets.bottom) {
24872490

2488-
// simple totally centered label or button
2489-
// can't have width or height here --- let the browser figure that out
2490-
fullyCenter(centeringNode, true);
2491-
fullyCenter(iconNode, false);
2492-
fullyCenter(textNode, false);
2491+
isFullyCentered = !isLabel;
2492+
if (isFullyCentered) {
2493+
// simple totally centered label or button
2494+
// can't have width or height here --- let the browser figure that out
2495+
fullyCenter(centeringNode, true);
2496+
fullyCenter(iconNode, false);
2497+
fullyCenter(textNode, false);
2498+
}
24932499
} else {
2494-
2500+
isFullyCentered = false;
24952501
DOMNode.setStyles(iconNode, "position", "absolute", "top", null, "left", null, "transform", null);
24962502
DOMNode.setStyles(textNode, "position", "absolute", "top", null, "left", null, "transform", null);
24972503

@@ -2595,7 +2601,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
25952601
yoff = "-50%";
25962602
break;
25972603
}
2598-
DOMNode.setStyles(centeringNode, "overflow","none");
2604+
DOMNode.setStyles(centeringNode, "overflow", "none");
25992605
DOMNode.setStyles(textNode, "top", top + "%", "transform",
26002606
"translateY(" + (yoff == null ? "-" + top + "%" : yoff + ")"));
26012607
DOMNode.setStyles(iconNode, "top", top + "%", "transform",

0 commit comments

Comments
 (0)