Example usage for java.awt Point equals

List of usage examples for java.awt Point equals

Introduction

In this page you can find the example usage for java.awt Point equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Determines whether or not two points are equal.

Usage

From source file:Main.java

public static void main(String[] args) {
    Point aPoint = new Point();
    Point bPoint = new Point(50, 25);
    Point cPoint = new Point(bPoint);

    System.out.println("cPoint is located at: " + cPoint);

    System.out.println("aPoint is located at: " + aPoint);
    aPoint.move(100, 50);//from   w  w  w. j ava  2 s.c  o m

    bPoint.x = 110;
    bPoint.y = 70;

    aPoint.translate(10, 20);
    System.out.println("aPoint is now at: " + aPoint);

    if (aPoint.equals(bPoint))
        System.out.println("aPoint and bPoint are at the same location.");
}

From source file:MainClass.java

public static void main(String[] args) {
    Point aPoint = new Point(); // Initialize to 0,0
    Point bPoint = new Point(50, 25);
    Point cPoint = new Point(bPoint);
    System.out.println("aPoint is located at: " + aPoint);
    aPoint.move(100, 50); // Change to position 100,50
    bPoint.x = 110;// www  .j a va2s. c  om
    bPoint.y = 70;
    aPoint.translate(10, 20); // Move by 10 in x and 20 in y
    System.out.println("aPoint is now at: " + aPoint);
    if (aPoint.equals(bPoint))
        System.out.println("aPoint and bPoint are at the same location.");
}

From source file:exploration.rendezvous.MultiPointRendezvousStrategy.java

@Override
public Point processWaitForParent() {
    RendezvousAgentData rvd = agent.getRendezvousAgentData();
    if (settings.moveToBetterCommsWhileWaiting) {
        //<editor-fold defaultstate="collapsed" desc="Try to move to a cell with better comms">
        Point point1 = agent.getLocation();
        Point point2 = agent.getRendezvousAgentData().getParentRendezvous().getParentLocation();
        Point newPoint = getBetterCommLocation(point1, point2, agent);
        if (agent.getParentTeammate().getID() == SimConstants.BASE_STATION_AGENT_ID) {
            if (!point1.equals(newPoint)) {
                return newPoint;
            } else {
                //let's head back to actual base station
                if (SimConstants.DEBUG_OUTPUT) {
                    System.out.println(
                            "Heading back to actual base station, as we cannot communicate with base station form here.");
                }/*from   w  ww  .ja va 2  s.co m*/
                Rendezvous meetingLocation = rvd.getParentRendezvous();
                meetingLocation.setChildLocation(agent.getParentTeammate().getLocation());
                meetingLocation.setParentLocation(agent.getParentTeammate().getLocation());
                rvd.setParentRendezvous(meetingLocation);
                Path newPath = agent.calculatePath(point1, agent.getParentTeammate().getLocation(), false,
                        false);
                agent.setPath(newPath);

                agent.setExploreState(Agent.ExplorationState.ReturnToBase);
                return agent.getLocation();
            }
        } else {
            return newPoint;
        }
    } else {
        return agent.getLocation();
    }
}

From source file:edu.ku.brc.services.mapping.LocalityMapper.java

/**
 * Grabs a new map from the web service and appropriately adorns it
 * with labels and markers./*from www  . j  ava2s . c  o m*/
 *
 * @return a map image as an icon
 * @throws HttpException a network error occurred while grabbing the map from the service
 * @throws IOException a network error occurred while grabbing the map from the service
 */
