All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class quicktime.app.display.QTCanvas

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----quicktime.app.display.QTCanvas

public class QTCanvas
extends Canvas
A specialized canvas which supplies access to the native graphics environment and offers expanded functionality to control its viewing or display size. The QTCanvas object can display any object which implements the Drawable interface. This Drawable object is set as the drawing client of the QTCanvas object.

The resize and alignment flags determine how the QTCanvas object acts when it has its setSize or setBounds method called. These flags allow the application to control or restrict the viewing size of a QTCanvas - generally desirable as the QuickTime client of a QTCanvas is constructed to be viewed in a particular best size or react in a desired manner when resized. The resize flags comments discuss the typically appropriate usage. If the kAnySize flag is used the QTCanvas will be resized as any other java.awt.Component.

The size of the QTCanvas and its Drawable client are kept synchronized. The actual size of the QTCanvas is determined by the size of its Drawable client when it is set (which becomes its "best" viewing size), the resize and alignement flag settings, and the size of the QTCanvas' java.awt.Container parent. The client, the resize and alignment flags determine how a QTCanvas reacts to a setBounds or setSize call - any resize flag other than the kAnySize flag will result in the QTCanvas' actual size being arbitrated with the best viewing size of its client. Thus in many cases the calls to setSize and setBounds on a QTCanvas object are requests and may not result in the QTCanvas actually being resized to that requested size.

When a QTCanvas' client is set the size of the client's current size is used by the QTCanvas to indicate that this is that client's best viewing size. By default (and an application can change this) this will also become the preferred size of the QTCanvas. This size is cached by the QTCanvas and used when it is responding to resize requests from its parent Container (for instance, the user resizes the window the QTCanvas is in).

If an application changes the size of the client after it has been set - for instance a Movie client is edited and the viewing area of the movie is now different - then the application must inform the QTCanvas that the client's best size is changed, before resizing the QTCanvas itself. This ensures that the QTCanvas will resize and redraw the client correctly, avoiding unwanted scaling of the client:

	// application changes the actual display size of a Movie through 
	// adding a video track to a movie that only had a sound track
	// this means that the movie client has now a best size that 
	// that is different when it was originally set as the client of this QTCanvas
	myQTCanvas.clientChanged (r.getWidth(), r.getHeight());
	myQTCanvas.invalidate();
 	//resize the QTCanvas' parent container so that the changed viewing conditions of the
	//client will be seen.
	//pack() is appropriate, as is getParent().setSize(), or getParent().setBounds()
	//The application could also just validate the parent if the parent should not change size
 

Once the application has notified the canvas that the client's best viewing size has changed the QTCanvas will correctly respond to the any new sizes that are given to it by it parent's layout manager or resizing actions.

In most interactions between a QTCanvas and its client this explicit resizing of the client is not required as all of the Drawable clients are able to scale themselves appropriately to a different display size. It is only required when the client's size itself has changed.

See Also:
Drawable

Variable Index

 o kAspectResize
Use this flag if the client can be resized to any size which preserves the initial aspect ratio.
 o kFreeResize
Use this flag if the client can be resized to any size >= the minimum and <= the maximum.
 o kHorizontalResize
Use this flag to allow the client's horizontal aspect to be any size, but the vertical axis will be the intial size of smaller.
 o kInitialSize
Use this flag if the client should revert to its initially specified size.
 o kIntegralResize
Use this flag if the client should maintain the aspect size of its original dimensions but grow bigger by integral increments (2x, 3x, 4x, etc.)
 o kPerformanceResize
Use this flag if the client can be resized to any size which is a factor of 2 of the initial size.
 o kVerticalResize
Use this flag to allow the client's vertical aspect to be any size, but the horizontal axis will be the intial size of smaller.

Constructor Index

 o QTCanvas()
Constructor for creating a client-less QTCanvas.
 o QTCanvas(int, float, float)
Constructor for creating a client-less QTCanvas.

Method Index

 o addNotify()
We use this method to notify an existing client that its NativeGraphics environment may have changed and it should recheck its status
 o addQTClientListener(ComponentListener)
A ComponentListener and ComponentEvent are used to listen to these types of events that occur to the QTCanvas' client - ie.
 o clientChanged(Dimension)
This method is used by an appliction to notify a QTCanvas that the best size of its' current client has changed.
 o clientChanged(int, int)
