/** * Puts diagram shapes in pseudo-3d order starting from back to front * */ public int compare(Object object1, Object object2) { if(!(object1 instanceof DiagramShape) || !(object2 instanceof DiagramShape)) throw new RuntimeException("This comparator can only compare DiagramShapeS"); DiagramShape shape1 = (DiagramShape) object1; DiagramShape shape2 = (DiagramShape) object2; double y1 = shape1.makeIntoPath().getBounds().getCenterY(); double y2 = shape2.makeIntoPath().getBounds().getCenterY(); if(y1 > y2) return -1; if(y1 < y2) return 1; return 0; }
public void drawCollapsedMarker(int x, int y, int width, int height) { // rectangle int rectangleWidth = MARKER_WIDTH; int rectangleHeight = MARKER_WIDTH; Rectangle rect = new Rectangle(x + (width - rectangleWidth) / 2, y + height - rectangleHeight - 3, rectangleWidth, rectangleHeight); g.draw(rect); // plus inside rectangle Line2D.Double line = new Line2D.Double(rect.getCenterX(), rect.getY() + 2, rect.getCenterX(), rect.getMaxY() - 2); g.draw(line); line = new Line2D.Double(rect.getMinX() + 2, rect.getCenterY(), rect.getMaxX() - 2, rect.getCenterY()); g.draw(line); }
private GeneralPath makeDecisionPath(Diagram diagram) { if(points.size() != 4) return null; Rectangle bounds = makeIntoPath().getBounds(); ShapePoint pointMid = new ShapePoint((float)bounds.getCenterX(), (float)bounds.getCenterY()); ShapePoint left = new ShapePoint((float)bounds.getMinX(), (float)pointMid.getY()); ShapePoint right = new ShapePoint((float)bounds.getMaxX(), (float)pointMid.getY()); ShapePoint top = new ShapePoint((float)pointMid.getX(), (float)bounds.getMinY()); ShapePoint bottom = new ShapePoint((float)pointMid.getX(), (float)bounds.getMaxY()); GeneralPath path = new GeneralPath(); path.moveTo(left.x, left.y); path.lineTo(top.x, top.y); path.lineTo(right.x, right.y); path.lineTo(bottom.x, bottom.y); path.closePath(); return path; }
private GeneralPath makeEllipsePath(Diagram diagram) { if(points.size() != 4) return null; Rectangle bounds = makeIntoPath().getBounds(); float xOff = (float) bounds.getWidth() * 0.5f * KAPPA; float yOff = (float) bounds.getHeight() * 0.5f * KAPPA; ShapePoint pointMid = new ShapePoint((float)bounds.getCenterX(), (float)bounds.getCenterY()); ShapePoint left = new ShapePoint((float)bounds.getMinX(), (float)pointMid.getY()); ShapePoint right = new ShapePoint((float)bounds.getMaxX(), (float)pointMid.getY()); ShapePoint top = new ShapePoint((float)pointMid.getX(), (float)bounds.getMinY()); ShapePoint bottom = new ShapePoint((float)pointMid.getX(), (float)bounds.getMaxY()); GeneralPath path = new GeneralPath(); path.moveTo(top.x, top.y); path.curveTo(top.x + xOff, top.y, right.x, right.y - yOff, right.x, right.y); path.curveTo(right.x, right.y + yOff, bottom.x + xOff, bottom.y, bottom.x, bottom.y); path.curveTo(bottom.x - xOff, bottom.y, left.x, left.y + yOff, left.x, left.y); path.curveTo(left.x, left.y - yOff, top.x - xOff, top.y, top.x, top.y); path.closePath(); return path; }
private static Point getLocPopAt() { Rectangle screen0 = Do.getDevice().getMonitor(); if (null == screen0) { return null; } return new Point((int) screen0.getCenterX(), (int) screen0.getCenterY()); }
/** * Calculates transforms suitable for aspect ratio matching. The world bounds will be centred in * the screen area. */ private void calculateCenteringTransforms() { double xscale = screenArea.getWidth() / bounds.getWidth(); double yscale = screenArea.getHeight() / bounds.getHeight(); double scale = Math.min(xscale, yscale); double xoff = bounds.getMedian(0) * scale - screenArea.getCenterX(); double yoff = bounds.getMedian(1) * scale + screenArea.getCenterY(); worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, yoff); try { screenToWorld = worldToScreen.createInverse(); } catch (NoninvertibleTransformException ex) { throw new RuntimeException("Unable to create coordinate transforms.", ex); } hasCenteringTransforms = true; }
Rectangle screenBounds = MouseInfo.getPointerInfo().getDevice().getDefaultConfiguration().getBounds(); int x = (int) screenBounds.getCenterX() - (jDialog.getWidth() / 2); int y = (int) screenBounds.getCenterY() - (jDialog.getHeight() / 2); jDialog.setLocation(x, y); jDialog.setVisible(true);
public static Point getRectangleCenterPoint(Rectangle r) { int x = (int) Math.round(r.getCenterX()); int y = (int) Math.round(r.getCenterY()); Point p = new Point(x, y); return p; } public SightPort getViewPort() {
public static Point getRectangleCenterPoint(Rectangle r) { int x = (int) Math.round(r.getCenterX()); int y = (int) Math.round(r.getCenterY()); Point p = new Point(x, y); return p; } public SightPort getViewPort() {
final int STEPS = 10000; //Number of steps in a full 360 degree rotation double theta = (2*Math.PI) / STEPS; //Single step "size" in radians Rectangle bounds = area.getBounds(); //Getting the bounds to find the center of the Area AffineTransform trans = AffineTransform.getRotateInstance(theta, bounds.getCenterX(), bounds.getCenterY()); //Transformation matrix for theta radians around the center //Rotate a full 360 degrees in small steps for(int i = 0; i < STEPS; i++) { area.transform(trans); }
@Override public Point getCentroid (Rectangle box) { if (centroidOffset == null) { computeCentroidOffset(); } return new Point( (int) Math.rint(box.getCenterX() + (box.getWidth() * centroidOffset.getX())), (int) Math.rint(box.getCenterY() + (box.getHeight() * centroidOffset.getY()))); }
private void initTransform(Rectangle _bounds, AffineTransform _transform) { double centerY = _bounds.getCenterY(); double centerX = _bounds.getCenterX(); _transform.translate(centerX, centerY); _transform.shear(shearX_, shearY_); _transform.rotate(rotation_); _transform.translate(-centerX, -centerY); }
void flatRender(Graphics2D _g, InstructionView _instructionView) { _g.setColor(unselectedColor); _g.fill(_instructionView.shape); _g.setColor(Color.black); stroke(_g, outlineStroke, _instructionView.shape); text(_g, _instructionView.label, _instructionView.shape.getBounds().getCenterX() - (_instructionView.shape.getBounds().getWidth() / 2), _instructionView.shape.getBounds().getCenterY()); }
private static Point getLocPopAt() { Rectangle screen0 = rt.getMonitor(0); if (null == screen0) { return null; } return new Point((int) screen0.getCenterX(), (int) screen0.getCenterY()); }
public void drawCollapsedMarker(int x, int y, int width, int height) { // rectangle int rectangleWidth = MARKER_WIDTH; int rectangleHeight = MARKER_WIDTH; Rectangle rect = new Rectangle(x + (width - rectangleWidth) / 2, y + height - rectangleHeight - 3, rectangleWidth, rectangleHeight); g.draw(rect); // plus inside rectangle Line2D.Double line = new Line2D.Double(rect.getCenterX(), rect.getY() + 2, rect.getCenterX(), rect.getMaxY() - 2); g.draw(line); line = new Line2D.Double(rect.getMinX() + 2, rect.getCenterY(), rect.getMaxX() - 2, rect.getCenterY()); g.draw(line); }
public static Point getLocation(String setting) { if (setting == null) { return null; } String[] split = setting.split(";"); if (split.length < 2) { return null; } IntegerPair coords = Helper.getNumbersFromString(split[0]); IntegerPair size = Helper.getNumbersFromString(split[1]); Rectangle r = new Rectangle(coords.a, coords.b, size.a, size.b); return new Point((int)r.getCenterX() - SPLASH_WIDTH/2, (int)r.getCenterY() - SPLASH_HEIGHT/2); }
public Point getVisibleCenterMatrixPos() { Rectangle rect = this.getVisibleRect(); Point centerPanePos = new Point((int)rect.getCenterX(),(int)rect.getCenterY()); Point centerMatrixPos = paneCoordToMatrixCoord(centerPanePos); return centerMatrixPos; }
private void scrollToCenterPath(final GeneralPath geoBoundaryPath, final JViewport viewport) { final GeneralPath pixelPath = ProductUtils.convertToPixelPath(geoBoundaryPath, wmPainter.getGeoCoding()); final Rectangle viewRect = viewport.getViewRect(); final Rectangle pathBounds = pixelPath.getBounds(); setCenter(viewRect, new Point((int) pathBounds.getCenterX(), (int) pathBounds.getCenterY())); final Dimension bounds = new Dimension(scaledImage.getWidth(null), scaledImage.getHeight(null)); ensureRectIsInBounds(viewRect, bounds); viewport.scrollRectToVisible(viewRect); }
private AliCursor createNewAliCursor(){ //alignment.clearSelection(); Point center = alignmentPane.matrixCoordToPaneCoord((new Point((int)alignmentPane.getVisibleRect().getCenterX(), (int)alignmentPane.getVisibleRect().getCenterY()))); AliCursor newAliCursor = new AliCursor(center.x, center.y); return newAliCursor; }
private static void setCenter(final Rectangle rectangle, final Point center) { final int diffX = center.x - (int) rectangle.getCenterX(); final int diffY = center.y - (int) rectangle.getCenterY(); final int x = ((int) rectangle.getX()) + diffX; final int y = (int) (rectangle.getY() + diffY); rectangle.setLocation(x, y); }