Java Code Examples for java.awt.Point#setLocation()
The following examples show how to use
java.awt.Point#setLocation() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Activity.java From jclic with GNU General Public License v2.0 | 8 votes |
public final void fitTo(Rectangle proposed, Rectangle bounds) { Point origin = new Point(0, 0); if (absolutePositioned && absolutePosition != null) { origin.x = Math.max(0, absolutePosition.x + proposed.x); origin.y = Math.max(0, absolutePosition.y + proposed.y); proposed.width -= absolutePosition.x; proposed.height -= absolutePosition.y; } Dimension d = setDimension(new Dimension(Math.max(2 * margin + Activity.MINIMUM_WIDTH, proposed.width), Math.max(2 * margin + Activity.MINIMUM_HEIGHT, proposed.height))); if (!absolutePositioned) { origin.setLocation(Math.max(0, proposed.x + (proposed.width - d.width) / 2), Math.max(0, proposed.y + (proposed.height - d.height) / 2)); } if (origin.x + d.width > bounds.width) origin.x = Math.max(0, bounds.width - d.width); if (origin.y + d.height > bounds.height) origin.y = Math.max(0, bounds.height - d.height); setBounds(origin.x, origin.y, d.width, d.height); }
Example 2
Source File: UIConfig.java From mars-sim with GNU General Public License v3.0 | 6 votes |
/** * Gets the origin location of an internal window on the desktop. * * @param windowName the window name. * @return location. */ public Point getInternalWindowLocation(String windowName) { try { Element root = configDoc.getRootElement(); Element internalWindows = root.getChild(INTERNAL_WINDOWS); List<Element> internalWindowNodes = internalWindows.getChildren(); Point result = new Point(0, 0); for (Object element : internalWindowNodes) { if (element instanceof Element) { Element internalWindow = (Element) element; String name = internalWindow.getAttributeValue(NAME); if (name.equals(windowName)) { int locationX = Integer.parseInt(internalWindow.getAttributeValue(LOCATION_X)); int locationY = Integer.parseInt(internalWindow.getAttributeValue(LOCATION_Y)); result.setLocation(locationX, locationY); } } } return result; } catch (Exception e) { return new Point(0, 0); } }
Example 3
Source File: SavedPointUI.java From haxademic with MIT License | 6 votes |
public void keyEvent(KeyEvent e) { if(active == false) return; if(e.getAction() == KeyEvent.PRESS) { // shift if(e.getKeyCode() == P.SHIFT) shiftDown = true; // reset timeout if(e.getKeyCode() == P.UP || e.getKeyCode() == P.LEFT || e.getKeyCode() == P.RIGHT || e.getKeyCode() == P.DOWN) resetInteractionTimeout(); // translate if arrow key Point translatePoint = new Point(0, 0); if(e.getKeyCode() == P.UP) translatePoint.setLocation(0, -1); if(e.getKeyCode() == P.LEFT) translatePoint.setLocation(-1, 0); if(e.getKeyCode() == P.RIGHT) translatePoint.setLocation(1, 0); if(e.getKeyCode() == P.DOWN) translatePoint.setLocation(0, 1); if(shiftDown) { translatePoint.x *= 10; translatePoint.y *= 10; } // apply transformation if needed if(translatePoint.x != 0 || translatePoint.y != 0) { position.add(translatePoint.x, translatePoint.y); save(); } } if(e.getAction() == KeyEvent.RELEASE) { if(e.getKeyCode() == P.SHIFT) shiftDown = false; } }
Example 4
Source File: JDomUtility.java From jclic with GNU General Public License v2.0 | 5 votes |
public static Point getPoint(org.jdom.Element e, String id, Point defaultValue) { if (id != null) { e = getChildWithId(e, POINT, id); } else if (e != null && !e.getName().equals(POINT)) { e = e.getChild(POINT); } if (e == null) { return defaultValue; } Point p = (defaultValue == null ? new Point() : new Point(defaultValue)); p.setLocation(getIntAttr(e, LEFT, p.x), getIntAttr(e, TOP, p.y)); return p; }
Example 5
Source File: DefaultCaseDiagramCanvas.java From flowable-engine with Apache License 2.0 | 5 votes |
/** * This method calculates intersections of two lines. * * @param a * Line 1 * @param b * Line 2 * @return Intersection point */ private static Point getLinesIntersection(Line2D a, Line2D b) { double d = (a.getX1() - a.getX2()) * (b.getY2() - b.getY1()) - (a.getY1() - a.getY2()) * (b.getX2() - b.getX1()); double da = (a.getX1() - b.getX1()) * (b.getY2() - b.getY1()) - (a.getY1() - b.getY1()) * (b.getX2() - b.getX1()); double ta = da / d; Point p = new Point(); p.setLocation(a.getX1() + ta * (a.getX2() - a.getX1()), a.getY1() + ta * (a.getY2() - a.getY1())); return p; }
Example 6
Source File: DefaultCaseDiagramCanvas.java From flowable-engine with Apache License 2.0 | 5 votes |
/** * This method calculates ellipse intersection with line * * @param shape * Bounds of this shape used to calculate parameters of inscribed into this bounds ellipse. * @param line * @return Intersection point */ private static Point getEllipseIntersection(Shape shape, Line2D.Double line) { double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); double x = shape.getBounds2D().getWidth() / 2 * Math.cos(angle) + shape.getBounds2D().getCenterX(); double y = shape.getBounds2D().getHeight() / 2 * Math.sin(angle) + shape.getBounds2D().getCenterY(); Point p = new Point(); p.setLocation(x, y); return p; }
Example 7
Source File: DefaultProcessDiagramCanvas.java From flowable-engine with Apache License 2.0 | 5 votes |
/** * This method calculates ellipse intersection with line * * @param shape * Bounds of this shape used to calculate parameters of inscribed into this bounds ellipse. * @param line * @return Intersection point */ private static Point getEllipseIntersection(Shape shape, Line2D.Double line) { double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); double x = shape.getBounds2D().getWidth() / 2 * Math.cos(angle) + shape.getBounds2D().getCenterX(); double y = shape.getBounds2D().getHeight() / 2 * Math.sin(angle) + shape.getBounds2D().getCenterY(); Point p = new Point(); p.setLocation(x, y); return p; }
Example 8
Source File: PointStrUtils.java From TranskribusCore with GNU General Public License v3.0 | 5 votes |
public static String translatePoints(String ptsStr, int x, int y) throws PointParseException { List<Point> pts = parsePoints(ptsStr); for (Point p : pts) { p.setLocation(p.x+x, p.y+y); } return pointsToString(pts); }
Example 9
Source File: Resize.java From Pixie with MIT License | 5 votes |
/** * Computes the corespondent position in the original image, of the given * pixel from the resized image. * * @param resizedPoint - the (x,y) coordinate of the pixel from the resized image * @return - returns a Point object with two elements: x and y coordinates of the point in the original image (in this order) */ public Point resizedToOriginal(Point resizedPoint) { if ((resizedPoint == null) || (Double.compare(ratioWidth, 0.0) == 0) || (Double.compare(ratioHeight, 0.0) == 0)) { return null; } Point origPoint = new Point(); origPoint.setLocation((int) (resizedPoint.getX() * ratioWidth), (int) (resizedPoint.getY() * ratioHeight)); return origPoint; }
Example 10
Source File: JDomUtility.java From jclic with GNU General Public License v2.0 | 5 votes |
public static Point getOffset(org.jdom.Element e, String id, Point defaultValue) { if (id != null) { e = getChildWithId(e, OFFSET, id); } else if (e != null && !e.getName().equals(OFFSET)) { e = e.getChild(OFFSET); } if (e == null) { return defaultValue; } Point p = (defaultValue == null ? new Point() : new Point(defaultValue)); p.setLocation(getIntAttr(e, RIGHT, p.x), getIntAttr(e, DOWN, p.y)); return p; }
Example 11
Source File: SwingComponent.java From ats-framework with Apache License 2.0 | 5 votes |
/** * Get the component center location {@link Point} * * @param component the target component * @return center location {@link Point} */ private Point getComponentCenterLocation( Component component ) { Point centerPoint = new Point(); centerPoint.setLocation(component.getX() + component.getWidth() / 2, component.getY() + component.getHeight() / 2); return centerPoint; }
Example 12
Source File: Java2DDisplaySurface.java From gama with GNU General Public License v3.0 | 5 votes |
@Override public void focusOn(final IShape geometry) { final Rectangle2D r = this.getManager().focusOn(geometry, this); if (r == null) { return; } final double xScale = getWidth() / r.getWidth(); final double yScale = getHeight() / r.getHeight(); double zoomFactor = Math.min(xScale, yScale); final Point center = new Point((int) Math.round(r.getCenterX()), (int) Math.round(r.getCenterY())); zoomFactor = applyZoom(zoomFactor); center.setLocation(center.x * zoomFactor, center.y * zoomFactor); centerOnDisplayCoordinates(center); updateDisplay(true); }
Example 13
Source File: FruchtermanReingoldLayout.java From netbeans with Apache License 2.0 | 5 votes |
private void layoutCirculary(Collection<GraphNode<I>> nodes, GraphNode<I> masterNode) { Point masterPoint = new Point(); NodeWidget master = getWidget(masterNode); masterPoint.setLocation(master.locX, master.locY); double r; double theta; double thetaStep = Math.PI / 5; r = 150; theta = 0; Iterator<GraphNode<I>> it = nodes.iterator(); NodeWidget nw = getWidget(it.next()); while (true) { AffineTransform tr = AffineTransform.getRotateInstance(theta); Point2D d2point = tr.transform(new Point2D.Double(0, r), null); Point point = new Point((int)d2point.getX() + masterPoint.x, (int)d2point.getY() + masterPoint.y); if (isThereFreeSpace(point, nw)) { nw.locX = point.getX(); nw.locY = point.getY(); nw.dispX = 0; nw.dispY = 0; if (it.hasNext()) { nw = getWidget(it.next()); } else { return; } } theta = theta + thetaStep; if (theta > (Math.PI * 2 - Math.PI / 10)) { r = r + 90; theta = theta - Math.PI * 2; thetaStep = thetaStep * 3 / 4; } } }
Example 14
Source File: FruchtermanReingoldLayout.java From netbeans with Apache License 2.0 | 5 votes |
private void finish() { for (GraphNode n : scene.getNodes()) { NodeWidget w = getWidget(n); Widget wid = scene.findWidget(n); Point point = new Point(); point.setLocation(w.locX, w.locY); if (scene.isAnimated()) { scene.getSceneAnimator().animatePreferredLocation(wid, point); } else { wid.setPreferredLocation(point); } } }
Example 15
Source File: BaseSavedQuadUI.java From haxademic with MIT License | 5 votes |
public void keyEvent(KeyEvent e) { if(active == false) return; if(e.getAction() == KeyEvent.PRESS) { // shift if(e.getKeyCode() == P.SHIFT) shiftDown = true; // reset timeout if(e.getKeyCode() == P.UP || e.getKeyCode() == P.LEFT || e.getKeyCode() == P.RIGHT || e.getKeyCode() == P.DOWN || e.getKeyCode() == P.TAB) resetInteractionTimeout(); // translate if arrow key Point translatePoint = new Point(0, 0); if(e.getKeyCode() == P.UP) translatePoint.setLocation(0, -1); if(e.getKeyCode() == P.LEFT) translatePoint.setLocation(-1, 0); if(e.getKeyCode() == P.RIGHT) translatePoint.setLocation(1, 0); if(e.getKeyCode() == P.DOWN) translatePoint.setLocation(0, 1); if(shiftDown) { translatePoint.x *= 10; translatePoint.y *= 10; } // tab to next point if(e.getKeyCode() == P.TAB) { if(SELECTED_POINT == points[0]) SELECTED_POINT = points[1]; else if(SELECTED_POINT == points[1]) SELECTED_POINT = points[2]; else if(SELECTED_POINT == points[2]) SELECTED_POINT = points[3]; else SELECTED_POINT = points[0]; resetInteractionTimeout(); } // apply transformation if needed if(translatePoint.x != 0 || translatePoint.y != 0) { if(SELECTED_POINT == points[0] || SELECTED_POINT == points[1] || SELECTED_POINT == points[2] || SELECTED_POINT == points[3]) { SELECTED_POINT.translate(translatePoint.x, translatePoint.y); save(); } else if(DRAGGING_QUAD == this) { for( int i=0; i < points.length; i++ ) { points[i].translate(translatePoint.x, translatePoint.y); } save(); } } updateCenter(); } if(e.getAction() == KeyEvent.RELEASE) { if(e.getKeyCode() == P.SHIFT) shiftDown = false; } }
Example 16
Source File: DefaultProcessDiagramCanvas.java From activiti6-boot2 with Apache License 2.0 | 5 votes |
/** * This method calculates intersections of two lines. * @param a Line 1 * @param b Line 2 * @return Intersection point */ private static Point getLinesIntersection(Line2D a, Line2D b) { double d = (a.getX1()-a.getX2())*(b.getY2()-b.getY1()) - (a.getY1()-a.getY2())*(b.getX2()-b.getX1()); double da = (a.getX1()-b.getX1())*(b.getY2()-b.getY1()) - (a.getY1()-b.getY1())*(b.getX2()-b.getX1()); // double db = (a.getX1()-a.getX2())*(a.getY1()-b.getY1()) - (a.getY1()-a.getY2())*(a.getX1()-b.getX1()); double ta = da/d; // double tb = db/d; Point p = new Point(); p.setLocation(a.getX1()+ta*(a.getX2()-a.getX1()), a.getY1()+ta*(a.getY2()-a.getY1())); return p; }
Example 17
Source File: VirtualBall.java From procamtracker with GNU General Public License v2.0 | 4 votes |
public Point getInitialVelocity() { Point p = new Point(); p.setLocation(initialVelocity[0], initialVelocity[1]); return p; }
Example 18
Source File: VisualGraphScrollWheelPanningPlugin.java From ghidra with Apache License 2.0 | 4 votes |
private void pan(MouseWheelEvent e) { GraphViewer<V, E> viewer = getGraphViewer(e); // // Number of 'units' by which to scroll. This is defined by the OS and is usually // something like 'lines of text'. // int scrollAmount = 1; if (e.getScrollType() == MouseWheelEvent.WHEEL_UNIT_SCROLL) { scrollAmount = e.getScrollAmount(); } // // The amount the mouse wheel has been rotated. By default this is usually 1, but // users can change how the OS accelerates mouse scrolling. // int wheelRotation = -e.getWheelRotation(); // // A magic magnification amount. This was chosen by testing on a few platforms. // int arbitraryAcceleration = 10; // // The scale of the current graph. We need to change the scroll amount when scaled out // so that we don't end up with tiny scrolling when zoomed out. // Double scale = GraphViewerUtils.getGraphScale(viewer); int unscaledOffset = wheelRotation * scrollAmount * arbitraryAcceleration; int offset = (int) (unscaledOffset * (1 / scale)); Point newPoint = new Point(0, offset); if (e.isAltDown()) { // control-alt is a horizontal pan newPoint.setLocation(offset, 0); } VisualGraphViewUpdater<V, E> updater = viewer.getViewUpdater(); updater.moveViewerLocationWithoutAnimation(newPoint); }
Example 19
Source File: ObjectPolygon.java From Pixie with MIT License | 2 votes |
/** * Moves one point with the specified offset and returns the new image * coordinates. * * @param xOffset - how much should the point move on the X axis * @param yOffset - how much the point should move on the Y axis * @param pointPosOrig - the position of the point in image coordinates */ public void movePoint(int xOffset, int yOffset, Point pointPosOrig) { pointPosOrig.setLocation(pointPosOrig.x + xOffset, pointPosOrig.y + yOffset); }
Example 20
Source File: Resize.java From Pixie with MIT License | 2 votes |
/** * Computes the corespondent position in the original image, of the given * pixel from the resized image. * * @param x - the X coordinate of the pixel from the resized image * @param y - the Y coordinate of the pixel from the resized image * @return - returns the corresponding point in the original image */ public Point resizedToOriginal(int x, int y) { Point origPoint = new Point(); origPoint.setLocation((int) (x * ratioWidth), (int) (y * ratioHeight)); return origPoint; }