1313 *******************************************************************************/
1414package org .eclipse .swt .snippets ;
1515
16+ import java .util .function .*;
17+
1618import org .eclipse .swt .*;
1719import org .eclipse .swt .graphics .*;
1820import org .eclipse .swt .layout .*;
@@ -65,8 +67,8 @@ public static void main (String [] args) {
6567 final Display display = new Display ();
6668
6769 final Image imageWithFileNameProvider = new Image (display , filenameProvider );
68- final Image disabledImageWithFileNameProvider = new Image (display ,imageWithFileNameProvider , SWT .IMAGE_DISABLE );
69- final Image greyImageWithFileNameProvider = new Image (display ,imageWithFileNameProvider , SWT .IMAGE_GRAY );
70+ final Supplier < Image > disabledImageWithFileNameProvider = () -> new Image (display ,imageWithFileNameProvider , SWT .IMAGE_DISABLE );
71+ final Supplier < Image > greyImageWithFileNameProvider = () -> new Image (display ,imageWithFileNameProvider , SWT .IMAGE_GRAY );
7072
7173 final Image imageWithDataProvider = new Image (display , imageDataProvider );
7274 final Image disabledImageWithDataProvider = new Image (display ,imageWithDataProvider , SWT .IMAGE_DISABLE );
@@ -76,6 +78,10 @@ public static void main (String [] args) {
7678 final Image disabledImageWithData = new Image (display ,imageWithData , SWT .IMAGE_DISABLE );
7779 final Image greyImageWithData = new Image (display ,imageWithData , SWT .IMAGE_GRAY );
7880
81+ final Supplier <Image > imageWithDataCopy = () -> new Image (display , imageWithDataProvider , SWT .IMAGE_COPY );
82+ final Supplier <Image > disabledImageWithDataCopy = () -> new Image (display ,disabledImageWithDataProvider , SWT .IMAGE_COPY );
83+ final Supplier <Image > greyImageWithDataCopy = () -> new Image (display ,greyImageWithDataProvider , SWT .IMAGE_COPY );
84+
7985 final ImageGcDrawer imageGcDrawer = (gc , width , height ) -> {
8086 gc .setBackground (display .getSystemColor (SWT .COLOR_RED ));
8187 gc .fillRectangle (0 , 0 , width , height );
@@ -111,42 +117,53 @@ public void handleEvent(Event e) {
111117 if (e .type == SWT .Paint ) {
112118 GC mainGC = e .gc ;
113119 GCData gcData = mainGC .getGCData ();
114-
120+ gcData . nativeZoom = 100 ;
115121
116122 try {
123+ mainGC .drawText ("--ImageFileNameProvider--" , 20 , 20 );
117124 drawImages (mainGC , gcData , "Normal" ,40 , imageWithFileNameProvider );
118- drawImages (mainGC , gcData , "Disabled" ,80 , disabledImageWithFileNameProvider );
119- drawImages (mainGC , gcData , "Greyed" ,120 , greyImageWithFileNameProvider );
120-
121- drawImages (mainGC , gcData , "Normal" ,160 , imageWithDataProvider );
122- drawImages (mainGC , gcData , "Disabled" ,200 , disabledImageWithDataProvider );
123- drawImages (mainGC , gcData , "Greyed" ,240 , greyImageWithDataProvider );
124-
125- drawImages (mainGC , gcData , "Normal" ,280 , imageWithDataProvider );
126- drawImages (mainGC , gcData , "Disabled" ,320 , disabledImageWithData );
127- drawImages (mainGC , gcData , "Greyed" ,360 , greyImageWithData );
128-
129- drawImages (mainGC , gcData , "Normal" , 400 , imageWithGcDrawer );
130- drawImages (mainGC , gcData , "Disabled" , 440 , disabledImageWithGcDrawer );
131- drawImages (mainGC , gcData , "Greyed" , 480 , greyImageWithGcDrawer );
132-
133- drawImages (mainGC , gcData , "Normal" , 520 , imageWithTransparentGcDrawer );
134- drawImages (mainGC , gcData , "Disabled" , 560 , disabledImageWithTransparentGcDrawer );
135- drawImages (mainGC , gcData , "Greyed" , 600 , greyImageWithTransparentGcDrawer );
125+ drawImages (mainGC , gcData , "Disabled" ,80 , disabledImageWithFileNameProvider .get ());
126+ drawImages (mainGC , gcData , "Greyed" ,120 , greyImageWithFileNameProvider .get ());
127+
128+ mainGC .drawText ("--ImageDataProvider--" , 20 , 150 );
129+ drawImages (mainGC , gcData , "Normal" ,180 , imageWithDataProvider );
130+ drawImages (mainGC , gcData , "Disabled" ,220 , disabledImageWithDataProvider );
131+ drawImages (mainGC , gcData , "Greyed" ,260 , greyImageWithDataProvider );
132+
133+ mainGC .drawText ("--Image with ImageData--" , 20 , 290 );
134+ drawImages (mainGC , gcData , "Normal" ,320 , imageWithData );
135+ drawImages (mainGC , gcData , "Disabled" ,360 , disabledImageWithData );
136+ drawImages (mainGC , gcData , "Greyed" ,400 , greyImageWithData );
137+
138+ mainGC .drawText ("--ImageDataProvider Copy--" , 20 , 430 );
139+ drawImages (mainGC , gcData , "Normal" ,460 , imageWithDataCopy .get ());
140+ drawImages (mainGC , gcData , "Disabled" ,500 , disabledImageWithDataCopy .get ());
141+ drawImages (mainGC , gcData , "Greyed" ,540 , greyImageWithDataCopy .get ());
142+
143+ mainGC .drawText ("--ImageGcDrawer--" , 20 , 570 );
144+ drawImages (mainGC , gcData , "Normal" , 600 , imageWithGcDrawer );
145+ drawImages (mainGC , gcData , "Disabled" , 640 , disabledImageWithGcDrawer );
146+ drawImages (mainGC , gcData , "Greyed" , 680 , greyImageWithGcDrawer );
147+
148+ mainGC .drawText ("--Transparent ImageGcDrawer--" , 20 , 710 );
149+ drawImages (mainGC , gcData , "Normal" , 740 , imageWithTransparentGcDrawer );
150+ drawImages (mainGC , gcData , "Disabled" , 780 , disabledImageWithTransparentGcDrawer );
151+ drawImages (mainGC , gcData , "Greyed" , 820 , greyImageWithTransparentGcDrawer );
136152 } finally {
137153 mainGC .dispose ();
138154 }
139155 }
140156 }
141157
142- private void drawImages (GC mainGC , GCData gcData , String text , int y , final Image imageWithFileNameProvider ) {
158+ private void drawImages (GC mainGC , GCData gcData , String text , int y , final Image image ) {
143159 gcData .nativeZoom = 100 ;
144160 mainGC .drawText (text , 0 , y );
145- mainGC .drawImage (imageWithFileNameProvider , 50 , y );
161+ mainGC .drawImage (image , 50 , y );
146162 gcData .nativeZoom = 150 ;
147- mainGC .drawImage (imageWithFileNameProvider , 100 , (int ) (y /1.5 ));
163+ mainGC .drawImage (image , 100 , (int ) (y /1.5 ));
148164 gcData .nativeZoom = 200 ;
149- mainGC .drawImage (imageWithFileNameProvider , 150 , y /2 );
165+ mainGC .drawImage (image , 150 , y /2 );
166+ gcData .nativeZoom = 100 ;
150167 }
151168 };
152169 shell .addListener (SWT .Paint , l );
0 commit comments