Skip to content

Commit 0e04bc9

Browse files
ShahzaibIbrahimfedejeanne
authored andcommitted
Deprecation: Cursor(Device, ImageData, ImageData, int, int)
The constructor Cursor(Device, ImageData source, ImageData mask, int hotspotX, int hotspotY) allows creating a cursor by providing a source image and a 1-bit mask to define transparency. This approach requires developers to manually define mask pixels and works reliably only in fixed DPI environments.recommended to use: Cursor(Device device, ImageDataProvider imageDataProvider, int hotspotX, int hotspotY).
1 parent 9e1ccc7 commit 0e04bc9

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,10 @@ public Cursor(Device device, int style) {
276276
* </ul>
277277
*
278278
* @see #dispose()
279+
*
280+
* @deprecated Use {@link #Cursor(Device, ImageDataProvider, int, int)} instead.
279281
*/
282+
@Deprecated
280283
public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
281284
super(device);
282285
if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,10 @@ public Cursor(Device device, int style) {
184184
* </ul>
185185
*
186186
* @see #dispose()
187+
*
188+
* @deprecated Use {@link #Cursor(Device, ImageDataProvider, int, int)} instead.
187189
*/
190+
@Deprecated
188191
public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
189192
super(device);
190193
if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ public Cursor(Device device, int style) {
146146
* </ul>
147147
*
148148
* @see #dispose()
149+
*
150+
* @deprecated Use {@link #Cursor(Device, ImageDataProvider, int, int)} instead.
149151
*/
152+
@Deprecated
150153
public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
151154
super(device);
152155
this.cursorHandleProvider = new ImageDataWithMaskCursorHandleProvider(source, mask, hotspotX, hotspotY);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public void test_ConstructorLorg_eclipse_swt_graphics_DeviceLorg_eclipse_swt_gra
140140
ImageData source = loader.load(stream)[0];
141141
ImageData mask = source.getTransparencyMask();
142142
if (mask != null && (source.depth == 1)) {
143+
@SuppressWarnings("deprecation")
143144
Cursor cursor = new Cursor(display, source, mask, 0, 0);
144145
cursor.dispose();
145146
}
@@ -176,12 +177,14 @@ public void test_InvalidArgumentsForAllConstructors() {
176177
});
177178

178179
assertThrows("When source is null", IllegalArgumentException.class, () -> {
180+
@SuppressWarnings("deprecation")
179181
Cursor cursorFromImageAndMask = new Cursor(Display.getDefault(), null, mask, 0, 0);
180182
cursorFromImageAndMask.dispose();
181183
});
182184

183185
assertThrows("When mask is null and source doesn't heve a mask",
184186
IllegalArgumentException.class, () -> {
187+
@SuppressWarnings("deprecation")
185188
Cursor cursorFromImageAndMask = new Cursor(Display.getDefault(), source, null, 0, 0);
186189
cursorFromImageAndMask.dispose();
187190
});
@@ -191,12 +194,14 @@ public void test_InvalidArgumentsForAllConstructors() {
191194
ImageData source32 = new ImageData(32, 32, 1, new PaletteData(new RGB[] { new RGB(0, 0, 0) }));
192195
ImageData mask16 = new ImageData(16, 16, 1, new PaletteData(new RGB[] { new RGB(0, 0, 0) }));
193196

197+
@SuppressWarnings("deprecation")
194198
Cursor cursorFromImageAndMask = new Cursor(Display.getDefault(), source32, mask16, 0, 0);
195199
cursorFromImageAndMask.dispose();
196200
});
197201

198202
assertThrows("When hotspot is outside the bounds of the image",
199203
IllegalArgumentException.class, () -> {
204+
@SuppressWarnings("deprecation")
200205
Cursor cursorFromImageAndMask = new Cursor(Display.getDefault(), source, mask, 18, 18);
201206
cursorFromImageAndMask.dispose();
202207
});

0 commit comments

Comments
 (0)