2828import org .eclipse .swt .graphics .Device ;
2929import org .eclipse .swt .graphics .GC ;
3030import org .eclipse .swt .graphics .Image ;
31+ import org .eclipse .swt .graphics .ImageGcDrawer ;
3132import org .eclipse .swt .graphics .Path ;
3233import org .eclipse .swt .graphics .Pattern ;
3334import org .eclipse .swt .graphics .Point ;
3435import org .eclipse .swt .graphics .Rectangle ;
36+ import org .eclipse .swt .internal .TransparencyColorImageGcDrawer ;
3537import org .eclipse .swt .layout .FormAttachment ;
3638import org .eclipse .swt .layout .FormData ;
3739import org .eclipse .swt .layout .FormLayout ;
@@ -325,11 +327,10 @@ static Image createThumbnail(Device device, String name) {
325327 Rectangle src = image .getBounds ();
326328 Image result = null ;
327329 if (src .width != 16 || src .height != 16 ) {
328- result = new Image (device , 16 , 16 );
329- GC gc = new GC (result );
330- Rectangle dest = result .getBounds ();
331- gc .drawImage (image , dest .x , dest .y , dest .width , dest .height );
332- gc .dispose ();
330+ ImageGcDrawer igc = (gc , iwidth , iheight ) -> {
331+ gc .drawImage (image , src .x , src .y , src .width , src .height , 0 , 0 , iwidth , iheight );
332+ };
333+ result = new Image (device , igc , 16 , 16 );
333334 }
334335 if (result != null ) {
335336 image .dispose ();
@@ -347,19 +348,26 @@ static Image createThumbnail(Device device, String name) {
347348 *
348349 * */
349350static Image createImage (Device device , Color color1 , Color color2 , int width , int height ) {
350- Image image = new Image (device , width , height );
351- GC gc = new GC (image );
352- Rectangle rect = image .getBounds ();
353- Pattern pattern = new Pattern (device , rect .x , rect .y , rect .width - 1 ,
354- rect .height - 1 , color1 , color2 );
355- gc .setBackgroundPattern (pattern );
356- gc .fillRectangle (rect );
357- gc .drawRectangle (rect .x , rect .y , rect .width - 1 , rect .height - 1 );
358- gc .dispose ();
359- pattern .dispose ();
351+ ImageGcDrawer igc = (gc , iwidth , iheight ) -> {
352+ Pattern pattern = new Pattern (device , 0 , 0 , iwidth - 1 ,
353+ iheight - 1 , color1 , color2 );
354+ gc .setBackgroundPattern (pattern );
355+ gc .fillRectangle (0 ,0 ,iwidth ,iheight );
356+ gc .drawRectangle (0 , 0 , iwidth - 1 , iheight - 1 );
357+ pattern .dispose ();
358+ };
359+ Image image = new Image (device , igc , width , height );
360360 return image ;
361361}
362362
363+ private static Color getTransparencyColor (Device device , Color color ) {
364+ Color transparencyColor = device .getSystemColor (SWT .COLOR_CYAN );
365+ if (transparencyColor .equals (color )) {
366+ transparencyColor = device .getSystemColor (SWT .COLOR_DARK_BLUE );
367+ }
368+ return transparencyColor ;
369+ }
370+
363371/**
364372 * Creates an image based on the color provided and returns it.
365373 *
@@ -368,16 +376,21 @@ static Image createImage(Device device, Color color1, Color color2, int width, i
368376 *
369377 * */
370378static Image createImage (Device device , Color color ) {
371- Image image = new Image (device , 16 , 16 );
372- GC gc = new GC (image );
373- gc .setBackground (color );
374- Rectangle rect = image .getBounds ();
375- gc .fillRectangle (rect );
376- if (color .equals (device .getSystemColor (SWT .COLOR_BLACK ))) {
377- gc .setForeground (device .getSystemColor (SWT .COLOR_WHITE ));
378- }
379- gc .drawRectangle (rect .x , rect .y , rect .width - 1 , rect .height - 1 );
380- gc .dispose ();
379+ @ SuppressWarnings ("restriction" )
380+ ImageGcDrawer iGC = new TransparencyColorImageGcDrawer (getTransparencyColor (device , color )) {
381+ @ Override
382+ public void drawOn (GC gc , int imageWidth , int imageHeight ) {
383+ gc .setBackground (getTransparencyColor (device , color ));
384+ gc .fillRectangle (0 , 0 , imageWidth , imageHeight );
385+ gc .setBackground (color );
386+ gc .fillRectangle (0 , 0 , imageWidth - 1 , imageHeight - 1 );
387+ if (color .equals (device .getSystemColor (SWT .COLOR_BLACK ))) {
388+ gc .setForeground (device .getSystemColor (SWT .COLOR_WHITE ));
389+ }
390+ gc .drawRectangle (0 , 0 , imageWidth - 1 , imageHeight - 1 );
391+ }
392+ };
393+ Image image = new Image (device , iGC , 16 , 16 );
381394 return image ;
382395}
383396
0 commit comments