This method is used by an appliction to notify a QTCanvas that the best size of its' current client has changed.
 o finalize()
 o getAlignmentX()
Returns the current setting of the x position alignment being used.
 o getAlignmentY()
Returns the current setting of the y position alignment being used.
 o getBestSize()
Returns the best size of the client, the size of the client when it was set to this QTCanvas, or the size if the appliction notified the QTCanvas that the clien't best size was changed.
 o getClient()
Returns the Drawable object currently associated with this QTCanvas.
 o getMaximumSize()
Returns the maximum acceptable size of this QTCanvas object.
 o getMinimumSize()
Returns the minimum acceptable size of this QTCanvas object.
 o getNativeGraphics()
Returns the NativeGrapics object that represents the Graphics Port that corresponds to the display space taken up by the QTCanvas.
 o getNGLocation()
Returns the coordinates of a component relative to the NativeGrapics window it is currently placed within.
 o getPort()
This method will return a QTJava object, QDGraphics, which is a reference to the native graphics drawing environment being used by this QTCanvas object.
 o getPreferredSize()
Returns the preferred size of the QTCanvas object.
 o getResizeFlag()
Returns the current setting of the resize flag being used.
 o paint(Graphics)
Override the standard paint method.
 o removeClient()
Removes the client from the canvas.
 o removeNotify()
Overridden to notify the client associated with this QTCanvas that it no longer has a grafport to draw to and should stop all graphics operations.
 o removeQTClientListener(ComponentListener)
Remove a previously registered ComponentListener that is listening to events that occur with the QTCanvas' QTDrawable client.
 o reshape(int, int, int, int)
Deprecated.
 o setAlignment(float, float)
Set the alignment position values.
 o setAlignmentX(float)
 o setAlignmentY(float)
 o setBounds(int, int, int, int)
Resizes and/or moves the QTCanvas object as well as the associated Drawable object to the parameters specified.
 o setClient(Drawable, boolean)
Associates a new client, a Drawable object, with this QTCanvas.
 o setClient(Drawable, QDRect)
Associates a new client, a Drawable object, with this QTCanvas.
 o setMaximumSize(Dimension)
Set the minimum size of the QTCanvas.
 o setMaximumSize(int, int)
Set the maximum size of the canvas.
 o setMinimumSize(Dimension)
Set the minimum size of the QTCanvas.
 o setMinimumSize(int, int)
Set the minimum size of the canvas.
 o setPreferredSize(Dimension)
Sets the preferred size of the QTCanvas object.
 o setPreferredSize(int, int)
Sets the preferred size of the QTCanvas object.
 o setResizeFlag(int)
Reset the resize flag and re-layout the component.
 o setSize(Dimension)
Resizes the QTCanvas object to the specified parameters.
 o setSize(int, int)
Resizes the QTCanvas object, as well as the associated Drawable object.
 o setVisible(boolean)
Sets the visible state of the Canvas.
 o toString()
Print information about this object.
 o translatePoint(int, int)
An incoming point (typically from some kind of MouseEvent) is in coordinates that have their origin set at the local coordinate system of the canvas.
 o update(Graphics)
We override the update method to call our paint method as the background colour repaint is not valid for a QTCanvas object.

Variables

 o kIntegralResize
 public static final int kIntegralResize
Use this flag if the client should maintain the aspect size of its original dimensions but grow bigger by integral increments (2x, 3x, 4x, etc.)

 o kInitialSize
 public static final int kInitialSize
Use this flag if the client should revert to its initially specified size. The client can be made smaller (using an aspect setting) but can be no larger than its initial size. The QTCanvas takes this initial size as the best viewing size for its client.

 o kFreeResize
 public static final int kFreeResize
Use this flag if the client can be resized to any size >= the minimum and <= the maximum.

 o kAspectResize
 public static final int kAspectResize
Use this flag if the client can be resized to any size which preserves the initial aspect ratio.

 o kPerformanceResize
 public static final int kPerformanceResize
Use this flag if the client can be resized to any size which is a factor of 2 of the initial size.

 o kHorizontalResize
 public static final int kHorizontalResize
Use this flag to allow the client's horizontal aspect to be any size, but the vertical axis will be the intial size of smaller. This is a good setting for QT VR content.

 o kVerticalResize
 public static final int kVerticalResize
