Skip to content

Commit d20fa9d

Browse files
hansonrhansonr
authored andcommitted
adds (singular style) DOMNode.setStyle
1 parent cf2f895 commit d20fa9d

16 files changed

+141
-112
lines changed

sources/net.sf.j2s.java.core/src/swingjs/api/js/DOMNode.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public static DOMNode lastChild(DOMNode node) {
8585
}
8686

8787
public static DOMNode setZ(DOMNode node, int z) {
88-
return setStyles(node, "z-index", "" + z);
88+
return setStyle(node, "z-index", "" + z);
8989
}
9090

9191
public static Object getAttr(Object node, String attr) {
@@ -161,12 +161,22 @@ public static DOMNode setAttrs(DOMNode node, Object... attr) {
161161
return node;
162162
}
163163

164-
public static DOMNode setStyles(DOMNode node, String... attr) {
164+
public static DOMNode setStyle(DOMNode node, String attr, String val) {
165165
/**
166166
* @j2sNative
167167
*
168-
* if (node) for (var i = 0; i < attr.length;) {
169-
* node.style[attr[i++]] = attr[i++];
168+
* node && (node.style[attr] = val);
169+
*
170+
*/
171+
return node;
172+
}
173+
174+
public static DOMNode setStyles(DOMNode node, String... av) {
175+
/**
176+
* @j2sNative
177+
*
178+
* if (node) for (var i = 0; i < av.length;) {
179+
* node.style[av[i++]] = av[i++];
170180
* }
171181
*
172182
*/
@@ -178,17 +188,15 @@ public static DOMNode setSize(DOMNode node, int width, int height) {
178188
}
179189

180190
public static DOMNode setPositionAbsolute(DOMNode node) {
181-
return DOMNode.setStyles(node, "position", "absolute");
191+
return DOMNode.setStyle(node, "position", "absolute");
182192
}
183193

184194
public static void setVisible(DOMNode node, boolean visible) {
185-
setStyles(node, "display", visible ? "block" : "none");
195+
setStyle(node, "display", visible ? "block" : "none");
186196
}
187197

188198
public static DOMNode setTopLeftAbsolute(DOMNode node, int top, int left) {
189-
DOMNode.setStyles(node, "top", top + "px");
190-
DOMNode.setStyles(node, "left", left + "px");
191-
return DOMNode.setStyles(node, "position", "absolute");
199+
return DOMNode.setStyles(node, "top", top + "px", "left", left + "px", "position", "absolute");
192200
}
193201

194202
public static void addHorizontalGap(DOMNode domNode, int gap) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ protected DOMNode createItem(String type, DOMNode buttonNode) {
149149
itemNode = newDOMObject("li", id);
150150
if (text == null && icon == null)
151151
return itemNode;
152-
DOMNode.setStyles(itemNode, "outline", "none");
152+
DOMNode.setStyle(itemNode, "outline", "none");
153153
menuAnchorNode = newDOMObject("div", id + "_a");// this needed? , "tabindex", "8");
154154
if (type != "_bar") {
155155
addClass(menuAnchorNode, "a");
@@ -201,9 +201,9 @@ protected void setupButton() {
201201
setIconAndText("button", (ImageIcon) button.getIcon(), button.getIconTextGap(), button.getText());
202202
// "emptyBorder" is not really empty.
203203
if (button.getBorder() == null || button.getBorder() == BorderFactory.emptyBorder)
204-
DOMNode.setStyles(buttonNode, "border", "none");
204+
DOMNode.setStyle(buttonNode, "border", "none");
205205
else if (button.getBorder() == BorderFactory.html5Border)
206-
DOMNode.setStyles(buttonNode, "border", null);
206+
DOMNode.setStyle(buttonNode, "border", null);
207207
//
208208
// System.out.println(button.getText() + " " + button.getBorder());
209209
if (!isMenuSep) {
@@ -784,7 +784,7 @@ protected void setInnerComponentBounds(int width, int height) {
784784
if (!(button.getBorder() instanceof UIResource)) {
785785
DOMNode.setTopLeftAbsolute(domNode, i.left, i.top);
786786
DOMNode.setSize(domNode, width-i.left - i.right, height-i.top - i.bottom);
787-
DOMNode.setStyles(domNode, "border",
787+
DOMNode.setStyle(domNode, "border",
788788
i.left + i.right + i.top + i.bottom > 0 ? "none" : null);
789789
}
790790
}
@@ -800,7 +800,7 @@ protected Dimension getHTMLSizePreferred(DOMNode obj, boolean addCSS) {
800800
@Override
801801
public void paint(Graphics g, JComponent c) {
802802
if (jc.秘paintsSelfEntirely())
803-
DOMNode.setStyles(centeringNode, "visibility", "visible");
803+
DOMNode.setStyle(centeringNode, "visibility", "visible");
804804
super.paint(g, c);
805805
}
806806

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

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1624,8 +1624,8 @@ public void updateCursorImmediately() {
16241624
protected void setCursor() {
16251625
myCursor = getCursor();
16261626
String curs = JSToolkit.getCursorName(myCursor);
1627-
DOMNode.setStyles(outerNode, "cursor", curs);
1628-
DOMNode.setStyles(domNode, "cursor", curs);
1627+
DOMNode.setStyle(outerNode, "cursor", curs);
1628+
DOMNode.setStyle(domNode, "cursor", curs);
16291629
setWaitImage(curs == "wait");
16301630
}
16311631

@@ -1714,7 +1714,7 @@ private Dimension getIconSize(AbstractButton b) {
17141714
private Dimension getTextSize(AbstractButton b) {
17151715
if (textNode == null)
17161716
return null;
1717-
DOMNode.setStyles(textNode, "padding", "0");
1717+
DOMNode.setStyle(textNode, "padding", "0");
17181718
String t = b.getText();
17191719
if (isAWT && t == "")
17201720
t = "\u00A0"; // AWT labels do not hide if ""
@@ -1796,9 +1796,9 @@ protected Dimension setHTMLSize1(DOMNode node, boolean addCSS, boolean usePrefer
17961796
if (!isHTML) {
17971797

17981798
// can't have these for getBoundingClientRect to work
1799-
DOMNode.setStyles(node, "position", null);
1800-
DOMNode.setStyles(textNode, "position", null);
1801-
DOMNode.setStyles(iconNode, "position", null);
1799+
DOMNode.setStyle(node, "position", null);
1800+
DOMNode.setStyle(textNode, "position", null);
1801+
DOMNode.setStyle(iconNode, "position", null);
18021802
}
18031803
}
18041804

@@ -1823,13 +1823,13 @@ protected Dimension setHTMLSize1(DOMNode node, boolean addCSS, boolean usePrefer
18231823
Dimension dim = getCSSAdjustment(addCSS, true);
18241824
dim.width += w;
18251825
dim.height += h;
1826-
DOMNode.setStyles(node, "position", null);
1826+
DOMNode.setStyle(node, "position", null);
18271827
if (w0 != null) {
18281828
DOMNode.setStyles(node, "width",
18291829
(isHTML && isLabel ? "inherit" : w0), "height", h0);
18301830
}
18311831
if (position != null) {
1832-
DOMNode.setStyles(node, "position", position);
1832+
DOMNode.setStyle(node, "position", position);
18331833
}
18341834
if (w0i != null) {
18351835
DOMNode.setStyles(domNode, "width", w0i, "height", h0i);
@@ -1847,7 +1847,7 @@ protected Dimension setHTMLSize1(DOMNode node, boolean addCSS, boolean usePrefer
18471847
protected Rectangle getBoundingRect(DOMNode node) {
18481848
if (tempDiv == null) {
18491849
tempDiv = DOMNode.createElement("div", "_temp");
1850-
DOMNode.setStyles(tempDiv, "display", "inline-block");
1850+
DOMNode.setStyle(tempDiv, "display", "inline-block");
18511851
DOMNode.setTopLeftAbsolute(tempDiv, 0, -100000);
18521852
$(body).after(tempDiv);
18531853
}
@@ -1935,7 +1935,7 @@ else if (domNode != outerNode && DOMNode.getParent(domNode) != outerNode)
19351935
DOMNode.setSize(outerNode, w, h);
19361936

19371937
if (isPanel || isContentPane || isRootPane) {
1938-
DOMNode.setStyles(outerNode, "overflow",
1938+
DOMNode.setStyle(outerNode, "overflow",
19391939
allowDivOverflow ? "visible" : "hidden");
19401940
if (isRootPane) {
19411941
if (jc.getFrameViewer().isApplet) {
@@ -1956,10 +1956,10 @@ && isFrameIndependent() && !isSticky) {
19561956
// that is where it is set. (All independent JInternalFrames are sticky when they are independent,
19571957
// because in that case, their parent JDesktopPane is hidden.)
19581958
DOMNode.transferTo(outerNode, body);
1959-
DOMNode.setStyles(outerNode, "position", "absolute");
1959+
DOMNode.setStyle(outerNode, "position", "absolute");
19601960
}
19611961
} else {
1962-
DOMNode.setStyles(outerNode, "overflow", "hidden");
1962+
DOMNode.setStyle(outerNode, "overflow", "hidden");
19631963
}
19641964
isTainted = false;
19651965

@@ -2071,14 +2071,14 @@ public void paint(Graphics g, JComponent c) {
20712071
setOverflow();
20722072
if (imageNode != null && !imagePersists) {
20732073
// the icon must paint itself; imageNode is just a placeholder
2074-
DOMNode.setStyles(imageNode, "visibility", "hidden");
2074+
DOMNode.setStyle(imageNode, "visibility", "hidden");
20752075
}
20762076

20772077
}
20782078

20792079
protected void setOverflow() {
20802080
if (textNode != null)
2081-
DOMNode.setStyles(textNode, "overflow", "hidden");
2081+
DOMNode.setStyle(textNode, "overflow", "hidden");
20822082
}
20832083

20842084
@Override
@@ -2520,7 +2520,7 @@ protected void setIconAndText(String prop, Icon icon, int gap, String text) {
25202520
h = icon.getIconHeight();
25212521
DOMNode.setStyles(iconNode, "height", h + "px", "width", w + "px");
25222522
if (!imagePersists)
2523-
DOMNode.setStyles(imageNode, "visibility", "hidden");
2523+
DOMNode.setStyle(imageNode, "visibility", "hidden");
25242524
}
25252525
}
25262526
}
@@ -2535,7 +2535,7 @@ protected void setIconAndText(String prop, Icon icon, int gap, String text) {
25352535
isPaintedOnly = true; // this cannot be undone
25362536
}
25372537
if (!isHTML || !isLabel)
2538-
DOMNode.setStyles(textNode, "white-space", "nowrap");
2538+
DOMNode.setStyle(textNode, "white-space", "nowrap");
25392539
if (icon == null) {
25402540
// tool tip does not allow text alignment
25412541
if (iconNode != null && allowTextAlignment && isMenuItem && actionNode == null && text != null) {
@@ -2660,9 +2660,9 @@ protected void addCentering(DOMNode node) {
26602660
protected void updateCenteringNode() {
26612661
if (jc.秘paintsSelfEntirely()) {
26622662
// component will be responsible for border, background, and text
2663-
DOMNode.setStyles(centeringNode, "visibility", "hidden");
2664-
DOMNode.setStyles(domNode, "border", "none");
2665-
DOMNode.setStyles(domNode, "background", "none");
2663+
DOMNode.setStyle(centeringNode, "visibility", "hidden");
2664+
DOMNode.setStyle(domNode, "border", "none");
2665+
DOMNode.setStyle(domNode, "background", "none");
26662666
}
26672667

26682668
}
@@ -2763,20 +2763,20 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
27632763
menuAnchorNode.appendChild(accelNode = DOMNode.createElement("span", id + "_acc"));
27642764
addClass(accelNode, "ui-j2smenu-accel");
27652765
DOMNode.setAttr(accelNode, "role", "menuitem");
2766-
DOMNode.setStyles(accelNode, "font-size", "0.8em");
2766+
DOMNode.setStyle(accelNode, "font-size", "0.8em");
27672767
setMenuItem(accelNode);
27682768
}
27692769
}
27702770
if (accel != null) {
2771-
DOMNode.setStyles(accelNode, "float", null);
2771+
DOMNode.setStyle(accelNode, "float", null);
27722772
DOMNode.setAttr(accelNode, "innerHTML", accel);// = accel + "\u00A0\u00A0");
27732773
wAccel = getHTMLSize(accelNode).width;
27742774
DOMNode.setStyles(accelNode, "float", ltr ? "right" : "left", "text-align", ltr ? "right" : "left",
27752775
"margin", "0px 5px", "transform", "translateY(15%)");
27762776
}
27772777
}
27782778
if (!isMenu || isMenuItem)
2779-
DOMNode.setStyles(menuAnchorNode, //"width", "90%",
2779+
DOMNode.setStyle(menuAnchorNode, //"width", "90%",
27802780
"min-width",
27812781
Math.max(75, (23 + 15 + wCtr + wAccel + margins.left + margins.right)) + "px"); // was 95%, but then the blue background extends past right end of menu item
27822782
}
@@ -2870,12 +2870,12 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
28702870
addJSKeyVal(cssCtr, "left", left + "px");
28712871
} else {
28722872
if (alignRight) {
2873-
DOMNode.setStyles(itemNode, "text-align", "right");
2873+
DOMNode.setStyle(itemNode, "text-align", "right");
28742874
addJSKeyVal(cssCtr, "right", "0px");
28752875
addJSKeyVal(cssTxt, "right", "23px");
28762876
addJSKeyVal(cssIcon, "right", "0px"); // was 3
28772877
} else {
2878-
DOMNode.setStyles(itemNode, "text-align", "left");
2878+
DOMNode.setStyle(itemNode, "text-align", "left");
28792879
addJSKeyVal(cssCtr, "left", "0px");
28802880
addJSKeyVal(cssIcon, "left", "0px"); // was 3
28812881
addJSKeyVal(cssTxt, "left", "23px");
@@ -2936,7 +2936,7 @@ protected void setAlignments(AbstractButton b, boolean justGetPreferred) {
29362936
addJSKeyVal(cssIcon, "top", top + "%", "transform",
29372937
"translateY(-" + itop + "%)" + (iscale == null ? "" : iscale));
29382938
} else {
2939-
DOMNode.setStyles(menuAnchorNode, "height", "1em");
2939+
DOMNode.setStyle(menuAnchorNode, "height", "1em");
29402940
// if (wIcon > 0)
29412941
// addJSKeyVal(cssTxt, "top", "50%", "transform", "translateY(-50%)");
29422942
addJSKeyVal(cssIcon, "top", "50%", "transform", "translateY(-80%) scale(0.6,0.6)");
@@ -3167,7 +3167,7 @@ public void setForegroundCUI(Color c) {
31673167

31683168
protected void setForegroundFor(DOMNode node, Color color) {
31693169
if (node != null)
3170-
DOMNode.setStyles(node, "color",
3170+
DOMNode.setStyle(node, "color",
31713171
(color == null ? "rgba(0,0,0,0)" : JSToolkit.getCSSColor(color == null ? Color.black : color)));
31723172
}
31733173

@@ -3593,7 +3593,7 @@ private void checkTransparent() {
35933593

35943594
private void setTransparent() {
35953595
if (allowPaintedBackground)
3596-
DOMNode.setStyles(domNode, "background", "transparent");
3596+
DOMNode.setStyle(domNode, "background", "transparent");
35973597
}
35983598

35993599
public void paintBackground(JSGraphics2D g) {
@@ -3633,7 +3633,7 @@ public void paintBackground(JSGraphics2D g) {
36333633
}
36343634

36353635
protected void setBackgroundDOM(DOMNode node, Color color) {
3636-
DOMNode.setStyles(node, "background-color",
3636+
DOMNode.setStyle(node, "background-color",
36373637
color == null ? null : JSToolkit.getCSSColor(color));
36383638
}
36393639

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,7 @@ public DOMNode updateDOMNode() {
208208
$(domNode).addClass("swingjs-doc");
209209
allowPaintedBackground = false;
210210
focusNode = enableNode = textNode = domNode;
211-
DOMNode.setStyles(domNode, "resize", "none", "margin", "0px", "padding", "1px");//,"scrollbar-width", "thin"); // otherwise it overflows
212-
DOMNode.setStyles(domNode, "box-sizing", "border-box");
211+
DOMNode.setStyles(domNode, "resize", "none", "margin", "0px", "padding", "1px", "box-sizing", "border-box");
213212
bindJSKeyEvents(focusNode, true);
214213
}
215214
textListener.checkDocument();

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public DOMNode updateDOMNode() {
126126

127127
closerWrap = newDOMObject("div", id + "_closerwrap");
128128
DOMNode.setTopLeftAbsolute(closerWrap, 0, 0);
129-
DOMNode.setStyles(closerWrap, "text-align", "right");
129+
DOMNode.setStyle(closerWrap, "text-align", "right");
130130

131131
closerNode = newDOMObject("label", id + "_closer", "innerHTML", "X");
132132
DOMNode.setStyles(closerNode, "width", "20px", "height", "20px", "position", "absolute", "text-align",
@@ -135,7 +135,7 @@ public DOMNode updateDOMNode() {
135135
titleBarNode.appendChild(titleNode);
136136
titleBarNode.appendChild(closerWrap);
137137
closerWrap.appendChild(closerNode);
138-
DOMNode.setStyles(closerNode, "background-color", "#DDD");// strColor);
138+
DOMNode.setStyle(closerNode, "background-color", "#DDD");// strColor);
139139
}
140140
bindWindowEvents();
141141
Insets s = getInsets();
@@ -146,10 +146,10 @@ public DOMNode updateDOMNode() {
146146
addFocusHandler();
147147
}
148148
String strColor = toCSSString(c.getBackground());
149-
DOMNode.setStyles(domNode, "background-color", strColor);
150-
DOMNode.setStyles(frameNode, "background", strColor);
149+
DOMNode.setStyle(domNode, "background-color", strColor);
150+
DOMNode.setStyle(frameNode, "background", strColor);
151151
// Why did I set background to DDD? 2019-03-15 12:25:57 commit ca0130f819e926a987a1010569a2fcb5c36ced7c
152-
DOMNode.setStyles(frameNode, "color", toCSSString(c.getForeground()));
152+
DOMNode.setStyle(frameNode, "color", toCSSString(c.getForeground()));
153153
setInnerComponentBounds(width, height);
154154
setTitle(frame.getTitle());
155155
if (!isDummyFrame) {
@@ -283,10 +283,10 @@ public boolean handleJSEvent(Object target, int eventType, Object jQueryEvent) {
283283
frameCloserAction();
284284
return HANDLED;
285285
case "mouseout":
286-
DOMNode.setStyles(closerNode, "background-color", "#DDD");// toCSSString(c.getBackground()));
286+
DOMNode.setStyle(closerNode, "background-color", "#DDD");// toCSSString(c.getBackground()));
287287
return HANDLED;
288288
case "mouseenter":
289-
DOMNode.setStyles(closerNode, "background-color", "red");
289+
DOMNode.setStyle(closerNode, "background-color", "red");
290290
return HANDLED;
291291
}
292292
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected boolean isFrameIndependent() {
4848
return false;
4949
isSticky = true;
5050
body.insertBefore(outerNode, DOMNode.firstChild(body));
51-
DOMNode.setStyles(outerNode, "position", "sticky");
51+
DOMNode.setStyle(outerNode, "position", "sticky");
5252
return true;
5353
}
5454

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public Dimension getMaximumSize(JComponent jc) {
8181
@Override
8282
public void paint(Graphics g, JComponent c) {
8383
if (jc.秘paintsSelfEntirely())
84-
DOMNode.setStyles(centeringNode, "visibility", "visible");
84+
DOMNode.setStyle(centeringNode, "visibility", "visible");
8585
super.paint(g, c);
8686
// TODO: implement this for buttons?
8787
if (isHTML)
@@ -93,7 +93,7 @@ public void paint(Graphics g, JComponent c) {
9393
// not the image, at this point. In order to get
9494
// a clientRectangle, the node must be visible, even for just
9595
// an instant.
96-
DOMNode.setStyles(imageNode, "visibility", null);
96+
DOMNode.setStyle(imageNode, "visibility", null);
9797
Rectangle r = imageNode.getBoundingClientRect();
9898
DOMNode parent = null;
9999
boolean isHidden = (r.width == 0);
@@ -105,7 +105,7 @@ public void paint(Graphics g, JComponent c) {
105105
Rectangle r0 = domNode.getBoundingClientRect();
106106
if (isHidden)
107107
DOMNode.transferTo(domNode, parent);
108-
DOMNode.setStyles(imageNode, "visibility", "hidden");
108+
DOMNode.setStyle(imageNode, "visibility", "hidden");
109109
icon.paintIcon(c, g, (int) (r.x - r0.x), (int) (r.y - r0.y));
110110
}
111111
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public DOMNode updateDOMNode() {
5252
setAlignments(jm, false);
5353
updateCenteringNode();
5454
if (isMenuBarMenu)
55-
DOMNode.setStyles(textNode, "left", "0px");
55+
DOMNode.setStyle(textNode, "left", "0px");
5656
return domNode;
5757
}
5858

0 commit comments

Comments
 (0)