Draw2D v2.0

org.eclipse.draw2d.geometry
Class Dimension

java.lang.Object
  |
  +--org.eclipse.draw2d.geometry.Dimension
All Implemented Interfaces:
Cloneable, Serializable

public class Dimension
extends Object
implements Cloneable, Serializable

Provides support for the physical entity of dimension.

See Also:
Serialized Form

Field Summary
 int height
           
 int width
           
 
Constructor Summary
Dimension()
          Constructs a Dimension of zero width and height.
Dimension(Dimension d)
          Constructs a Dimension with the width and height of the passed Dimension.
Dimension(Image image)
          Constructs a Dimension with the width and height of the Image supplied as input.
Dimension(int w, int h)
          Constructs a Dimension with the supplied width and height values.
Dimension(Point pt)
          Constructs a Dimension where the width and height are the x and y distances of the input point from the origin.
 
Method Summary
 boolean contains(Dimension d)
          Returns whether the input Dimension fits into this Dimension.
 boolean containsProper(Dimension d)
          Returns whether the input Dimension fits into this Dimension.
 void copyFrom(Dimension d)
          Copies the width and height values of the input Dimension to this Dimension.
 boolean equals(int w, int h)
          Returns whether this Dimension's width and height are equal to the given width and height.
 boolean equals(Object o)
          Returns whether the input Dimension is same as this Dimension.
 Dimension expand(Dimension d)
          Increases the size of this Dimension by the Dimension supplied as input, and returns this for convenience.
 Dimension expand(int w, int h)
          Increases the size of this Dimension by the width and height values supplied as input, and returns this for convenience.
 Dimension expand(Point pt)
          Increases the size of this Dimension with the distances of the input point from the origin along each of the axes, and returns this for convenience.
 int getArea()
          Returns the area covered by this Dimension.
 Dimension getCopy()
          Returns a copy of this Dimension
 Dimension getDifference(Dimension d)
          Returns a Dimension comprised of the differences in width and height of this Dimension compared to the passsed Dimension.
 Dimension getExpanded(Dimension d)
          Returns a new Dimension which is comprised of this Dimension's width expanded by d.width and this Dimension's height expanded by d.height.
 Dimension getExpanded(int w, int h)
          Returns a new Dimension which is comprised of this Dimension's width expanded by w.
 Dimension getIntersected(Dimension d)
          Creates and returns a new Dimension representing the intersecting region of this Dimension and the given Dimension.
 Dimension getNegated()
          Returns a new Dimension with a negated copy of this Dimension.
 Dimension getScaled(float amount)
          Returns a new Dimension with its width and height scaled by the input value supplied.
 Dimension getTransposed()
          Returns a new Dimension with its height and width interchanged.
 Dimension getUnioned(Dimension d)
          Returns a new Dimension containing the union of this and the supplied Dimension.
 boolean greaterThan(Dimension d)
          Returns true if this Dimension is greater than the given Dimension in at least one dimension and greater than or equal to in the other.
 Dimension intersect(Dimension d)
          Modifies this Dimension in such a way that its width becomes the greater of this Dimension's height and d's height, and its height becomes the greater of this Dimension's width and d's width.
 boolean isEmpty()
          Returns whether the Dimension has width or height greater than 0.
 Dimension negate()
          Negates this Dimension
 Dimension scale(float amount)
          Scales the width and height of this Dimension by the amount supplied, and returns this for convenience.
 Dimension scale(float w, float h)
          Scales the width of this Dimension by w and scales the height of this Dimension by h.
 Dimension shrink(int w, int h)
          Reduces the width of this Dimension by w, and reduces the height of this Dimension by h.
 String toString()
          Returns a String description of this Dimension.
 Dimension transpose()
          Switches the width and height of this Dimension, and returns this for convenience.
 Dimension union(Dimension d)
          Sets the width of this Dimension to the greater of this Dimension's width and d.width.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

width

public int width

height

public int height
Constructor Detail

