Skip to content

Commit b8844f1

Browse files
hansonrhansonr
authored andcommitted
track cursor for setting later
1 parent e45aedf commit b8844f1

File tree

1 file changed

+42
-56
lines changed

1 file changed

+42
-56
lines changed

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

Lines changed: 42 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.awt.Color;
55
import java.awt.Component;
66
import java.awt.Container;
7+
import java.awt.Cursor;
78
import java.awt.Dimension;
89
import java.awt.Font;
910
import java.awt.FontMetrics;
@@ -1387,12 +1388,10 @@ protected boolean setUIDisabled(boolean b) {
13871388
* can be set false to never draw a background, primarily because Mac OS will
13881389
* paint a non-rectangular object.
13891390
*
1390-
* (textfield, textarea, button, combobox, menuitem, scrollbar)
1391+
* (InternalFrame, Button, ComboBox, MenuBar, MenuItem, ScrollBar, TextField, TextArea, EditorPane)
13911392
*/
13921393
protected boolean allowPaintedBackground = true;
13931394

1394-
//private boolean backgroundPainted;
1395-
13961395
/**
13971396
* Label will render its image, drawing to the canvas; Button will not
13981397
* (as of this writing), so we need a flag to know when to not hide it.
@@ -1456,9 +1455,47 @@ public DOMNode updateDOMNode() {
14561455
protected DOMNode updateDOMNodeCUI() {
14571456
if (cellComponent != null)
14581457
updateCellNode();
1458+
if (myCursor != getCursor())
1459+
setCursor();
14591460
return domNode;
14601461
}
14611462

1463+
1464+
@Override
1465+
public void updateCursorImmediately() {
1466+
if (isUIDisabled)
1467+
return;
1468+
setHTMLElement(); // for a frame, this is the call that connects it to BODY
1469+
setCursor();
1470+
}
1471+
1472+
private void setCursor() {
1473+
myCursor = getCursor();
1474+
String curs = JSToolkit.getCursorName(myCursor);
1475+
DOMNode.setStyles(outerNode, "cursor", curs);
1476+
DOMNode.setStyles(domNode, "cursor", curs);
1477+
setWaitImage(curs == "wait");
1478+
}
1479+
1480+
1481+
private Cursor getCursor() {
1482+
Cursor cur = c.getCursor();
1483+
return (cur == Cursor.getDefaultCursor() ? null : cur);
1484+
}
1485+
1486+
1487+
protected void setWaitImage(boolean doShow) {
1488+
if (waitImage == null) {
1489+
if (!doShow)
1490+
return;
1491+
String path = (/** @j2sNative this.applet._j2sPath || */null) + "/img/cursor_wait.gif";
1492+
waitImage = newDOMObject("image", id + "_waitImage", "src", path);
1493+
}
1494+
if (doShow)
1495+
$(waitImage).show();
1496+
else
1497+
$(waitImage).hide();
1498+
}
14621499
protected DOMNode setCssFont(DOMNode obj, Font font) {
14631500
if (font != null) {
14641501
int istyle = font.getStyle();
@@ -1817,23 +1854,6 @@ public void update(Graphics g, JComponent c) {
18171854
paint(g, c);
18181855
}
18191856

1820-
1821-
// /**
1822-
// * This flag is set by border painting and background painting detection to
1823-
// * indicate that a cell renderer must do that painting.
1824-
// */
1825-
// public void setPainted(Object g) {
1826-
// if (g == null) {
1827-
// // reset
1828-
// backgroundPainted = false;
1829-
// if (allowPaintedBackground)
1830-
// DOMNode.setStyles(domNode, "background", null);
1831-
// } else {
1832-
// backgroundPainted = true;
1833-
// setTransparent(domNode);
1834-
// }
1835-
// }
1836-
18371857
/**
18381858
* from ComponentPeer; not implemented in SwingJS
18391859
*/
@@ -2335,6 +2355,8 @@ protected int getDefaultIconTextGap() {
23352355
*/
23362356
private boolean isFullyCentered;
23372357

2358+
private Cursor myCursor;
2359+
23382360
protected static Insets zeroInsets = new Insets(0, 0, 0, 0);
23392361

23402362
protected void getJSInsets() {
@@ -2879,41 +2901,6 @@ public void setFont(Font f) {
28792901
setCssFont((textNode == null ? domNode : textNode), f);
28802902
}
28812903

2882-
@Override
2883-
public void updateCursorImmediately() {
2884-
if (isUIDisabled)
2885-
return;
2886-
setHTMLElement();
2887-
String curs = JSToolkit.getCursorName(c.getCursor());
2888-
DOMNode.setStyles(outerNode, "cursor", curs);
2889-
DOMNode.setStyles(domNode, "cursor", curs);
2890-
setWaitImage(curs == "wait");
2891-
}
2892-
2893-
protected void setWaitImage(boolean doShow) {
2894-
if (waitImage != null) {
2895-
if (!doShow)
2896-
return;
2897-
String path = "";
2898-
/**
2899-
* @j2sNative
2900-
*
2901-
* path = this.applet._j2sPath;
2902-
*
2903-
*/
2904-
{
2905-
}
2906-
path += "/img/cursor_wait.gif";
2907-
if (debugging)
2908-
System.out.println("loading wait cursor " + path);
2909-
waitImage = newDOMObject("image", id + "_waitImage", "src", path);
2910-
}
2911-
if (doShow)
2912-
$(waitImage).show();
2913-
else
2914-
$(waitImage).hide();
2915-
}
2916-
29172904
@Override
29182905
public Image createImage(ImageProducer producer) {
29192906
JSUtil.notImplemented("");
@@ -3221,7 +3208,6 @@ public void setRenderer(JSComponent rendererComponent, int width, int height, DO
32213208
return;
32223209
}
32233210
cellComponent = (JComponent) rendererComponent;
3224-
//backgroundPainted = false;
32253211
if (width == 0)
32263212
return;
32273213
cellWidth = width;

0 commit comments

Comments
 (0)