PATH  Documentation > Mac OS X > Foundation Reference: Java



Table of Contents

NSSize


Inherits from:
Object
Implements:
Cloneable
Package:
com.apple.yellow.foundation


Class Description


An NSSize object represents a dimension, a specification of width and height. An NSSize, together with an NSPoint, can be used to represent a rectangle (NSRect). The methods of NSSize allow you access the height and width of an object, to compare and test NSSizes, to convert NSSizes to AWT Dimension objects, and to convert NSSizes to and from string objects.

NSSize provides the following constant as a convenience; you can use it to compare values returned by some NSSize methods:


Constant Type Description
ZeroSize NSSize An NSSize set to zero in both dimensions.




Method Types


Constructors
NSSize
Accessing dimensions
height
width
Testing NSSizes
equals
hashCode
isEmpty
isEqualToSize
Transforming NSSizes
toAWTDimension
toString
fromString


Constructors



NSSize

public NSSize()

Initializes the instance to a dimension-less NSSize.

public NSSize( float w, float h)

Initializes the NSSize with the width dimension w and the height dimension y; throws an IllegalArgumentException if either value is negative.

public NSSize(NSSize aSize)

Initializes the new NSSize with the width and height values of an existing NSSize; this constructor is used in cloning the receiver.

public NSSize(java.awt.Dimension javaDimension)

Initializes the NSSize with the values extracted from an AWT Dimension object.


Static Methods



fromString

public static NSSize fromString(String sizeAsString)

Creates an NSSize from the string sizeAsString, which must be of the form "{w,h}" where w is a float representation of the width and h is a float representation of the height. Throws an IllegalArgumentException if the string is improperly formatted.

See Also: toString




Instance Methods



clone

public Object clone()

Description forthcoming.

equals

public boolean equals(Object otherObject)

Returns whether otherObject is an NSSize and is equal in width and height to the receiver.

See Also: isEqualToSize



hashCode

public int hashCode()

Provides an appropriate hash code useful for storing the receiver in a hash-based data structure. This value is the sum of the receiver's width and height, rounded to the nearest integer.

height

public float height()

Returns the height dimension of the receiver.

See Also: width



isEmpty

public boolean isEmpty()

Returns whether either dimension (width or height) of the receiver is zero.

isEqualToSize

public boolean isEqualToSize(NSSize aSize)

Returns whether the NSSize aSize is equal in width and height to the receiver.

See Also: equals



toAWTDimension

public java.awt.Dimension toAWTDimension()

Returns the receiver as a AWT Dimension object. The float values of width and height are rounded up to the nearest integers with which the resulting Dimension can enclose the original size.

See Also: toString



toString

public String toString()

Returns the receiver as converted to a string object in the form of "{w,h}" where w is the float representation of width and h is the float representation of height.

See Also: fromString



width

public float width()

Returns the width of the receiver.

See Also: height




Table of Contents