Dimension

public Dimension()
Constructs a Dimension of zero width and height.
Since:
2.0

Dimension

public Dimension(Dimension d)
Constructs a Dimension with the width and height of the passed Dimension.
Parameters:
d - Dimension supplying the initial values.
Since:
2.0

Dimension

public Dimension(Point pt)
Constructs a Dimension where the width and height are the x and y distances of the input point from the origin.
Parameters:
pt - Point supplying the initial values.
Since:
2.0

Dimension

public Dimension(int w,
                 int h)
Constructs a Dimension with the supplied width and height values.
Parameters:
w - Width of the Dimension.
h - Height of the Dimension.
Since:
2.0

Dimension

public Dimension(Image image)
Constructs a Dimension with the width and height of the Image supplied as input.
Parameters:
image - SWT Image supplying the dimensions.
Since:
2.0
See Also:
Image
Method Detail

contains

public boolean contains(Dimension d)
Returns whether the input Dimension fits into this Dimension. A Dimension of the same size is considered to "fit".
Parameters:
d - Dimension being tested.
boolean - specifying the result of the fit test.
Since:
2.0

containsProper

public boolean containsProper(Dimension d)
Returns whether the input Dimension fits into this Dimension. A Dimension of the same size is considered to not "fit".
Parameters:
d - Dimension being tested.
boolean - specifying the result of the fit test.
Since:
2.0

copyFrom

public void copyFrom(Dimension d)
Copies the width and height values of the input Dimension to this Dimension.
Parameters:
d - Dimension supplying the values.
Since:
2.0

getArea

public int getArea()
Returns the area covered by this Dimension.
Returns:
Returns the area covered by this Dimension.
Since:
2.0

getCopy

public Dimension getCopy()
Returns a copy of this Dimension
Returns:
A copy of this Dimension
Since:
2.0

getDifference

public Dimension getDifference(Dimension d)
Returns a Dimension comprised of the differences in width and height of this Dimension compared to the passsed Dimension.
Parameters:
d - Dimension being compared.
Returns:
A new Dimension signifying the difference of width and height.
Since:
2.0
See Also:
getExpanded(Dimension), getExpanded(int,int)

getExpanded

public Dimension getExpanded(Dimension d)
Returns a new Dimension which is comprised of this Dimension's width expanded by d.width and this Dimension's height expanded by d.height.
Parameters:
d - Dimension providing the expansion width and height.
Returns:
A new Dimension containing the expanded width and height.
Since:
2.0
See Also:
getDifference(Dimension)

getExpanded

public Dimension getExpanded(int w,
                             int h)
Returns a new Dimension which is comprised of this Dimension's width expanded by w. and this Dimension's height expanded by h.
Parameters:
w - Value by which the width of this is to be expanded.
h - Value by which the height of this is to be expanded.
Returns:
A new Dimension containing the expanded width and height.
Since:
2.0
See Also:
getDifference(Dimension)

getIntersected

public Dimension getIntersected(Dimension d)
Creates and returns a new Dimension representing the intersecting region of this Dimension and the given Dimension.
Since:
2.0
See Also:
intersect(Dimension)

getNegated

public Dimension getNegated()
Returns a new Dimension with a negated copy of this Dimension.
Returns:
A negated copy of this Dimension
Since:
2.0

equals

public boolean equals(Object o)
Returns whether the input Dimension is same as this Dimension. True if the height and width of this Dimension are equivalent to the input Dimension, false otherwise.
Overrides:
equals in class Object
Parameters:
o - Object being tested for equality.
Returns:
Result of the size test.
Since:
2.0

equals

public boolean equals(int w,
                      int h)
Returns whether this Dimension's width and height are equal to the given width and height.
Since:
2.0

expand

public Dimension expand(Dimension d)
Increases the size of this Dimension by the Dimension supplied as input, and returns this for convenience.
Parameters:
d - Dimension providing the expansion width and height.
Returns:
Returns this Dimension with the expanded widht and height.
Since:
2.0
See Also:
expand(int,int), shrink(int,int)

