Skip to content

Commit 5170784

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 5170784

File tree

8 files changed

+19
-6
lines changed

8 files changed

+19
-6
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,10 @@ private void createRepFromSourceAndApplyFlag(NSBitmapImageRep srcRep, int srcWid
527527
* </ul>
528528
*
529529
* @see #dispose()
530+
*
531+
* @deprecated use {@link Image#Image(Device, int, int)} instead
530532
*/
533+
@Deprecated(since = "2025-06", forRemoval = true)
531534
public Image(Device device, Rectangle bounds) {
532535
super(device);
533536
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,10 @@ public Image(Device device, Image srcImage, int flag) {
403403
* </ul>
404404
*
405405
* @see #dispose()
406+
*
407+
* @deprecated use {@link Image#Image(Device, int, int)} instead
406408
*/
409+
@Deprecated(since = "2025-06", forRemoval = true)
407410
public Image(Device device, Rectangle bounds) {
408411
super(device);
409412
if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,10 @@ 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
341343
*/
344+
@Deprecated(since = "2025-06", forRemoval = true)
342345
public Image(Device device, Rectangle bounds) {
343346
super(device);
344347
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceII() {
119119
image.dispose();
120120
}
121121

122+
@SuppressWarnings("removal")
122123
@Test
123124
public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_graphics_Rectangle() {
124125
Image image;
@@ -522,7 +523,7 @@ public void test_getBounds() {
522523
image.dispose();
523524
assertEquals(bounds, bounds1);
524525

525-
image = new Image(display, bounds);
526+
image = new Image(display, bounds.width, bounds.height);
526527
bounds1 = image.getBounds();
527528
image.dispose();
528529
assertEquals(bounds, bounds1);
@@ -694,7 +695,7 @@ void getImageData_int(int zoom) {
694695
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);
695696

696697
// creates second bitmap image and compare size of imageData
697-
image = new Image(display, bounds);
698+
image = new Image(display, bounds.width, bounds.height);
698699
imageDataAtZoom = image.getImageData(zoom);
699700
boundsAtZoom = new Rectangle(0, 0, imageDataAtZoom.width, imageDataAtZoom.height);
700701
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)