/*
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package javafx.scene;
import java.util.HashMap;
import java.util.Map;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.property.ReadOnlyDoublePropertyBase;
import javafx.beans.property.ReadOnlyObjectProperty;
import javafx.beans.property.ReadOnlyObjectPropertyBase;
import javafx.geometry.Dimension2D;
import javafx.scene.image.Image;
import com.sun.javafx.cursor.CursorFrame;
import com.sun.javafx.cursor.ImageCursorFrame;
import com.sun.javafx.tk.Toolkit;
import java.util.Arrays;
import javafx.beans.NamedArg;
/**
* A custom image representation of the mouse cursor. On platforms that don't
* support custom cursors, {@code Cursor.DEFAULT} will be used in place of the
* specified ImageCursor.
*
*
Example:
*
import javafx.scene.*;
import javafx.scene.image.*;
Image image = new Image("mycursor.png");
Scene scene = new Scene(400, 300);
scene.setCursor(new ImageCursor(image,
image.getWidth() / 2,
image.getHeight() /2));
*
*
* @since JavaFX 2.0
*/
public class ImageCursor extends Cursor {
/**
* The image to display when the cursor is active. If the image is null,
* {@code Cursor.DEFAULT} will be used.
*
* @defaultValue null
*/
private ObjectPropertyImpl image;
public final Image getImage() {
return image == null ? null : image.get();
}
public final ReadOnlyObjectProperty imageProperty() {
return imagePropertyImpl();
}
private ObjectPropertyImpl imagePropertyImpl() {
if (image == null) {
image = new ObjectPropertyImpl("image");
}
return image;
}
/**
* The X coordinate of the cursor's hot spot. This hotspot represents the
* location within the cursor image that will be displayed at the mouse
* position. This must be in the range of [0,image.width-1]. A value
* less than 0 will be set to 0. A value greater than
* image.width-1 will be set to image.width-1.
*
* @defaultValue 0
*/
private DoublePropertyImpl hotspotX;
public final double getHotspotX() {
return hotspotX == null ? 0.0 : hotspotX.get();
}
public final ReadOnlyDoubleProperty hotspotXProperty() {
return hotspotXPropertyImpl();
}
private DoublePropertyImpl hotspotXPropertyImpl() {
if (hotspotX == null) {
hotspotX = new DoublePropertyImpl("hotspotX");
}
return hotspotX;
}
/**
* The Y coordinate of the cursor's hot spot. This hotspot represents the
* location within the cursor image that will be displayed at the mouse
* position. This must be in the range of [0,image.height-1]. A value
* less than 0 will be set to 0. A value greater than
* image.height-1 will be set to image.height-1.
*
* @defaultValue 0
*/
private DoublePropertyImpl hotspotY;
public final double getHotspotY() {
return hotspotY == null ? 0.0 : hotspotY.get();
}
public final ReadOnlyDoubleProperty hotspotYProperty() {
return hotspotYPropertyImpl();
}
private DoublePropertyImpl hotspotYPropertyImpl() {
if (hotspotY == null) {
hotspotY = new DoublePropertyImpl("hotspotY");
}
return hotspotY;
}
private CursorFrame currentCursorFrame;
/**
* Stores the first cursor frame. For non-animated cursors there is only one
* frame and so the {@code restCursorFrames} is {@code null}.
*/
private ImageCursorFrame firstCursorFrame;
/**
* Maps platform images to cursor frames. It doesn't store the first cursor
* frame and so it needs to be created only for animated cursors.
*/
private Map