expand

public Dimension expand(Point pt)
Increases the size of this Dimension with the distances of the input point from the origin along each of the axes, and returns this for convenience.
Parameters:
pt - Point supplying the dimensional values.
Returns:
Returns this Dimension with the incremented sizes.
Since:
2.0
See Also:
shrink(int,int)

expand

public Dimension expand(int w,
                        int h)
Increases the size of this Dimension by the width and height values supplied as input, and returns this for convenience.
Parameters:
w - Value by which the width should be increased.
h - Value by which the height should be increased.
Returns:
Returns this Dimension with the incremented sizes.
Since:
2.0

getScaled

public Dimension getScaled(float amount)
Returns a new Dimension with its width and height scaled by the input value supplied.
Parameters:
amount - Value by which the width and height are scaled.
Returns:
A new Dimension containing the scaled width and height.
Since:
2.0

getTransposed

public Dimension getTransposed()
Returns a new Dimension with its height and width interchanged. Useful in orientation change calculations.
Returns:
Returns a new Dimension containing the switched width and height.
Since:
2.0

getUnioned

public Dimension getUnioned(Dimension d)
Returns a new Dimension containing the union of this and the supplied Dimension. The union operation takes the maximum of the width and height.
Parameters:
d - Dimension to be unioned.
Returns:
Returns a new Dimension with the unioned sizes.'
Since:
2.0
See Also:
getDifference(Dimension)

greaterThan

public boolean greaterThan(Dimension d)
Returns true if this Dimension is greater than the given Dimension in at least one dimension and greater than or equal to in the other.
Parameters:
d - Dimension against which this Dimension is compared.
Returns:
A boolean indicating whether or not this Dimension is greater than d.
Since:
2.0

intersect

public Dimension intersect(Dimension d)
Modifies this Dimension in such a way that its width becomes the greater of this Dimension's height and d's height, and its height becomes the greater of this Dimension's width and d's width. this modified Dimension is returned for convenience.
Since:
2.0

isEmpty

public boolean isEmpty()
Returns whether the Dimension has width or height greater than 0.
Returns:
boolean containing the emptiness test.
Since:
2.0

negate

public Dimension negate()
Negates this Dimension
Returns:
Returns this Dimension for convenience.
Since:
2.0

scale

public Dimension scale(float amount)
Scales the width and height of this Dimension by the amount supplied, and returns this for convenience.
Parameters:
amount - Value by which this Dimension's width and height are to be scaled.
Returns:
Returns this Dimension with the scaled values.
Since:
2.0

scale

public Dimension scale(float w,
                       float h)
Scales the width of this Dimension by w and scales the height of this Dimension by h. Returns this for convenience.
Parameters:
w - Value by which the width is to be scaled.
h - Value by which the height is to be scaled.
Returns:
Returns this Dimension with the scaled values.
Since:
2.0

shrink

public Dimension shrink(int w,
                        int h)
Reduces the width of this Dimension by w, and reduces the height of this Dimension by h. Returns this for convenience.
Parameters:
w - Value by which the width is to be reduced.
h - Value by which the height is to be reduced.
Returns:
Returns this Dimension with the reduced width and height values.
Since:
2.0

toString

public String toString()
Returns a String description of this Dimension.
Overrides:
toString in class Object
Returns:
Description as a String.
Since:
2.0

transpose

public Dimension transpose()
Switches the width and height of this Dimension, and returns this for convenience. Can be useful in orientation changes.
Returns:
This Dimension with the switched values.
Since:
2.0

union

public Dimension union(Dimension d)
Sets the width of this Dimension to the greater of this Dimension's width and d.width. Likewise for this Dimension's height.
Parameters:
d - Dimension to union with this Dimension.
Returns:
Returns this Dimension with the unioned width and height.
Since:
2.0

Draw2D v2.0