List of usage examples for java.awt Point Point
public Point(int x, int y)
From source file:Main.java
static public Point fitComponentInsideScreen(Dimension componentSize, Point location) { Point newLocation = new Point(location.x, location.y); if (newLocation.x < 0) newLocation.x = 0;/*from www. j av a 2 s . com*/ if (newLocation.y < 0) newLocation.y = 0; if ((newLocation.x + componentSize.width) > SCREEN_SIZE.width) newLocation.x = SCREEN_SIZE.width - componentSize.width; if ((newLocation.y + componentSize.height) > SCREEN_SIZE.height) newLocation.y = SCREEN_SIZE.height - componentSize.height; return (newLocation); }
From source file:Main.java
public static Point scale(Point p, float k) { return new Point((int) (k * p.x), (int) (k * p.y)); }
From source file:Main.java
public static Point add(Point p1, Point p2) { return new Point(p1.x + p2.x, p1.y + p2.y); }
From source file:Main.java
public static Point max(Point p1, Point p2) { return new Point(Math.max(p1.x, p2.x), Math.max(p1.y, p2.y)); }
From source file:Main.java
public static Point diff(Point p1, Point p2) { return new Point(p1.x - p2.x, p1.y - p2.y); }
From source file:Main.java
public static Point moveToScreenCenter(Component component) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension componentSize = component.getSize(); int newComponentX = screenSize.width - componentSize.width; if (newComponentX >= 0) newComponentX = newComponentX / 2; else/*from w w w . j av a2s. c o m*/ newComponentX = 0; int newComponentY = screenSize.height - componentSize.height; if (newComponentY >= 0) newComponentY = newComponentY / 2; else newComponentY = 0; Point location = new Point(newComponentX, newComponentY); component.setLocation(location); return location; }
From source file:Main.java
public static Point dimensionToPoint(Dimension d) { return d != null ? new Point(d.width, d.height) : null; }
From source file:Main.java
private static AttributeSet getAttributes(MouseEvent e) { JTextPane text = (JTextPane) e.getSource(); Point mouseLocation = new Point(e.getX(), e.getY()); int pos = text.viewToModel(mouseLocation); if (pos >= 0) { try {// w w w . ja v a2s . c o m Rectangle rect = text.modelToView(pos); int lowerCorner = rect.y + rect.height; if (e.getX() < rect.x && e.getY() < lowerCorner && pos > 0) { pos--; } } catch (BadLocationException ex) { ex.printStackTrace(); } StyledDocument doc = text.getStyledDocument(); Element element = doc.getCharacterElement(pos); return element.getAttributes(); } return null; }
From source file:Main.java
static public void centerOnParent(final Window child, final boolean absolute) { child.pack();//ww w . java2 s . co m boolean useChildsOwner = child.getOwner() != null ? ((child.getOwner() instanceof JFrame) || (child.getOwner() instanceof JDialog)) : false; final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); final Dimension parentSize = useChildsOwner ? child.getOwner().getSize() : screenSize; final Point parentLocationOnScreen = useChildsOwner ? child.getOwner().getLocationOnScreen() : new Point(0, 0); final Dimension childSize = child.getSize(); childSize.width = Math.min(childSize.width, screenSize.width); childSize.height = Math.min(childSize.height, screenSize.height); child.setSize(childSize); int x; int y; if ((child.getOwner() != null) && child.getOwner().isShowing()) { x = (parentSize.width - childSize.width) / 2; y = (parentSize.height - childSize.height) / 2; x += parentLocationOnScreen.x; y += parentLocationOnScreen.y; } else { x = (screenSize.width - childSize.width) / 2; y = (screenSize.height - childSize.height) / 2; } if (!absolute) { x /= 2; y /= 2; } child.setLocation(x, y); }
From source file:Main.java
public static void setCenterOfParent(JDialog 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);//from www .jav a 2 s . c o m }