Skip to content

IllegalArgumentException for GMF cursors if display zoom is not 100%/200% #90

@ptziegler

Description

@ptziegler

See eclipse-emf/org.eclipse.emf#73 for context. The SEG_ADD and SEG_MOVE cursors are created using the following snippet:

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);
}

The problem: The source are two PNG files for 100% and 200% display zoom, respectively. If the zoom level is e.g. 125%, getImageData(125) returns null, which then triggers an IllegalArgumentException by SWT.

Suggestion:

Check if the image data for the given zoom level is null and if so, artificially scale it.

public static ImageData scaledImageData(ImageDescriptor descriptor, int zoom) {
    // Default case: Image in matching resolution has been found
    ImageData data = descriptor.getImageData(zoom);
    if (data != null) {
        return data;
    }
    // Otherwise artifically scale the image
    Image image = descriptor.createImage();
    try {
        return image.getImageData(zoom);
    } finally {
        image.dispose();
    }
}

Though I believe the provided ImageData should generally be at 100% zoom. Otherwise the scaling is done twice: Once by GMF and once by SWT (which would then lead to e.g. a 400% zoom cursor at 200% zoom).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions