Skip to content

Commit 985854a

Browse files
hansonrhansonr
authored andcommitted
fix for simple buttons? and labels jumping
1 parent 478e0a5 commit 985854a

File tree

2 files changed

+43
-41
lines changed

2 files changed

+43
-41
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public DOMNode updateDOMNode() {
9292
if (domNode == null) {
9393
setDoPropagate();
9494
domNode = enableNode = buttonNode = newDOMObject("button", id + "_dom", "type", "button");
95+
//DOMNode.setStyles(domNode,"transform","translateY(0.5px)translateX(0.5px)");
9596
isFocusable();
9697
setDataFocusComponent(focusNode);
9798
DOMNode.setPositionAbsolute(domNode);

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

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ protected void setMnemonic(int newValue) {
13111311
*
13121312
*/
13131313
@SuppressWarnings("unused")
1314-
private boolean layingOut;
1314+
protected boolean layingOut;
13151315

13161316
/**
13171317
* has been disposed; will need to reattach it if it ever becomes visible again.
@@ -1456,12 +1456,12 @@ protected void debugDump(DOMNode d) {
14561456
System.out.println(DOMNode.getAttr(d, "outerHTML"));
14571457
}
14581458

1459-
protected static void vCenter(DOMNode obj, int offset, float scale) {
1460-
DOMNode.setStyles(obj, "top", "50%", "transform",
1461-
(scale > 0 ? "scale(" + scale + "," + scale + ")" : "")
1462-
+"translateY(" + offset + "%)");
1463-
}
1464-
1459+
// protected static void vCenter(DOMNode obj, int offset, float scale) {
1460+
// DOMNode.setStyles(obj, "top", "50%", "transform",
1461+
// (scale > 0 ? "scale(" + scale + "," + scale + ")" : "")
1462+
// +"translateY(" + offset + "%)");
1463+
// }
1464+
//
14651465
/**
14661466
* overloaded to allow panel and radiobutton to handle slightly differently
14671467
*
@@ -1724,24 +1724,6 @@ protected boolean isFrameIndependent() {
17241724
return true;
17251725
}
17261726

1727-
private void setOuterLocationFromComponent() {
1728-
// In SwingJS we just use the "local" lightweight location
1729-
// for all components, not the native adjusted one, because
1730-
// we maintain the hierarchy of the divs. I think this is
1731-
// saying that everything is basically heavyweight. It
1732-
// "paints" itself.
1733-
1734-
if (outerNode != null && !isMenuItem) {
1735-
// Considering the possibility of the parent being created
1736-
// before children are formed. So here we can add them later.
1737-
if (parent == null && jc.getParent() != null && (parent = (JSComponentUI) jc.getParent().getUI()) != null
1738-
&& parent.outerNode != null)
1739-
DOMNode.appendChildSafely(parent.outerNode, outerNode);
1740-
DOMNode.setPositionAbsolute(outerNode);
1741-
DOMNode.setStyles(outerNode, "left", (x = c.getX()) + "px", "top", (y = c.getY()) + "px");
1742-
}
1743-
}
1744-
17451727
protected Component[] getChildren() {
17461728
// but see JSMenuUI and JTableUI
17471729
return JSComponent.秘getChildArray(jc);
@@ -1804,7 +1786,8 @@ public void update(Graphics g, JComponent c) {
18041786
* @return
18051787
*/
18061788
public boolean doPaintBackground() {
1807-
return !backgroundPainted && c.isOpaque() && allowPaintedBackground;
1789+
return( //NO! 6/10/2019 !backgroundPainted &&
1790+
c.isOpaque() && allowPaintedBackground);
18081791
}
18091792

18101793
/**
@@ -2154,16 +2137,31 @@ public void setBounds(int x, int y, int width, int height, int op) {
21542137
}
21552138
}
21562139

2140+
private void setOuterLocationFromComponent() {
2141+
// In SwingJS we just use the "local" lightweight location
2142+
// for all components, not the native adjusted one, because
2143+
// we maintain the hierarchy of the divs. I think this is
2144+
// saying that everything is basically heavyweight. It
2145+
// "paints" itself.
2146+
2147+
if (outerNode != null && !isMenuItem) {
2148+
// Considering the possibility of the parent being created
2149+
// before children are formed. So here we can add them later.
2150+
if (parent == null && jc.getParent() != null && (parent = (JSComponentUI) jc.getParent().getUI()) != null
2151+
&& parent.outerNode != null)
2152+
DOMNode.appendChildSafely(parent.outerNode, outerNode);
2153+
DOMNode.setPositionAbsolute(outerNode);
2154+
DOMNode.setStyles(outerNode, "left", (x = c.getX()) + "px", "top", (y = c.getY()) + "px");
2155+
}
2156+
}
2157+
21572158
private void setSizeFromComponent(int width, int height, int op) {
21582159
// allow for special adjustments
21592160
// currently MenuItem, TextField, and TextArea
21602161
Dimension size = getCSSAdjustment(true);
21612162
// if (this.width != width || this.height != height) {
21622163
this.width = width;
21632164
this.height = height;
2164-
if (debugging)
2165-
System.out.println(id + " setBounds " + x + " " + y + " " + this.width + " " + this.height + " op=" + op
2166-
+ " createDOM?" + (domNode == null));
21672165
if (domNode == null)
21682166
updateDOMNode();
21692167
setJSDimensions(width + size.width, height + size.height);
@@ -2172,16 +2170,13 @@ private void setSizeFromComponent(int width, int height, int op) {
21722170

21732171
protected void setJSDimensions(int width, int height) {
21742172
if (jsActualWidth > 0)
2175-
width = jsActualWidth;
2173+
width = jsActualWidth; // list only
21762174
if (jsActualHeight > 0)
2177-
height = jsActualHeight;
2175+
height = jsActualHeight; // list only
21782176
DOMNode.setSize(domNode, width, height);
21792177
if (outerNode != null) {
21802178
DOMNode.setSize(outerNode, width, height);
21812179
}
2182-
// if (menuAnchorNode != null) {
2183-
// DOMNode.setSize(menuAnchorNode, width, height);
2184-
// }
21852180
}
21862181

21872182
protected void setInnerComponentBounds(int width, int height) {
@@ -2514,12 +2509,9 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
25142509

25152510
// simple totally centered label or button
25162511
// can't have width or height here --- let the browser figure that out
2517-
DOMNode.setStyles(centeringNode, "width", null, "top", "50%", "left", "50%", "transform",
2518-
"translateX(-50%)translateY(-50%)", "position", "absolute");
2519-
DOMNode.setStyles(iconNode, "top", "50%", "left", "50%", "transform", "translateX(-50%)translateY(-50%)",
2520-
"position", "absolute");
2521-
DOMNode.setStyles(textNode, "top", "50%", "left", "50%", "transform", "translateX(-50%)translateY(-50%)",
2522-
"position", "absolute");
2512+
fullyCenter(centeringNode, true);
2513+
fullyCenter(iconNode, false);
2514+
fullyCenter(textNode, false);
25232515
} else {
25242516

25252517
DOMNode.setStyles(iconNode, "position", "absolute", "top", null, "left", null, "transform", null);
@@ -2641,6 +2633,15 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
26412633
updateCellNode();
26422634
}
26432635

2636+
protected void fullyCenter(DOMNode node, boolean isCtr) {
2637+
if (isLabel)
2638+
DOMNode.setStyles(node, "width", null, "top", "50%", "left", "50%", "transform",
2639+
"translateX(-50%)translateY(-50%)translateY(0.5px)translateX(0.5px)", "position", "absolute");
2640+
else
2641+
DOMNode.setStyles(node, "width", null, "top", null, "left", null, "transform", null, "position", null, "height", null);
2642+
}
2643+
2644+
26442645
private void updateCellNode() {
26452646
// could be editor or cell
26462647
if (cellWidth == 0 || cellHeight == 0) {
@@ -2821,7 +2822,7 @@ public void setBackground(Color c) {
28212822
setBackgroundFor(domNode, c);
28222823
}
28232824

2824-
private void setForegroundFor(DOMNode node, Color color) {
2825+
protected void setForegroundFor(DOMNode node, Color color) {
28252826
if (node != null)
28262827
DOMNode.setStyles(node, "color",
28272828
(color == null ? "rgba(0,0,0,0)" : JSToolkit.getCSSColor(color == null ? Color.black : color)));

0 commit comments

Comments
 (0)