Skip to content

Commit 0e101be

Browse files
authored
Merge pull request #116 from BobHanson/master
AWT background and update() handling
2 parents 8183511 + c2e8c59 commit 0e101be

File tree

100 files changed

+2325
-1728
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+2325
-1728
lines changed
400 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190606154615
1+
20190617071320
400 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190606154615
1+
20190617071320
400 KB
Binary file not shown.

sources/net.sf.j2s.java.core/doc/Differences.txt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ System.exit(0) does not stop all processes
270270
list cell renderers must be JComponents
271271
myClass.getField not implemented
272272
"window" and other reserved JavaScript names
273-
273+
qualified field and method names
274+
missing Math methods
275+
component.getGraphics(), graphics.dispose()
274276

275277
MAJOR ISSUES--for Bob and Udo within SwingJS
276278
============================================
@@ -488,14 +490,28 @@ qualified field and method names
488490

489491
In order to minimize the chance of added SwingJS field and method names colliding with
490492
ones developers might use in subclassing Java classes, we have added U+79D8 (Mandarin "secrect")
491-
to the characaters already disrecommended by Java documentation ("$" and "_"). The only problem
493+
to the characters already disrecommended by Java documentation ("$" and "_"). The only problem
492494
would be if you use that character followed by certain English words in certain classes. For example
493495
\u79D8canvas for JComponents (in java.awt.JSComponent) and \u79D8byte (in java.io.File).
494496

495497
missing Math methods
496498
--------------------
497499

498-
A few java.lang.Math
500+
A few of the more obscure java.lang.Math methods are missing. This is a
501+
result of continued Java development. It is easy enough to add these
502+
methods if you have the source. They go into j2sClazz.js, which is
503+
combined with other initial libraries into swingjs2.js.
504+
505+
506+
component.getGraphics(), graphics.dispose()
507+
-------------------------------------------
508+
509+
Use of component.getGraphics() is discouraged in Java and in SwingJS.
510+
Specifically in SwingJS, any call to component.getGraphics() or
511+
component.createGraphics() must be matched with graphics.dispose(),
512+
particularly when it is called outside the context of a paint(Graphics)
513+
call from the system.
514+
499515

500516
MAJOR ISSUES--for Bob and Udo within SwingJS
501517
============================================

sources/net.sf.j2s.java.core/src/java/applet/JSApplet.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@
4343
import javax.swing.JRootPane;
4444
import javax.swing.RepaintManager;
4545