Use this flag to allow the client's vertical aspect to be any size, but the horizontal axis will be the intial size of smaller.

Constructors

 o QTCanvas
 public QTCanvas()
Constructor for creating a client-less QTCanvas. Default settings are:
Resize Flag is kFreeResize
xAlignment and yAlignment are both set to 0 (top left)
Minimum size is (1, 1)
Maximum size is (Integer.MAX_VALUE, Integer.MAX_VALUE)

 o QTCanvas
 public QTCanvas(int resizeFlag,
                 float xAlignment,
                 float yAlignment)
Constructor for creating a client-less QTCanvas.

Parameters:
resizeFlag - the resize control setting
xAlignment - a value between 0 and 1 that sets the position of the drawable client within the space that AWT will give to the canvas when layed out. 0 means left, 1 means right, 0.5 means centre.
yAlignment - a value between 0 and 1 that sets the position of the drawable client within the space that AWT will give to the canvas when layed out. 0 means top, 1 means bottom, 0.5 means centre.

Methods

 o getPort
 public final QDGraphics getPort() throws QTUnknownOSException, NativeGraphicsException
This method will return a QTJava object, QDGraphics, which is a reference to the native graphics drawing environment being used by this QTCanvas object. If the canvas is invisible it will return an offscreen QDGraphics that will never be seen.

Returns:
a QDGraphics object
Throws: QTUnknownOSException
if the current operating system is unknown to QuickTime
Throws: NativeGraphicsException
if there was a problem initialising the NativeGraphics environment
 o getNGLocation
 public final Point getNGLocation() throws QTUnknownOSException, NativeGraphicsException
Returns the coordinates of a component relative to the NativeGrapics window it is currently placed within.

Returns:
a Point object representing the location of the QTCanvas in the native graphics environment
 o getNativeGraphics
 public final NativeGraphics getNativeGraphics()
Returns the NativeGrapics object that represents the Graphics Port that corresponds to the display space taken up by the QTCanvas. It may return null if there is currently no native graphics environment

Returns:
a NativeGraphics object.
 o translatePoint
 public final QDPoint translatePoint(int x,
                                     int y) throws QTUnknownOSException, NativeGraphicsException
An incoming point (typically from some kind of MouseEvent) is in coordinates that have their origin set at the local coordinate system of the canvas. This method converts those coordinates into the native graphics location that is the coordinate system of the canvas' client.

Parameters:
x - the x location
y - the y location
Returns:
a QDPoint that translates the x and y into the NativeGraphics coordinate system.
 o removeClient
 public final synchronized void removeClient()
Removes the client from the canvas.

 o setClient
 public synchronized void setClient(Drawable client,
                                    boolean layoutFlag) throws QTException
Associates a new client, a Drawable object, with this QTCanvas. The flag determines if awt will perform a layout and how the client will be integrated with the canvas. If the flag is false then the new client will take on the current size and position of the canvas. If the flag is true, then awt will layout the canvas again, using the initial size of the client and the resize flags to resize the canvas and its client.

The size of the client when this method is called is used to ascertain the best size for viewing this client's media.

This method can throw a number of exceptions:
QTUnknownOSException the application is trying to run on a platform that is not supported by QuickTime
NativeGraphicsException the native graphics environment is not initialised
QTException or subclass - there was a problem within QuickTime itself in dealing with this client

Parameters:
client - a Drawable object - if null the method will remove the client
layoutFlag - if true java.awt will re-layout the canvas, if false the client will fit into the existing state (display size, etc) of the canvas, disregarding any resize that might have occured to honour the layout flag setting with respect to the different size of the new client.
 o setClient
 public synchronized void setClient(Drawable client,
                                    QDRect initialBounds) throws QTException
Associates a new client, a Drawable object, with this QTCanvas. It will use existing alignment and resize restrictions.

This method can throw a number of exceptions:
QTUnknownOSException the application is trying to run on a platform that is not supported by QuickTime
NativeGraphicsException the native graphics environment is not initialised
QTException or subclass - there was a problem within QuickTime itself in dealing with this client

Parameters:
client - a Drawable object - if null the method will remove the client
initialBounds - the best size of the client
 o getClient
 public final Drawable getClient()
Returns the Drawable object currently associated with this QTCanvas.