protected Icon grabNewMap() throws HttpException, IOException {
    recalculateBoundingBox();

    if (!cacheValid) {
        //            Image mapImage = getMapFromService("mapus.jpl.nasa.gov",
        //                    "/wms.cgi?request=GetMap&srs=EPSG:4326&format=image/png&styles=visual",
        //                    "global_mosaic",
        //                    mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth);
        //
        //            Image overlayImage = getMapFromService("129.237.201.132",
        //                    "/cgi-bin/mapserv?map=/var/www/maps/specify.map&service=WMS&request=GetMap&srs=EPSG:4326&version=1.3.1&format=image/png&transparent=true",
        //                    "states,rivers",
        //                    mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth);

        Image mapImage = getMapFromService("lifemapper.org", //$NON-NLS-1$
                "/ogc?map=specify.map&service=WMS&request=GetMap&srs=EPSG:4326&version=1.3.1&STYLES=&format=image/png&transparent=TRUE", //$NON-NLS-1$
                "global_mosaic,states,rivers", //$NON-NLS-1$
                mapMinLat, mapMinLong, mapMaxLat, mapMaxLong, maxMapHeight, maxMapWidth);

        mapIcon = new ImageIcon(mapImage);
        //            overlayIcon = new ImageIcon(overlayImage);
        cacheValid = true;

        mapWidth = mapIcon.getIconWidth();
        mapHeight = mapIcon.getIconHeight();

        if (mapWidth < 0 || mapHeight < 0) {
            throw new IOException("Request for map failed.  Received map has negative width or height."); //$NON-NLS-1$
        }

        mapLatRange = mapMaxLat - mapMinLat;
        mapLongRange = mapMaxLong - mapMinLong;

        pixelPerLatRatio = mapHeight / mapLatRange;
        pixelPerLongRatio = mapWidth / mapLongRange;

        for (int i = 0; i < mapLocations.size(); ++i) {
            MapLocationIFace loc = mapLocations.get(i);
            Point iconLoc = determinePixelCoordsOfMapLocationIFace(loc);
            markerLocations.set(i, iconLoc);
        }

        cacheValid = true;
    }

    Icon icon = new Icon() {
        public void paintIcon(Component c, Graphics g, int x, int y) {
            // this helps keep the labels inside the map
            g.setClip(x, y, mapWidth, mapHeight);
            // log the x and y for the MouseMotionListener
            mostRecentPaintedX = x;
            mostRecentPaintedY = y;
            Point currentLocPoint = null;
            if (currentLoc != null) {
                currentLocPoint = determinePixelCoordsOfMapLocationIFace(currentLoc);
            }

            mapIcon.paintIcon(c, g, x, y);
            //                overlayIcon.paintIcon(c, g, x, y);

            Point lastLoc = null;
            for (int i = 0; i < mapLocations.size(); ++i) {
                Point markerLoc = markerLocations.get(i);
                String label = labels.get(i);
                boolean current = (currentLoc != null) && markerLoc.equals(currentLocPoint);

                if (markerLoc == null) {
                    log.error("A marker location is null"); //$NON-NLS-1$
                    continue;
                }
                if (!pointIsOnMapIcon(x + markerLoc.x, y + markerLoc.y)) {
                    log.error("A marker location is off the map"); //$NON-NLS-1$
                    continue;
                }
                if (showArrows && lastLoc != null) {
                    int x1 = x + lastLoc.x;
                    int y1 = y + lastLoc.y;
                    int x2 = x + markerLoc.x;
                    int y2 = y + markerLoc.y;
                    Color origColor = g.getColor();
                    if (current && !animationInProgress) {
                        g.setColor(getCurrentLocColor());
                    } else {
                        g.setColor(arrowColor);
                    }
                    GraphicsUtils.drawArrow(g, x1, y1, x2, y2, 2, 2);
                    g.setColor(origColor);
                }
                if (current) {
                    currentLocMarker.paintIcon(c, g, markerLoc.x + x, markerLoc.y + y);
                } else {
                    marker.paintIcon(c, g, markerLoc.x + x, markerLoc.y + y);
                }
                if (label != null) {
                    Color origColor = g.getColor();
                    FontMetrics fm = g.getFontMetrics();
                    int length = fm.stringWidth(label);
                    g.setColor(Color.WHITE);
                    g.fillRect(markerLoc.x + x - (length / 2), markerLoc.y + y - (fm.getHeight() / 2), length,
                            fm.getHeight());
                    g.setColor(labelColor);
                    GraphicsUtils.drawCenteredString(label, g, markerLoc.x + x, markerLoc.y + y);
                    g.setColor(origColor);
                }

                lastLoc = markerLoc;
            }
            if (showArrowAnimations && animationInProgress) {
                int startIndex = mapLocations.indexOf(animStartLoc);
                int endIndex = mapLocations.indexOf(animEndLoc);
                if (startIndex != -1 && endIndex != -1) {
                    Point startPoint = markerLocations.get(startIndex);
                    Point endPoint = markerLocations.get(endIndex);
                    Point arrowEnd = GraphicsUtils.getPointAlongLine(startPoint, endPoint, percent);
                    Color orig = g.getColor();
                    g.setColor(getCurrentLocColor());
                    GraphicsUtils.drawArrow(g, startPoint.x + x, startPoint.y + y, arrowEnd.x + x,
                            arrowEnd.y + y, 5, 3);
                    g.setColor(orig);
                }
            }
        }

        public int getIconWidth() {
            return mapWidth;
        }

        public int getIconHeight() {
            return mapHeight;
        }
    };

    return icon;
}

