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 getDirectionPoint(double bearing, Point posFrom, int length) {
    int x = (int) (Math.sin(bearing) * length);
    int y = (int) (Math.cos(bearing) * length);
    return new Point(posFrom.x + x, posFrom.y + y);
}

From source file:Main.java

/** Returns the center of the first display.
 * @return  the center (displayWidht/2,diplayHight/2) of the first display.
 *///from   w  w w. j  a va 2 s . com
public static Point getScreenCenter() {
    Dimension dimension = getScreenSize();
    return new Point(dimension.width / 2, dimension.height / 2);
}

From source file:Main.java

public static Point getCenterPoint() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    double desktopHeight = toolkit.getScreenSize().getHeight();
    double desktopWidth = toolkit.getScreenSize().getWidth();
    return new Point((int) desktopWidth / 2, (int) desktopHeight / 2);
}

From source file:Main.java

public static void showPopupMenu(final JPopupMenu popup, final Component component, int x, int y) {
    final Point p = new Point(x, y);
    SwingUtilities.convertPointToScreen(p, component);
    final Dimension size = popup.getPreferredSize();
    final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    boolean horiz = false;
    boolean vert = false;

    final int origX = x;

    if ((p.x + size.width > screen.width) && (size.width < screen.width)) {
        x += (screen.width - p.x - size.width);
        horiz = true;//from  ww  w. j  av  a 2 s .co  m
    }

    if ((p.y + size.height > screen.height) && (size.height < screen.height)) {
        y += (screen.height - p.y - size.height);
        vert = true;
    }

    if (horiz && vert) {
        x = origX - size.width - 2;
    }
    popup.show(component, x, y);
}

From source file:Main.java

public static void setCenterOfParent(JFrame parent, JDialog dialog) {
    Point parentPosition = parent.getLocation();
    Dimension parentSize = parent.getSize();
    Dimension size = dialog.getSize();
    Point position = new Point(parentPosition.x + (parentSize.width / 2 - size.width / 2),
            parentPosition.y + (parentSize.height / 2 - size.height / 2));
    dialog.setLocation(position);/* w  w w . j  av a  2s. c  o m*/
}

From source file:Main.java

public static void centerWindowOnScreen(Window aWindow) {
    Rectangle bounds = getScreenBounds(aWindow);
    Point p = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
    Dimension windowSize = aWindow.getSize();
    p.x -= windowSize.width / 2;//www .j  a v  a2s  .com
    p.y -= windowSize.height / 2;
    aWindow.setLocation(p);
}

From source file:Main.java

/**
 * Get an empty cursor//w ww.  j  a v  a  2  s .co m
 * 
 * @return
 */
public static Cursor createEmptyCursor() {
    Image cursorImage = Toolkit.getDefaultToolkit().createImage(new byte[] {});
    return Toolkit.getDefaultToolkit().createCustomCursor(cursorImage, new Point(0, 0), "cursor");
}

From source file:Main.java

public static void centerWindow(Window w, Window reference) {
    Point refCorner = reference.getLocation();
    Point center = new Point(refCorner.x + reference.getWidth() / 2, refCorner.y + reference.getHeight() / 2);
    centerWindow(w, center);/*from   w  ww. j  a va 2s. co m*/
}

From source file:Main.java

public static Point toPoint(Node n) {
    if (!n.getNodeName().equals("center")) {
        throw new IllegalArgumentException(n.getNodeName());
    }/* w w w.  ja v a 2  s.co m*/
    NamedNodeMap map = n.getAttributes();
    int x = Integer.parseInt(map.getNamedItem("x").getNodeValue());
    int y = Integer.parseInt(map.getNamedItem("y").getNodeValue());
    return new Point(x, y);
}

From source file:Main.java

public static MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) {
    Point p = SwingUtilities.convertPoint(source, new Point(sourceEvent.getX(), sourceEvent.getY()),
            destination);//from w  w  w. ja  v a 2 s .c o  m
    Component newSource;

    if (destination != null)
        newSource = destination;
    else
        newSource = source;

    MouseEvent newEvent;
    if (sourceEvent instanceof MouseWheelEvent) {
        MouseWheelEvent sourceWheelEvent = (MouseWheelEvent) sourceEvent;
        newEvent = new MouseWheelEvent(newSource, sourceWheelEvent.getID(), sourceWheelEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceWheelEvent.getClickCount(), sourceWheelEvent.isPopupTrigger(),
                sourceWheelEvent.getScrollType(), sourceWheelEvent.getScrollAmount(),
                sourceWheelEvent.getWheelRotation());
    } else if (sourceEvent instanceof MenuDragMouseEvent) {
        MenuDragMouseEvent sourceMenuDragEvent = (MenuDragMouseEvent) sourceEvent;
        newEvent = new MenuDragMouseEvent(newSource, sourceMenuDragEvent.getID(), sourceMenuDragEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceMenuDragEvent.getClickCount(), sourceMenuDragEvent.isPopupTrigger(),
                sourceMenuDragEvent.getPath(), sourceMenuDragEvent.getMenuSelectionManager());
    } else {
        newEvent = new MouseEvent(newSource, sourceEvent.getID(), sourceEvent.getWhen(),
                sourceEvent.getModifiers() | sourceEvent.getModifiersEx(), p.x, p.y,
                sourceEvent.getClickCount(), sourceEvent.isPopupTrigger(), sourceEvent.getButton());
    }
    return newEvent;
}