Example usage for java.awt Cursor getType

List of usage examples for java.awt Cursor getType

Introduction

In this page you can find the example usage for java.awt Cursor getType.

Prototype

public int getType() 

Source Link

Document

Returns the type for this cursor.

Usage

From source file:org.eclipse.birt.chart.device.swing.SwingEventHandler.java

private void setCursor(JComponent composite, org.eclipse.birt.chart.model.attribute.Cursor cursor,
        Cursor defaultCursor) {//from w  w w . j  a  v a 2  s  . c om
    if (cursor == null || cursor.getType() == CursorType.AUTO) {
        composite.setCursor(defaultCursor);
        return;
    } else if (cursor.getType() == CursorType.CUSTOM) {
        // Find the first valid image as custom cursor.
        EList<org.eclipse.birt.chart.model.attribute.Image> uris = cursor.getImage();
        for (org.eclipse.birt.chart.model.attribute.Image uri : uris) {
            try {
                Image image = null;
                if (uri instanceof EmbeddedImage) {
                    try {
                        byte[] data = Base64.decodeBase64(((EmbeddedImage) uri).getData().getBytes());

                        image = new ImageIcon(data).getImage();
                    } catch (Exception ilex) {
                        logger.log(ilex);
                    }
                } else {
                    URI u = new URI(uri.getURL());
                    image = composite.getToolkit().createImage(SecurityUtil.toURL(u));
                }

                if (image != null) {
                    composite.setCursor(composite.getToolkit().createCustomCursor(image, new Point(0, 0), ""));//$NON-NLS-1$
                    return;
                }
            } catch (URISyntaxException e) {
                // Do not process exception here.
            } catch (MalformedURLException e) {
                // Do not process exception here.
            }
        }

        // No valid image is found, set default cursor.
        composite.setCursor(defaultCursor);
        return;
    }

    composite.setCursor(Cursor.getPredefinedCursor(SwingHelper.CURSOR_MAP.get(cursor.getType()).intValue()));
}