Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/******************************************************************************
* Copyright (c) 2002, 2003 IBM Corporation and others.
* Copyright (c) 2002, 2025 IBM Corporation and others.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
Expand All @@ -12,14 +12,18 @@

package org.eclipse.gmf.runtime.gef.ui.internal.l10n;

import org.eclipse.swt.graphics.Cursor;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Device;
import org.eclipse.swt.graphics.ImageDataProvider;

/**
* This is class that stores a series of globally accessible cursors.
* Stores a series of globally accessible cursors.
*
* @author sshaw
*
*/
public class Cursors {

Expand All @@ -30,30 +34,27 @@ public class Cursors {
public static final Cursor CURSOR_SEG_ADD;

/**
* Constant define for a cusor used to move an existing line segment
* Constant define for a cursor used to move an existing line segment
*/
public static final Cursor CURSOR_SEG_MOVE;

private static int deviceZoom = -1;

static {
CURSOR_SEG_ADD = new Cursor(null, GefUIPluginImages.DESC_SEG_ADD.getImageData(getDeviceZoom()), 0, 0);
CURSOR_SEG_MOVE = new Cursor(null, GefUIPluginImages.DESC_SEG_MOVE.getImageData(getDeviceZoom()), 0, 0);
CURSOR_SEG_ADD = createCursor(GefUIPluginImages.DESC_SEG_ADD, 0, 0);
CURSOR_SEG_MOVE = createCursor(GefUIPluginImages.DESC_SEG_MOVE, 0, 0);
}

// Taken from org.eclipse.gef.SharedCursors.java
private static int getDeviceZoom() {
if (deviceZoom == -1) {
deviceZoom = 100; // default value
String deviceZoomProperty = System.getProperty("org.eclipse.swt.internal.deviceZoom"); //$NON-NLS-1$
if (deviceZoomProperty != null) {
try {
deviceZoom = Integer.parseInt(deviceZoomProperty);
} catch (NumberFormatException ex) {
// if the property can not be parsed we keep the default 100% zoom level
}
}
// Taken from org.eclipse.gef.internal.InternalGEFPlugin.java
// https://github.com/eclipse-gef/gef-classic/blob/467992a631d37b3a5268765ad87bcae8425a9d21/org.eclipse.gef/src/org/eclipse/gef/internal/InternalGEFPlugin.java#L127
private static Cursor createCursor(ImageDescriptor source, int hotspotX, int hotspotY) {
try {
Constructor<Cursor> ctor = Cursor.class.getConstructor(Device.class, ImageDataProvider.class, int.class,
int.class);
return ctor.newInstance(null, (ImageDataProvider) source::getImageData, hotspotX, hotspotY);
} catch (NoSuchMethodException e) {
// SWT version < 3.131.0 (no ImageDataProvider-based constructor)
return new Cursor(null, source.getImageData(100), hotspotX, hotspotY); // older constructor
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Failed to instantiate Cursor", e); //$NON-NLS-1$
}
return deviceZoom;
}
}