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:CursorUtil.java

public static Cursor createCursor(BufferedImage img, int hotspotX, int hotspotY, String name)
        throws IndexOutOfBoundsException, Exception {
    return createCursor(img, new Point(hotspotX, hotspotY), name);
}

From source file:Main.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);//  w  ww  .  jav  a  2s .co  m

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;
        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

                jv.setViewPosition(new Point(newX, newY));
            }
        }

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}

From source file:fr.lig.sigma.astral.gui.graph.sugiyama.Node.java

void setPos(double x, double y) {
    p = new Point(x, y);
    layout.setLocation(e, new Point2D.Double(x + nodeSize.x / 2, y + nodeSize.y / 2));
}

From source file:org.jfree.chart.demo.MouseListenerDemo4.java

public void chartMouseClicked(ChartMouseEvent chartmouseevent) {
    int i = chartmouseevent.getTrigger().getX();
    int j = chartmouseevent.getTrigger().getY();
    System.out.println("x = " + i + ", y = " + j);
    Point2D point2d = chartPanel.translateScreenToJava2D(new Point(i, j));
    XYPlot xyplot = (XYPlot) chart.getPlot();
    ChartRenderingInfo chartrenderinginfo = chartPanel.getChartRenderingInfo();
    java.awt.geom.Rectangle2D rectangle2d = chartrenderinginfo.getPlotInfo().getDataArea();
    ValueAxis valueaxis = xyplot.getDomainAxis();
    org.jfree.ui.RectangleEdge rectangleedge = xyplot.getDomainAxisEdge();
    ValueAxis valueaxis1 = xyplot.getRangeAxis();
    org.jfree.ui.RectangleEdge rectangleedge1 = xyplot.getRangeAxisEdge();
    double d = valueaxis.java2DToValue(point2d.getX(), rectangle2d, rectangleedge);
    double d1 = valueaxis1.java2DToValue(point2d.getY(), rectangle2d, rectangleedge1);
    System.out.println("Chart: x = " + d + ", y = " + d1);
}

From source file:Utils.java

/**
 * <p/>//  www  .  ja  v a  2 s .c  o m
 * Returns the <code>Point</code> at which a window should be placed to
 * center that window on the given desktop.
 * </p>
 * <p/>
 * Some thought was taken as to whether to implement a method such as this,
 * or to simply make a method that, given a window, will center it.  It was
 * decided that it is better to not alter an object within a method.
 * </p>
 *
 * @param window  The window (JInternalFrame) to calculate the center point
 *                for.  This object can not be null.
 *
 * @return the <code>Point</code> at which the window should be placed to
 *         center that window on the given desktop
 */
public static Point getPointForCentering(JInternalFrame window) {
    try {
        //assert window != null;
        Point mousePoint = MouseInfo.getPointerInfo().getLocation();
        GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices();
        for (GraphicsDevice device : devices) {
            Rectangle bounds = device.getDefaultConfiguration().getBounds();
            //check to see if the mouse cursor is within these bounds
            if (mousePoint.x >= bounds.x && mousePoint.y >= bounds.y
                    && mousePoint.x <= (bounds.x + bounds.width)
                    && mousePoint.y <= (bounds.y + bounds.height)) {
                //this is it
                int screenWidth = bounds.width;
                int screenHeight = bounds.height;
                int width = window.getWidth();
                int height = window.getHeight();
                return new Point(((screenWidth - width) / 2) + bounds.x,
                        ((screenHeight - height) / 2) + bounds.y);
            }
        }
    } catch (Exception e) {

    }
    return new Point(0, 0);
}

From source file:vteaexploration.plotgatetools.gates.PolygonGate.java

public Point getBoundingAnchor() {

    int x = ((Double) boundingbox.getMaxX()).intValue();
    int y = ((Double) boundingbox.getMaxY()).intValue();

    return new Point(x, y);

}

From source file:Main.java

public void mouseDragged(MouseEvent e) {
    Point current = this.getScreenLocation(e);
    Point offset = new Point((int) current.getX() - (int) start_drag.getX(),
            (int) current.getY() - (int) start_drag.getY());
    JFrame frame = this.getFrame(target);
    Point new_location = new Point((int) (this.start_loc.getX() + offset.getX()),
            (int) (this.start_loc.getY() + offset.getY()));
    frame.setLocation(new_location);
}

From source file:org.talend.dataprofiler.chart.util.ToolTipChartComposite.java

/**
 * Returns a string for the tooltip./*from   ww w .ja v a 2s .c  o  m*/
 * 
 * @param e the mouse event.
 * 
 * @return A tool tip or <code>null</code> if no tooltip is available.
 */
@Override
public String getToolTipText(org.eclipse.swt.events.MouseEvent e) {
    // OK, we're using an SWT MouseEvent here, not much difference...
    String result = getTooltipAtPoint(new Point(e.x, e.y));
    if (result != null) {
        return result;
    }

    return super.getToolTipText();
}

From source file:SaveYourDrawingToFile.java

public void mousePressed(MouseEvent e) {
    Point p = new Point(e.getX(), e.getY());
    displayList.add(p);
}

From source file:GrabAndDragDemo.java

public GrabAndScrollLabel(ImageIcon i) {
    super(i);/*from ww w . jav a2s  .c  o m*/

    MouseInputAdapter mia = new MouseInputAdapter() {
        int xDiff, yDiff;

        boolean isDragging;

        Container c;

        public void mouseDragged(MouseEvent e) {
            c = GrabAndScrollLabel.this.getParent();
            if (c instanceof JViewport) {
                JViewport jv = (JViewport) c;
                Point p = jv.getViewPosition();
                int newX = p.x - (e.getX() - xDiff);
                int newY = p.y - (e.getY() - yDiff);

                int maxX = GrabAndScrollLabel.this.getWidth() - jv.getWidth();
                int maxY = GrabAndScrollLabel.this.getHeight() - jv.getHeight();
                if (newX < 0)
                    newX = 0;
                if (newX > maxX)
                    newX = maxX;
                if (newY < 0)
                    newY = 0;
                if (newY > maxY)
                    newY = maxY;

                jv.setViewPosition(new Point(newX, newY));
            }
        }

        public void mousePressed(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
            xDiff = e.getX();
            yDiff = e.getY();
        }

        public void mouseReleased(MouseEvent e) {
            setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
        }
    };
    addMouseMotionListener(mia);
    addMouseListener(mia);
}