Important: The information in this document is obsolete and should not be used for new development.
Inherits from | |
Implements | |
Package | com.apple.cocoa.application |
Companion guide |
The NSCell class provides a mechanism for displaying text or images in an NSView without the overhead of a full NSView subclass. It’s used heavily by most of the NSControl classes to implement their internal workings.
setObjectValue
objectValue
hasValidObjectValue
setIntValue
intValue
setStringValue
stringValue
setDoubleValue
doubleValue
setFloatValue
floatValue
setCellAttribute
cellAttribute
setType
type
setEnabled
isEnabled
setBezeled
isBezeled
setBordered
isBordered
isOpaque
allowsUndo
setAllowsUndo
setEditable
isEditable
setSelectable
isSelectable
setScrollable
isScrollable
setAlignment
alignment
setFont
font
lineBreakMode
setLineBreakMode
setWraps
wraps
setAttributedStringValue
attributedStringValue
setAllowsEditingTextAttributes
allowsEditingTextAttributes
setImportsGraphics
importsGraphics
setUpFieldEditorAttributes
setTitle
acceptsFirstResponder
setShowsFirstResponder
showsFirstResponder
setTitleWithMnemonic
mnemonic
refusesFirstResponder
setMnemonicLocation
setRefusesFirstResponder
mnemonicLocation
performClick
trackMouse
startTrackingMouse
continueTrackingMouse
stopTrackingMouse
mouseDownFlags
prefersTrackingUntilMouseUp
calcDrawInfo
cellSize
cellSizeForBounds
drawingRectForBounds
imageRectForBounds
titleRectForBounds
controlSize
setControlSize
drawWithFrameInView
highlightColorWithFrameInView
drawInteriorWithFrameInView
controlView
setControlView
highlightWithFrameInView
setHighlighted
isHighlighted
setControlTint
controlTint
editWithFrameInView
selectAndEditWithFrameInView
sendsActionOnEndEditing
setSendsActionOnEndEditing
endEditing
Creates an empty NSCell.
public NSCell
()
Creates an NSCell initialized with aString and set to have the cell’s default menu.
public NSCell
(String aString)
If no field editor (a shared NSText object) has been created for all NSCells, one is created.
Creates an NSCell initialized with anImage and set to have the cell’s default menu.
public NSCell
(NSImage anImage)
If anImage is null
, no image is set.
Returns the default type of focus ring.
public static int defaultFocusRingType
()
Possible values are listed in the “Constants” section of NSGraphics.
Returns the default menu for instances of the receiver.
public static NSMenu defaultMenu
()
The default implementation returns null
.
The default implementation returns false
, so tracking stops when the cursor leaves the NSCell; subclasses may override.
public static boolean prefersTrackingUntilMouseUp
()
Returns whether or not the receiver will accept first responder status.
public boolean acceptsFirstResponder
()
The default implementation returns true
if the receiver is enabled, and refusesFirstResponder
returns false
; subclasses can override.
Implemented by NSActionCell and its subclasses to return the selector of the receiver’s action method. The default implementation returns a null selector.
public NSSelector action
()
Returns the alignment of text in the receiver: NSText.LeftTextAlignment
, NSText.RightTextAlignment
, NSText.CenterTextAlignment
, NSText.JustifiedTextAlignment
, or NSText.NaturalTextAlignment
.
public int alignment
()
Returns whether the receiver allows user editing of textual attributes.
public boolean allowsEditingTextAttributes
()
Returns true
if the receiver has three states: on, off, and mixed.
public boolean allowsMixedState
()
Returns false
if the receiver has two states: on and off.
Returns true
if undo operations are handled directly by the cell.
public boolean allowsUndo
()
By default, the NSTextFieldCell class uses this feature to handle undo operations for edited text. Other controls set a value that is appropriate for their implementation.
Returns the value of the receiver as an attributed string (that is, a string with attributes), using the receiver’s formatter object (if one exists) to create the attributed string.
public NSAttributedString attributedStringValue
()
The textual attributes are the default paragraph style, the receiver’s font and alignment, and whether the receiver is enabled and scrollable.
For Mac OS X v10.3 and later: If you use a class that responds to the selector attributedStringValue
for the object value of a cell, then the cell will use that method to fetch the string to draw rather than using stringValue
.
Implemented by subclasses to recalculate drawing sizes with reference to aRect.
public void calcDrawInfo
(NSRect aRect)
Objects (such as NSControls) that manage NSCells generally maintain a flag that informs them if any of their cells has been modified in such a way that the location or size of the cell should be recomputed. If so, NSControl’s calcSize
method is automatically invoked prior to the display of the NSCell, and that method invokes the NSCell’s calcDrawInfo
method. The default implementation does nothing.
Depending on aParameter, returns a setting for a cell attribute, such as the receiver’s state, and whether it’s disabled, editable, or highlighted.
public int cellAttribute
(int aParameter)
Returns the minimum size needed to display the receiver, taking account of the size of the image or text within a certain offset determined by the border type.
public NSSize cellSize
()
If the receiver is of neither image nor text type, a size of 10000.0 x 10000.0 is returned; if the receiver is of image type, and no image has been set, NSSize.ZeroSize
is returned.
Returns the minimum size needed to display the receiver, taking account of the size of the image or text within an offset determined by the border type.
public NSSize cellSizeForBounds
(NSRect aRect)
If the receiver is of text type, the text is resized to fit within aRect (as much as aRect is within the bounds of the cell). If the receiver is of neither image nor text type, the size of aRect parameter is returned; if the receiver is of image type, and no image has been set, a size with zero width and height is returned.
Compares the string values of the receiver and otherCell (which must be a kind of NSCell), disregarding case.
public int compare
(Object otherCell)
Throws BadComparisonException
if otherCell is not of the NSCell class.
Returns whether mouse tracking should continue in the receiving cell based on lastPoint and currentPoint within controlView.
public boolean continueTrackingMouse
(NSPoint lastPoint, NSPoint currentPoint, NSView controlView)
currentPoint is the current location of the cursor while lastPoint is either the initial location of the cursor or the previous currentPoint. This method is invoked in trackMouse
. The default implementation returns true
if the cell is set to continuously send action messages to its target when the mouse button is down or the mouse is being dragged. Subclasses can override this method to provide more sophisticated tracking behavior.
Returns the size of the receiver.
public int controlSize
()
Valid return values are described in “Constants.”
Returns the receiver’s control tint.
public int controlTint
()
Valid return values are described in “Constants.”
Implemented by subclasses to return the NSView last drawn in (normally an NSControl).
public NSView controlView
()
The default implementation returns null
.
Returns the receiver’s value as a double.
public double doubleValue
()
If the receiver is not a text-type cell or the cell value is not scannable, the method returns 0.
Returns the rectangle within which the receiver draws itself; this rectangle is slightly inset from theRect on all sides to take the border into account.
public NSRect drawingRectForBounds
(NSRect theRect)
calcSize
(NSControl)Draws the “inside” of the receiver—including the image or text within the receiver’s frame in controlView (usually the cell’s NSControl) but excluding the border.
public void drawInteriorWithFrameInView
(NSRect cellFrame, NSView controlView)
cellFrame is the frame of the NSCell or, in some cases, a portion of it. Text-type NSCells display their contents in a rectangle slightly inset from cellFrame using a global NSText object. Image-type NSCells display their contents centered within cellFrame. If the proper attributes are set, it also displays the dotted-line rectangle to indicate first responder and highlights the cell. This method is invoked from NSControl’s drawCellInside
to visually update what the NSCell displays when its contents change. This drawing is minimal and becomes more complex in objects such as NSButtonCell and NSSliderCell.
This method draws the cell in the currently focused view, which can be different from the controlView passed in. Taking advantage of this is not recommended.
Subclasses often override this method to provide more sophisticated drawing of cell contents. Because drawWithFrameInView
invokes drawInteriorWithFrameInView
after it draws the NSCell’s border, don’t invoke drawWithFrameInView
in your override implementation.
Draws the receiver’s regular or bezeled border (if those attributes are set) and then draws the interior of the cell by invoking drawInteriorWithFrameInView
.
public void drawWithFrameInView
(NSRect cellFrame, NSView controlView)
This method draws the cell in the currently focused view, which can be different from the controlView passed in. Taking advantage of this is not recommended.
Begins editing of the receiver’s text using the field editor textObj.
public void editWithFrameInView
(NSRect aRect, NSView controlView, NSText textObj, Object anObject, NSEvent theEvent)
This method is usually invoked in response to a mouse-down event. aRect must be the rectangle used for displaying the NSCell. theEvent is the NSEvent.LeftMouseDown
event. anObject is made the delegate of textObj and so will receive various NSText delegation and notification messages.
If the receiver isn’t a text-type NSCell, no editing is performed. Otherwise, textObj is sized to aRect and its superview is set to controlView, so it exactly covers the NSCell. Then it’s activated and editing begins. It’s the responsibility of the delegate to end editing when responding to textShouldEndEditing
. In doing this, it should remove any data from textObj.
Ends any editing of text, using the field editor textObj, occurring in the receiver begun with editWithFrameInView
and selectAndEditWithFrameInView
.
public void endEditing
(NSText textObj)
Returns the type of data the user can type into the receiver.
public int entryType
()
If the receiver is not a text-type cell, or if no type has been set, AnyType
is returned. See “Constants” for a list of type constants.
Returns the receiver’s value as a float.
public float floatValue
()
If the receiver is not a text-type cell or the cell value is not scannable, the method returns 0.
Returns the type of focus ring currently set.
public int focusRingType
()
Possible values are listed in the “Constants” section of NSGraphics You can disable a view's focus ring drawing by overriding this method so it always returns NSGraphics.FocusRingTypeNone
, or by calling setFocusRingType
with NSGraphics.FocusRingTypeNone
. You should only disable a view from drawing its focus ring if you want to draw your own focus ring, or if there isn't sufficient space to display a focus ring in the default location.
Returns the font used to display text in the receiver or null
if the receiver is not a text-type cell.
public NSFont font
()
Returns the formatter object (a kind of NSFormatter) associated with the receiver.
public NSFormatter formatter
()
This object handles translation of the receiver’s contents between its onscreen representation and its object value.
Returns whether the object associated with the receiver has a valid object value.
public boolean hasValidObjectValue
()
A valid object value is one that the receiver’s formatter can “understand.” Objects are always assumed to be valid unless they are rejected by the formatter. Invalid objects can still be accepted by the delegate of the receiver’s NSControl (in controlDidFailToFormatStringErrorDescription
).
Returns the color to use when drawing the receiver’s selection highlight in cellFrame.
public NSColor highlightColorWithFrameInView
(NSRect cellFrame, NSView controlView)
You should not assume that a cell would necessarily want to draw itself with the value returned from selectedControlColor
. A cell may wish to draw with different a selection highlight color depending on such things as the key state of its controlView.
If the receiver’s highlight status is different from flag, sets that status to flag and, if flag is true
, highlights the rectangle cellFrame in the NSControl (controlView).
public void highlightWithFrameInView
(boolean flag, NSRect cellFrame, NSView controlView)
Note that NSCell’s highlighting does not appear when highlighted cells are printed (although instances of NSTextFieldCell, NSButtonCell, and others can print themselves highlighted). Generally, you cannot depend on highlighting being printed because implementations of this method may choose (or not choose) to use transparency.
Returns the image displayed by the receiver or null
if the receiver is not an image-type cell.
public NSImage image
()
Returns the rectangle the receiver’s image is drawn in, which is slightly offset from theRect.
public NSRect imageRectForBounds
(NSRect theRect)
Returns whether the text of the receiver (if a text-type cell) is of Rich Text Format (RTF) and thus can import graphics.
public boolean importsGraphics
()
Returns the amount of time that the cell pauses between messages when it’s sending action messages continuously to target objects.
public float interval
()
Override this method to supply your own interval value.
Returns the receiver’s value as an int.
public int intValue
()
If the receiver is not a text-type cell or the cell value is not scannable, the method returns 0.
Returns whether the receiver has a bezeled border.
public boolean isBezeled
()
Returns whether the receiver has a plain border.
public boolean isBordered
()
Returns whether the receiver sends its action message continuously on mouse down.
public boolean isContinuous
()
Returns whether the receiver is editable.
public boolean isEditable
()
Returns whether the receiver responds to mouse events.
public boolean isEnabled
()
Returns whether a string representing a numeric or date value (aString) is formatted in a way suitable to the entry type.
public boolean isEntryAcceptable
(String aString)
Note: This method is being deprecated in favor of a new class of formatter objects. For more information, see NSFormatter. This documentation is provided only for developers who need to modify older applications.
Returns whether the receiver is highlighted.
public boolean isHighlighted
()
Returns whether the receiver is opaque (nontransparent).
public boolean isOpaque
()
Returns whether the receiver scrolls typed text that exceeds the cell’s bounds.
public boolean isScrollable
()
Returns whether the text of the receiver can be selected.
public boolean isSelectable
()
Implemented by subclasses to return a key equivalent to clicking the cell.
public String keyEquivalent
()
The default implementation returns an empty string object.
Returns the line break mode currently used when drawing text.
public int lineBreakMode
()
Returns the menu with commands contextually related to the cell or null
if no menu is associated.
public NSMenu menu
()
Returns the NSMenu associated with the receiver through the setMenu
method and related to anEvent when the cursor is detected within cellFrame.
public NSMenu menuForEvent
(NSEvent anEvent, NSRect cellFrame, NSView aView)
It is usually invoked by the NSControl (aView) managing the receiver. The default implementation simply invokes menu
and returns null
if no menu has been set. Subclasses can override to customize the returned menu according to the event received and the area in which the mouse event occurs.
Returns the character in the receiver’s title that appears underlined for use as a mnemonic.
public String mnemonic
()
If there is no mnemonic character, returns an empty string. Mnemonics are not supported in Mac OS X
Returns the position of the underlined character in the receiver’s title used as a mnemonic.
public int mnemonicLocation
()
If there is no mnemonic character, returns NSArray.NotFound
. Mnemonics are not supported in Mac OS X.
Returns the modifier flags for the last (left) mouse-down event, or 0 if tracking hasn’t occurred yet for the cell or no modifier keys accompanied the mouse-down event.
public int mouseDownFlags
()
modifierFlags
(NSEvent)Returns the receiver’s next state.
public int nextState
()
If the receiver has three states, it cycles through them in this order: on, off, mixed, on, and so forth. If the receiver has two states, it toggles between them.
Returns the receiver’s value as an object if a valid object has been associated with the receiver; otherwise, returns null
.
public Object objectValue
()
To be valid, the receiver must have a formatter capable of converting the object to and from its textual representation.
Can be used to simulate a single mouse click on the receiver.
public void performClick
(Object sender)
The receiver must be enabled and either the receiver's current controlView
must be valid or sender, which must be a subclass of NSView, is used instead. The receiver's action is performed on its target. Throws an exception if the action message cannot be successfully sent.
Returns the amount of time that the cell pauses before sending its first message when it’s sending action messages continuously to target objects.
public float periodicDelay
()
Override this method to supply your own delay value.
Returns true
if the receiver can never become the first responder.
public boolean refusesFirstResponder
()
To find out whether the receiver can become first responder at this time, use the method acceptsFirstResponder
.
Returns the object the receiver represents.
public Object representedObject
()
For example, you could have a pop-up list of color names, and the represented objects could be the appropriate NSColor objects.
Sets the receiver to show the I-beam cursor within cellFrame while it tracks the mouse.
public void resetCursorRect
(NSRect cellFrame, NSView controlView)
The receiver must be an enabled and selectable (or editable) text-type cell. controlView is the NSControl that manages the cell.
This method is invoked by resetCursorRects
and in general you do not need to call this method unless you have a custom NSView that uses a cell.
Uses the field editor textObj to select text in a range marked by selStart and selLength, which will be highlighted and selected as though the user had dragged the cursor over it.
public void selectAndEditWithFrameInView
(NSRect aRect, NSView controlView, NSText textObj, Object anObject, int selStart, int selLength)
This method is similar to editWithFrameInView
, except that it can be invoked in any situation, not only on a mouse-down event. aRect is the rectangle in which the selection should occur, controlView is the NSControl managing the receiver, and anObject is the delegate of the field editor. Returns without doing anything if controlView, textObj, or the receiver is null
, or if the receiver has no font set for it.
Returns whether the receiver’s NSControl object sends its action message whenever the user finishes editing the cell’s text.
public boolean sendsActionOnEndEditing
()
If it returns true
, the receiver’s NSControl object sends its action message when the user does one of the following:
Presses the Return key
Presses the Tab key to move out of the field
Clicks another text field
If it returns false
, the cell’s NSControl object sends its action message only when the user presses the Return key.
public void setAction
(NSSelector aSelector)
In NSCell, throws InternalInconsistencyException
. However, NSActionCell overrides this method to set the action method, depending on the value of aSelector, as part of the implementation of the target/action mechanism.
Sets the alignment of text in the receiver.
public void setAlignment
(int mode)
mode is one of five constants: NSText.LeftTextAlignment
, NSText.RightTextAlignment
, NSText.CenterTextAlignment
, NSText.JustifiedTextAlignment
, and NSText.NaturalTextAlignment
(the default alignment for the text).
Sets whether the textual attributes of the receiver can be modified by the user.
public void setAllowsEditingTextAttributes
(boolean flag)
If flag is false
, the receiver also cannot import graphics (that is, it does not support RTFD text).
public void setAllowsMixedState
(boolean flag)
If flag is true
, the receiver has three states: on, off, and mixed. If flag is false
, the receiver has two states: on and off.
If allowsUndo is true
, the receiver assumes responsibility for undo operations within the cell.
public void setAllowsUndo
(boolean allowsUndo)
If allowsUndo is false
, undo operations are handled by the application’s custom undo manager.
Sets the value of the receiver to the attributed string attribStr.
public void setAttributedStringValue
(NSAttributedString attribStr)
If a formatter is set for the receiver, but the formatter does not understand the attributed string, it marks attribStr as an invalid object. If the receiver is not a text-type cell, it’s converted to one.
For Mac OS X v10.3 and later: If you use a class that responds to the selector attributedStringValue
for the object value of a cell, then the cell will use that method to fetch the string to draw rather than using stringValue
.
Sets whether the receiver draws itself with a bezeled border, depending on the Boolean value flag.
public void setBezeled
(boolean flag)
The setBezeled
and setBordered
methods are mutually exclusive (that is, a border can be only plain or bezeled). Invoking this method results in setBordered
being sent with a value of false
.
Sets whether the receiver draws itself outlined with a plain border, depending on the Boolean value flag.
public void setBordered
(boolean flag)
The setBezeled
and setBordered
methods are mutually exclusive (that is, a border can be only plain or bezeled). Invoking this method results in setBezeled
being sent with a value of false
.
Sets a cell attribute identified by aParameter—such as the receiver’s state and whether it’s disabled, editable, or highlighted—to value.
public void setCellAttribute
(int aParameter, int value)
Sets whether the receiver continuously sends its action message to its target while it tracks the mouse, depending on the Boolean value flag.
public void setContinuous
(boolean flag)
In practice, the continuous setting has meaning only for instances of NSActionCell and its subclasses, which implement the target/action mechanism. Some NSControl subclasses, notably NSMatrix, send a default action to a default target when a cell doesn’t provide a target or action.
Sets the size of the receiver.
public void setControlSize
(int size)
Valid values for size are described in “Constants.”
Changing the cell’s control size does not change the font of the cell. Use the NSFont class method systemFontSizeForControlSize
to obtain the system font based on the new control size and set it.
Sets the receiver’s control tint.
public void setControlTint
(int controlTint)
Valid values for controlTint are described in “Constants.”
Sets the receiver’s control view.
public void setControlView
(NSView view)
The control view represents the control currently being rendered by the cell.
Sets the value of the receiver to an object aDouble, representing a double value.
public void setDoubleValue
(double aDouble)
In its implementation, this method invokes setObjectValue
. Does nothing if the receiver is not a text-type cell.
Sets whether the user can edit the receiver’s text, depending on the Boolean value flag.
public void setEditable
(boolean flag)
If flag is true
, the text is also made selectable. If flag is false
, the selectable attribute is restored to the value it was before the cell was last made editable.
Sets whether the receiver is enabled or disabled, depending on the Boolean value flag.
public void setEnabled
(boolean flag)
The text of disabled cells is changed to gray. If a cell is disabled, it cannot be highlighted, does not support mouse tracking (and thus cannot participate in target/action functionality), and cannot be edited. However, you can still alter many attributes of a disabled cell programmatically (setState
, for instance, will still work).
Sets how numeric data is formatted in the receiver and places restrictions on acceptable input.
public void setEntryType
(int aType)
aType can be one of the types defined in “Constants.” The formatter associated with the receiver is replaced with a newly instantiated formatter appropriate to the entry type.
If the receiver isn’t a text-type cell, this method converts it to one; in the process, it makes its title “Cell” and sets its font to the user’s system font at 12 points.
You can check whether formatted strings conform to the entry types of cells with the isEntryAcceptable
method. NSControl subclasses also use isEntryAcceptable
to validate what users have typed in editable cells. You can control the format of values accepted and displayed in cells by creating a custom subclass of NSFormatter and associating an instance of that class with cells (through setFormatter
). In custom NSCell subclasses, you can also override isEntryAcceptable
to check for the validity of data entered into cells.
Note: This method is being deprecated in favor of a new class of formatter objects. For more information, see NSFormatter. This documentation is provided only for developers who need to modify older applications.
Sets the conditions on which the receiver sends action messages to its target and returns a bit mask with which to detect the previous settings.
public int setEventMaskForSendingAction
(int mask)
setEventMaskForSendingAction
is used during mouse tracking when the mouse button state changes, the mouse moves, or, if the cell is marked to send its action continuously while tracking, periodically. Because of this, the only bits checked in mask are NSEvent.LeftMouseDownMask
, NSEvent.LeftMouseUpMask
, NSEvent.LeftMouseDraggedMask
, and NSEvent.PeriodicMask
.
You can use setContinuous
to turn on the flag corresponding to NSEvent.PeriodicMask
or NSEvent.LeftMouseDraggedMask
, whichever is appropriate to the given subclass of NSCell.
Sets whether floating-point numbers are autoranged in the receiver and sets the sizes of the fields to the left and right of the decimal point.
public void setFloatingPointFormat
(boolean autoRange, int leftDigits, int rightDigits)
If autoRange is false
, leftDigits specifies the maximum number of digits to the left of the decimal point, and rightDigits specifies the number of digits to the right (the fractional digit places will be padded with zeros to fill this width). However, if a number is too large to fit its integer part in leftDigits digits, as many places as are needed on the left are effectively removed from rightDigits when the number is displayed.
If autoRange is true
, leftDigits and rightDigits are simply added to form a maximum total field width for the receiver (plus 1 for the decimal point). The fractional part will be padded with zeros on the right to fill this width, or truncated as much as possible (up to removing the decimal point and displaying the number as an integer). The integer portion of a number is never truncated—that is, it is displayed in full no matter what the field width limit is.
Sets the value of the receiver to an object aFloat, representing a float value.
public void setFloatValue
(float aFloat)
In its implementation, this method invokes setObjectValue
. Does nothing if the receiver is not a text-type cell.
Sets the type of focus ring to be used.
public void setFocusRingType
(int focusRingType)
Possible values are listed in the “Constants” section of NSGraphics. You can disable a view's focus ring drawing by calling this method with NSGraphics.FocusRingTypeNone
. You should only disable a view from drawing its focus ring if you want to draw your own focus ring, or if there isn't sufficient space to display a focus ring in the default location.
Sets the font to be used when the receiver displays text.
public void setFont
(NSFont fontObj)
If the receiver is not a text-type cell, the method converts it to that type.
Sets the formatter object used to format the textual representation of the receiver’s object value and to validate cell input and convert it to that object value.
public void setFormatter
(NSFormatter newFormatter)
If the new formatter cannot interpret the receiver’s current object value, that value is converted to a string object. If newFormatter is null
, the receiver is disassociated from the current formatter.
Sets whether the receiver has a highlighted appearance, depending on the Boolean value flag.
public void setHighlighted
(boolean flag)
By default, it does nothing. NSButtonCell overrides this method to draw the button with the appearance specified by LightsByBackground
, LightsByContents
, or LightsByGray
.
Sets the image to be displayed by the receiver.
public void setImage
(NSImage image)
If the receiver is not an image-type cell, the method converts it to that type.
Sets whether the receiver can import images into its text (that is, whether it supports RTFD text).
public void setImportsGraphics
(boolean flag)
If flag is true
, the receiver is also set to allow editing of text attributes (setAllowsEditingTextAttributes
).
Sets the value of the receiver to an object anInt, representing an integer value.
public void setIntValue
(int anInt)
In its implementation, this method invokes setObjectValue
. Does nothing if the receiver is not a text-type cell.
Sets the line break mode used when drawing text to mode.
public void setLineBreakMode
(int mode)
The line break mode can also be modified by calling the setWraps
method.
Associates a menu with the cell that has commands contextually related to the receiver.
public void setMenu
(NSMenu aMenu)
The associated menu is retained. If aMenu is null
, any association with a previous menu is removed.
Sets the character of the receiver’s title identified by location to be underlined.
public void setMnemonicLocation
(int location)
Mnemonics are not supported in Mac OS X.
Sets the receiver to its next state.
public void setNextState
()
If the receiver has three states, it cycles through them in this order: on, off, mixed, on, and so forth. If the receiver has two states, it toggles between them.
Sets the receiver’s object value to object.
public void setObjectValue
(Object object)
Sets whether the receiver can become the first responder.
public void setRefusesFirstResponder
(boolean flag)
If flag is true
, the receiver cannot become the first responder.
If refusesFirstResponder
returns false
and the cell is enabled, the method acceptsFirstResponder
returns true
, allowing the cell to become first responder.
Sets the object represented by the receiver—f
public void setRepresentedObject
(Object anObject)
or example, an NSColor object for a cell with a title of “Blue.”
Sets whether excess text in the receiver is scrolled past the cell’s bounds.
public void setScrollable
(boolean flag)
If flag is true
, wrapping is turned off.
Sets whether text in the receiver can be selected, depending on the Boolean value flag.
public void setSelectable
(boolean flag)
If flag is false
, editability is also disabled. If flag is true
, editability is not affected.
Sets whether the receiver’s NSControl object sends its action message whenever the user finishes editing the cell’s text.
public void setSendsActionOnEndEditing
(boolean flag)
If flag is true
, the receiver’s NSControl object sends its action message when the user does one of the following:
Presses the Return key
Presses the Tab key to move out of the field
Clicks another text field
If flag is false
, the cell’s NSControl object sends its action message only when the user presses the Return key.
Sets whether the receiver draws some indication of its first responder status.
public void setShowsFirstResponder
(boolean flag)
NSCell itself does not draw any indication but subclasses may use flag to decide to draw a focus ring.
Sets the receiver’s state to value, which can be OnState
, OffState
, or MixedState
.
public void setState
(int value)
A cell can have two or three states. If it has two, value can be OffState
(the normal or unpressed state) or OnState
(the alternate or pressed state). If it has three, value can be OnState
(the feature is in effect everywhere), OffState
(the feature is in effect nowhere), or MixedState
(the feature is in effect somewhere). Note that if the cell has only two states and value is MixedState
, this method sets the cell’s state to OnState
.
Although using the enumerated constants is preferred, value can also be an integer. If the cell has two states, 0 is treated as OffState
, and a nonzero value is treated as OnState
. If the cell has three states, 0 is treated as OffState
; a negative value, as MixedState
; and a positive value, as OnState
.
Note that the value state
returns may not be the same value you passed into setState
.
To check whether the cell has three states (and uses the mixed state), invoke the method allowsMixedState
.
Sets the value of the receiver to aString.
public void setStringValue
(String aString)
In its implementation, this method invokes setObjectValue
. If no formatter is assigned to the receiver or if the formatter cannot “translate” aString to an underlying object, the receiver is flagged as having an invalid object. If the receiver is not a text-type cell, this method converts it to one before setting the object value.
For Mac OS X v10.3 and later: If you use a class that responds to the selector attributedStringValue
for the object value of a cell, then the cell will use that method to fetch the string to draw rather than using stringValue
.
Implemented by NSActionCell to set the receiver’s tag integer to anInt.
public void setTag
(int anInt)
NSCell’s implementation throws InternalInconsistencyException
. Tags allow you to identify particular cells. Tag values are not used internally; they are only changed by external invocations of setTag
. You typically set tag values in Interface Builder. When you set the tag of a control with a single cell in Interface Builder, it sets the tags of both the control and the cell to the same value as a convenience.
Implemented by NSActionCell to set the receiver’s target object receiving the action message to anObject.
public void setTarget
(Object anObject)
NSCell’s implementation throws InternalInconsistencyException
.
Sets the title of the receiver to aString.
public void setTitle
(String aString)
Sets the title of the receiver to aString with a character denoted as an access key.
public void setTitleWithMnemonic
(String aString)
Mnemonics are not supported in Mac OS X.
If the type of the receiver is different from aType, sets it to aType, which must be one of TextCellType
, ImageCellType
, or NullCellType
.
public void setType
(int aType)
If aType is TextCellType
, converts the receiver to a cell of that type, giving it a default title and setting the font to the system font at the default size. If aType is ImageCellType
, sets a null
image. If aType is set to ImageCellType
and the image is set to null
, the cell type will be reported as NullCellType
until a new, non-null
image is set.
Sets textual and background attributes of textObj, depending on certain attributes.
public NSText setUpFieldEditorAttributes
(NSText textObj)
If the receiver is disabled, sets the text color to dark gray; otherwise sets it to the default color. If the receiver has a bezeled border, sets the background to the default color for text backgrounds; otherwise, sets it to the color of the receiver’s NSControl.
You should not use this method to substitute a new field editor. setUpFieldEditorAttributes
is intended to modify the attributes of the text object (that is, the field editor) passed into it and return that text object. If you want to substitute your own field editor, use the NSWindow method fieldEditorForObject
or the NSWindow delegate method windowWillReturnFieldEditor
.
Sets whether text in the receiver wraps when its length exceeds the frame of the cell.
public void setWraps
(boolean flag)
If flag is true
, then it also sets the receiver to be nonscrollable.
If the text of the receiver is an attributed string value you must explicitly set the paragraph style line break mode. Calling this method with the value true
is equivalent to calling the setLineBreakMode:
method with the value NSLineBreakByWordWrapping.
Returns whether the receiver should draw some indication when it assumes first responder status.
public boolean showsFirstResponder
()
public boolean startTrackingMouse
(NSPoint startPoint, NSView controlView)
NSCell’s implementation of trackMouse
invokes this method when tracking begins. startPoint is the point the cursor is currently at, and controlView is the NSControl managing the receiver. NSCell’s default implementation returns true
if the receiver is either set to respond continuously or set to respond when the mouse is dragged. Otherwise, false
is returned. Subclasses override this method to implement special mouse-tracking behavior at the beginning of mouse tracking—for example, displaying a special cursor.
Returns the receiver’s state.
public int state
()
The receiver can have two or three states. If it has two, it returns either OffState
(the normal or unpressed state) or OnState
(the alternate or pressed state). If it has three, it returns OnState
(the feature is in effect everywhere), OffState
(the feature is in effect nowhere), or MixedState
(the feature is in effect somewhere).
To check whether the receiver uses the mixed state, use the method allowsMixedState
.
Note that the value state
returns may not be the same value you passed into setState
.
public void stopTrackingMouse
(NSPoint lastPoint, NSPoint stopPoint, NSView controlView, boolean flag)
NSCell’s implementation of trackMouse
invokes this method when the cursor has left the bounds of the receiver or the mouse button goes up (in which case flag is true
). lastPoint is the point the cursor was at, and stopPoint is its current point. controlView is the NSControl managing the receiver. NSCell’s default implementation does nothing. Subclasses often override this method to provide customized tracking behavior.
Returns the receiver’s value as a String as converted by the receiver’s formatter, if one exists.
public String stringValue
()
If no formatter exists and the value is a String, returns the value as a plain, attributed, or localized formatted string. If the value is not a String or can’t be converted to one, returns an empty string.
For Mac OS X v10.3 and later: If you use a class that responds to the selector attributedStringValue
for the object value of a cell, then the cell will use that method to fetch the string to draw rather than using stringValue
.
Implemented by NSActionCell to return the receiver’s tag integer.
public int tag
()
NSCell’s implementation returns –1. Tags allow you to identify particular cells. You typically set tag values in Interface Builder. When you set the tag of a control with a single cell in Interface Builder, it sets the tags of both the control and the cell to the same value as a convenience.
Sets the receiver’s own value as a double using the double value of sender.
public void takeDoubleValue
(Object sender)
Sets the receiver’s own value as a float using the float value of sender.
public void takeFloatValue
(Object sender)
Sets the receiver’s own value as an int using the int value of sender.
public void takeIntValue
(Object sender)
Sets the receiver’s own value as an object using the object value of sender.
public void takeObjectValue
(Object sender)
Sets the receiver’s own value as a string object using the String value of sender.
public void takeStringValue
(Object sender)
public Object target
()
Implemented by NSActionCell to return the target object to which the receiver’s action message is sent. NSCell’s implementation returns null
.
public NSRect titleRectForBounds
(NSRect theRect)
If the receiver is a text-type cell, resizes the drawing rectangle for the title (theRect) inward by a small offset to accommodate the cell border. If the receiver is not a text-type cell, the method does nothing.
Invoked by an NSControl to initiate the tracking behavior of one of its NSCells.
public boolean trackMouse
(NSEvent theEvent, NSRect cellFrame, NSView controlView, boolean untilMouseUp)
It’s generally not overridden because the default implementation invokes other NSCell methods that can be overridden to handle specific events in a dragging session. This method’s return value depends on the untilMouseUp flag. If untilMouseUp is set to true
, this method returns true
if the mouse button goes up while the cursor is anywhere; false
, otherwise. If untilMouseUp is set to false
, this method returns true
if the mouse button goes up while the cursor is within cellFrame; false
, otherwise. The argument theEvent is typically the mouse event received by the initiating NSControl, usually identified by controlView. The untilMouseUp argument indicates whether tracking should continue until the mouse button goes up; if it's false
, tracking ends when the mouse leaves the cell frame even if the mouse button isn't released.
This method first invokes startTrackingMouse
. If that method returns true
, then as mouse-dragged events are intercepted, continueTrackingMouse
is invoked until either the method returns false
or the mouse is released. Finally, stopTrackingMouse
is invoked if the mouse is released. If untilMouseUp is true
, it’s invoked when the mouse button goes up while the cursor is anywhere. If untilMouseUp is false
, it’s invoked when the mouse button goes up while the cursor is within cellFrame. (If cellFrame is NULL
, then the bounds are considered infinitely large.) You usually override one or more of these methods to respond to specific mouse events.
Returns the type of the receiver, one of TextCellType
, ImageCellType
, or NullCellType
.
public int type
()
If the receiver’s type is set to ImageCellType
and its image is set to null
, the cell type will be reported as NullCellType
until a new, non-null
image is set.
Returns whether text of the receiver wraps when it exceeds the borders of the cell.
public boolean wraps
()
These constants specify how a cell formats numeric data. They’re used by setEntryType
and entryType
.
These constants specify what a cell contains. They’re used by setType
and type
.
Constant | Description |
---|---|
NullCellType | Cell displays nothing. |
TextCellType | Cell displays text. |
ImageCellType | Cell displays images. |
These constants specify how a button behaves when pressed and how it displays its state. They’re used by NSButton and NSButtonCell:
Constant |
Description |
---|---|
If the cell’s state is |
|
If the cell’s state is |
|
If the cell’s state is |
|
Does not let the user manipulate the cell. |
|
Lets the user edit the cell’s contents. |
|
|
Controls the position of the cell’s image and text. To place the image above, set none of them. To place the image below, set |
Draws the cell with a highlighted appearance. This constant is deprecated. Use |
|
Draws a border around the cell. |
|
Insets the cell’s contents from the border. By default, they’re inset by 2 pixels. This constant is ignored if the cell is unbordered. |
|
If the cell is pushed in, changes the cell’s background color from gray to white. |
|
If the cell is pushed in, displays the cell’s alternate image. |
|
If the cell is pushed in, displays the cell’s image as darkened. |
|
Determines whether the cell’s image and text appear to be shifted down and to the right. |
|
The cell’s state. It can be |
These constants specify the position of a button’s image relative to its title. They’re used by NSButton’s and NSButtonCell’s setImagePosition
and imagePosition
.
These constants specify a cell’s state and are used mostly for buttons. They’re described in “Cell States”.
Constant | Description |
---|---|
MixedState | The corresponding feature is in effect somewhere. |
OffState | The corresponding feature is in effect nowhere. |
OnState | The corresponding feature is in effect everywhere. |
These constants specify what happens when a button is pressed or is displaying its alternate state. They’re used by NSButtonCell’s highlightsBy
and showsStateBy
.
Constant | Description |
---|---|
NoCellMask | The button cell doesn’t change. |
PushInCellMask | The button cell “pushes in” if it has a border. |
ContentsCellMask | The button cell displays its alternate icon and/or title. |
ChangeGrayCellMask | The button cell swaps the “control color” (NSColor’s |
ChangeBackgroundCellMask | Same as |
These constants specify a cell’s tint. They’re used by controlTint
and setControlTint
.
Constant | Description |
---|---|
DefaultControlTint | The current default tint setting |
ClearControlTint | Clear control tint |
BlueControlTint | Aqua control tint |
GraphiteControlTint | Graphite control tint |
These constants specify a cell’s size. They’re used by controlSize
and setControlSize
.
© 1997, 2007 Apple Inc. All Rights Reserved. (Last updated: 2007-02-01)