
javax.tv.media.AWTVideoSize Maven / Gradle / Ivy
/*
* @(#)AWTVideoSize.java 1.12 00/08/06
*
* Copyright 1998-2000 by Sun Microsystems, Inc.,
* 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
* All rights reserved.
*
* This software is the confidential and proprietary information
* of Sun Microsystems, Inc. ("Confidential Information"). You
* shall not disclose such Confidential Information and shall use
* it only in accordance with the terms of the license agreement
* you entered into with Sun.
*/
package javax.tv.media;
import java.awt.Rectangle;
import java.awt.Point;
/**
* AWTVideoSize
is a data holder that represents the
* position, scaling, and clipping of a JMF Player, as controlled via
* an AWTVideoSizeControl. All coordinates are expressed in the same
* coordinate space as AWT components. Because background video might
* be larger than the addressible AWT area, some of the positions
* might be negative.
*
* An AWTVideoSize represents a transformation
* of video where the video is first positioned, then scaled, and then
* clipped. A rectangle (in the screen's coordinate system) of the
* source video is translated, scaled and clipped to fit within a
* rectangle specified in the screen's coordinate system.
*
* @version 1.12, 08/06/00
*
* @see javax.tv.media.AWTVideoSizeControl */
public class AWTVideoSize {
private Rectangle source, dest;
private float scaleX = 1, scaleY = 1;
/**
* Constructs a new AWTVideoSize
instance. This
* AWTVideoSize
represents a transformation where the
* rectangle source
in the source video is scaled and
* clipped to be within the rectangle dest
.
*
*
The instance of AWTVideoSize created with this constructor
* will not maintain a reference to either of the constructor's
* parameters.
*
* @param source The rectangle representing the portion of the source
* video to display, in the coordinate system of the screen.
*
* @param dest The rectangle representing where the video is to be
* displayed, in the coordinate system of the screen. */
public AWTVideoSize(Rectangle source, Rectangle dest) {
if ( source == null || dest == null ) {
throw new NullPointerException("null rectangle");
}
this.source = new Rectangle(source);
this.dest = new Rectangle(dest);
scaleX = getXScale();
scaleY = getYScale();
}
/**
* Return a copy of the rectangle representing the portion of the source
* video to display, in the coordinate system of the screen.
*
* @return The source Rectangle
.
*/
public Rectangle getSource() {
return new Rectangle(this.source);
}
/**
* Return a copy of the rectangle representing where the video is to be
* displayed, in the coordinate system of the screen.
*
* @return The destination Rectangle
.
*/
public Rectangle getDestination() {
return new Rectangle(this.dest);
}
/**
* Give the scaling factor applied to the video in the horizontal
* dimension, i.e.,
* getDestination().width / getSource().width
.
*
* @return The horizontal scaling factor applied to the video.
*/
public float getXScale() {
return (float)getDestination().width / (float)getSource().width;
}
/**
* Give the scaling factor applied to the video in the vertical
* dimension, i.e.,
* getDestination().height / getSource().height
.
*
* @return The vertical scaling factor applied to the video.
*/
public float getYScale() {
return (float)getDestination().height / (float)getSource().height;
}
/**
* Generates a hash code value for this AWTVideoSize
.
* Two AWTVideoSize
instances for which
* AWTVideoSize.equals()
is true
will
* have identical hash code values.
*
* @return The hashcode value for this AWTVideoSize
.
**/
public int hashCode() {
return toString().hashCode();
}
/**
* Compares this AWTVideoSize
with the given object
* for equality. Returns true
if and only if the
* given object is also of type AWTVideoSize
and
* contains data members equal to those of this
* AWTVideoSizetrue
if the two AWTVideoSize instances are
* equal; false
otherwise.
**/
public boolean equals(Object other) {
if (!(other instanceof AWTVideoSize))
return false;
AWTVideoSize vs1 = this;
AWTVideoSize vs2 = (AWTVideoSize)other;
if (vs1.getDestination().equals(vs2.getDestination()) == false)
return false;
if (vs1.getSource().equals(vs2.getSource()) == false)
return false;
return true;
}
/**
* Returns a string representation of this
* AWTVideoSize
and its values.
*
* @return A string representation of this object.
**/
public String toString() {
return "source[x=" +source.x+ ",y=" +source.y+
",width=" +source.width+ ",height=" +source.height+ "]" +
"dest[x=" +dest.x+ ",y=" +dest.y+
",width=" +dest.width+ ",height=" +dest.height+ "]" +
"scaleX=" + scaleX + ", scaleY=" + scaleY;
}
}