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


[Previous] [Class List] [Next]

NSSliderCell


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


Class Description


An NSSliderCell controls the appearance and behavior of an NSSlider, or of a single slider in an NSMatrix. A slider can have tick marks to either side of it. The values represented by the tick marks are determined by the number of tick marks and the minimum and maximum values of the slider; a slider's values can be pegged to the values represented by the tick marks.

You can customize an NSSliderCell to a certain degree, using its set... methods. If these do not allow you sufficient flexibility, you can create a subclass. In that subclass, you can override any of the following methods: knobRectFlipped, drawBarInside, drawKnob, or prefersTrackingUntilMouseUp.


Method Types


Asking about the cell's behavior
altIncrementValue
prefersTrackingUntilMouseUp
trackRect
Changing the cell's behavior
setAltIncrementValue
Displaying the cell
knobRectFlipped
drawBarInside
drawKnob
drawKnobInRect
Asking about the cell's appearance
knobThickness
isVertical
title
titleCell
titleFont
titleColor
Changing the cell's appearance
setKnobThickness
setTitle
setTitleCell
setTitleColor
setTitleFont
Asking about the value limits
maxValue
minValue
Changing the value limits
setMaxValue
setMinValue
Managing tick marks
allowsTickMarkValuesOnly
closestTickMarkValueToValue
indexOfTickMarkAtPoint
numberOfTickMarks
rectOfTickMarkAtIndex
setAllowsTickMarkValuesOnly
setNumberOfTickMarks
setTickMarkPosition
tickMarkPosition
tickMarkValueAtIndex

Constructors


NSSliderCell

public NSSliderCell(String aString)

<<Description Forthcoming>>

public NSSliderCell(NSImage anImage)

<<Description Forthcoming>>

Static Methods



prefersTrackingUntilMouseUp

public static boolean prefersTrackingUntilMouseUp()

