1313package org .eclipse .gef .ui .palette ;
1414
1515import java .beans .PropertyChangeSupport ;
16+ import java .lang .reflect .Constructor ;
17+ import java .lang .reflect .InvocationTargetException ;
1618import java .util .ArrayList ;
1719import java .util .List ;
1820import java .util .function .BiConsumer ;
3234import org .eclipse .swt .events .MouseTrackAdapter ;
3335import org .eclipse .swt .events .MouseTrackListener ;
3436import org .eclipse .swt .graphics .Cursor ;
37+ import org .eclipse .swt .graphics .Device ;
3538import org .eclipse .swt .graphics .Font ;
3639import org .eclipse .swt .graphics .GC ;
37- import org .eclipse .swt .graphics .ImageData ;
40+ import org .eclipse .swt .graphics .ImageDataProvider ;
3841import org .eclipse .swt .graphics .Point ;
3942import org .eclipse .swt .graphics .Rectangle ;
4043import org .eclipse .swt .widgets .Canvas ;
8891import org .eclipse .gef .GraphicalViewer ;
8992import org .eclipse .gef .dnd .TemplateTransfer ;
9093import org .eclipse .gef .internal .GEFMessages ;
91- import org .eclipse .gef .internal .InternalGEFPlugin ;
9294import org .eclipse .gef .internal .InternalImages ;
9395import org .eclipse .gef .ui .views .palette .PaletteView ;
9496
@@ -1608,13 +1610,19 @@ public static Cursor getCursor(int code) {
16081610 */
16091611 private static Cursor createCursor (String sourceName ) {
16101612 ImageDescriptor source = PlatformUI .getWorkbench ().getSharedImages ().getImageDescriptor (sourceName );
1611- int deviceZoom = InternalGEFPlugin .getOrDefaultDeviceZoom ();
1612- // Scales the image if the display is using neither 100% nor 200% zoom
1613- ImageData sourceData = InternalGEFPlugin .scaledImageData (source , deviceZoom );
16141613 // Hotspot should be the center of the image. e.g. (16, 16) on 100% zoom
1615- int hotspotX = sourceData .width / 2 ;
1616- int hotspotY = sourceData .height / 2 ;
1617- return new Cursor (null , sourceData , hotspotX , hotspotY );
1614+ int hotspotX = source .getImageData (100 ).width / 2 ;
1615+ int hotspotY = source .getImageData (100 ).height / 2 ;
1616+ try {
1617+ Constructor <Cursor > ctor = Cursor .class .getConstructor (Device .class , ImageDataProvider .class , int .class ,
1618+ int .class );
1619+ return ctor .newInstance (null , (ImageDataProvider ) source ::getImageData , hotspotX , hotspotY );
1620+ } catch (NoSuchMethodException e ) {
1621+ // SWT version < 3.131.0 (no ImageDataProvider-based constructor)
1622+ return new Cursor (null , source .getImageData (100 ), hotspotX , hotspotY ); // older constructor
1623+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException e ) {
1624+ throw new RuntimeException ("Failed to instantiate Cursor" , e ); //$NON-NLS-1$
1625+ }
16181626 }
16191627 }
16201628}
0 commit comments