< prev index next >

core/JemmyCore/src/org/jemmy/Rectangle.java

Print this page




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package org.jemmy;
  27 
  28 
  29 import java.io.Serializable;
  30 
  31 
  32 /**
  33  * Replacement for java.awt.Rectangle
  34  * @author Alexander Kouznetsov <mrkam@mail.ru>
  35  */
  36 public class Rectangle implements Serializable {
  37 
  38     /**
  39      * The X coordinate of the upper-left corner of the <code>Rectangle</code>.
  40      *
  41      * @serial
  42      * @see #setLocation(int, int)
  43      * @see #getLocation()
  44      */
  45     public int x;
  46 
  47     /**
  48      * The Y coordinate of the upper-left corner of the <code>Rectangle</code>.
  49      *
  50      * @serial
  51      * @see #setLocation(int, int)
  52      * @see #getLocation()
  53      */
  54     public int y;


 881 
 882         if (y1 < y0) {
 883             // Non-existant in Y direction
 884             y1 -= y0;
 885             if (y1 < Integer.MIN_VALUE) y1 = Integer.MIN_VALUE;
 886             if (y0 < Integer.MIN_VALUE) y0 = Integer.MIN_VALUE;
 887             else if (y0 > Integer.MAX_VALUE) y0 = Integer.MAX_VALUE;
 888         } else { // (y1 >= y0)
 889             if (y0 < Integer.MIN_VALUE) y0 = Integer.MIN_VALUE;
 890             else if (y0 > Integer.MAX_VALUE) y0 = Integer.MAX_VALUE;
 891             y1 -= y0;
 892             if (y1 < Integer.MIN_VALUE) y1 = Integer.MIN_VALUE;
 893             else if (y1 > Integer.MAX_VALUE) y1 = Integer.MAX_VALUE;
 894         }
 895 
 896         setBounds((int) x0, (int) y0, (int) x1, (int) y1);
 897     }
 898 
 899     /**
 900      * {@inheritDoc}
 901      * @return
 902      */
 903     public boolean isEmpty() {
 904         return (width <= 0) || (height <= 0);
 905     }
 906 
 907     /**
 908      * Checks whether two rectangles are equal.
 909      * <p>
 910      * The result is <code>true</code> if and only if the argument is not
 911      * <code>null</code> and is a <code>Rectangle</code> object that has the
 912      * same upper-left corner, width, and height as
 913      * this <code>Rectangle</code>.
 914      * @param obj the <code>Object</code> to compare with
 915      *                this <code>Rectangle</code>
 916      * @return    <code>true</code> if the objects are equal;
 917      *            <code>false</code> otherwise.
 918      */
 919     @Override
 920     public boolean equals(Object obj) {
 921         if (obj instanceof Rectangle) {
 922             Rectangle r = (Rectangle)obj;
 923             return ((x == r.x) &&
 924                 (y == r.y) &&
 925                 (width == r.width) &&
 926                 (height == r.height));
 927         }
 928         return super.equals(obj);
 929     }
 930 
 931     /**
 932      * {@inheritDoc }
 933      * @return
 934      */
 935     @Override
 936     public int hashCode() {
 937         int hash = 7;
 938         hash = 29 * hash + this.x;
 939         hash = 29 * hash + this.y;
 940         hash = 29 * hash + this.width;
 941         hash = 29 * hash + this.height;
 942         return hash;
 943     }
 944 
 945     /**
 946      * Returns a <code>String</code> representing this
 947      * <code>Rectangle</code> and its values.
 948      * @return a <code>String</code> representing this
 949      *               <code>Rectangle</code> object's coordinate and size values.
 950      */
 951     @Override
 952     public String toString() {
 953         return getClass().getName() + "[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]";




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package org.jemmy;
  27 
  28 
  29 import java.io.Serializable;
  30 
  31 
  32 /**
  33  * Replacement for java.awt.Rectangle
  34  * @author mrkam
  35  */
  36 public class Rectangle implements Serializable {
  37 
  38     /**
  39      * The X coordinate of the upper-left corner of the <code>Rectangle</code>.
  40      *
  41      * @serial
  42      * @see #setLocation(int, int)
  43      * @see #getLocation()
  44      */
  45     public int x;
  46 
  47     /**
  48      * The Y coordinate of the upper-left corner of the <code>Rectangle</code>.
  49      *
  50      * @serial
  51      * @see #setLocation(int, int)
  52      * @see #getLocation()
  53      */
  54     public int y;


 881 
 882         if (y1 < y0) {
 883             // Non-existant in Y direction
 884             y1 -= y0;
 885             if (y1 < Integer.MIN_VALUE) y1 = Integer.MIN_VALUE;
 886             if (y0 < Integer.MIN_VALUE) y0 = Integer.MIN_VALUE;
 887             else if (y0 > Integer.MAX_VALUE) y0 = Integer.MAX_VALUE;
 888         } else { // (y1 >= y0)
 889             if (y0 < Integer.MIN_VALUE) y0 = Integer.MIN_VALUE;
 890             else if (y0 > Integer.MAX_VALUE) y0 = Integer.MAX_VALUE;
 891             y1 -= y0;
 892             if (y1 < Integer.MIN_VALUE) y1 = Integer.MIN_VALUE;
 893             else if (y1 > Integer.MAX_VALUE) y1 = Integer.MAX_VALUE;
 894         }
 895 
 896         setBounds((int) x0, (int) y0, (int) x1, (int) y1);
 897     }
 898 
 899     /**
 900      * {@inheritDoc}

 901      */
 902     public boolean isEmpty() {
 903         return (width <= 0) || (height <= 0);
 904     }
 905 
 906     /**
 907      * Checks whether two rectangles are equal.
 908      * <p>
 909      * The result is <code>true</code> if and only if the argument is not
 910      * <code>null</code> and is a <code>Rectangle</code> object that has the
 911      * same upper-left corner, width, and height as
 912      * this <code>Rectangle</code>.
 913      * @param obj the <code>Object</code> to compare with
 914      *                this <code>Rectangle</code>
 915      * @return    <code>true</code> if the objects are equal;
 916      *            <code>false</code> otherwise.
 917      */
 918     @Override
 919     public boolean equals(Object obj) {
 920         if (obj instanceof Rectangle) {
 921             Rectangle r = (Rectangle)obj;
 922             return ((x == r.x) &&
 923                 (y == r.y) &&
 924                 (width == r.width) &&
 925                 (height == r.height));
 926         }
 927         return super.equals(obj);
 928     }
 929 
 930     /**
 931      * {@inheritDoc }

 932      */
 933     @Override
 934     public int hashCode() {
 935         int hash = 7;
 936         hash = 29 * hash + this.x;
 937         hash = 29 * hash + this.y;
 938         hash = 29 * hash + this.width;
 939         hash = 29 * hash + this.height;
 940         return hash;
 941     }
 942 
 943     /**
 944      * Returns a <code>String</code> representing this
 945      * <code>Rectangle</code> and its values.
 946      * @return a <code>String</code> representing this
 947      *               <code>Rectangle</code> object's coordinate and size values.
 948      */
 949     @Override
 950     public String toString() {
 951         return getClass().getName() + "[x=" + x + ",y=" + y + ",width=" + width + ",height=" + height + "]";


< prev index next >