Developer Documentation
PATH  Mac OS X Documentation > Application Kit Reference: Java

Table of Contents

NSCursor


Inherits from:
NSObject
Package:
com.apple.yellow.application


Class Description


Instances of the NSCursor class manage the appearance of the cursor. When you initialize a cursor, you assign it a 16-by-16 pixel NSImage and a point to be the hot spot. The image is usually a small, opaque icon-for example, a pair of cross-hairs-surrounded by transparent pixels. The pixels in the cursor image are mapped on a flipped coordinate system: the upper left pixel is (0,0); the lower right is (15,15).

To determine exactly when the mouse is inside a particular cursor rectangle, the Application Kit tracks a single pixel in the cursor image. This pixel is known as the hot spot, and you can reference it using the hotSpot method. By definition, the location of the current cursor's hot spot is the location of the mouse; when the hot spot is inside a cursor rectangle, so is the mouse. The hot spot is useful not only for determining which cursor is current, but for determining where a mouse click should have its effect.

An NSCursor object is immutable: you cannot change its hot spot or image after it's created. Instead, use a constructor to create a new one with the new settings.

An application may use several cursor instances-for example, one that looks like an arrow and one that looks like an I-beam. The instance that currently appears on the screen is called the "current cursor," and is referenced by the currentCursor class method. You can set the current cursor in several ways:

The cursor rectangle is a region inside an NSView that triggers a change in the current cursor. To create a cursor rectangle, use the addCursorRect method of NSView to associate a region of the view with the cursor, as shown in the following example:

aView.addCursorRect(aRect, aCursor);
aCursor.setOnMouseEntered(true);

This assignment means that when the mouse enters aRect, aCursor will receive a mouseEntered event message, which the cursor uses to make itself the current cursor. However, before the cursor can acknowledge the mouseEntered message, you must invoke the cursor's setOnMouseEntered method. Alternatively, you can set the cursor when the mouse leaves the cursor rectangle by invoking the setOnMouseExited method instead of setOnMouseEntered. A cursor that sets itself upon leaving the cursor rectangle receives a mouseExited event message to instigate the change.

The Application Kit provides two ready-made cursors for commonly used cursor images. You can retrieve these cursors by using the arrowCursor and IBeamCursor static methods. There is no NSCursor instance for the wait cursor, because the system automatically displays it at the appropriate times.




Method Types


Constructors
NSCursor
Setting cursor attributes
image
hotSpot
hide
unhide
setHiddenUntilMouseMoves
Controlling which cursor is current
pop
pop
push
set
mouseEntered
setOnMouseEntered
isSetOnMouseEntered
mouseExited
setOnMouseExited
isSetOnMouseExited
Retrieving cursor instances
arrowCursor
currentCursor
IBeamCursor


Constructors



NSCursor

public NSCursor()

Description forthcoming.

public NSCursor( NSImage newImage, NSPoint aPoint)

This method creates a cursor, assigns it anImage (which must be 16-by-16 pixels) and sets its hot spot to aPoint.

public NSCursor( NSImage newImage, NSColor fg, NSColor bg, NSPoint hotSpot)

Creates a new cursor, assigns it anImage (which must be 16-by-16 pixels) and sets its hot spot to aPoint. The foreground and background colors are currently ignored.


Static Methods



arrowCursor

public static NSCursor arrowCursor()

Returns the default cursor, a slanted arrow with its hot spot at the tip. The arrow cursor is the one you're used to seeing over buttons, scrollers and many other objects in the window system.

See Also: IBeamCursor, currentCursor, hotSpot



currentCursor

public static NSCursor currentCursor()

Returns the cursor currently displayed on the screen.

See Also: set, push, pop, mouseEntered, mouseExited



hide

public static void hide()

Makes the current cursor invisible. If another cursor becomes current, that cursor will be invisible, too. It will remain invisible until you invoke the unhide method.

hide overrides setHiddenUntilMouseMoves.



IBeamCursor

public static NSCursor IBeamCursor()

Returns a cursor that looks like a capital I with a tiny crossbeam at its middle. This is the cursor that you're used to seeing over editable or selectable text. The I-beam cursor's default hot spot is where the crossbeam intersects the I.

See Also: arrowCursor, currentCursor



popCursor

public static void popCursor()

Pops the current cursor off the top of the stack. The new object on the top of the stack becomes the current cursor. If the current cursor is the only cursor on the stack, this method does nothing.

See Also: push



setHiddenUntilMouseMoves

public static void setHiddenUntilMouseMoves(boolean flag)

If flag is trueYES, hides the cursor. The cursor remains invisible until:

Do not try to counter this method by invoking unhide. The results are undefined.

See Also: hide



unhide

public static void unhide()

Negates an earlier call to hide by showing the current cursor.

See Also: setHiddenUntilMouseMoves, hide




Instance Methods



hotSpot

public NSPoint hotSpot()

Returns the position of the hot spot, specified according to the cursor's flipped 16-by-16 coordinate system. For a more complete explanation, see the class description.

Note that an NSCursor object is immutable: you cannot change its hot spot after it's created. Instead, use a constructor to create a new cursor with the new settings.



image

public NSImage image()

Returns the image for the receiving cursor, or null if none exists.

Note that an NSCursor object is immutable: you cannot change its image after it's created. Instead, use a constructor to create a new cursor with the new settings.



isSetOnMouseEntered

public boolean isSetOnMouseEntered()

Returns true if the receiving cursor will become current when it receives a mouseEntered message; otherwise, returns false.

To receive such a message, the receiver must first be assigned a cursor rectangle. This assignment can be made using NSView's addCursorRect method. For a more complete explanation, see the class description.

See Also: setOnMouseEntered, isSetOnMouseExited



isSetOnMouseExited

public boolean isSetOnMouseExited()

Returns true if the receiving cursor becomes current when it receives a mouseExited message; otherwise, returns false.

To receive such a message, the receiver must first be assigned a cursor rectangle. This assignment can be made using NSView's addCursorRect method. For a more complete explanation, see the class description.

See Also: setOnMouseExited



mouseEntered

public void mouseEntered(NSEvent anEvent)

This message is automatically sent to the receiver when the mouse enters the receiver's cursor rectangle. If used after setOnMouseEntered has been called with an argument of true, mouseEntered can make the receiver the current cursor.

In your programs, you won't invoke mouseEntered explicitly. It's only included in the class interface so you can override it.

For a more complete explanation, see the class description.

See Also: isSetOnMouseEntered, mouseExited



mouseExited

public void mouseExited(NSEvent anEvent)

This message is automatically sent to the receiver when the mouse exits the receiver's cursor rectangle. Like mouseEntered, it is part of the class interface only so you can override it.

See Also: setOnMouseExited, isSetOnMouseExited



pop

public void pop()

Sends a popCursor message to the instance's class.

See Also: push, pop



push

public void push()

Puts the receiver on top of the cursor stack and makes it the current cursor.

See Also: pop, pop



set

public void set()

Makes the receiver the current cursor.

See Also: currentCursor



setOnMouseEntered

public void setOnMouseEntered(boolean flag)

If flag is true, the cursor accepts future mouseEntered event messages, otherwise it ignores them. Accepting mouseEntered event messages allows the cursor to be made the current cursor when the mouse enters a view's cursor rectangle.

See Also: mouseEntered



setOnMouseExited

public void setOnMouseExited(boolean flag)

If flag is true, the cursor accepts future mouseExited event messages, otherwise it ignores them. Accepting mouseExited event messages allows the cursor to be made the current cursor when the mouse exits a view's cursor rectangle.


Table of Contents