13
13
*******************************************************************************/
14
14
package org .eclipse .swt .snippets ;
15
15
16
+ import java .util .function .*;
17
+
16
18
import org .eclipse .swt .*;
17
19
import org .eclipse .swt .graphics .*;
18
20
import org .eclipse .swt .layout .*;
@@ -65,8 +67,8 @@ public static void main (String [] args) {
65
67
final Display display = new Display ();
66
68
67
69
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 );
70
72
71
73
final Image imageWithDataProvider = new Image (display , imageDataProvider );
72
74
final Image disabledImageWithDataProvider = new Image (display ,imageWithDataProvider , SWT .IMAGE_DISABLE );
@@ -76,6 +78,10 @@ public static void main (String [] args) {
76
78
final Image disabledImageWithData = new Image (display ,imageWithData , SWT .IMAGE_DISABLE );
77
79
final Image greyImageWithData = new Image (display ,imageWithData , SWT .IMAGE_GRAY );
78
80
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
+
79
85
final ImageGcDrawer imageGcDrawer = (gc , width , height ) -> {
80
86
gc .setBackground (display .getSystemColor (SWT .COLOR_RED ));
81
87
gc .fillRectangle (0 , 0 , width , height );
@@ -111,42 +117,53 @@ public void handleEvent(Event e) {
111
117
if (e .type == SWT .Paint ) {
112
118
GC mainGC = e .gc ;
113
119
GCData gcData = mainGC .getGCData ();
114
-
120
+ gcData . nativeZoom = 100 ;
115
121
116
122
try {
123
+ mainGC .drawText ("--ImageFileNameProvider--" , 20 , 20 );
117
124
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 );
136
152
} finally {
137
153
mainGC .dispose ();
138
154
}
139
155
}
140
156
}
141
157
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 ) {
143
159
gcData .nativeZoom = 100 ;
144
160
mainGC .drawText (text , 0 , y );
145
- mainGC .drawImage (imageWithFileNameProvider , 50 , y );
161
+ mainGC .drawImage (image , 50 , y );
146
162
gcData .nativeZoom = 150 ;
147
- mainGC .drawImage (imageWithFileNameProvider , 100 , (int ) (y /1.5 ));
163
+ mainGC .drawImage (image , 100 , (int ) (y /1.5 ));
148
164
gcData .nativeZoom = 200 ;
149
- mainGC .drawImage (imageWithFileNameProvider , 150 , y /2 );
165
+ mainGC .drawImage (image , 150 , y /2 );
166
+ gcData .nativeZoom = 100 ;
150
167
}
151
168
};
152
169
shell .addListener (SWT .Paint , l );
0 commit comments