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

public static Point getPointForCentering(Window window) {
    Rectangle usableBounds = getUsableDeviceBounds(window);
    int screenWidth = usableBounds.width;
    int screenHeight = usableBounds.height;
    int width = window.getWidth();
    int height = window.getHeight();

    return new Point(((screenWidth - width) / 2) + usableBounds.x,
            ((screenHeight - height) / 2) + usableBounds.y);
}

From source file:laystream.LayNodeFactory.java

public LayNode create() {
    String id = "Node" + nodeCount++;
    Point position = new Point(rnd.nextInt(90), rnd.nextInt(90));
    LayNode v = new LayNode(id, position);
    return v;/*w w w.  jav a2  s . c o m*/
}

From source file:Main.java

public static Point arrangeWithin(final Shape shapeToArrange, final Rectangle window, final int arrangement,
        Insets padding) {//from  w ww  .j  a va2s  . c o m
    if (shapeToArrange == null)
        throw new IllegalArgumentException("Parameter 'shapeToArrange' must not be null!");
    if (window == null)
        throw new IllegalArgumentException("Parameter 'window' must not be null!");
    if (padding == null)
        padding = new Insets(0, 0, 0, 0);

    final Rectangle bounds = shapeToArrange.getBounds();

    switch (arrangement) {
    case SwingConstants.NORTH:
        return new Point((window.width - bounds.width) / 2, padding.top);
    case SwingConstants.NORTH_EAST:
        return new Point(window.width - padding.right, padding.top);
    case SwingConstants.EAST:
        return new Point(window.width - padding.right, (window.height - bounds.height) / 2);
    case SwingConstants.SOUTH_EAST:
        return new Point(window.width - padding.right, window.height - padding.bottom);
    case SwingConstants.SOUTH:
        return new Point((window.width - bounds.width) / 2, window.height - padding.bottom);
    case SwingConstants.SOUTH_WEST:
        return new Point(padding.left, window.height - padding.bottom);
    case SwingConstants.WEST:
        return new Point(padding.left, (window.height - bounds.height) / 2);
    case SwingConstants.NORTH_WEST:
        return new Point(padding.left, padding.top);
    case SwingConstants.CENTER:
        return new Point((window.width - bounds.width) / 2, (window.height - bounds.height) / 2);
    default:
        throw new IllegalArgumentException("Illegal arrangement key, expected one of the SwingConstants keys");
    }
}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.transform(new Point(1, 2), new Point(2, 3));

    g2.setTransform(at);//from  w  w  w .  j a  v a  2  s.  c  o m
    g2.draw(shape);

}

From source file:eu.transkribus.swt_canvas.util.GeomUtils.java

/**
 * Returns closest point on segment to point
 * /* ww w .j ava2s.  c  o  m*/
 * @param sx1
 *            segment x coord 1
 * @param sy1
 *            segment y coord 1
 * @param sx2
 *            segment x coord 2
 * @param sy2
 *            segment y coord 2
 * @param px
 *            point x coord
 * @param py
 *            point y coord
 * @return closets point on segment to point
 */
public static Point getClosestPointOnSegment(int sx1, int sy1, int sx2, int sy2, int px, int py) {
    double xDelta = sx2 - sx1;
    double yDelta = sy2 - sy1;

    if ((xDelta == 0) && (yDelta == 0)) { // segment is a point -> return this point as it must be the closest one!
        return new Point(sx1, sy1);
        //         throw new IllegalArgumentException("Segment start equals segment end");
    }

    double u = ((px - sx1) * xDelta + (py - sy1) * yDelta) / (xDelta * xDelta + yDelta * yDelta);

    final Point closestPoint;
    if (u < 0) {
        closestPoint = new Point(sx1, sy1);
    } else if (u > 1) {
        closestPoint = new Point(sx2, sy2);
    } else {
        closestPoint = new Point((int) Math.round(sx1 + u * xDelta), (int) Math.round(sy1 + u * yDelta));
    }

    return closestPoint;
}

From source file:Main.java

private static List<String> getLines(JTextArea textArea) {
    int lineHeight = getLineHeight(textArea);
    List<String> list = new ArrayList<String>();
    for (int num = 0;; num++) {
        int i = textArea.viewToModel(new Point(0, num * lineHeight));
        int j = textArea.viewToModel(new Point(0, (num + 1) * lineHeight));
        if (i == 0 && j == 0) {
            continue;
        }/*from ww w . java 2s .c om*/
        if (textArea.getDocument().getLength() == i && i == j) {
            break;
        }
        String s = removeTrailingNewLine(textArea.getText().substring(i, j));
        list.add(s);
    }
    return list;
}

From source file:Main.java

public Main(JFrame frame) {
    analyzer = new MyDialog(frame);
    analyzer.pack();/*from   www .ja v  a 2  s. c o m*/
    analyzer.setLocationRelativeTo(frame);
    Point location = analyzer.getLocation();
    location = new Point(location.x - LOC_SHIFT, location.y - LOC_SHIFT);
    analyzer.setLocation(location);
    analyzer.setVisible(true);

    add(new JButton(new AbstractAction(DISABLE_DIALOG_COMPONENTS) {
        @Override
        public void actionPerformed(ActionEvent evt) {
            AbstractButton btn = (AbstractButton) evt.getSource();
            if (btn.getText().equals(DISABLE_DIALOG_COMPONENTS)) {
                btn.setText(ENABLE_DIALOG_COMPONENTS);
                analyzer.setComponentEnabled(false);
            } else {
                btn.setText(DISABLE_DIALOG_COMPONENTS);
                analyzer.setComponentEnabled(true);
            }
        }
    }));
    add(new JButton(new AbstractAction(DISABLE_DIALOG) {
        @Override
        public void actionPerformed(ActionEvent evt) {
            AbstractButton btn = (AbstractButton) evt.getSource();
            if (btn.getText().equals(DISABLE_DIALOG)) {
                btn.setText(ENABLE_DIALOG);
                analyzer.setEnabled(false);
            } else {
                btn.setText(DISABLE_DIALOG);
                analyzer.setEnabled(true);
            }
        }
    }));
}

From source file:SparseTableModel.java

public Object getValueAt(int row, int column) {
    return lookup.get(new Point(row, column));
}

From source file:Win.java

public static void position(Window frame, Component ref, double xfrac, double yfrac) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = frame.getSize();
    Dimension refSize = (ref != null) ? ref.getSize() : screenSize;
    Point origin = (ref != null) ? ref.getLocationOnScreen() : new Point(0, 0);

    int x = origin.x + relativePoint(xfrac, refSize.width, size.width);
    int y = origin.y + relativePoint(yfrac, refSize.height, size.height);

    // make sure frame is entirely on screen
    x = Math.max(0, Math.min(screenSize.width - size.width, x));
    y = Math.max(0, Math.min(screenSize.height - size.height, y));

    frame.setLocation(x, y);/*from ww w . ja v  a2s  .  c om*/
}

From source file:Main.java

@Override
public void actionPerformed(ActionEvent evt) {
    currLocation = frame.getLocationOnScreen();

    Point position1 = new Point(currLocation.x + iDisplaceXBy, currLocation.y + iDisplaceYBy);
    Point position2 = new Point(currLocation.x - iDisplaceXBy, currLocation.y - iDisplaceYBy);
    for (int i = 0; i < 20; i++) {
        frame.setLocation(position1);/*  w ww .java 2  s  .  co m*/
        frame.setLocation(position2);
    }
    frame.setLocation(currLocation);
}