By default, this method returns true, so an NSSliderCell continues to track the mouse even after the mouse leaves the cell's tracking rectangle. This means that, once you take hold of a slider's knob (by putting the mouse inside the cell's frame rectangle and pressing the mouse button), you retain control of the knob until you release the mouse button, even if you drag the mouse clear to the other side of the screen.

Never call this method explicitly. Override it if you create a subclass of NSSliderCell that you want to track the mouse differently.




Instance Methods



allowsTickMarkValuesOnly

public boolean allowsTickMarkValuesOnly()

Returns whether the receiver fixes its values to those values represented by its tick marks.

See Also: setAllowsTickMarkValuesOnly



altIncrementValue

public double altIncrementValue()

Returns the amount the slider will change its value when the user drags the knob with the Alt key held down.

Unless you call setAltIncrementValue, altIncrementValue returns -1.0, and the slider behaves no differently with the Alt key down than with it up.

See Also: setAltIncrementValue



closestTickMarkValueToValue

public double closestTickMarkValueToValue(double aValue)

Returns the value of the tick mark closest to aValue.

See Also: indexOfTickMarkAtPoint



drawBarInside

public void drawBarInside(NSRect aRect, boolean flipped)

Draws the slider's bar-but not its bezel or knob-in aRect.

flipped indicates whether the cell's control view-that is, the NSSlider or NSMatrix associated with the NSSliderCell-has a flipped coordinate system.

You should never invoke this method explicitly. It's included so you can override it in a subclass.

See Also: drawKnobInRect



drawKnob

public void drawKnob()

Calculates the rectangle in which the knob should be drawn, then invokes drawKnobInRect to actually draw the knob. Before this message is sent, a lockFocus method must be sent to the cell's control view.

You might invoke this method if you override one of the display methods belonging to NSControl or NSCell.

If you create a subclass of NSSliderCell, don't override this method. Override drawKnobInRect instead.



drawKnobInRect

public void drawKnobInRect(NSRect knobRect)

Draws the knob in knobRect. Before this message is sent, a lockFocus message must be sent to the cell's control view.

You should never invoke this method explicitly. It's included so you can override it in a subclass.



indexOfTickMarkAtPoint

public int indexOfTickMarkAtPoint(NSPoint point)

Returns the index of the tick mark closest to the location of the slider represented by point. If point is not within the bounding rectangle (plus an extra pixel of space) of any tick mark, the method returns NSNotFound. This method invokes rectOfTickMarkAtIndex for each tick mark on the slider until it finds a tick mark containing point.

isVertical

public int isVertical()

Returns 1 if the slider is vertical, 0 if it's horizontal, and -1 if the orientation can't be determined (for example, if the slider hasn't been displayed yet). A slider is defined as vertical if its height is greater than its width.

knobRectFlipped

public NSRect knobRectFlipped(boolean flipped)

Returns the rectangle in which the knob will be drawn, specified in the coordinate system of the NSSlider or NSMatrix with which the NSSliderCell is associated. flipped indicates whether that coordinate system is flipped, a question you can answer by sending NSView's isFlipped message to the NSMatrix or NSSlider.

The knob rectangle depends on where in the slider the knob belongs-that is, it depends on the NSSliderCell's minimum and maximum values, and on the value the position of the knob will represent.

You should never invoke this method explicitly. It's included so you can override it in a subclass.



knobThickness

public float knobThickness()

Returns the knob's thickness, in pixels. The thickness is defined to be the extent of the knob along the long dimension of the bar. In a vertical slider, then, a knob's thickness is its height; in a horizontal slider, its thickness is its width.

See Also: setKnobThickness



maxValue

public double maxValue()

Returns the maximum value the slider can send to its target. A horizontal slider sends its maximum value when the knob is at the right end of the slider; a vertical slider sends it when the knob is at the top.

See Also: setMaxValue



minValue

public double minValue()

Returns the minimum value the slider can send to its target. A vertical slider sends this value when its knob is at the bottom; a horizontal slider sends it when its knob is all the way to the left.

numberOfTickMarks

public int numberOfTickMarks()

Returns the number of tick marks associated with the slider. The tick marks assigned to the minimum and maximum values are included.

See Also: setNumberOfTickMarks



rectOfTickMarkAtIndex

public NSRect rectOfTickMarkAtIndex(int index)

Returns the bounding rectangle of the tick mark identified by index (the minimum-value tick mark is at index 0). If no tick mark is associated with index, the method throws an exception

See Also: indexOfTickMarkAtPoint



setAllowsTickMarkValuesOnly

public void setAllowsTickMarkValuesOnly(boolean flag)

Sets whether the receiver's values are fixed to the values represented by the tick marks. For example, if a slider has a minimum value of 0, a maximum value of 100, and five markers, the allowable values are 0, 25, 50, 75, and 100. When users move the slider's knob, it jumps to the tick mark nearest the cursor when the mouse is released. This method has no effect if the slider has no tick marks.

See Also: allowsTickMarkValuesOnly



setAltIncrementValue

public void setAltIncrementValue(double increment)

Sets the amount by which the NSSliderCell modifies its value when the knob is Alt-dragged. increment should fit the range of values the slider can represent-for example, if the slider has a minimum value of 5 and a maximum value of 10, increment should be between 0 and 5.

If you don't call this method, the slider behaves the same with the Alt key down as with it up. This is also the result when you call setAltIncrementValue with an increment of -1.

See Also: maxValue, minValue



setKnobThickness

public void setKnobThickness(float thickness)

Lets you set the knob's thickness, measured in pixels. The thickness is defined to be the extent of the knob along the long dimension of the bar. In a vertical slider, then, a knob's thickness is its height; in a horizontal slider, its thickness is its width.

See Also: knobThickness



setMaxValue

public void setMaxValue(double aDouble)

Sets the maximum value the slider can send to its target. A horizontal slider sends its maximum value when its knob is all the way to the right; a vertical slider sends its maximum value when its knob is at the top.

See Also: maxValue



setMinValue

public void setMinValue(double aDouble)

Sets the minimum value the slider can send to its target. A horizontal slider sends its minimum value when its knob is all the way to the left; a vertical slider sends its minimum value when its knob is at the bottom.

See Also: minValue



setNumberOfTickMarks

public void setNumberOfTickMarks(int numberOfTickMarks)

Sets the number of tick marks displayed by the receiver (which include those assigned to the minimum and maximum values). By default, this value is zero, and no tick marks appear. The number of tick marks assigned to a slider, along with the slider's minimum and maximum values, determine the values associated with the tick marks.

See Also: numberOfTickMarks



setTickMarkPosition

public void setTickMarkPosition(int position)

Sets where tick marks appear relative to the receiver. For horizontal sliders, position can be TickMarksBelow (the default) or TickMarksAbove; for vertical sliders, position can be TickMarksLeft (the default) or TickMarksRight. This method has no effect if no tick marks have been assigned (that is, numberOfTickMarks returns zero).

See Also: tickMarkPosition



setTitle

public void setTitle(String title)

Sets the title in the bar behind the slider's knob to title.

See Also: title



setTitleCell

public void setTitleCell(NSCell aCell)

Sets the cell used to draw the slider's title. You only need to invoke this method if the default title cell, NSTextFieldCell, doesn't suit your needs-that is, if you want to display the title in a manner that NSTextFieldCell doesn't permit. When you do choose to override the default, aCell should be an instance of a subclass of NSTextFieldCell.

See Also: titleCell



setTitleColor

public void setTitleColor(NSColor color)

Sets the color used to draw the slider's title.

See Also: titleColor



setTitleFont

public void setTitleFont(NSFont font)

Sets the font used to draw the slider's title.

See Also: titleFont



tickMarkPosition

public int tickMarkPosition()

Returns how the receiver's tick marks are aligned with it. Possible return values are TickMarkBelow, TickMarkAbove, TickMarkLeft, or TickMarkRight (the last two are for vertical sliders). The default alignments are TickMarkBelow and TickMarkLeft.

See Also: setTickMarkPosition



tickMarkValueAtIndex

public double tickMarkValueAtIndex(int index)

Returns the receiver's value represented by the tick mark at index (the minimum-value tick mark has an index of zero).

title

public String title()

Returns the slider's title. The default title is the empty string ("").

See Also: setTitle



titleCell

public NSCell titleCell()

Returns the cell used to draw the title. The default is an NSTextFieldCell.

See Also: setTitleCell



titleColor

public NSColor titleColor()

Returns the color used to draw the slider's title. The default color is NSColor's controlTextColor.

See Also: setTitleColor



titleFont

public NSFont titleFont()

Returns the font used to draw the slider's title.

See Also: setTitleFont



trackRect

public NSRect trackRect()

Returns the rectangle within which the cell tracks the mouse while the mouse button is down. This rectangle includes the slider bar, but not the bezel.


[Previous] [Next]