Skip to content

Commit 3e30a45

Browse files
Deprecate Image(Rectangle) constructor and replace usages
Deprecate Image constructor that accepts Rectangle in favor of Image(display, width, height).
1 parent dd30aff commit 3e30a45

File tree

6 files changed

+21
-14
lines changed

6 files changed

+21
-14
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Image.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,11 @@ public Image(Device device, Image srcImage, int flag) {
338338
* </ul>
339339
*
340340
* @see #dispose()
341+
*
342+
* @deprecated use {@link Image#Image(Device, int, int)} instead
343+
* @since 3.130
341344
*/
345+
@Deprecated
342346
public Image(Device device, Rectangle bounds) {
343347
super(device);
344348
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet215.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public static void main(String[] args) {
3838

3939
/* Take the screen shot */
4040
GC gc = new GC(display);
41-
final Image image = new Image(display, display.getBounds());
41+
Rectangle rect = display.getBounds();
42+
final Image image = new Image(display, rect.width, rect.height);
4243
gc.copyArea(image, 0, 0);
4344
gc.dispose();
4445

examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet292.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public static void main(String[] args) {
5555
button.addListener (SWT.Selection, e -> {
5656
Image image = label.getImage ();
5757
if (image != null) image.dispose ();
58-
image = new Image (display, group.getBounds ());
58+
Rectangle rect = group.getBounds();
59+
image = new Image (display, rect.width, rect.height);
5960
GC gc = new GC (image);
6061
boolean success = group.print (gc);
6162
gc.dispose ();

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Image.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,35 +124,35 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra
124124
Image image;
125125
IllegalArgumentException e;
126126
Rectangle bounds1 = null;
127-
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds1));
127+
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds1.width, bounds1.height));
128128
assertSWTProblem("Incorrect exception thrown for rectangle == null", SWT.ERROR_NULL_ARGUMENT, e);
129129

130130
Rectangle bounds2 = new Rectangle(0, 0, -1, 10);
131-
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds2));
131+
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds2.width, bounds2.height));
132132
assertSWTProblem("Incorrect exception thrown for width < 0", SWT.ERROR_INVALID_ARGUMENT, e);
133133

134134
Rectangle bounds3 = new Rectangle(0, 0, 0, 10);
135-
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds3));
135+
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds3.width, bounds3.height));
136136
assertSWTProblem("Incorrect exception thrown for width == 0", SWT.ERROR_INVALID_ARGUMENT, e);
137137

138138
Rectangle bounds4 = new Rectangle(0, 0, 10, -1);
139-
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds4));
139+
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds4.width, bounds4.height));
140140
assertSWTProblem("Incorrect exception thrown for height < 0", SWT.ERROR_INVALID_ARGUMENT, e);
141141

142142
Rectangle bounds5 = new Rectangle(0, 0, 10, 0);
143-
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds5));
143+
e = assertThrows(IllegalArgumentException.class, () -> new Image(display, bounds5.width, bounds5.height));
144144
assertSWTProblem("Incorrect exception thrown for height == 0", SWT.ERROR_INVALID_ARGUMENT, e);
145145

146146
// valid images
147147
Rectangle bounds = new Rectangle(-1, -10, 10, 10);
148-
image = new Image(display, bounds);
148+
image = new Image(display, bounds.width, bounds.height);
149149
image.dispose();
150150

151151
bounds = new Rectangle(0, 0, 10, 10);
152-
image = new Image(null, bounds);
152+
image = new Image(null, bounds.width, bounds.height);
153153
image.dispose();
154154

155-
image = new Image(display, bounds);
155+
image = new Image(display, bounds.width, bounds.height);
156156
image.dispose();
157157
}
158158

@@ -522,7 +522,7 @@ public void test_getBounds() {
522522
image.dispose();
523523
assertEquals(bounds, bounds1);
524524

525-
image = new Image(display, bounds);
525+
image = new Image(display, bounds.width, bounds.height);
526526
bounds1 = image.getBounds();
527527
image.dispose();
528528
assertEquals(bounds, bounds1);
@@ -694,7 +694,7 @@ void getImageData_int(int zoom) {
694694
assertEquals(":a: Size of ImageData returned from Image.getImageData(int) method doesn't return matches with bounds in Pixel values.", scaleBounds(bounds, zoom, 100), boundsAtZoom);
695695

696696
// creates second bitmap image and compare size of imageData
697-
image = new Image(display, bounds);
697+
image = new Image(display, bounds.width, bounds.height);
698698
imageDataAtZoom = image.getImageData(zoom);
699699
boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
700700
bounds = image.getBounds();

tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_TextLayout.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,8 @@ public void test_bug568740_multilineTextStyle() {
10091009
private Image draw(TextLayout layout, int antialias) {
10101010
GC gc = null;
10111011
try {
1012-
Image image = new Image(display, layout.getBounds());
1012+
Rectangle rect = layout.getBounds();
1013+
Image image = new Image(display, rect.width, rect.height);
10131014
gc = new GC(image);
10141015
gc.setBackground(display.getSystemColor(SWT.COLOR_WHITE));
10151016
gc.fillRectangle(image.getBounds());

tests/org.eclipse.swt.tests/ManualTests/org/eclipse/swt/tests/manual/Bug529534_CTabFolder_topRight_wrapped.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public static void main(String[] args) {
9696

9797
private static Image image(Display display, int shapeColor) {
9898
Rectangle bounds = new Rectangle(0, 0, 16, 16);
99-
Image image = new Image(display, bounds);
99+
Image image = new Image(display, bounds.width, bounds.height);
100100
GC gc = new GC(image);
101101
gc.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
102102
gc.fillRectangle(bounds);

0 commit comments

Comments
 (0)