public class ImageCursor extends Cursor
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));
Type | Property and Description |
---|---|
ReadOnlyDoubleProperty |
hotspotX
The X coordinate of the cursor's hot spot.
|
ReadOnlyDoubleProperty |
hotspotY
The Y coordinate of the cursor's hot spot.
|
<any> |
image
The image to display when the cursor is active.
|
Modifier and Type | Class and Description |
---|---|
private static class |
ImageCursor.DelayedInitialization |
private class |
ImageCursor.DoublePropertyImpl |
private class |
ImageCursor.ObjectPropertyImpl<T> |
Modifier and Type | Field and Description |
---|---|
private int |
activeCounter
Indicates whether the image cursor is currently in use.
|
private CursorFrame |
currentCursorFrame |
private ImageCursorFrame |
firstCursorFrame
Stores the first cursor frame.
|
private ImageCursor.DoublePropertyImpl |
hotspotX
The X coordinate of the cursor's hot spot.
|
private ImageCursor.DoublePropertyImpl |
hotspotY
The Y coordinate of the cursor's hot spot.
|
private ImageCursor.ObjectPropertyImpl<Image> |
image
The image to display when the cursor is active.
|
private InvalidationListener |
imageListener |
private java.util.Map<java.lang.Object,ImageCursorFrame> |
otherCursorFrames
Maps platform images to cursor frames.
|
Constructor and Description |
---|
ImageCursor()
Constructs a new empty
ImageCursor which will look as
Cursor.DEFAULT . |
ImageCursor(Image image)
Constructs an
ImageCursor from the specified image. |
ImageCursor(Image image,
double hotspotX,
double hotspotY)
Constructs an
ImageCursor from the specified image and hotspot
coordinates. |
Modifier and Type | Method and Description |
---|---|
(package private) void |
activate()
Activates the cursor.
|
private void |
bindImage(Image toImage) |
static ImageCursor |
chooseBestCursor(Image[] images,
double hotspotX,
double hotspotY)
Creates a custom image cursor from one of the specified images.
|
(package private) void |
deactivate()
Deactivates the cursor.
|
private static Image |
findBestImage(Image[] images) |
static Dimension2D |
getBestSize(double preferredWidth,
double preferredHeight)
Gets the supported cursor size that is closest to the specified preferred
size.
|
(package private) CursorFrame |
getCurrentFrame() |
double |
getHotspotX()
Gets the value of the property hotspotX.
|
double |
getHotspotY()
Gets the value of the property hotspotY.
|
Image |
getImage()
Gets the value of the property image.
|
private InvalidationListener |
getImageListener() |
static int |
getMaximumColors()
Returns the maximum number of colors supported in a custom image cursor
palette.
|
ReadOnlyDoubleProperty |
hotspotXProperty()
The X coordinate of the cursor's hot spot.
|
private ImageCursor.DoublePropertyImpl |
hotspotXPropertyImpl() |
ReadOnlyDoubleProperty |
hotspotYProperty()
The Y coordinate of the cursor's hot spot.
|
private ImageCursor.DoublePropertyImpl |
hotspotYPropertyImpl() |
<any> |
imageProperty()
The image to display when the cursor is active.
|
private ImageCursor.ObjectPropertyImpl<Image> |
imagePropertyImpl() |
private void |
initialize(Image[] images,
double hotspotX,
double hotspotY) |
private void |
initialize(Image newImage,
double newHotspotX,
double newHotspotY) |
private void |
invalidateCurrentFrame() |
private static boolean |
needsDelayedInitialization(Image[] images) |
private void |
unbindImage(Image fromImage) |
public final <any> imageProperty
Cursor.DEFAULT
will be used.getImage()
public final ReadOnlyDoubleProperty hotspotXProperty
getHotspotX()
public final ReadOnlyDoubleProperty hotspotYProperty
getHotspotY()
private ImageCursor.ObjectPropertyImpl<Image> image
Cursor.DEFAULT
will be used.private ImageCursor.DoublePropertyImpl hotspotX
private ImageCursor.DoublePropertyImpl hotspotY
private CursorFrame currentCursorFrame
private ImageCursorFrame firstCursorFrame
restCursorFrames
is null
.private java.util.Map<java.lang.Object,ImageCursorFrame> otherCursorFrames
private int activeCounter
private InvalidationListener imageListener
public ImageCursor()
ImageCursor
which will look as
Cursor.DEFAULT
.public ImageCursor(Image image)
ImageCursor
from the specified image. The cursor's
hot spot will default to the upper left corner.image
- the imagepublic ImageCursor(Image image, double hotspotX, double hotspotY)
ImageCursor
from the specified image and hotspot
coordinates.image
- the imagehotspotX
- the X coordinate of the cursor's hot spothotspotY
- the Y coordinate of the cursor's hot spotpublic final Image getImage()
public final <any> imageProperty()
Cursor.DEFAULT
will be used.getImage()
private ImageCursor.ObjectPropertyImpl<Image> imagePropertyImpl()
public final double getHotspotX()
public final ReadOnlyDoubleProperty hotspotXProperty()
getHotspotX()
private ImageCursor.DoublePropertyImpl hotspotXPropertyImpl()
public final double getHotspotY()
public final ReadOnlyDoubleProperty hotspotYProperty()
getHotspotY()
private ImageCursor.DoublePropertyImpl hotspotYPropertyImpl()
public static Dimension2D getBestSize(double preferredWidth, double preferredHeight)
Note: if an image is used whose dimensions don't match a supported size (as returned by this method), the implementation will resize the image to a supported size. This may result in a loss of quality.
Note: These values can vary between operating systems, graphics cards and screen resolution, but at the time of this writing, a sample Windows Vista machine returned 32x32 for all requested sizes, while sample Mac and Linux machines returned the requested size up to a maximum of 64x64. Applications should provide a 32x32 cursor, which will work well on all platforms, and may optionally wish to provide a 64x64 cursor for those platforms on which it is supported.
preferredWidth
- the preferred width of the cursorpreferredHeight
- the preferred height of the cursorpublic static int getMaximumColors()
Note: if an image is used which has more colors in its palette than the supported maximum, the implementation will attempt to flatten the palette to the maximum. This may result in a loss of quality.
Note: These values can vary between operating systems, graphics cards and screen resolution, but at the time of this writing, a sample Windows Vista machine returned 256, a sample Mac machine returned Integer.MAX_VALUE, indicating support for full color cursors, and a sample Linux machine returned 2. Applications may want to target these three color depths for an optimal cursor on each platform.
public static ImageCursor chooseBestCursor(Image[] images, double hotspotX, double hotspotY)
On platforms that don't support custom cursors, Cursor.DEFAULT
will
be used in place of the returned ImageCursor.
images
- a sequence of images from which to choose, in order of preferencehotspotX
- the X coordinate of the hotspot within the first image
in the images sequencehotspotY
- the Y coordinate of the hotspot within the first image
in the images sequenceCursorFrame getCurrentFrame()
getCurrentFrame
in class Cursor
private void invalidateCurrentFrame()
void activate()
Cursor
getCurrentFrame
returns up-to date values.void deactivate()
Cursor
deactivate
in class Cursor
private void initialize(Image[] images, double hotspotX, double hotspotY)
private void initialize(Image newImage, double newHotspotX, double newHotspotY)
private InvalidationListener getImageListener()
private void bindImage(Image toImage)
private void unbindImage(Image fromImage)
private static boolean needsDelayedInitialization(Image[] images)
private static Image findBestImage(Image[] images)