CursorDescriptor desc = new CursorDescriptor(purl, x, y);
//
// Check if there is a cursor in the cache for this url
//
Cursor cachedCursor = cursorCache.getCursor(desc);
if (cachedCursor != null) {
return cachedCursor;
}
//
// Load image into Filter f and transform hotSpot to
// cursor space.
//
Point2D.Float hotSpot = new Point2D.Float(x, y);
Filter f = cursorHrefToFilter(cursorElement,
purl,
hotSpot);
if (f == null) {
cursorCache.clearCursor(desc);
return null;
}
// The returned Filter is guaranteed to create a
// default rendering of the desired size
Rectangle cursorSize = f.getBounds2D().getBounds();
RenderedImage ri = f.createScaledRendering(cursorSize.width,
cursorSize.height,
null);
Image img = null;
if (ri instanceof Image) {
img = (Image)ri;
} else {
img = renderedImageToImage(ri);
}
// Make sure the not spot does not fall out of the cursor area. If it
// does, then clamp the coordinates to the image space.
hotSpot.x = hotSpot.x < 0 ? 0 : hotSpot.x;
hotSpot.y = hotSpot.y < 0 ? 0 : hotSpot.y;
hotSpot.x = hotSpot.x > (cursorSize.width-1) ? cursorSize.width - 1 : hotSpot.x;
hotSpot.y = hotSpot.y > (cursorSize.height-1) ? cursorSize.height - 1: hotSpot.y;
//
// The cursor image is now into 'img'
//
Cursor c = Toolkit.getDefaultToolkit()
.createCustomCursor(img,
new Point((int)Math.round(hotSpot.x),
(int)Math.round(hotSpot.y)),
purl.toString());