3737import javax .swing .RootPaneContainer ;
3838import javax .swing .UIDefaults ;
3939import javax .swing .UIManager ;
40+ import javax .swing .border .AbstractBorder ;
41+ import javax .swing .border .Border ;
4042import javax .swing .plaf .ComponentUI ;
4143import javax .swing .plaf .FontUIResource ;
4244import javax .swing .plaf .UIResource ;
@@ -93,7 +95,46 @@ public interface A2SWrappedComponent {
9395 public Component 秘getWrap ();
9496
9597 }
96- /**
98+
99+ protected boolean 秘isAppletFrame ;
100+ public boolean 秘isFramedApplet ;
101+
102+ public String 秘htmlName ;
103+
104+ protected int 秘num ;
105+ private static int 秘incr ;
106+ private Insets 秘tempInsets ;
107+ public JSGraphics2D 秘gtemp ; // indicates that we are painting, so that g.setBackground() should also be set
108+
109+ public boolean 秘isRootPane , 秘isContentPane ;
110+ public JSAppletViewer 秘appletViewer = ((JSAppletThread ) Thread .currentThread ()).秘appletViewer ;
111+ private JSFrameViewer 秘frameViewer , 秘topFrameViewer ;
112+ public HTML5Canvas 秘canvas ;
113+ public ComponentUI ui ; // from JComponent
114+
115+ private String 秘uiClassID ;
116+
117+ Boolean 秘peerVis ;
118+
119+ protected Border 秘border ; // from private JComponent field
120+
121+ public final static int PAINTS_SELF_NO = -1 ;
122+ public final static int PAINTS_SELF_YES = 1 ;
123+ public final static int PAINTS_SELF_UNKNOWN = 0 ;
124+
125+ /**
126+ * will be set to 1 if paint(graphics) is found to be overridden, signally that
127+ * we can't depend upon this component to be drawn by itself; JLabel will
128+ * also set this to 1 if there there is an icon
129+ *
130+ */
131+ private int 秘iPaintMyself = PAINTS_SELF_UNKNOWN ;
132+
133+ // trying to replace these two:
134+ // public boolean 秘isBackgroundPainted;
135+ // protected boolean 秘alwaysPaint; // in AWT canvas
136+
137+ /**
97138 * overridden in Applet
98139 *
99140 * SwingJS Applet repurposes resize(width, height) to call
@@ -105,9 +146,7 @@ public interface A2SWrappedComponent {
105146 * @param width
106147 * @param height
107148 */
108- @ SuppressWarnings ("deprecation" )
109149 public void 秘resizeOriginal (int width , int height ) {
110- // o
111150 resize (width , height );
112151 }
113152
@@ -145,45 +184,6 @@ public interface A2SWrappedComponent {
145184 *
146185 */
147186
148- protected boolean 秘isAppletFrame ;
149- public boolean 秘isFramedApplet ;
150-
151- public String 秘htmlName ;
152-
153- protected int 秘num ;
154- private static int 秘incr ;
155- public boolean 秘isBackgroundPainted ;
156- protected boolean 秘alwaysPaint ;
157- private Insets 秘tempInsets ;
158- public JSGraphics2D 秘gtemp ; // indicates that we are painting, so that g.setBackground() should also be set
159-
160-
161- public boolean 秘isRootPane , 秘isContentPane ;
162- public JSAppletViewer 秘appletViewer = ((JSAppletThread ) Thread .currentThread ()).秘appletViewer ;
163- private JSFrameViewer 秘frameViewer , 秘topFrameViewer ;
164- public HTML5Canvas 秘canvas ;
165- public ComponentUI ui ; // from JComponent
166-
167- private String 秘uiClassID ;
168-
169- Boolean 秘peerVis ;
170-
171- /**
172- * not totally successful; triggered for images, background, and fillBox
173- *
174- */
175-
176- public boolean selfOrChildIsPainted () {
177- if (秘alwaysPaint || 秘isBackgroundPainted )
178- return true ;
179- Component [] a = JSComponent .秘getChildArray ((Container ) this );
180- for (int i = ((Container ) this ).getComponentCount (); --i >= 0 ;)
181- if (((JSComponent ) a [i ]).selfOrChildIsPainted ())
182- return true ;
183- return false ;
184- }
185-
186-
187187 public JSComponent () {
188188 super ();
189189 秘num = ++秘incr ;
@@ -222,6 +222,13 @@ public Graphics getGraphics() {
222222 // if (g instanceof ConstrainableGraphics) {
223223 // ((ConstrainableGraphics) g).constrain(x, y, width, height);
224224 // } else {
225+ // Check to see if the subclass is getting this graphics
226+ // object directly, without using paint(Graphics).
227+ if (!JComponent .isComponentObtainingGraphicsFrom (null ) && !秘paintsSelf ()) {
228+ 秘setPaintsSelf ();
229+ ((JSComponentUI ) ui ).clearPaintPath ();
230+ }
231+
225232 g .translate (x , (秘isContentPane ? 0 : y ));
226233 g .clipRect (0 , 0 , width , height ); // BH changed 2018.12.05 was setClip
227234 // }
@@ -325,41 +332,21 @@ public void updateUI() {
325332 return (/** @j2sNative g.mark$ ? g : */ null );
326333 }
327334
328- /**
329- * This method is added to ensure that if a jpanel or other object's
330- * background is painted to, that it becomes transparent -- since the actual
331- * painting is not to this canvas but instead to the JRootPane canvas.
332- *
333- * @param jsg
334- */
335- public void 秘checkBackgroundPainted (JSGraphics2D jsg , boolean init ) {
336- if (jsg == null || init ) {
337- 秘isBackgroundPainted = false ;
338- 秘gtemp = jsg ;
339- return ;
340- }
341- 秘gtemp = null ;
342- 秘isBackgroundPainted = 秘alwaysPaint || jsg .isBackgroundPainted ();
343- if (秘isBackgroundPainted ) {
344- ((JSComponentUI ) ui ).setPainted (jsg );
345- // It's all one canvas, and it is behind the root pane (bad design?)
346- // so if it is painted, we should make the root pane transparent
347- ((JSComponentUI ) ((JComponent ) this ).getRootPane ().getUI ()).setPainted (jsg );
348- }
349- }
350-
335+ @ SuppressWarnings ("unused" )
351336 @ Override
352337 public boolean isBackgroundSet () {
353338 return (background == null ? false
354339 : /** @j2sNative this.isAWT$ || */ false ? !(background instanceof UIResource ) : true );
355340 }
356341
342+ @ SuppressWarnings ("unused" )
357343 @ Override
358344 public boolean isForegroundSet () {
359345 return (foreground == null ? false
360346 : /** @j2sNative this.isAWT$ || */ false ? !(foreground instanceof UIResource ) : true );
361347 }
362348
349+ @ SuppressWarnings ("unused" )
363350 @ Override
364351 public boolean isFontSet () {
365352 return (font == null ? null : /** @j2sNative this.isAWT$ || */ false ? !(font instanceof FontUIResource ) : true );
@@ -464,6 +451,13 @@ public void validate() {
464451 秘checkBackgroundPainted (jcg , false );
465452 }
466453
454+ public void 秘paintContainerBackgroundCheck (Graphics g ) {
455+ JSGraphics2D jcg = 秘getJSGraphic2D (g );
456+ 秘checkBackgroundPainted (jcg , true );
457+ ((Container ) this ).paintContainer (g );
458+ 秘checkBackgroundPainted (jcg , false );
459+ }
460+
467461 @ Override
468462 public void addKeyListener (KeyListener l ) {
469463 super .addKeyListener (l );
@@ -525,38 +519,82 @@ public void removeKeyListener(KeyListener l) {
525519 return 秘isFocusableSet && isFocusable ();
526520 }
527521
528- /**
529- * will be set to 1 if paint(graphics) is found to be overridden, signally that
530- * we can't depend upon this component to be drawn by itself; JLabel will
531- * also set this to 1 if there there is an icon
532- *
533- */
534- protected int 秘paintOverridden = 0 ;
522+ /**
523+ * This method is added to ensure that if a jpanel or other object's
524+ * background is painted to, that it becomes transparent -- since the actual
525+ * painting is not to this canvas but instead to the JRootPane canvas.
526+ *
527+ * @param jsg
528+ */
529+ public void 秘checkBackgroundPainted (JSGraphics2D jsg , boolean init ) {
530+ if (jsg == null || init ) {
531+ // 秘isBackgroundPainted = false;
532+ 秘gtemp = jsg ;
533+ ((JSComponentUI ) ui ).paintBackground (jsg );
534+ return ;
535+ }
536+ 秘gtemp = null ;
537+ // 秘isBackgroundPainted = 秘alwaysPaint || jsg.isBackgroundPainted();
538+ // if (秘isBackgroundPainted) {
539+ // ((JSComponentUI) ui).setPainted(jsg);
540+ // // It's all one canvas, and it is behind the root pane (bad design?)
541+ // // so if it is painted, we should make the root pane transparent
542+ // ((JSComponentUI) ((JComponent) this).getRootPane().getUI()).setPainted(jsg);
543+ // }
544+ }
535545
546+ public int 秘setPaintsSelf () {
547+ return 秘iPaintMyself = PAINTS_SELF_YES ;
548+ }
549+
536550 /**
537- * A component in SwingJS can paint immediately if it is opaque (as in Java) or
538- * if its paint(Graphics) method is not overridden. Note that AWT Applet and Panel
539- * do override paint(graphics)
551+ * Used by:
552+ *
553+ * JComponent to checked to see if a component in SwingJS can paint immediately
554+ * because it is opaque or DOES NOT paint itself;
555+ *
556+ * JScrollPane to check if it needs to fire a repaint()
557+ * on the scrolled component; and
558+ *
559+ * JSComponentUI to check if it can use a CSS background
540560 *
541561 * @return
542562 */
543- public boolean canPaintImmediately () {
544- if (isOpaque ())
545- return true ;
546- if (秘paintOverridden == 0 ) {
547- if (((Container ) this ).getComponentCount () != 0 ) {
548- 秘paintOverridden = -1 ;
549- } else {
550- Object f = JSUtil .getJ2SAlias (this , "paint$java_awt_Graphics" );
551- 秘paintOverridden = (JSUtil .isOverridden (f , JComponent .class ) ? 1 : -1 );
552- }
563+ public boolean 秘paintsSelf () {
564+ if (秘iPaintMyself == PAINTS_SELF_UNKNOWN ) {
565+ // don't allow if not opaque and has components
566+ // don't allow if JComponent.paint(Graphics) has been overridden
567+ // don't allow if AbstractBorder.paintBorder(...) has been overridden
568+ // unchecked here is if a class calls getGraphics outside of this context
569+ 秘iPaintMyself = (JSUtil .isOverridden (this , "paint$java_awt_Graphics" , JComponent .class )
570+ || JSUtil .isOverridden (this , "paintComponent$java_awt_Graphics" , JComponent .class )
571+ || JSUtil .isOverridden (this , "paintContainer$java_awt_Graphics" , Container .class )
572+ || JSUtil .isOverridden (秘border , "paintBorder$java_awt_Component$java_awt_Graphics$I$I$I$I" ,
573+ AbstractBorder .class )
574+ ? 秘setPaintsSelf () : PAINTS_SELF_NO );
553575 }
554576 // TODO -- still need to set RepaintManager so that
555577 // objects with the same paintable root can be grouped together.
556-
557- return (秘paintOverridden == - 1 );
578+
579+ return (秘iPaintMyself == PAINTS_SELF_YES );
558580 }
559581
582+ /**
583+ * JScrollBar needs to know if we need to paint this component when it is scrolled
584+ *
585+ */
560586
587+ public boolean 秘selfOrChildIsPainted () {
588+ return 秘paintsSelf ();
589+ }
561590
591+ // private boolean childPaintsItself() {
592+ // Component[] a = JSComponent.秘getChildArray((Container) this);
593+ // for (int i = ((Container) this).getComponentCount(); --i >= 0;)
594+ // if (((JSComponent) a[i]).秘selfOrChildIsPainted())
595+ // return true;
596+ // return false;
597+ // }
598+
599+
562600}
0 commit comments