Skip to content

Commit 4f5a9bd

Browse files
hansonrhansonr
authored andcommitted
Background and update() handling for AWT
1 parent 47b569f commit 4f5a9bd

Some content is hidden

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

79 files changed

+612
-380
lines changed
402 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190614172837
1+
20190617071320
402 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190614172837
1+
20190617071320
402 KB
Binary file not shown.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public AppletContext getAppletContext() {
263263
public void setVisible(boolean b) {
264264
super.setVisible(b);
265265
if (b)
266-
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.
267267
}
268268

269269

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

Lines changed: 6 additions & 7 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

@@ -3834,6 +3834,9 @@ protected void dispatchEventImplComp(AWTEvent e) {
38343834
// selectively for non-native components on Windows only.
38353835
// - Fred.Ecks@Eng.sun.com, 5-8-98
38363836

3837+
case PaintEvent.UPDATE:
3838+
((JSComponent)this).秘update();
3839+
break;
38373840
case KeyEvent.KEY_PRESSED:
38383841
case KeyEvent.KEY_RELEASED:
38393842
Container p = (Container) ((this instanceof Container) ? this : parent);
@@ -5404,7 +5407,7 @@ protected void processFocusEvent(FocusEvent e) {
54045407
*/
54055408
protected void processKeyEvent(KeyEvent e) {
54065409
KeyListener listener = keyListener;
5407-
if (listener != null && (/** @j2sNative this.isAWT$ || */ 秘isFocusableSet)) {
5410+
if (listener != null && (((JSComponent)this).秘isAWT()|| 秘isFocusableSet)) {
54085411
int id = e.getID();
54095412
switch (id) {
54105413
case KeyEvent.KEY_TYPED:
@@ -5787,10 +5790,6 @@ public boolean action(Event evt, Object what) {
57875790
* @since JDK1.0
57885791
*/
57895792
public void addNotify() {
5790-
addNotifyComp();
5791-
}
5792-
5793-
protected void addNotifyComp() {
57945793
synchronized (getTreeLock()) {
57955794
ComponentPeer peer = getOrCreatePeer();
57965795
// this.peer;

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ public void remove(Component comp) {
12841284
* @see #add
12851285
* @see #remove
12861286
*/
1287-
public void removeAll() {
1287+
public void removeAll() {
12881288
synchronized (getTreeLock()) {
12891289
adjustListeningChildren(AWTEvent.HIERARCHY_EVENT_MASK,
12901290
-listeningChildren);
@@ -1316,20 +1316,12 @@ public void removeAll() {
13161316
HierarchyEvent.PARENT_CHANGED,
13171317
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
13181318
}
1319-
if (peer != null) {
1320-
if (layoutMgr == null && isVisible()) {
1321-
updateCursorImmediately();
1322-
}
1323-
if (isVisible()) {
1324-
// this did not work -- see _mpEnigma_Applets_textana_Textanalyzer2_node4.htm
1325-
Graphics g = getGraphics();
1326-
if (g != null)
1327-
g.clearRect(0, 0, width, height);
1328-
1329-
}
1319+
if (peer != null && layoutMgr == null && isVisible()) {
1320+
updateCursorImmediately();
13301321
}
13311322
invalidateIfValid();
13321323
}
1324+
super.removeAll();
13331325
}
13341326

13351327
// Should only be called while holding tree lock
@@ -2739,7 +2731,7 @@ public void addNotify() {
27392731
// on this instance, so we first call addNotifyComp() and
27402732
// possibly create an lightweight event dispatcher before calling
27412733
// addNotify() on the children which may be lightweight.
2742-
addNotifyComp();
2734+
super.addNotify();
27432735
if (! (peer instanceof LightweightPeer)) {
27442736
setDispatcher();
27452737
}

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;

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

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.awt.event.KeyListener;
3131
import java.awt.peer.ComponentPeer;
32+
import java.awt.peer.LightweightPeer;
3233
import java.beans.PropertyChangeListener;
3334
import java.util.Arrays;
3435

@@ -120,6 +121,7 @@ public interface A2SWrappedComponent {
120121

121122
public final static int PAINTS_SELF_NO = -1;
122123
public final static int PAINTS_SELF_YES = 1;
124+
public final static int PAINTS_SELF_ALWAYS = 2;
123125
public final static int PAINTS_SELF_UNKNOWN = 0;
124126

125127
/**
@@ -129,6 +131,7 @@ public interface A2SWrappedComponent {
129131
*
130132
*/
131133
private int 秘iPaintMyself = PAINTS_SELF_UNKNOWN;
134+
private boolean 秘repaintAsUpdate = true;
132135

133136
// trying to replace these two:
134137
// public boolean 秘isBackgroundPainted;
@@ -225,7 +228,7 @@ public Graphics getGraphics() {
225228
// Check to see if the subclass is getting this graphics
226229
// object directly, without using paint(Graphics).
227230
if (!JComponent.isComponentObtainingGraphicsFrom(null) && !秘paintsSelf()) {
228-
秘setPaintsSelf();
231+
秘setPaintsSelf(PAINTS_SELF_YES);
229232
((JSComponentUI) ui).clearPaintPath();
230233
}
231234

@@ -236,6 +239,12 @@ public Graphics getGraphics() {
236239
return g;
237240
}
238241

242+
public void addNotify() {
243+
if (秘paintsSelf())
244+
((JSComponentUI) ui).clearPaintPath();
245+
super.addNotify();
246+
}
247+
239248
public JSFrameViewer setFrameViewer(JSFrameViewer viewer) {
240249
// JApplet, JDialog, JFrame (including JInternalFrame), JRootPane, JWindow
241250
return 秘frameViewer = (viewer == null ? viewer = new JSFrameViewer().setForWindow((RootPaneContainer) this) : viewer);
@@ -332,6 +341,25 @@ public void updateUI() {
332341
return (/** @j2sNative g.mark$ ? g : */ null);
333342
}
334343

344+
public boolean 秘isAWT() {
345+
return (/** @j2sNative !!this.isAWT$ || */ false);
346+
}
347+
348+
protected void 秘setIsAWT() {
349+
/**
350+
* @j2sNative
351+
* this.isAWT$ = true;
352+
*/
353+
}
354+
355+
356+
@Override
357+
protected boolean canPaint() {
358+
// meaning can UPDATE
359+
return (秘repaintAsUpdate && 秘isAWT() || !(peer instanceof LightweightPeer));
360+
}
361+
362+
335363
@SuppressWarnings("unused")
336364
@Override
337365
public boolean isBackgroundSet() {
@@ -543,8 +571,8 @@ public void removeKeyListener(KeyListener l) {
543571
// }
544572
}
545573

546-
public int 秘setPaintsSelf() {
547-
return 秘iPaintMyself = PAINTS_SELF_YES;
574+
public int 秘setPaintsSelf(int flag) {
575+
return (秘iPaintMyself == PAINTS_SELF_ALWAYS ? PAINTS_SELF_ALWAYS : (秘iPaintMyself = flag));
548576
}
549577

550578
/**
@@ -566,17 +594,18 @@ public void removeKeyListener(KeyListener l) {
566594
// don't allow if JComponent.paint(Graphics) has been overridden
567595
// don't allow if AbstractBorder.paintBorder(...) has been overridden
568596
// unchecked here is if a class calls getGraphics outside of this context
569-
秘iPaintMyself = (JSUtil.isOverridden(this, "paint$java_awt_Graphics", JComponent.class)
597+
秘iPaintMyself = 秘setPaintsSelf(JSUtil.isOverridden(this, "paint$java_awt_Graphics", JComponent.class)
570598
|| JSUtil.isOverridden(this, "paintComponent$java_awt_Graphics", JComponent.class)
571599
|| JSUtil.isOverridden(this, "paintContainer$java_awt_Graphics", Container.class)
600+
|| JSUtil.isOverridden(this, "update$java_awt_Graphics", JComponent.class)
572601
|| JSUtil.isOverridden(秘border, "paintBorder$java_awt_Component$java_awt_Graphics$I$I$I$I",
573602
AbstractBorder.class)
574-
? 秘setPaintsSelf() : PAINTS_SELF_NO);
603+
? PAINTS_SELF_YES : PAINTS_SELF_NO);
575604
}
576605
// TODO -- still need to set RepaintManager so that
577606
// objects with the same paintable root can be grouped together.
578607

579-
return (秘iPaintMyself == PAINTS_SELF_YES);
608+
return (秘iPaintMyself != PAINTS_SELF_NO);
580609
}
581610

582611
/**
@@ -588,6 +617,39 @@ public void removeKeyListener(KeyListener l) {
588617
return 秘paintsSelf();
589618
}
590619

620+
public void removeAll() {
621+
秘setPaintsSelf(PAINTS_SELF_UNKNOWN);
622+
((JComponent) this).paintImmediately(0, 0, width, height);
623+
}
624+
625+
public void 秘update() {
626+
// from AWT repaint() via a PaintEvent.UPDATE
627+
Graphics g = getGraphics();
628+
try {
629+
update(g);
630+
} finally {
631+
g.dispose();
632+
}
633+
}
634+
635+
/**
636+
* AWT controls will regard repaint() as update() unless called this way (from
637+
* javax.swing, primarily)
638+
*/
639+
public void 秘repaint() {
640+
if (秘isAWT()) {
641+
秘repaintAsUpdate = false;
642+
try {
643+
((JComponent) this).repaint();
644+
} finally {
645+
秘repaintAsUpdate = true;
646+
}
647+
} else {
648+
repaint();
649+
}
650+
}
651+
652+
591653
// private boolean childPaintsItself() {
592654
// Component[] a = JSComponent.秘getChildArray((Container) this);
593655
// for (int i = ((Container) this).getComponentCount(); --i >= 0;)

0 commit comments

Comments
 (0)