From source file:net.cantab.hayward.george.OCS.Statics.java

/**
 * Returns hex zone if point is a hex shadowed by a hex zone
 *//* w  w  w .ja va2s .  co  m*/
OcsHexZone isHexZone(Point p) {
    buildHexZoneList();
    for (OcsHexZone h : hexZones) {
        if (h.theHex != null && p.equals(h.theHex))
            return h;
    }
    return null;
}

From source file:oct.analysis.application.comp.EZWorker.java

/**
 * Recursively search for a contour to the right of the supplied starting
 * point. If the contour returned contains the starting point then the
 * contour traced back to the start point rather than towards the edge of
 * the image./*from w w w.  jav  a2  s.  co  m*/
 *
 * @param searchPoint point to search from
 * @param startPoint start search point
 * @param contourList list to add the contour points to
 * @param sharpOCT OCT to find the contour in
 * @return the next point in the contour after the search point
 */
public Point findContourRight(Point searchPoint, Cardinality searchDirection, Point startPoint,
        Cardinality startDirection, LinkedList<Point> contourList, BufferedImage sharpOCT, int depth)
        throws InterruptedException {
    if (debug) {
        publish(searchPoint);
        Thread.sleep(debug_sleep);
    }
    depth++;
    if (depth > depthThreshold) {
        //the recursive search has gone awry, we must terminate it before causing the stack to overflow
        return null;
    }
    Point nextPoint;
    Cardinality nextDirection;
    switch (searchDirection) {
    case SOUTH:
        if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x + 1, searchPoint.y)) > 0) {
            nextPoint = new Point(searchPoint);
            nextDirection = Cardinality.EAST;
        } else if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x + 1, searchPoint.y + 1)) == 0) {
            nextPoint = new Point(searchPoint.x + 1, searchPoint.y + 1);
            nextDirection = Cardinality.WEST;
        } else {
            nextPoint = new Point(searchPoint.x + 1, searchPoint.y);
            nextDirection = Cardinality.SOUTH;
        }
        break;
    case EAST:
        if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x, searchPoint.y - 1)) > 0) {
            nextPoint = new Point(searchPoint);
            nextDirection = Cardinality.NORTH;
        } else if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x + 1, searchPoint.y - 1)) == 0) {
            nextPoint = new Point(searchPoint.x + 1, searchPoint.y - 1);
            nextDirection = Cardinality.SOUTH;
        } else {
            nextPoint = new Point(searchPoint.x, searchPoint.y - 1);
            nextDirection = Cardinality.EAST;
        }
        break;
    case WEST:
        if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x, searchPoint.y + 1)) > 0) {
            nextPoint = new Point(searchPoint);
            nextDirection = Cardinality.SOUTH;
        } else if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x - 1, searchPoint.y + 1)) == 0) {
            nextPoint = new Point(searchPoint.x - 1, searchPoint.y + 1);
            nextDirection = Cardinality.NORTH;
        } else {
            nextPoint = new Point(searchPoint.x, searchPoint.y + 1);
            nextDirection = Cardinality.WEST;
        }
        break;
    case NORTH:
        if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x - 1, searchPoint.y)) > 0) {
            nextPoint = new Point(searchPoint);
            nextDirection = Cardinality.WEST;
        } else if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x - 1, searchPoint.y - 1)) == 0) {
            nextPoint = new Point(searchPoint.x - 1, searchPoint.y - 1);
            nextDirection = Cardinality.EAST;
        } else {
            nextPoint = new Point(searchPoint.x - 1, searchPoint.y);
            nextDirection = Cardinality.NORTH;
        }
        break;
    default:
        //will never happen, just placed in to make code compile
        nextPoint = new Point(searchPoint);
        nextDirection = Cardinality.EAST;
        break;
    }
    if (!((nextPoint.equals(startPoint) && nextDirection == startDirection) || nextPoint.y < 100
            || nextPoint.y > sharpOCT.getHeight() - 20 || nextPoint.x <= 20
            || nextPoint.x >= sharpOCT.getWidth() - 20)) {
        contourList.add(findContourRight(nextPoint, nextDirection, startPoint, startDirection, contourList,
                sharpOCT, depth));
    }
    return nextPoint;
}

