Skip to content

Commit 99f554c

Browse files
hansonrhansonr
authored andcommitted
AWT fixing inheritance
1 parent 889c3ca commit 99f554c

File tree

2 files changed

+190
-55
lines changed

2 files changed

+190
-55
lines changed

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

Lines changed: 99 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@
2727
*/
2828
package java.awt;
2929

30+
import java.applet.JSApplet;
3031
import java.awt.event.KeyListener;
3132
import java.awt.peer.ComponentPeer;
3233
import java.beans.PropertyChangeListener;
3334
import java.util.Arrays;
3435

3536
import javax.swing.JComponent;
37+
import javax.swing.JPopupMenu;
3638
import javax.swing.RootPaneContainer;
3739
import javax.swing.UIDefaults;
3840
import javax.swing.UIManager;
3941
import javax.swing.plaf.ComponentUI;
4042
import javax.swing.plaf.FontUIResource;
43+
import javax.swing.plaf.UIResource;
4144

4245
import swingjs.JSAppletThread;
4346
import swingjs.JSAppletViewer;
@@ -281,19 +284,77 @@ public void checkBackgroundPainted(JSGraphics2D jsg, boolean init) {
281284
_gtemp = null;
282285
_isBackgroundPainted = jsg.isBackgroundPainted();
283286
if (_isBackgroundPainted) {
284-
((JSComponentUI) ui).setPainted(null);
287+
((JSComponentUI) ui).setPainted(jsg);
285288
// It's all one canvas, and it is behind the root pane (bad design?)
286289
// so if it is painted, we should make the root pane transparent
287-
((JSComponentUI) ((JComponent) this).getRootPane().getUI()).setPainted(null);
290+
((JSComponentUI) ((JComponent) this).getRootPane().getUI()).setPainted(jsg);
288291
}
289292
}
290293

291294
@Override
292295
public boolean isBackgroundSet() {
293-
return background != null;// false;// TODO (background != null &&
294-
// !isBackgroundPainted);
296+
return (background == null ? false
297+
: /** @j2sNative this.isAWT$ || */false ? !(background instanceof UIResource) : true);
295298
}
296299

300+
@Override
301+
public boolean isForegroundSet() {
302+
return (foreground == null ? false
303+
: /** @j2sNative this.isAWT$ || */false ? !(foreground instanceof UIResource) : true);
304+
}
305+
306+
@Override
307+
public boolean isFontSet() {
308+
return (font == null ? null : /** @j2sNative this.isAWT$ || */false ? !(font instanceof FontUIResource) : true);
309+
}
310+
311+
// @Override
312+
// @SuppressWarnings("unused")
313+
// public Color getBackground() {
314+
// if (/** @j2sNative !this.isAWT$ || */ false) {
315+
// return getBackground_NoClient();
316+
// }
317+
// // AWT only - don't use Swing's UIResource
318+
// Color background = this.background;
319+
// if (background!= null && !(background instanceof UIResource)) {
320+
// return background;
321+
// }
322+
// background = (parent != null) ? parent.getBackground() : null;
323+
// return (background == null ? getBackground_NoClient() : background);
324+
// }
325+
//
326+
// @Override
327+
// @SuppressWarnings("unused")
328+
// public Color getForeground() {
329+
// if (/** @j2sNative !this.isAWT$ || */ false) {
330+
// return getForeground_NoClient();
331+
// }
332+
// // AWT only - don't use Swing's UIResource
333+
// Color foreground = this.foreground;
334+
// if (foreground!= null && !(foreground instanceof UIResource)) {
335+
// return foreground;
336+
// }
337+
// foreground = (parent != null) ? parent.getForeground() : null;
338+
// return (foreground == null ? getForeground_NoClient() : foreground);
339+
// }
340+
//
341+
//
342+
// @SuppressWarnings("unused")
343+
// @Override
344+
// public Font getFont() {
345+
// if (/** @j2sNative !this.isAWT$ || */ false) {
346+
// return getFont_NoClientCode();
347+
// }
348+
// // AWT only - don't use Swing's UIResource
349+
// Font font = this.font;
350+
// if (font != null && !(font instanceof FontUIResource)) {
351+
// return font;
352+
// }
353+
// font = (parent == null ? null : parent.getFont());
354+
// return (font == null ? getFont_NoClientCode() : font);
355+
// }
356+
//
357+
297358
protected void updateUIZOrder() {
298359

299360
// developer could have created their own LayeredPane
@@ -360,31 +421,44 @@ public void removeKeyListener(KeyListener l) {
360421
((JSComponentUI)ui).enableJSKeys(false);
361422
}
362423

363-
public Font getFont() {
364-
if (/** @j2sNative this.isAWT$ || */ false) {
365-
return getFontAWT();
366-
}
367-
return getFont_NoClientCode();
368-
}
369424

370-
public boolean isFontSet() {
371-
return (font != null && (/** @j2sNative this.isAWT$ || */false ? !(font instanceof FontUIResource) : false));
372-
}
373-
425+
/**
426+
* Invoker must be focusable and could cross from popupmenu to associated component
427+
* SwingJS from KeyboardManager. Brought here because it is smarter to do this
428+
* before going through all the keys first. And I want to debug this only
429+
* when it's necessary! BH
430+
*
431+
* @param c
432+
* @param focusable TODO
433+
* @return
434+
*/
435+
public static Container getTopInvokableAncestor(Component c, boolean andFocusable) {
436+
for(Component p = c; p != null; p = nextHigher(p)) {
437+
if (p instanceof Window && (!andFocusable || ((Window)p).isFocusableWindow())
438+
|| p instanceof JSApplet
439+
) {
440+
return (Container) p;
441+
}
442+
}
443+
return null;
444+
}
445+
374446
/**
375-
* For AWT components, first try nondefault font, and then,
376-
* only as a last resort, use the default font.
447+
* SwingJS -- this was in KeyboardManager, way too late in the process. It was
448+
* just parent(), but in SwingJS the popup windows do not have parents, only
449+
* invokers. Perhaps that is a mistake. But it has to do with the fact that we
450+
* do not have to repaint anything relating to the popup -- of course, the
451+
* browser does that for us!
377452
*
453+
* @param c
378454
* @return
379455
*/
380-
public Font getFontAWT() {
381-
Font font = this.font;
382-
if (font != null && !(font instanceof FontUIResource)) {
383-
return font;
384-
}
385-
Container parent = this.parent;
386-
font = (parent == null ? null : parent.getFontAWT());
387-
return (font != null ? font : getFont_NoClientCode());
388-
}
456+
public static Container nextHigher(Component c) {
457+
Container p = c.getParent();
458+
if (p == null && c instanceof JPopupMenu)
459+
p = (Container) ((JPopupMenu) c).getInvoker();
460+
return p;
461+
}
462+
389463

390464
}

0 commit comments

Comments
 (0)