FileDocCategorySizeDatePackage
Box.javaAPI DocphoneME MR2 API (J2ME)4782Wed May 02 18:00:34 BST 2007com.sun.perseus.j2d

Box

public class Box extends Object implements org.w3c.dom.svg.SVGRect
This class represents an "SVGRect" datatype, consisting of a minimum X, minimum Y, width and height values.
author
Kevin Wong
version
$Id: Box.java,v 1.4 2006/04/21 06:35:00 st125089 Exp $

Fields Summary
public float
x
The smallest x-axis value of the rectangle
public float
y
The smallest y-axis value of the rectangle
public float
width
The width value of the rectangle
public float
height
The height value of the rectangle
Constructors Summary
public Box(float x, float y, float w, float h)

param
x the rect's x-axis origin.
param
y the rect's y-axis origin.
param
w the rect's x-axis width.
param
h the rect's y-axis height.

        this.x = x;
        this.y = y;
        this.width = w;
        this.height = h;
    
public Box(Box b)
Copy constructor

param
b the Box to copy. Should not be null.

        this(b.x, b.y, b.width, b.height);
    
Methods Summary
public booleanequals(java.lang.Object cmp)

return
true if the input object is this Box or if x, y, width and height are equals.

        if (cmp == this) {
            return true;
        }

        if (cmp == null) {
            return false;
        }

        if (cmp instanceof Box) {
            Box b = (Box) cmp;
            return b.x == x
                &&
                b.y == y
                &&
                b.width == width
                &&
                b.height == height;
        }
        
        return false;
    
public floatgetHeight()

        return height;
    
public floatgetWidth()

        return width;
    
public floatgetX()

        return x;
    
public floatgetY()

        return y;
    
public voidsetHeight(float value)

        height = value;
    
public voidsetWidth(float value)

        width = value;
    
public voidsetX(float value)

        x = value;
    
public voidsetY(float value)

        y = value;
    
public voidsnap()
Snaps this Box instance to the integer grid.

        float fmaxX = x + width;
        float fmaxY = y + height;
        
        // x and y need to snap to the left of the integer grid.
        // We cannot simply cast as we need pixel accurate results.
        
        // Narrowing rounds towards zero
        int x = (int) this.x; 
        if (this.x < 0 && (this.x - x != 0)) {
            x -= 1;
        }
        
        int y = (int) this.y; // Narrowing
        if (this.y < 0 && (this.y - y) != 0) {
            y -= 1;
        }
        
        // maxX and maxY need to snap to the right of the integer grid.
        int maxX = (int) fmaxX;
        if (fmaxX > 0 && (fmaxX - maxX) != 0) {
            maxX += 1;
        }
        
        int maxY = (int) fmaxY;
        if (fmaxY > 0 && (fmaxY - maxY) != 0) {
            maxY += 1;
        }
        
        this.x = x;
        this.y = y;
        this.width = (maxX - x);
        this.height = (maxY - y);
    
public java.lang.StringtoString()
Debugging helper.

        return "Box(" + x + ", " + y + ", " + width + ", " + height + ")";