|
27 | 27 | */ |
28 | 28 | package java.awt; |
29 | 29 |
|
| 30 | +import java.applet.JSApplet; |
30 | 31 | import java.awt.event.KeyListener; |
31 | 32 | import java.awt.peer.ComponentPeer; |
32 | 33 | import java.beans.PropertyChangeListener; |
33 | 34 | import java.util.Arrays; |
34 | 35 |
|
35 | 36 | import javax.swing.JComponent; |
| 37 | +import javax.swing.JPopupMenu; |
36 | 38 | import javax.swing.RootPaneContainer; |
37 | 39 | import javax.swing.UIDefaults; |
38 | 40 | import javax.swing.UIManager; |
39 | 41 | import javax.swing.plaf.ComponentUI; |
40 | 42 | import javax.swing.plaf.FontUIResource; |
| 43 | +import javax.swing.plaf.UIResource; |
41 | 44 |
|
42 | 45 | import swingjs.JSAppletThread; |
43 | 46 | import swingjs.JSAppletViewer; |
@@ -281,19 +284,77 @@ public void checkBackgroundPainted(JSGraphics2D jsg, boolean init) { |
281 | 284 | _gtemp = null; |
282 | 285 | _isBackgroundPainted = jsg.isBackgroundPainted(); |
283 | 286 | if (_isBackgroundPainted) { |
284 | | - ((JSComponentUI) ui).setPainted(null); |
| 287 | + ((JSComponentUI) ui).setPainted(jsg); |
285 | 288 | // It's all one canvas, and it is behind the root pane (bad design?) |
286 | 289 | // 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); |
288 | 291 | } |
289 | 292 | } |
290 | 293 |
|
291 | 294 | @Override |
292 | 295 | 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); |
295 | 298 | } |
296 | 299 |
|
| 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 | + |
297 | 358 | protected void updateUIZOrder() { |
298 | 359 |
|
299 | 360 | // developer could have created their own LayeredPane |
@@ -360,31 +421,44 @@ public void removeKeyListener(KeyListener l) { |
360 | 421 | ((JSComponentUI)ui).enableJSKeys(false); |
361 | 422 | } |
362 | 423 |
|
363 | | - public Font getFont() { |
364 | | - if (/** @j2sNative this.isAWT$ || */ false) { |
365 | | - return getFontAWT(); |
366 | | - } |
367 | | - return getFont_NoClientCode(); |
368 | | - } |
369 | 424 |
|
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 | + |
374 | 446 | /** |
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! |
377 | 452 | * |
| 453 | + * @param c |
378 | 454 | * @return |
379 | 455 | */ |
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 | + |
389 | 463 |
|
390 | 464 | } |
0 commit comments