From source file:oct.analysis.application.comp.EZWorker.java

/**
 * Recursively search for a contour to the left of the supplied starting
 * point. If the contour returned contains the starting point then the
 * contour traced back to the start point rather than towards the edge of
 * the image.//w w w . j a v a2  s . c o m
 *
 * @param searchPoint point to search from
 * @param startPoint start search point
 * @param contourList list to add the contour points to
 * @param sharpOCT OCT to find the contour in
 * @return the next point in the contour after the search point
 */
public Point findContourLeft(Point searchPoint, Cardinality searchDirection, Point startPoint,
        Cardinality startDirection, LinkedList<Point> contourList, BufferedImage sharpOCT)
        throws InterruptedException {
    if (debug) {
        publish(searchPoint);
        Thread.sleep(debug_sleep);
    }
    Point nextPoint;
    Cardinality nextDirection;
    switch (searchDirection) {
    case SOUTH:
        if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x - 1, searchPoint.y)) > 0) {
            nextPoint = new Point(searchPoint);
            nextDirection = Cardinality.WEST;
        } else if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x - 1, searchPoint.y + 1)) == 0) {
            nextPoint = new Point(searchPoint.x - 1, searchPoint.y + 1);
            nextDirection = Cardinality.EAST;
        } else {
            nextPoint = new Point(searchPoint.x - 1, searchPoint.y);
            nextDirection = Cardinality.SOUTH;
        }
        break;
    case EAST:
        if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x, searchPoint.y + 1)) > 0) {
            nextPoint = new Point(searchPoint);
            nextDirection = Cardinality.SOUTH;
        } else if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x + 1, searchPoint.y + 1)) == 0) {
            nextPoint = new Point(searchPoint.x + 1, searchPoint.y + 1);
            nextDirection = Cardinality.NORTH;
        } else {
            nextPoint = new Point(searchPoint.x, searchPoint.y + 1);
            nextDirection = Cardinality.EAST;
        }
        break;
    case WEST:
        if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x, searchPoint.y - 1)) > 0) {
            nextPoint = new Point(searchPoint);
            nextDirection = Cardinality.NORTH;
        } else if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x - 1, searchPoint.y - 1)) == 0) {
            nextPoint = new Point(searchPoint.x - 1, searchPoint.y - 1);
            nextDirection = Cardinality.SOUTH;
        } else {
            nextPoint = new Point(searchPoint.x, searchPoint.y - 1);
            nextDirection = Cardinality.WEST;
        }
        break;
    case NORTH:
        if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x + 1, searchPoint.y)) > 0) {
            nextPoint = new Point(searchPoint);
            nextDirection = Cardinality.EAST;
        } else if (Util.calculateGrayScaleValue(sharpOCT.getRGB(searchPoint.x + 1, searchPoint.y - 1)) == 0) {
            nextPoint = new Point(searchPoint.x + 1, searchPoint.y - 1);
            nextDirection = Cardinality.WEST;
        } else {
            nextPoint = new Point(searchPoint.x + 1, searchPoint.y);
            nextDirection = Cardinality.NORTH;
        }
        break;
    default:
        //will never happen, just placed in to make code compile
        nextPoint = new Point(searchPoint);
        nextDirection = Cardinality.EAST;
        break;
    }
    if (!((nextPoint.equals(startPoint) && nextDirection == startDirection) || nextPoint.y < 100
            || nextPoint.y > sharpOCT.getHeight() - 20 || nextPoint.x <= 20
            || nextPoint.x >= sharpOCT.getWidth() - 20)) {
        contourList.add(
                findContourLeft(nextPoint, nextDirection, startPoint, startDirection, contourList, sharpOCT));
    }
    return nextPoint;
}

From source file:org.eclipse.jubula.rc.common.driver.MouseMovementStrategy.java

