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

Table of Contents

NSGraphicsContext


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


Class Description


The NSGraphicsContext class is the programmatic interface to objects that represent graphics contexts. A context can be thought of as a destination to which drawing and graphics state operations are sent for execution. Each graphics context contains its own graphics environment and state.

At any time there is the notion of the current context. The current context for the current thread may be set using setCurrentContext.

The NSGraphicsContext class is an superclass for destination-specific graphics contexts.

Graphics contexts are maintained on a stack. You push a graphics context onto the stack by sending it a saveGraphicsState message, and push it off the stack by sending it a restoreGraphicsState message. By sending restoreGraphicsState to an NSGraphicsContext object you remove it from the stack and the next graphics context on stack becomes the current graphics context.




Method Types


Constructors
NSGraphicsContext
Creating a graphics context
graphicsContextWithAttributes
graphicsContextWithWindow
Testing the drawing destination
currentContextDrawingToScreen
isDrawingToScreen
Setting and identifying the current context
currentContext
restoreGraphicsContext
setCurrentContext
saveGraphicsContext
Getting information about a context
attributes
Controlling the context -flush
flush
flushGraphics
restoreGraphicsState
saveGraphicsState
setGraphicsState
synchronize


Constructors



NSGraphicsContext

public NSGraphicsContext()

Description forthcoming.


Static Methods



currentContext

public static NSGraphicsContext currentContext()

Returns the current graphics context of the current thread. Returns a concrete subclass of NSGraphicsContext.

currentContextDrawingToScreen

public static boolean currentContextDrawingToScreen()

Convenience method equivalent to sending isDrawingToScreen to the result of currentContext.

graphicsContextWithAttributes

public static NSGraphicsContext graphicsContextWithAttributes(NSDictionary attributes)

Instantiates from an appropriate concrete subclass depending on attributes.

graphicsContextWithWindow

public static NSGraphicsContext graphicsContextWithWindow(NSWindow aWindow)

Description forthcoming.

restoreGraphicsContext

public static void restoreGraphicsContext()

Pops a graphics context from the per-thread stack, makes it current, and calls restoreGraphicsState .

saveGraphicsContext

public static void saveGraphicsContext()

Calls saveGraphicsState, and pushes the current graphics context on the per-thread stack.

setCurrentContext

public static void setCurrentContext(NSGraphicsContext context)

Sets the current graphics context of the current thread to context. context must be a concrete subclass of NSGraphicsContext.

setGraphicsState

public static void setGraphicsState(int graphicsState)

Makes graphicState's context current, and resets graphics state. The graphicState must be created in the calling thread


Instance Methods



attributes

public NSDictionary attributes()

Returns the receiver's attributes.

flush

public void flush()

Forces any buffered operations or data to be sent to the receiver's destination. Graphics contexts use buffers to queue pending operations but for efficiency reasons may not always empty those buffers immediately. This method forces the buffers to be emptied.

flushGraphics

public void flushGraphics()

Description forthcoming.

isDrawingToScreen

public boolean isDrawingToScreen()

Returns true if the drawing destination is the screen, false otherwise.

restoreGraphicsState

public void restoreGraphicsState()

Removes the receiver's graphics state from the top of the graphics state stack and makes the next graphics state the current graphics state. This method must have been proceeded with a saveGraphicsState message to add the graphics state to the stack. Invocations of saveGraphicsState and restoreGraphicsState methods may be nested.

Restoring the graphics state restores such attributes as the current drawing style, transformation matrix, color, and font of the original graphics state.



saveGraphicsState

public void saveGraphicsState()

Saves the current graphics state and creates a new graphics state on the top of the stack. The new graphics state is a copy of the previous state that can be modified to handle new drawing operations.

Saving the graphics state saves such attributes as the current drawing style, transformation matrix, color, and font. To set drawing style attributes, use the methods of NSBezierPath. Other attributes are accessed through appropriate objects such as NSAffineTransform, NSColor, and NSFont.



synchronize

public void synchronize()

Waits until the NSGraphicsContext's destination is ready to receive more input. This method returns when the underlying graphics subsystem has processed all operations sent through this context.


Table of Contents