Returns:
a Drawable object
 o setAlignment
 public void setAlignment(float xAlignment,
                          float yAlignment)
Set the alignment position values. The alignment values must be between 0.0 and 1.0. Values out of this range will be reset to either 0.0 or 1.0, whichever is closest to the given argument.

Alignment Positioning works like this:

x=0.0 y=0.0
is equivalent to a top-left position
x=1.0 y=1.0
is equivalent to a bottom-right position
x=0.5 y=0.5
is equivalent to a centered position
x=0.25 y=0.75
is equivalent to 1/4 in from the the left and 3/4 down from the top
Position alignments can be varied to any degree, limited by the pixel resolution of the display surface.

Parameters:
xAlignment - a float between 0.0 and 1.0 representing the x position alignment
yAlignment - a float between 0.0 and 1.0 representing the y position alignment
 o setAlignmentX
 public final void setAlignmentX(float x)
See Also:
setAlignment
 o setAlignmentY
 public final void setAlignmentY(float y)
See Also:
setAlignment
 o getAlignmentX
 public float getAlignmentX()
Returns the current setting of the x position alignment being used.

Returns:
s the x position alignment
Overrides:
getAlignmentX in class Component
 o getAlignmentY
 public float getAlignmentY()
Returns the current setting of the y position alignment being used.

Returns:
s the y position alignment
Overrides:
getAlignmentY in class Component
 o setResizeFlag
 public void setResizeFlag(int rFlag)
Reset the resize flag and re-layout the component.

Parameters:
rFlag - the new value for the resizeFlag
 o getResizeFlag
 public int getResizeFlag()
Returns the current setting of the resize flag being used.

Returns:
the resize flag value
 o setMinimumSize
 public void setMinimumSize(Dimension minSize)
Set the minimum size of the QTCanvas. If the QTCanvas is currently smaller than the minimum size passed in, it will be adjusted to meet the new minimum size requirements, in accordance with the setting of the resizeFlag.

Parameters:
minSize - a Dimension object
 o setMinimumSize
 public void setMinimumSize(int width,
                            int height)
Set the minimum size of the canvas.

Parameters:
width - the minimum width
height - the minimum height
 o getMinimumSize
 public Dimension getMinimumSize()
Returns the minimum acceptable size of this QTCanvas object.

Returns:
a Dimension object which defines the minimum size
Overrides:
getMinimumSize in class Component
 o getBestSize
 public Dimension getBestSize()
Returns the best size of the client, the size of the client when it was set to this QTCanvas, or the size if the appliction notified the QTCanvas that the clien't best size was changed. This may not be the size of the display space of the QTCanvas depending on java layout instructions and current display space available to the canvas.

Returns:
a Dimension object which details the client's known initial size
See Also:
clientChanged
 o clientChanged
 public void clientChanged(Dimension bestSize)
This method is used by an appliction to notify a QTCanvas that the best size of its' current client has changed. This is typically the initial or actual size of the client before any matrix transforamations have been applied to the client.

An application only needs to call this if the display characteristics of the client have been changed. For instance, the client is a movie and some of the visual tracks of this movie have been disabled, or a new video track was added. Thus the movie itself has changed its best size and the application must use this method to notify the QTCanvas that the client's best size has changed.

This will not effect the display area of the QTCanvas, the application should invalidate the QTCanvas and re-layout the parent container to have this change take effect. getBestSize() returns this newly notified size.

In the normal operation of a QTCanvas and its client there is no need for an application to use this method.

Parameters:
bestSize - the client's new best width and height
 o clientChanged
 public void clientChanged(int bestWidth,
                           int bestHeight)
This method is used by an appliction to notify a QTCanvas that the best size of its' current client has changed. This is typically the initial or actual size of the client before any matrix transforamations have been applied to the client.

An application only needs to call this if the display characteristics of the client have been changed. For instance, the client is a movie and some of the visual tracks of this movie have been disabled, or a new video track was added. Thus the movie itself has changed its best size and the application must use this method to notify the QTCanvas that the client's best size has changed.

This will not effect the display area of the QTCanvas, the application should invalidate the QTCanvas and re-layout the parent container to have this change take effect. getBestSize() returns this newly notified size.

In the normal operation of a QTCanvas and its client there is no need for an application to use this method.