/**
 * /*w  w  w  .  j a v  a  2s  .  c o  m*/
 * @param from The point from which the mouse pointer is being moved.
 *             May not be <code>null</code>. Coordinates must be 
 *             non-negative.
 * @param to The point to which the mouse pointer is being moved.
 *           May not be <code>null</code>. Coordinates must be 
 *           non-negative.
 * @param isMoveInSteps <code>true</code> if the movement strategy should 
 *                      be executed in steps. Otherwise, <code>false</code>.
 * @param firstHorizontal <code>true</code> if the movement strategy should
 *                      be executed using first the x axis. Otherwise, 
 *                      <code>false</code>.
 * @return an array of <code>Point</code>s indicating the path the pointer
 *         should follow in order to reach the destination point 
 *         <code>to</code>. This path includes the point <code>to</code>, 
 *         but does not contain <code>from</code>.
 */
public static Point[] getMovementPath(Point from, Point to, boolean isMoveInSteps, boolean firstHorizontal) {

    Validate.notNull(from, "Initial point must not be null."); //$NON-NLS-1$
    Validate.notNull(to, "End point must not be null."); //$NON-NLS-1$
    Validate.isTrue(to.x >= 0, "End x-coordinate must not be negative."); //$NON-NLS-1$
    Validate.isTrue(to.y >= 0, "End y-coordinate must not be negative."); //$NON-NLS-1$
    Validate.isTrue(from.x >= 0, "Initial x-coordinate must not be negative."); //$NON-NLS-1$
    Validate.isTrue(from.y >= 0, "Initial y-coordinate must not be negative."); //$NON-NLS-1$

    if (!isMoveInSteps) {
        // Adjacent point followed by target point
        return new Point[] { new Point(to.x - 1, to.y - 1), to };
    }

    List path = new ArrayList();
    int[] xCoords = getMovementPath(from.x, to.x);
    int[] yCoords = getMovementPath(from.y, to.y);
    if (firstHorizontal) {
        for (int i = 0; i < xCoords.length; i++) {
            path.add(new Point(xCoords[i], from.y));
        }
        for (int i = 0; i < yCoords.length; i++) {
            path.add(new Point(to.x, yCoords[i]));
        }
    } else {
        for (int i = 0; i < yCoords.length; i++) {
            path.add(new Point(from.x, yCoords[i]));
        }
        for (int i = 0; i < xCoords.length; i++) {
            path.add(new Point(xCoords[i], to.y));
        }
    }

    if (path.isEmpty() || !to.equals(path.get(path.size() - 1))) {
        path.add(new Point(to));
    }

    return (Point[]) path.toArray(new Point[path.size()]);
}

From source file:org.eclipse.jubula.rc.javafx.driver.RobotJavaFXImpl.java

/**
 * Checks if the mouse has to be moved on <code>p</code> or if the mouse
 * pointer already resides on this location.
 *
 * @param p//from w w  w  .j  a v a2 s.  c  o  m
 *            The point to move to
 * @return <code>true</code> if the mouse pointer resides on a different
 *         point, otherwise <code>false</code>.
 */
private boolean isMouseMoveRequired(Point p) {
    boolean result = true;
    Point point = getCurrentMousePosition();
    if (point != null) {
        result = !point.equals(p);
        if (log.isDebugEnabled()) {
            log.debug("Last converted screen point  : " + point); //$NON-NLS-1$
            log.debug("Required screen point        : " + p); //$NON-NLS-1$
            log.debug("Mouse move required?         : " + result); //$NON-NLS-1$
        }
    }
    return result;
}

From source file:org.eclipse.jubula.rc.swing.driver.RobotAwtImpl.java

/**
 * Checks if the mouse has to be moved on <code>p</code> or if the mouse
 * pointer already resides on this location. 
 * @param p The point to move to//w  w w . j a  va2 s .co  m
 * @return <code>true</code> if the mouse pointer resides on a different point, otherwise <code>false</code>.
 */
private boolean isMouseMoveRequired(Point p) {
    boolean result = true;
    Point point = m_mouseMotionTracker.getLastMousePointOnScreen();
    if (point != null) {
        result = !point.equals(p);
        if (log.isDebugEnabled()) {
            MouseEvent event = (MouseEvent) m_mouseMotionTracker.getLastMouseMotionEvent();
            if (event != null) {
                log.debug("Last mouse motion event point: " //$NON-NLS-1$
                        + event.getPoint());
            }
            log.debug("Last converted screen point  : " + point); //$NON-NLS-1$
            log.debug("Required screen point        : " + p); //$NON-NLS-1$
            log.debug("Mouse move required?         : " + result); //$NON-NLS-1$
        }
    }
    return result;
}