< prev index next >

core/JemmyCore/src/org/jemmy/Point.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.Point
  34  * @author Alexander Kouznetsov <mrkam@mail.ru>
  35  */
  36 public class Point implements Serializable{
  37     /**
  38      * The X coordinate of this <code>Point</code>.
  39      * If no X coordinate is set it will default to 0.
  40      *
  41      * @serial
  42      * @see #getLocation()
  43      * @see #move(int, int)
  44      */
  45     public int x;
  46 
  47     /**
  48      * The Y coordinate of this <code>Point</code>.
  49      * If no Y coordinate is set it will default to 0.
  50      *
  51      * @serial
  52      * @see #getLocation()
  53      * @see #move(int, int)
  54      */


  84      */
  85     public Point(int x, int y) {
  86         this.x = x;
  87         this.y = y;
  88     }
  89 
  90     /**
  91      * Constructs and initializes a point at the specified
  92      * {@code (x,y)} location in the coordinate space. All {@code double}
  93      * values are rounded and stored as {@code int} values.
  94      * @param x the X coordinate of the newly constructed <code>Point</code>
  95      * @param y the Y coordinate of the newly constructed <code>Point</code>
  96      */
  97     public Point(double x, double y) {
  98         this.x = (int) Math.round(x);
  99         this.y = (int) Math.round(y);
 100     }
 101 
 102     /**
 103      * {@inheritDoc}
 104      * @return
 105      */
 106     public int getX() {
 107         return x;
 108     }
 109 
 110     /**
 111      * {@inheritDoc}
 112      * @return
 113      */
 114     public int getY() {
 115         return y;
 116     }
 117 
 118     /**
 119      * Returns the location of this point.
 120      * @return      a copy of this point, at the same location
 121      * @see         org.jemmy.Point#setLocation(org.jemmy.Point)
 122      * @see         org.jemmy.Point#setLocation(int, int)
 123      */
 124     public Point getLocation() {
 125         return new Point(x, y);
 126     }
 127 
 128     /**
 129      * Sets the location of the point to the specified location.
 130      * @param       p  a point, the new location for this point
 131      * @return
 132      * @see         org.jemmy.Point#getLocation
 133      */
 134     public Point setLocation(Point p) {
 135         setLocation(p.x, p.y);
 136         return this;
 137     }
 138 
 139     /**
 140      * Changes the point to have the specified location.
 141      * <p>
 142      * Its behavior is identical with <code>move(int,&nbsp;int)</code>.
 143      * @param       x the X coordinate of the new location
 144      * @param       y the Y coordinate of the new location
 145      * @return self
 146      * @see         org.jemmy.Point#getLocation
 147      * @see         org.jemmy.Point#move(int, int)
 148      */
 149     public Point setLocation(int x, int y) {
 150         move(x, y);
 151         return this;


 186 
 187     /**
 188      * Translates this point, at location {@code (x,y)},
 189      * by {@code dx} along the {@code x} axis and {@code dy}
 190      * along the {@code y} axis so that it now represents the point
 191      * {@code (x + dx,y + dy)}.
 192      *
 193      * @param       dx   the distance to move this point
 194      *                            along the X axis
 195      * @param       dy    the distance to move this point
 196      *                            along the Y axis
 197      * @return self
 198      */
 199     public Point translate(int dx, int dy) {
 200         this.x += dx;
 201         this.y += dy;
 202         return this;
 203     }
 204 
 205     /**

 206      *
 207      * @param v
 208      * @return self
 209      */
 210     public Point translate(Vector v) {
 211         this.x = (int) Math.round(x + v.getX());
 212         this.y = (int) Math.round(y + v.getY());
 213         return this;
 214     }
 215     /**
 216      * Determines whether or not two points are equal. Two instances of
 217      * <code>Point</code> are equal if the values of their
 218      * <code>x</code> and <code>y</code> member fields, representing
 219      * their position in the coordinate space, are the same.
 220      * @param obj an object to be compared with this <code>Point</code>
 221      * @return <code>true</code> if the object to be compared is
 222      *         an instance of <code>Point</code> and has
 223      *         the same values; <code>false</code> otherwise.
 224      */
 225     @Override
 226     public boolean equals(Object obj) {
 227         if (obj instanceof Point) {
 228             Point pt = (Point)obj;
 229             return (x == pt.x) && (y == pt.y);
 230         }
 231         return super.equals(obj);
 232     }
 233 
 234     /**
 235      * {@inheritDoc}
 236      * @return
 237      */
 238     @Override
 239     public int hashCode() {
 240         int hash = 7;
 241         hash = 89 * hash + this.x;
 242         hash = 89 * hash + this.y;
 243         return hash;
 244     }
 245 
 246     /**
 247      * Returns a string representation of this point and its location
 248      * in the {@code (x,y)} coordinate space. This method is
 249      * intended to be used only for debugging purposes, and the content
 250      * and format of the returned string may vary between implementations.
 251      * The returned string may be empty but may not be <code>null</code>.
 252      *
 253      * @return  a string representation of this point
 254      */
 255     @Override
 256     public String toString() {


  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.Point
  34  * @author mrkam
  35  */
  36 public class Point implements Serializable{
  37     /**
  38      * The X coordinate of this <code>Point</code>.
  39      * If no X coordinate is set it will default to 0.
  40      *
  41      * @serial
  42      * @see #getLocation()
  43      * @see #move(int, int)
  44      */
  45     public int x;
  46 
  47     /**
  48      * The Y coordinate of this <code>Point</code>.
  49      * If no Y coordinate is set it will default to 0.
  50      *
  51      * @serial
  52      * @see #getLocation()
  53      * @see #move(int, int)
  54      */


  84      */
  85     public Point(int x, int y) {
  86         this.x = x;
  87         this.y = y;
  88     }
  89 
  90     /**
  91      * Constructs and initializes a point at the specified
  92      * {@code (x,y)} location in the coordinate space. All {@code double}
  93      * values are rounded and stored as {@code int} values.
  94      * @param x the X coordinate of the newly constructed <code>Point</code>
  95      * @param y the Y coordinate of the newly constructed <code>Point</code>
  96      */
  97     public Point(double x, double y) {
  98         this.x = (int) Math.round(x);
  99         this.y = (int) Math.round(y);
 100     }
 101 
 102     /**
 103      * {@inheritDoc}

 104      */
 105     public int getX() {
 106         return x;
 107     }
 108 
 109     /**
 110      * {@inheritDoc}

 111      */
 112     public int getY() {
 113         return y;
 114     }
 115 
 116     /**
 117      * Returns the location of this point.
 118      * @return      a copy of this point, at the same location
 119      * @see         org.jemmy.Point#setLocation(org.jemmy.Point)
 120      * @see         org.jemmy.Point#setLocation(int, int)
 121      */
 122     public Point getLocation() {
 123         return new Point(x, y);
 124     }
 125 
 126     /**
 127      * Sets the location of the point to the specified location.
 128      * @param       p  a point, the new location for this point
 129      * @return      self
 130      * @see         org.jemmy.Point#getLocation
 131      */
 132     public Point setLocation(Point p) {
 133         setLocation(p.x, p.y);
 134         return this;
 135     }
 136 
 137     /**
 138      * Changes the point to have the specified location.
 139      * <p>
 140      * Its behavior is identical with <code>move(int,&nbsp;int)</code>.
 141      * @param       x the X coordinate of the new location
 142      * @param       y the Y coordinate of the new location
 143      * @return      self
 144      * @see         org.jemmy.Point#getLocation
 145      * @see         org.jemmy.Point#move(int, int)
 146      */
 147     public Point setLocation(int x, int y) {
 148         move(x, y);
 149         return this;


 184 
 185     /**
 186      * Translates this point, at location {@code (x,y)},
 187      * by {@code dx} along the {@code x} axis and {@code dy}
 188      * along the {@code y} axis so that it now represents the point
 189      * {@code (x + dx,y + dy)}.
 190      *
 191      * @param       dx   the distance to move this point
 192      *                            along the X axis
 193      * @param       dy    the distance to move this point
 194      *                            along the Y axis
 195      * @return self
 196      */
 197     public Point translate(int dx, int dy) {
 198         this.x += dx;
 199         this.y += dy;
 200         return this;
 201     }
 202 
 203     /**
 204      * Translates the current point according to the given vector.
 205      *
 206      * @param v vector by which to translate the point 
 207      * @return self
 208      */
 209     public Point translate(Vector v) {
 210         this.x = (int) Math.round(x + v.getX());
 211         this.y = (int) Math.round(y + v.getY());
 212         return this;
 213     }
 214     /**
 215      * Determines whether or not two points are equal. Two instances of
 216      * <code>Point</code> are equal if the values of their
 217      * <code>x</code> and <code>y</code> member fields, representing
 218      * their position in the coordinate space, are the same.
 219      * @param obj an object to be compared with this <code>Point</code>
 220      * @return <code>true</code> if the object to be compared is
 221      *         an instance of <code>Point</code> and has
 222      *         the same values; <code>false</code> otherwise.
 223      */
 224     @Override
 225     public boolean equals(Object obj) {
 226         if (obj instanceof Point) {
 227             Point pt = (Point)obj;
 228             return (x == pt.x) && (y == pt.y);
 229         }
 230         return super.equals(obj);
 231     }
 232 
 233     /**
 234      * {@inheritDoc}

 235      */
 236     @Override
 237     public int hashCode() {
 238         int hash = 7;
 239         hash = 89 * hash + this.x;
 240         hash = 89 * hash + this.y;
 241         return hash;
 242     }
 243 
 244     /**
 245      * Returns a string representation of this point and its location
 246      * in the {@code (x,y)} coordinate space. This method is
 247      * intended to be used only for debugging purposes, and the content
 248      * and format of the returned string may vary between implementations.
 249      * The returned string may be empty but may not be <code>null</code>.
 250      *
 251      * @return  a string representation of this point
 252      */
 253     @Override
 254     public String toString() {
< prev index next >