2424import org .eclipse .swt .graphics .Color ;
2525import org .eclipse .swt .graphics .GC ;
2626import org .eclipse .swt .graphics .Image ;
27+ import org .eclipse .swt .graphics .ImageGcDrawer ;
2728import org .eclipse .swt .graphics .Point ;
2829import org .eclipse .swt .graphics .Rectangle ;
2930import org .eclipse .swt .widgets .Composite ;
@@ -314,9 +315,9 @@ private void putTitleBarColor(String key, Color color) {
314315
315316 @ Override
316317 protected void onPaint (PaintEvent e ) {
317- Color bg = null ;
318- Color fg = null ;
319- Color border = null ;
318+ Color bg = ( titleColors != null ) ? titleColors . getOrDefault ( COLOR_BG , getBackground ()) : getBackground () ;
319+ Color fg = ( titleColors != null ) ? getTitleBarForeground () : getForeground () ;
320+ Color border = ( titleColors != null ) ? titleColors . getOrDefault ( COLOR_BORDER , fg ) : fg ;
320321
321322 GC gc = e .gc ;
322323 Image buffer = null ;
@@ -326,85 +327,81 @@ protected void onPaint(PaintEvent e) {
326327 return ;
327328 }
328329 boolean hasTitleBar = (getExpansionStyle () & TITLE_BAR ) != 0 ;
329- int theight = 5 ;
330- int gradientheight = 0 ;
331330 int tvmargin = IGAP ;
332331
333- bg = (titleColors != null ) ? titleColors .getOrDefault (COLOR_BG , getBackground ()) : getBackground ();
334- fg = (titleColors != null ) ? getTitleBarForeground () : getForeground ();
335- border = (titleColors != null ) ? titleColors .getOrDefault (COLOR_BORDER , fg ) : fg ;
336-
337332 if (hasTitleBar ) {
338- buffer = new Image (getDisplay (), bounds .width , bounds .height );
339- buffer .setBackground (getBackground ());
340- gc = new GC (buffer );
341-
342- // calculate height
343- Point tsize = null ;
344- Point tcsize = null ;
345- if (toggle != null )
346- tsize = toggle .getSize ();
347- if (getTextClient () != null )
348- tcsize = getTextClient ().getSize ();
349- Point size = textLabel == null ? new Point (0 ,0 ) : textLabel .getSize ();
350- if (tsize != null )
351- theight += Math .max (theight , tsize .y );
352- gradientheight = theight ;
353- if (tcsize != null ) {
354- theight = Math .max (theight , tcsize .y );
355- }
356- theight = Math .max (theight , size .y );
357- gradientheight = Math .max (gradientheight , size .y );
358- theight += tvmargin + tvmargin ;
359- gradientheight += tvmargin + tvmargin ;
360-
361- // Background
362- if (getBackgroundImage () == null )
363- updateHeaderImage (bg , bounds , gradientheight , theight );
364- gc .setBackground (getBackground ());
365- gc .fillRectangle (bounds .x , bounds .y , bounds .width , bounds .height );
366- drawBackground (gc , bounds .x , bounds .y , bounds .width , theight - 2 );
367- if (marginWidth > 0 ) {
368- // fix up margins
369- gc .setBackground (getBackground ());
370- gc .fillRectangle (0 , 0 , marginWidth , theight );
371- gc .fillRectangle (bounds .x + bounds .width - marginWidth , 0 ,
372- marginWidth , theight );
373- }
374- gc .setBackground (getBackground ());
375- FormUtil .setAntialias (gc , SWT .ON );
376- // repair the upper left corner
377- gc .fillPolygon (new int [] { marginWidth , marginHeight , marginWidth ,
378- marginHeight + 2 , marginWidth + 2 , marginHeight });
379- // repair the upper right corner
380- gc .fillPolygon (new int [] { bounds .width - marginWidth - 3 ,
381- marginHeight , bounds .width - marginWidth , marginHeight ,
382- bounds .width - marginWidth , marginHeight + 3 });
383- gc .setForeground (border );
384-
385- // Draw Lines
386- // top left curve
387- gc .drawLine (marginWidth , marginHeight + 2 , marginWidth + 2 , marginHeight );
388- // top edge
389- gc .drawLine (marginWidth + 2 , marginHeight , bounds .width - marginWidth - 3 , marginHeight );
390- // top right curve
391- gc .drawLine (bounds .width - marginWidth - 3 , marginHeight , bounds .width - marginWidth - 1 , marginHeight + 2 );
392-
393- // Expand conditions
394- // left vertical edge gradient
395- gc .fillGradientRectangle (marginWidth , marginHeight + 2 , 1 , theight + 2 , true );
396- // right vertical edge gradient
397- gc .fillGradientRectangle (bounds .width - marginWidth - 1 , marginHeight + 2 , 1 , theight + 2 , true );
398-
399- // New in 3.3 - edge treatment
400- gc .setForeground (getBackground ());
401- gc .drawPolyline (new int [] { marginWidth + 1 , marginHeight + gradientheight + 4 , marginWidth + 1 ,
402- marginHeight + 2 , marginWidth + 2 , marginHeight + 2 , marginWidth + 2 , marginHeight + 1 ,
403- bounds .width - marginWidth - 3 , marginHeight + 1 , bounds .width - marginWidth - 3 , marginHeight + 2 ,
404- bounds .width - marginWidth - 2 , marginHeight + 2 , bounds .width - marginWidth - 2 ,
405- marginHeight + gradientheight + 4 });
333+ final ImageGcDrawer imageGcDrawer = (iGc , width , height ) -> {
334+ // calculate height
335+ int gradientheight = 0 ;
336+ int theight = 5 ;
337+ Point tsize = null ;
338+ Point tcsize = null ;
339+ if (toggle != null )
340+ tsize = toggle .getSize ();
341+ if (getTextClient () != null )
342+ tcsize = getTextClient ().getSize ();
343+ Point size = textLabel == null ? new Point (0 , 0 ) : textLabel .getSize ();
344+ if (tsize != null )
345+ theight += Math .max (theight , tsize .y );
346+ gradientheight = theight ;
347+ if (tcsize != null ) {
348+ theight = Math .max (theight , tcsize .y );
349+ }
350+ theight = Math .max (theight , size .y );
351+ gradientheight = Math .max (gradientheight , size .y );
352+ theight += tvmargin + tvmargin ;
353+ gradientheight += tvmargin + tvmargin ;
354+
355+ // Background
356+ if (getBackgroundImage () == null )
357+ updateHeaderImage (bg , bounds , gradientheight , theight );
358+ iGc .setBackground (getBackground ());
359+ iGc .fillRectangle (bounds .x , bounds .y , width , height );
360+ drawBackground (iGc , bounds .x , bounds .y , width , theight - 2 );
361+ if (marginWidth > 0 ) {
362+ // fix up margins
363+ iGc .setBackground (getBackground ());
364+ iGc .fillRectangle (0 , 0 , marginWidth , theight );
365+ iGc .fillRectangle (bounds .x + width - marginWidth , 0 , marginWidth , theight );
366+ }
367+ iGc .setBackground (getBackground ());
368+ FormUtil .setAntialias (iGc , SWT .ON );
369+ // repair the upper left corner
370+ iGc .fillPolygon (new int [] { marginWidth , marginHeight , marginWidth , marginHeight + 2 , marginWidth + 2 ,
371+ marginHeight });
372+ // repair the upper right corner
373+ iGc .fillPolygon (new int [] { width - marginWidth - 3 , marginHeight , width - marginWidth , marginHeight ,
374+ width - marginWidth , marginHeight + 3 });
375+ iGc .setForeground (border );
376+
377+ // Draw Lines
378+ // top left curve
379+ iGc .drawLine (marginWidth , marginHeight + 2 , marginWidth + 2 , marginHeight );
380+ // top edge
381+ iGc .drawLine (marginWidth + 2 , marginHeight , width - marginWidth - 3 , marginHeight );
382+ // top right curve
383+ iGc .drawLine (width - marginWidth - 3 , marginHeight , width - marginWidth - 1 ,
384+ marginHeight + 2 );
385+
386+ // Expand conditions
387+ // left vertical edge gradient
388+ iGc .fillGradientRectangle (marginWidth , marginHeight + 2 , 1 , theight + 2 , true );
389+ // right vertical edge gradient
390+ iGc .fillGradientRectangle (width - marginWidth - 1 , marginHeight + 2 , 1 , theight + 2 , true );
391+
392+ // New in 3.3 - edge treatment
393+ iGc .setForeground (getBackground ());
394+ iGc .drawPolyline (new int [] { marginWidth + 1 , marginHeight + gradientheight + 4 , marginWidth + 1 ,
395+ marginHeight + 2 , marginWidth + 2 , marginHeight + 2 , marginWidth + 2 , marginHeight + 1 ,
396+ width - marginWidth - 3 , marginHeight + 1 , width - marginWidth - 3 , marginHeight + 2 ,
397+ width - marginWidth - 2 , marginHeight + 2 , width - marginWidth - 2 ,
398+ marginHeight + gradientheight + 4 });
399+ };
406400
401+ buffer = new Image (getDisplay (), imageGcDrawer , bounds .width , bounds .height );
402+ buffer .setBackground (getBackground ());
407403 } else if (isExpanded ()) {
404+ int theight = 5 ;
408405 gc .setForeground (bg );
409406 gc .setBackground (getBackground ());
410407 gc .fillGradientRectangle (marginWidth , marginHeight , bounds .width
@@ -431,7 +428,6 @@ protected void onPaint(PaintEvent e) {
431428 }
432429
433430 if (buffer != null ) {
434- gc .dispose ();
435431 e .gc .drawImage (buffer , 0 , 0 );
436432 buffer .dispose ();
437433 }
0 commit comments