Next Page > Hide TOC

Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

NSSize

Inherits from
Object
Implements
Cloneable
Package
com.apple.cocoa.foundation
Companion guide
Geometry and Range Utilities

Overview

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 to 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.

Tasks

Constructors

Accessing Dimensions

Testing NSSizes

Transforming NSSizes

Copying

Constructors

NSSize

public NSSize()

Discussion

Initializes the instance to a dimensionless NSSize.

public NSSize(float w, float h)

Discussion

Initializes the NSSize with the width dimension w and the height dimension y.

Normally, the values of w and h are non-negative. The constructors that create an NSSize do not prevent you from setting a negative value for these attributes. If the value of w or h is negative, however, the behavior of some methods may be undefined.

public NSSize(NSSize aSize)

Discussion

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

public NSSize(java.awt.Dimension javaDimension)

Discussion

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

Static Methods

fromString

public static NSSize fromString(String sizeAsString)

Discussion

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

Instance Methods

clone

Creates and returns a copy of the receiver.

public Object clone()

equals

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

public boolean equals(Object otherObject)

See Also

hashCode

Provides an appropriate hash code useful for storing the receiver in a hash-based data structure.

public int hashCode()

Discussion

This value is the sum of the receiver’s width and height, rounded to the nearest integer.

height

Returns the height dimension of the receiver.

public float height()

See Also

isEmpty

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

public boolean isEmpty()

isEqualToSize

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

public boolean isEqualToSize(NSSize aSize)

See Also

toAWTDimension

Returns the receiver as an AWT Dimension object.

public java.awt.Dimension toAWTDimension()

Discussion

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

See Also

toString

Returns the receiver as converted to a string object.

public String toString()

Discussion

The string has the form of “{w, h}”, where w is the float representation of width and h is the float representation of height.

See Also

width

Returns the width of the receiver.

public float width()

See Also

Constants

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

Constant

Description

ZeroSize

An NSSize set to 0 in both dimensions



Next Page > Hide TOC


© 1997, 2006 Apple Computer, Inc. All Rights Reserved. (Last updated: 2006-07-24)


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.