@@ -289,7 +289,7 @@ private JSTableHeaderUI getHeaderUI() {
289289 * @param col
290290 * @return
291291 */
292- private JSComponent getCellComponent (TableCellRenderer renderer , int row , int col , int w , int h , DOMNode td ,
292+ private JSComponent getCellRendererComponent (TableCellRenderer renderer , int row , int col , int w , int h , DOMNode td ,
293293 boolean fullPaint ) {
294294 // SwingJS adds the idea that the default renderers need only be prepared once
295295 // the
@@ -298,27 +298,33 @@ private JSComponent getCellComponent(TableCellRenderer renderer, int row, int co
298298 // one.
299299 JSComponent cNoPrep = /** @j2sNative renderer.秘getComponent$ && renderer.秘getComponent$() || */
300300 null ;
301- JSComponent c = (cNoPrep == null ? (JSComponent ) table .prepareRenderer (renderer , row , col ) : cNoPrep );
301+ JSComponent c = (cNoPrep == null ? (JSComponent ) table .prepareRenderer (renderer , row , col ) : cNoPrep );
302302 if (c != null ) {
303- JSComponentUI ui = c .秘getUI ();
304- boolean wasDisabled = ui .isUIDisabled ;
305- c .秘reshape (c .getX (), c .getY (), w , h , false );
306- ui .setRenderer (c , w , h , null );
307- ui .setTargetParent (table );
308- if (fullPaint && wasDisabled || cNoPrep != null ) {
309- // repeat, now that the UI is enabled
310- if (wasDisabled ) {
311- ui .restoreCellNodes (td );
312- // at this point td COULD still empty, if we wanted it to be, and
313- // domNode is just an attribute of td.
314- }
315- ui .setTainted ();
303+ if (prepareCellRendererUI (c , cNoPrep != null , w , h , td , fullPaint , (JComponent ) table ))
316304 table .prepareRenderer (renderer , row , col );
317- }
318305 }
319306 return c ;
320307 }
321308
309+ static boolean prepareCellRendererUI (JSComponent c , boolean forcePrep , int w , int h , DOMNode td , boolean fullPaint , JComponent table ) {
310+ JSComponentUI ui = c .秘getUI ();
311+ boolean wasDisabled = ui .isUIDisabled ;
312+ c .秘reshape (c .getX (), c .getY (), w , h , false );
313+ ui .setRenderer (c , w , h , null );
314+ ui .setTargetParent (table );
315+ if (fullPaint && wasDisabled || forcePrep ) {
316+ // repeat, now that the UI is enabled
317+ if (wasDisabled ) {
318+ ui .restoreCellNodes (td );
319+ // at this point td COULD still empty, if we wanted it to be, and
320+ // domNode is just an attribute of td.
321+ }
322+ ui .setTainted ();
323+ return true ;
324+ }
325+ return false ;
326+ }
327+
322328 @ Override
323329 protected Component [] getChildren () {
324330 return null ;
@@ -434,12 +440,7 @@ private DOMNode addElements(int rminx, int rminy, int rmaxx, int rmaxy, int h, i
434440 w = cw [col ];
435441 if (tx + w < rminx )
436442 continue ;
437- DOMNode td = CellHolder .findCellNode (this , null , row , col );
438- if (td == null ) {
439- td = CellHolder .createCellOuterNode (this , row , col );
440- tr .appendChild (td );
441- }
442- DOMNode .setStyles (td , "left" , tx + "px" , "width" , w + "px" , "height" , "inherit" , "top" , ty + "px" );
443+ DOMNode td = CellHolder .findOrCreateNode ((JSComponentUI ) this , row , col , tx , ty , w , tr );
443444 updateCellNode (td , row , col , w , h );
444445 if (rminx < 0 )
445446 return td ;
@@ -449,9 +450,9 @@ private DOMNode addElements(int rminx, int rminy, int rmaxx, int rmaxy, int h, i
449450 }
450451
451452 private void updateCellNode (DOMNode td , int row , int col , int w , int h ) {
452- JSComponent cell = (JSComponent ) getCellComponent (table .getCellRenderer (row , col ), row , col , w , h , td , true );
453- if (cell != null )
454- CellHolder .updateCellNode (td , cell , -1 , -1 );
453+ JSComponent c = (JSComponent ) getCellRendererComponent (table .getCellRenderer (row , col ), row , col , w , h , td , true );
454+ if (c != null )
455+ CellHolder .updateCellNode (td , c , -1 , -1 );
455456 }
456457
457458 JComponent editorComp ;
@@ -2399,49 +2400,50 @@ private void paintCells(Graphics g, int rMin0, int rMax0, int rMin, int rMax, in
23992400 havePainted = true ;
24002401 }
24012402
2402- private void paintCell (Graphics g , Rectangle cellRect , int row , int col , int h , DOMNode tr ,
2403- boolean forceNew , boolean colTainted ) {
2403+ private void paintCell (Graphics g , Rectangle cellRect , int row , int col , int h , DOMNode tr , boolean forceNew ,
2404+ boolean colTainted ) {
24042405
24052406 if (table .isEditing () && table .getEditingRow () == row && table .getEditingColumn () == col ) {
24062407 Component component = table .getEditorComponent ();
24072408 if (component instanceof JTextField ) {
2408- component .setBounds (new Rectangle (cellRect .x - 2 , cellRect .y - 2 , cellRect .width , cellRect .height ));
2409+ component .setBounds (new Rectangle (cellRect .x - 2 , cellRect .y - 2 , cellRect .width , cellRect .height ));
24092410 } else {
24102411 component .setBounds (cellRect );
24112412 }
24122413 component .validate ();
2413- } else {
2414- // Get the appropriate rendering component
2415- // and switch its ui domNode to the one for the
2416- // given row and column. Painting the component
2417- // then modifies this particular cell. and switch it back
2418- DOMNode td = (forceNew || tr == null ? null : CellHolder .findCellNode (this , null , row , col ));
2419- boolean newtd = (td == null );
2420- if (newtd ) {
2421- td = addElement (row , col , h );
2422- } else if (colTainted ) {
2423- DOMNode .setStyles (td , "left" , cellRect .x + "px" , "width" , cw [col ] + "px" , "display" , null );
2424- } else {
2425- DOMNode .setStyle (td , "display" , null );
2426- }
2427- boolean fullPaint = (newtd || !havePainted || !isScrolling || table .getSelectedRowCount () > 0 );
2428- TableCellRenderer renderer = (fullPaint ? table .getCellRenderer (row , col )
2429- : table .getCellRendererOrNull (row , col , isScrolling ));
2430- if (!fullPaint ) {
2431- // no need to paint the default renderers with nothing selected
2432- /**
2433- * @j2sNative if (!renderer || renderer.__CLASS_NAME__.indexOf("javax.swing.") == 0) return;
2434- */
2435- }
2436- JComponent comp = (JComponent ) getCellComponent (renderer , row , col , cw [col ], h , td , fullPaint );
2437- if (comp == null )
2438- return ;
2439- boolean shouldValidate = fullPaint && !isScrolling ;
2440- rendererPane .paintComponent (g , comp , table , cellRect .x , cellRect .y , cellRect .width , cellRect .height ,
2441- shouldValidate );
2442- // Note that this sets ui.jc = null.
2443- comp .秘getUI ().setRenderer (null , 0 , 0 , td );
2414+ return ;
24442415 }
2416+ // Get the appropriate rendering component
2417+ // and switch its ui domNode to the one for the
2418+ // given row and column. Painting the component
2419+ // then modifies this particular cell. and switch it back
2420+ DOMNode td = (forceNew || tr == null ? null : CellHolder .findCellNode (this , null , row , col ));
2421+ boolean newtd = (td == null );
2422+ if (newtd ) {
2423+ td = addElement (row , col , h );
2424+ } else if (colTainted ) {
2425+ DOMNode .setStyles (td , "left" , cellRect .x + "px" , "width" , cw [col ] + "px" , "display" , null );
2426+ } else {
2427+ DOMNode .setStyle (td , "display" , null );
2428+ }
2429+ boolean fullPaint = (newtd || !havePainted || !isScrolling || table .getSelectedRowCount () > 0 );
2430+ TableCellRenderer renderer = (fullPaint ? table .getCellRenderer (row , col )
2431+ : table .getCellRendererOrNull (row , col , isScrolling ));
2432+ if (!fullPaint ) {
2433+ // no need to paint the default renderers with nothing selected
2434+ /**
2435+ * @j2sNative if (!renderer || renderer.__CLASS_NAME__.indexOf("javax.swing.")
2436+ * == 0) return;
2437+ */
2438+ }
2439+ JComponent comp = (JComponent ) getCellRendererComponent (renderer , row , col , cw [col ], h , td , fullPaint );
2440+ if (comp == null )
2441+ return ;
2442+ boolean shouldValidate = fullPaint && !isScrolling ;
2443+ rendererPane .paintComponent (g , comp , table , cellRect .x , cellRect .y , cellRect .width , cellRect .height ,
2444+ shouldValidate );
2445+ // Note that this sets ui.jc = null.
2446+ comp .秘getUI ().setRenderer (null , 0 , 0 , td );
24452447 }
24462448
24472449 /*
0 commit comments