Parameters:
bestWidth - the client's new best width
bestHeight - the client's new actual height
 o getPreferredSize
 public Dimension getPreferredSize()
Returns the preferred size of the QTCanvas object. If you haven't explicitly set the preferred size of the canvas this will be the initial size of the canvas' client.

Returns:
a Dimension object which defines the preferred size
Overrides:
getPreferredSize in class Component
 o setPreferredSize
 public void setPreferredSize(Dimension prefSize)
Sets the preferred size of the QTCanvas object.

Returns:
a Dimension object which defines the preferred size
 o setPreferredSize
 public void setPreferredSize(int width,
                              int height)
Sets the preferred size of the QTCanvas object. Passing in values of less than zero for width and height will reset the behaviour of the QTCanvas to retrieve the preferred size as the initial size of the current or new client of the QTCanvas.

Parameters:
width - the minimum width
height - the minimum height
 o setMaximumSize
 public void setMaximumSize(Dimension maxSize)
Set the minimum size of the QTCanvas. If the QTCanvas is currently larger than the maximum size passed in, it will be adjusted to meet the new maximum size requirements, in accordance with the setting of the resizeFlag.

Parameters:
maxSize - a Dimension object
 o setMaximumSize
 public void setMaximumSize(int width,
                            int height)
Set the maximum size of the canvas.

Parameters:
width - the minimum width
height - the minimum height
 o getMaximumSize
 public Dimension getMaximumSize()
Returns the maximum acceptable size of this QTCanvas object.

Returns:
a Dimension object which defines the maximum size
Overrides:
getMaximumSize in class Component
 o setSize
 public void setSize(Dimension dim)
Resizes the QTCanvas object to the specified parameters.

Parameters:
dim - a Dimension object with the new width and height
Overrides:
setSize in class Component
 o setSize
 public void setSize(int width,
                     int height)
Resizes the QTCanvas object, as well as the associated Drawable object.

Parameters:
width - the width, in pixels, to make this component
height - the height, in pixels, to make this component
Overrides:
setSize in class Component
 o reshape
 public final void reshape(int x,
                           int y,
                           int width,
                           int height)
Overrides:
reshape in class Component
 o setBounds
 public final synchronized void setBounds(int x,
                                          int y,
                                          int width,
                                          int height)
Resizes and/or moves the QTCanvas object as well as the associated Drawable object to the parameters specified.

Parameters:
x - the x coordinate, in pixels, relative to the parent of this component
y - the y coordinate, in pixels, relative to the parent of this component
width - the width, in pixels, to make this component
height - the height, in pixels, to make this component
Overrides:
setBounds in class Component
 o paint
 public void paint(Graphics g)
Override the standard paint method.

Overrides:
paint in class Canvas
 o update
 public void update(Graphics g)
We override the update method to call our paint method as the background colour repaint is not valid for a QTCanvas object. However, subclasses can override the update method to do whatever is appropriate for their particular situation.

Overrides:
update in class Component
 o setVisible
 public synchronized void setVisible(boolean b)
Sets the visible state of the Canvas.

Parameters:
b - if true canvas is visible, if false then its not
Overrides:
setVisible in class Component
 o addQTClientListener
 public void addQTClientListener(ComponentListener e)
A ComponentListener and ComponentEvent are used to listen to these types of events that occur to the QTCanvas' client - ie. when the QTCanvas' client is resized, moved, shown or hidden. These events generally occur in conjunction with the Component events they mirror - with some exceptions:
 o removeQTClientListener
 public void removeQTClientListener(ComponentListener e)
Remove a previously registered ComponentListener that is listening to events that occur with the QTCanvas' QTDrawable client.

Parameters:
e - the ComponentListener
See Also:
addQTClientListener
 o addNotify
 public synchronized void addNotify()
We use this method to notify an existing client that its NativeGraphics environment may have changed and it should recheck its status

Overrides:
addNotify in class Canvas
 o removeNotify
 public synchronized void removeNotify()
Overridden to notify the client associated with this QTCanvas that it no longer has a grafport to draw to and should stop all graphics operations.

Overrides:
removeNotify in class Component
 o toString
 public String toString()
Print information about this object.

Returns:
a string representing this QTCanvas object
Overrides:
toString in class Component
 o finalize
 protected void finalize() throws Throwable
Overrides:
finalize in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index