46-
import swingjs.plaf.JSComponentUI;
47-
4846
/**
4947
* SwingJS note: This class is the original java.applet.Applet class.
5048
* It is subclassed by JApplet. The replacement java.applet.Applet class
@@ -265,7 +263,7 @@ public AppletContext getAppletContext() {
265263
public void setVisible(boolean b) {
266264
super.setVisible(b);
267265
if (b)
268-
repaint(); // BH SwingJS needs this, because there is no system event set to do this.
266+
秘repaint(); // BH SwingJS needs this, because there is no system event set to do this.
269267
}
270268

271269

@@ -289,8 +287,8 @@ public void resizeHTML(int width, int height) {
289287
// Added 2/23/2019 to force layout prior to Canvas painting in mpFrakta.Applets.Geomet
290288
JRootPane root = ((JApplet) this).getRootPane();
291289
root.invalidate();
292-
((JSComponentUI)root.getUI()).setPainted(null);
293-
root.秘isBackgroundPainted = false;
290+
// ((JSComponentUI)root.getUI()).setPainted(null);
291+
// root.秘isBackgroundPainted = false;
294292
RepaintManager.currentManager(this).addInvalidComponent(root);
295293
}
296294
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ protected void updatePeerVisibilityOrig(boolean isVisible) {
14881488
createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED, this, parent, HierarchyEvent.SHOWING_CHANGED,
14891489
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
14901490
if (peer instanceof LightweightPeer) {
1491-
repaint();
1491+
((JSComponent)this).秘repaint();
14921492
}
14931493
updateCursorImmediately();
14941494
}
@@ -2112,7 +2112,7 @@ private void repaintParentIfNeeded(int oldX, int oldY, int oldWidth, int oldHeig
21122112
// Have the parent redraw the area this component occupied.
21132113
parent.repaint(oldX, oldY, oldWidth, oldHeight);
21142114
// Have the parent redraw the area this component *now* occupies.
2115-
repaint();
2115+
((JSComponent)this).秘repaint();
21162116
}
21172117
}
21182118

@@ -2697,7 +2697,9 @@ protected final void invalidateIfValid() {
26972697

26982698
/**
26992699
*
2700-
* For SwingJS, we have the graphics without needing to get it from a peer.
2700+
* Unused in SwingJS. For SwingJS, we have the graphics without needing to get it from a peer.
2701+
* @see JSComponent.getGraphics
2702+
*
27012703
* Creates a graphics context for this component. This method will return
27022704
* <code>null</code> if this component is currently not displayable.
27032705
*
@@ -3832,6 +3834,9 @@ protected void dispatchEventImplComp(AWTEvent e) {
38323834
// selectively for non-native components on Windows only.
38333835
// - Fred.Ecks@Eng.sun.com, 5-8-98
38343836

3837+
case PaintEvent.UPDATE:
3838+
((JSComponent)this).秘update();
3839+
break;
38353840
case KeyEvent.KEY_PRESSED:
38363841
case KeyEvent.KEY_RELEASED:
38373842
Container p = (Container) ((this instanceof Container) ? this : parent);
@@ -5402,7 +5407,7 @@ protected void processFocusEvent(FocusEvent e) {
54025407
*/
54035408
protected void processKeyEvent(KeyEvent e) {
54045409
KeyListener listener = keyListener;
5405-
if (listener != null && (/** @j2sNative this.isAWT$ || */ 秘isFocusableSet)) {
5410+
if (listener != null && (((JSComponent)this).秘isAWT()|| 秘isFocusableSet)) {
54065411
int id = e.getID();
54075412
switch (id) {
54085413
case KeyEvent.KEY_TYPED:
@@ -5785,10 +5790,6 @@ public boolean action(Event evt, Object what) {
57855790
* @since JDK1.0
57865791
*/
57875792
public void addNotify() {
5788-
addNotifyComp();
5789-
}
5790-
5791-
protected void addNotifyComp() {
57925793
synchronized (getTreeLock()) {
57935794
ComponentPeer peer = getOrCreatePeer();
57945795
// this.peer;
@@ -8308,4 +8309,5 @@ static boolean doesImplement(Object obj, String interfaceName) {
83088309
return doesClassImplement(obj.getClass(), interfaceName);
83098310
}
83108311

8312+
83118313
}

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,13 @@ public Insets getInsets() {
367367
return (i == null ? NULL_INSETS : i);
368368
}
369369

370+
public Insets 秘getInsetsC() {
371+
// in SwingJS, we do not clone. Everything is a ContainerPeer.
372+
// it is inconsistent with other classes that this would need cloning.
373+
Insets i = (peer == null ? null : ((ContainerPeer) peer).getInsets());
374+
return (i == null ? NULL_INSETS : i);
375+
}
376+
370377
@Deprecated
371378
public Insets insets() {
372379
return getInsets();
@@ -1277,7 +1284,7 @@ public void remove(Component comp) {
12771284
* @see #add
12781285
* @see #remove
12791286
*/
1280-
public void removeAll() {
1287+
public void removeAll() {
12811288
synchronized (getTreeLock()) {
12821289
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
12831290
-listeningChildren);
@@ -1309,20 +1316,12 @@ public void removeAll() {
13091316
HierarchyEvent.PARENT_CHANGED,
13101317
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
13111318
}
1312-
if (peer != null) {
1313-
if (layoutMgr == null && isVisible()) {
1314-
updateCursorImmediately();
1315-
}
1316-
if (isVisible()) {
1317-
// this did not work -- see _mpEnigma_Applets_textana_Textanalyzer2_node4.htm
1318-
Graphics g = getGraphics();
1319-
if (g != null)
1320-
g.clearRect(0, 0, width, height);
1321-
1322-
}
1319+
if (peer != null && layoutMgr == null && isVisible()) {
1320+
updateCursorImmediately();
13231321
}
13241322
invalidateIfValid();
13251323
}
1324+
super.removeAll();
13261325
}
13271326

13281327
// Should only be called while holding tree lock
@@ -2732,7 +2731,7 @@ public void addNotify() {
27322731
// on this instance, so we first call addNotifyComp() and
27332732
// possibly create an lightweight event dispatcher before calling
27342733
// addNotify() on the children which may be lightweight.
2735-
addNotifyComp();
2734+
super.addNotify();
27362735
if (! (peer instanceof LightweightPeer)) {
27372736
setDispatcher();
27382737
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,10 @@ private void postEventNow(AWTEvent theEvent, int priority) {
313313
}
314314

315315
private boolean coalescePaintEvent(PaintEvent e) {
316-
ComponentPeer sourcePeer = ((Component) e.getSource()).peer;
317-
if (sourcePeer != null) {
318-
sourcePeer.coalescePaintEvent(e);
319-
}
316+
//SwingJS ComponentPeer sourcePeer = ((Component) e.getSource()).peer;
317+
// if (sourcePeer != null) {
318+
// sourcePeer.coalescePaintEvent(e);
319+
// }
320320
EventQueueItem[] cache = ((Component) e.getSource()).eventCache;
321321
if (cache == null) {
322322
return false;

0 commit comments

Comments
 (0)