Example usage for java.awt Point Point

List of usage examples for java.awt Point Point

Introduction

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

Prototype

public Point(int x, int y) 

Source Link

Document

Constructs and initializes a point at the specified (x,y) location in the coordinate space.

Usage

From source file:Main.java

public static Point getChildAsPoint(Element parent, String childName) {
    if (doesElementContainChildren(parent, childName)) {
        String pointString = getFirstChildElement(parent, childName).getTextContent();
        String[] coords = pointString.split(",");
        if (coords.length == 2) {
            Point point = new Point(Integer.parseInt(coords[0].replaceAll(" ", "")),
                    Integer.parseInt(coords[1].replaceAll(" ", "")));
            return point;
        }//from  w w w . ja  v  a 2 s . c  o m
    }
    return null;
}

From source file:Main.java

public static Point getPointForCentering(Dialog dialog, Window parent) {
    Dimension size = dialog.getSize();
    Dimension parentSize = parent.getSize();
    int centerX = (int) ((parentSize.getWidth() - size.getWidth()) / 2 + parent.getX());
    int centerY = (int) ((parentSize.getHeight() - size.getHeight()) / 2 + parent.getY());
    return new Point(centerX, centerY);
}

From source file:Main.java

public static void center(Component c) {
    Dimension screenSize = c.getToolkit().getScreenSize();
    Dimension componentSize = c.getSize();
    int xPos = (screenSize.width - componentSize.width) / 2;
    xPos = Math.max(xPos, 0);//from  w ww.j a va2  s  .  c om
    int yPos = (screenSize.height - componentSize.height) / 2;
    yPos = Math.max(yPos, 0);
    c.setLocation(new Point(xPos, yPos));
}

From source file:Main.java

public static void centralizeComponent(Component component, Component otherComponent) {

    Dimension othersDimension = null;
    Point othersLocation = null;//w  w  w  .j  ava 2  s .c o  m
    if (otherComponent == null || !otherComponent.isVisible()) {
        othersDimension = Toolkit.getDefaultToolkit().getScreenSize();
        othersLocation = new Point(0, 0);
    } else {
        othersDimension = otherComponent.getSize();
        othersLocation = otherComponent.getLocation();
    }
    Point centerPoint = new Point(
            (int) Math.round(othersDimension.width / HALF - component.getWidth() / HALF) + othersLocation.x,
            (int) Math.round(othersDimension.height / HALF - component.getHeight() / HALF) + othersLocation.y);
    component.setLocation(centerPoint);
}

From source file:Main.java

/**
 * Returns a point that is a google tile reference for the tile containing
 * the lat/lng and at the zoom level./*from w  ww  .  j  ava2 s.  com*/
 */
public static Point toTileXY(double lat, double lng, int zoom) {
    Point2D normalised = toNormalisedPixelCoords(lat, lng);
    int scale = 1 << zoom;

    // can just truncate to integer, this looses the fractional "pixel offset"
    return new Point((int) (normalised.getX() * scale), (int) (normalised.getY() * scale));
}

From source file:Main.java

/**
 * Returns a <code>Point</code> used as location for a window that
 * should be centered on the screen.//from  www.j  a v a2s  . c o  m
 * 
 * @param size a <code>Dimension</code> describing the window's size
 * @return a <code>Point</code> describing the top-left position
 */
public static Point getCenteredLocation(Dimension size) {

    final Toolkit tk = Toolkit.getDefaultToolkit();
    final Dimension screenSize = tk.getScreenSize();

    return new Point(((screenSize.width - size.width) / 2), ((screenSize.height - size.height) / 2));
}

From source file:Main.java

/**
 * Zentriert ein Window relativ zu dem Parent-Window
 * //  w w w  . ja va  2 s.  c  o  m
 * @param parent
 *            Parent-Window, wenn null, dann wird relativ zu dem Bildschirm
 *            zentriert
 * @param child
 *            Window das zentrirt werden soll.
 */
static public void centreWindow(Window parent, Window child) {
    if (child == null)
        return;
    Point parentLocation = null;
    Dimension parentSize = null;
    if (parent == null) {
        parentLocation = new Point(0, 0);
        parentSize = child.getToolkit().getScreenSize();
    } else {
        parentLocation = parent.getLocationOnScreen();
        parentSize = parent.getSize();
    }
    Dimension childSize = child.getSize();
    child.setLocation((int) (parentLocation.getX() + parentSize.getWidth() / 2 - childSize.getWidth() / 2),
            (int) (parentLocation.getY() + parentSize.getHeight() / 2 - childSize.getHeight() / 2));
}

From source file:Main.java

/**
 * //from  w  ww.j a va  2  s  . co m
 * @return The middle point on the screen, for the window
 */
public static Point getCenterPoint(Window window) {
    // Get the size of the screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();

    // Determine the new location of the window
    int w = window.getSize().width;
    int h = window.getSize().height;
    int x = (dim.width - w) / 2;
    int y = (dim.height - h) / 2;

    return new Point(x, y);
}

From source file:Main.java

public static void center(Component c) {
    Dimension screenSize = c.getToolkit().getScreenSize();
    screenSize.width -= BORDER_SIZE;/*ww w  .j  ava2 s .c  o  m*/
    screenSize.height -= BORDER_SIZE;
    Dimension componentSize = c.getSize();
    int xPos = (screenSize.width - componentSize.width) / 2;
    xPos = Math.max(xPos, 0);
    int yPos = (screenSize.height - componentSize.height) / 2;
    yPos = Math.max(yPos, 0);
    c.setLocation(new Point(xPos, yPos));
}

From source file:Main.java

/**
 * Returns the most reasonable position for the specified rectangle to be placed at so as to
 * maximize its containment by the specified bounding rectangle while still placing it as near
 * its original coordinates as possible.
 *
 * @param rect the rectangle to be positioned.
 * @param bounds the containing rectangle.
 *///from   ww  w .j a v  a 2s  .  c o m
public static Point fitRectInRect(Rectangle rect, Rectangle bounds) {
    // Guarantee that the right and bottom edges will be contained and do our best for the top
    // and left edges.
    return new Point(Math.min(bounds.x + bounds.width - rect.width, Math.max(rect.x, bounds.x)),
            Math.min(bounds.y + bounds.height - rect.height, Math.max(rect.y, bounds.y)));
}